source: trunk/libtransmission/announcer-common.h @ 12204

Last change on this file since 12204 was 12204, checked in by jordan, 11 years ago

(trunk) #4138 "use stdbool.h instead of tr_bool" -- done.

  • Property svn:keywords set to Date Rev Author Id
File size: 6.8 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This file is licensed by the GPL version 2. Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: announcer-common.h 12204 2011-03-22 15:19:54Z jordan $
11 */
12
13#ifndef __LIBTRANSMISSION_ANNOUNCER_MODULE___
14 #error only the libtransmission announcer module should #include this header.
15#endif
16
17#ifndef _TR_ANNOUNCER_COMMON_H_
18#define _TR_ANNOUNCER_COMMON_H_
19
20#include "transmission.h" /* SHA_DIGEST_LENGTH */
21#include "session.h" /* PEER_ID_LEN */
22
23/***
24****  SCRAPE
25***/
26
27enum
28{
29  /* pick a number small enough for common tracker software:
30   *  - ocelot has no upper bound
31   *  - opentracker has an upper bound of 64
32   *  - udp protocol has an upper bound of 74
33   *  - xbtt has no upper bound */
34  TR_MULTISCRAPE_MAX = 64
35};
36
37typedef struct
38{
39    /* the scrape URL */
40    char * url;
41
42    /* the name to use when deep logging is enabled */
43    char log_name[128];
44
45    /* info hashes of the torrents to scrape */
46    uint8_t info_hash[TR_MULTISCRAPE_MAX][SHA_DIGEST_LENGTH];
47
48    /* how many hashes to use in the info_hash field */
49    int info_hash_count;
50}
51tr_scrape_request;
52
53struct tr_scrape_response_row
54{
55    /* the torrent's info_hash */
56    uint8_t info_hash[SHA_DIGEST_LENGTH];
57
58    /* how many peers are seeding this torrent */
59    int seeders;
60
61    /* how many peers are downloading this torrent */
62    int leechers;
63
64    /* how many times this torrent has been downloaded */
65    int downloads;
66
67    /* the number of active downloaders in the swarm.
68     * this is a BEP 21 extension that some trackers won't support.
69     * http://www.bittorrent.org/beps/bep_0021.html#tracker-scrapes  */
70    int downloaders;
71};
72
73typedef struct
74{
75    /* whether or not we managed to connect to the tracker */
76    bool did_connect;
77
78    /* whether or not the scrape timed out */
79    bool did_timeout;
80
81    /* how many info hashes are in the 'rows' field */
82    int row_count;
83
84    /* the individual torrents' scrape results */
85    struct tr_scrape_response_row rows[TR_MULTISCRAPE_MAX];
86
87    /* the raw scrape url */
88    char * url;
89
90    /* human-readable error string on failure, or NULL */
91    char * errmsg;
92
93    /* minimum interval (in seconds) allowed between scrapes.
94     * this is an unofficial extension that some trackers won't support. */
95    int min_request_interval;
96}
97tr_scrape_response;
98
99typedef void tr_scrape_response_func( tr_session                * session,
100                                      const tr_scrape_response  * response,
101                                      void                      * user_data );
102
103void tr_tracker_http_scrape( tr_session               * session,
104                             const tr_scrape_request  * req,
105                             tr_scrape_response_func    response_func,
106                             void                     * user_data );
107
108void tr_tracker_udp_scrape( tr_session               * session,
109                            const tr_scrape_request  * req,
110                            tr_scrape_response_func    response_func,
111                            void                     * user_data );
112
113/***
114****  ANNOUNCE
115***/
116
117typedef enum
118{
119    TR_ANNOUNCE_EVENT_NONE,
120    TR_ANNOUNCE_EVENT_COMPLETED,
121    TR_ANNOUNCE_EVENT_STARTED,
122    TR_ANNOUNCE_EVENT_STOPPED
123}
124tr_announce_event;
125
126const char * tr_announce_event_get_string( tr_announce_event );
127
128typedef struct
129{
130    tr_announce_event event;
131    bool partial_seed;
132
133    /* the port we listen for incoming peers on */
134    int port;
135
136    /* per-session key */
137    int key;
138
139    /* the number of peers we'd like to get back in the response */
140    int numwant;
141
142    /* the number of bytes we uploaded since the last 'started' event */
143    uint64_t up;
144
145    /* the number of good bytes we downloaded since the last 'started' event */
146    uint64_t down;
147
148    /* the number of bad bytes we downloaded since the last 'started' event */
149    uint64_t corrupt;
150
151    /* the total size of the torrent minus the number of bytes completed */
152    uint64_t left;
153
154    /* the tracker's announce URL */
155    char * url;
156
157    /* key generated by and returned from an http tracker.
158     * see tr_announce_response.tracker_id_str */
159    char * tracker_id_str;
160
161    /* the torrent's peer id.
162     * this changes when a torrent is stopped -> restarted. */
163    char peer_id[PEER_ID_LEN];
164
165    /* the torrent's info_hash */
166    uint8_t info_hash[SHA_DIGEST_LENGTH];
167
168    /* the name to use when deep logging is enabled */
169    char log_name[128];
170}
171tr_announce_request;
172
173struct tr_pex;
174
175typedef struct
176{
177    /* the torrent's info hash */
178    uint8_t info_hash[SHA_DIGEST_LENGTH];
179
180    /* whether or not we managed to connect to the tracker */
181    bool did_connect;
182
183    /* whether or not the scrape timed out */
184    bool did_timeout;
185
186    /* preferred interval between announces.
187     * transmission treats this as the interval for periodic announces */
188    int interval;
189
190    /* minimum interval between announces. (optional)
191     * transmission treats this as the min interval for manual announces */
192    int min_interval;
193
194    /* how many peers are seeding this torrent */
195    int seeders;
196
197    /* how many peers are downloading this torrent */
198    int leechers;
199
200    /* how many times this torrent has been downloaded */
201    int downloads;
202
203    /* number of items in the 'pex' field */
204    size_t pex_count;
205
206    /* IPv4 peers that we acquired from the tracker */
207    struct tr_pex * pex;
208
209    /* number of items in the 'pex6' field */
210    size_t pex6_count;
211
212    /* IPv6 peers that we acquired from the tracker */
213    struct tr_pex * pex6;
214
215    /* human-readable error string on failure, or NULL */
216    char * errmsg;
217
218    /* human-readable warning string or NULL */
219    char * warning;
220
221    /* key generated by and returned from an http tracker.
222     * if this is provided, subsequent http announces must include this. */
223    char * tracker_id_str;
224}
225tr_announce_response;
226
227typedef void tr_announce_response_func( tr_session                 * session,
228                                        const tr_announce_response * response,
229                                        void                       * userdata );
230
231void tr_tracker_http_announce( tr_session                 * session,
232                               const tr_announce_request  * req,
233                               tr_announce_response_func    response_func,
234                               void                       * user_data );
235
236void tr_tracker_udp_announce( tr_session                 * session,
237                              const tr_announce_request  * req,
238                              tr_announce_response_func    response_func,
239                              void                       * user_data );
240
241void tr_tracker_udp_start_shutdown( tr_session * session );
242
243#endif /* _TR_ANNOUNCER_COMMON_H_ */
Note: See TracBrowser for help on using the repository browser.