transmission/libtransmission/announcer-common.h

239 lines
6.3 KiB
C
Raw Normal View History

/*
* This file Copyright (C) 2010-2014 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
* $Id$
*/
#ifndef __LIBTRANSMISSION_ANNOUNCER_MODULE__
#error only the libtransmission announcer module should #include this header.
#endif
#ifndef _TR_ANNOUNCER_COMMON_H_
#define _TR_ANNOUNCER_COMMON_H_
#include "transmission.h" /* SHA_DIGEST_LENGTH */
#include "session.h" /* PEER_ID_LEN */
/***
**** SCRAPE
***/
enum
{
/* pick a number small enough for common tracker software:
* - ocelot has no upper bound
* - opentracker has an upper bound of 64
* - udp protocol has an upper bound of 74
* - xbtt has no upper bound */
TR_MULTISCRAPE_MAX = 64
};
typedef struct
{
2013-01-30 20:00:43 +00:00
/* the scrape URL */
char * url;
2013-01-30 20:00:43 +00:00
/* the name to use when deep logging is enabled */
char log_name[128];
2013-01-30 20:00:43 +00:00
/* info hashes of the torrents to scrape */
uint8_t info_hash[TR_MULTISCRAPE_MAX][SHA_DIGEST_LENGTH];
2013-01-30 20:00:43 +00:00
/* how many hashes to use in the info_hash field */
int info_hash_count;
}
tr_scrape_request;
struct tr_scrape_response_row
{
2013-01-30 20:00:43 +00:00
/* the torrent's info_hash */
uint8_t info_hash[SHA_DIGEST_LENGTH];
2013-01-30 20:00:43 +00:00
/* how many peers are seeding this torrent */
int seeders;
2013-01-30 20:00:43 +00:00
/* how many peers are downloading this torrent */
int leechers;
2013-01-30 20:00:43 +00:00
/* how many times this torrent has been downloaded */
int downloads;
2013-01-30 20:00:43 +00:00
/* the number of active downloaders in the swarm.
* this is a BEP 21 extension that some trackers won't support.
* http://www.bittorrent.org/beps/bep_0021.html#tracker-scrapes */
int downloaders;
};
typedef struct
{
2013-01-30 20:00:43 +00:00
/* whether or not we managed to connect to the tracker */
bool did_connect;
2013-01-30 20:00:43 +00:00
/* whether or not the scrape timed out */
bool did_timeout;
2013-01-30 20:00:43 +00:00
/* how many info hashes are in the 'rows' field */
int row_count;
2013-01-30 20:00:43 +00:00
/* the individual torrents' scrape results */
struct tr_scrape_response_row rows[TR_MULTISCRAPE_MAX];
2013-01-30 20:00:43 +00:00
/* the raw scrape url */
char * url;
2013-01-30 20:00:43 +00:00
/* human-readable error string on failure, or NULL */
char * errmsg;
2013-01-30 20:00:43 +00:00
/* minimum interval (in seconds) allowed between scrapes.
* this is an unofficial extension that some trackers won't support. */
int min_request_interval;
}
tr_scrape_response;
typedef void (*tr_scrape_response_func) (const tr_scrape_response * response,
void * user_data);
void tr_tracker_http_scrape (tr_session * session,
const tr_scrape_request * req,
tr_scrape_response_func response_func,
void * user_data);
void tr_tracker_udp_scrape (tr_session * session,
const tr_scrape_request * req,
tr_scrape_response_func response_func,
void * user_data);
/***
**** ANNOUNCE
***/
typedef enum
{
2013-01-30 20:00:43 +00:00
TR_ANNOUNCE_EVENT_NONE,
TR_ANNOUNCE_EVENT_COMPLETED,
TR_ANNOUNCE_EVENT_STARTED,
TR_ANNOUNCE_EVENT_STOPPED
}
tr_announce_event;
const char * tr_announce_event_get_string (tr_announce_event);
typedef struct
{
2013-01-30 20:00:43 +00:00
tr_announce_event event;
bool partial_seed;
2013-01-30 20:00:43 +00:00
/* the port we listen for incoming peers on */
int port;
2013-01-30 20:00:43 +00:00
/* per-session key */
int key;
2013-01-30 20:00:43 +00:00
/* the number of peers we'd like to get back in the response */
int numwant;
2013-01-30 20:00:43 +00:00
/* the number of bytes we uploaded since the last 'started' event */
uint64_t up;
2013-01-30 20:00:43 +00:00
/* the number of good bytes we downloaded since the last 'started' event */
uint64_t down;
2013-01-30 20:00:43 +00:00
/* the number of bad bytes we downloaded since the last 'started' event */
uint64_t corrupt;
2013-01-30 20:00:43 +00:00
/* the total size of the torrent minus the number of bytes completed */
uint64_t leftUntilComplete;
2013-01-30 20:00:43 +00:00
/* the tracker's announce URL */
char * url;
2013-01-30 20:00:43 +00:00
/* key generated by and returned from an http tracker.
* see tr_announce_response.tracker_id_str */
char * tracker_id_str;
2013-01-30 20:00:43 +00:00
/* the torrent's peer id.
* this changes when a torrent is stopped -> restarted. */
char peer_id[PEER_ID_LEN];
2013-01-30 20:00:43 +00:00
/* the torrent's info_hash */
uint8_t info_hash[SHA_DIGEST_LENGTH];
2013-01-30 20:00:43 +00:00
/* the name to use when deep logging is enabled */
char log_name[128];
}
tr_announce_request;
struct tr_pex;
typedef struct
{
2013-01-30 20:00:43 +00:00
/* the torrent's info hash */
uint8_t info_hash[SHA_DIGEST_LENGTH];
2013-01-30 20:00:43 +00:00
/* whether or not we managed to connect to the tracker */
bool did_connect;
2013-01-30 20:00:43 +00:00
/* whether or not the scrape timed out */
bool did_timeout;
2013-01-30 20:00:43 +00:00
/* preferred interval between announces.
* transmission treats this as the interval for periodic announces */
int interval;
2013-01-30 20:00:43 +00:00
/* minimum interval between announces. (optional)
* transmission treats this as the min interval for manual announces */
int min_interval;
2013-01-30 20:00:43 +00:00
/* how many peers are seeding this torrent */
int seeders;
2013-01-30 20:00:43 +00:00
/* how many peers are downloading this torrent */
int leechers;
2013-01-30 20:00:43 +00:00
/* how many times this torrent has been downloaded */
int downloads;
2013-01-30 20:00:43 +00:00
/* number of items in the 'pex' field */
size_t pex_count;
2013-01-30 20:00:43 +00:00
/* IPv4 peers that we acquired from the tracker */
struct tr_pex * pex;
2013-01-30 20:00:43 +00:00
/* number of items in the 'pex6' field */
size_t pex6_count;
2013-01-30 20:00:43 +00:00
/* IPv6 peers that we acquired from the tracker */
struct tr_pex * pex6;
2013-01-30 20:00:43 +00:00
/* human-readable error string on failure, or NULL */
char * errmsg;
2013-01-30 20:00:43 +00:00
/* human-readable warning string or NULL */
char * warning;
2013-01-30 20:00:43 +00:00
/* key generated by and returned from an http tracker.
* if this is provided, subsequent http announces must include this. */
char * tracker_id_str;
}
tr_announce_response;
typedef void (*tr_announce_response_func) (const tr_announce_response * response,
void * userdata);
void tr_tracker_http_announce (tr_session * session,
const tr_announce_request * req,
tr_announce_response_func response_func,
void * user_data);
void tr_tracker_udp_announce (tr_session * session,
const tr_announce_request * req,
tr_announce_response_func response_func,
void * user_data);
void tr_tracker_udp_start_shutdown (tr_session * session);
#endif /* _TR_ANNOUNCER_COMMON_H_ */