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 13310 2012-05-20 14:14:59Z 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 | |
---|
27 | enum |
---|
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 | |
---|
37 | typedef 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 | } |
---|
51 | tr_scrape_request; |
---|
52 | |
---|
53 | struct 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 | |
---|
73 | typedef 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 | } |
---|
97 | tr_scrape_response; |
---|
98 | |
---|
99 | typedef void tr_scrape_response_func( const tr_scrape_response * response, |
---|
100 | void * user_data ); |
---|
101 | |
---|
102 | void tr_tracker_http_scrape( tr_session * session, |
---|
103 | const tr_scrape_request * req, |
---|
104 | tr_scrape_response_func response_func, |
---|
105 | void * user_data ); |
---|
106 | |
---|
107 | void tr_tracker_udp_scrape( tr_session * session, |
---|
108 | const tr_scrape_request * req, |
---|
109 | tr_scrape_response_func response_func, |
---|
110 | void * user_data ); |
---|
111 | |
---|
112 | /*** |
---|
113 | **** ANNOUNCE |
---|
114 | ***/ |
---|
115 | |
---|
116 | typedef enum |
---|
117 | { |
---|
118 | TR_ANNOUNCE_EVENT_NONE, |
---|
119 | TR_ANNOUNCE_EVENT_COMPLETED, |
---|
120 | TR_ANNOUNCE_EVENT_STARTED, |
---|
121 | TR_ANNOUNCE_EVENT_STOPPED |
---|
122 | } |
---|
123 | tr_announce_event; |
---|
124 | |
---|
125 | const char * tr_announce_event_get_string( tr_announce_event ); |
---|
126 | |
---|
127 | typedef struct |
---|
128 | { |
---|
129 | tr_announce_event event; |
---|
130 | bool partial_seed; |
---|
131 | |
---|
132 | /* the port we listen for incoming peers on */ |
---|
133 | int port; |
---|
134 | |
---|
135 | /* per-session key */ |
---|
136 | int key; |
---|
137 | |
---|
138 | /* the number of peers we'd like to get back in the response */ |
---|
139 | int numwant; |
---|
140 | |
---|
141 | /* the number of bytes we uploaded since the last 'started' event */ |
---|
142 | uint64_t up; |
---|
143 | |
---|
144 | /* the number of good bytes we downloaded since the last 'started' event */ |
---|
145 | uint64_t down; |
---|
146 | |
---|
147 | /* the number of bad bytes we downloaded since the last 'started' event */ |
---|
148 | uint64_t corrupt; |
---|
149 | |
---|
150 | /* the total size of the torrent minus the number of bytes completed */ |
---|
151 | uint64_t leftUntilComplete; |
---|
152 | |
---|
153 | /* the tracker's announce URL */ |
---|
154 | char * url; |
---|
155 | |
---|
156 | /* key generated by and returned from an http tracker. |
---|
157 | * see tr_announce_response.tracker_id_str */ |
---|
158 | char * tracker_id_str; |
---|
159 | |
---|
160 | /* the torrent's peer id. |
---|
161 | * this changes when a torrent is stopped -> restarted. */ |
---|
162 | char peer_id[PEER_ID_LEN]; |
---|
163 | |
---|
164 | /* the torrent's info_hash */ |
---|
165 | uint8_t info_hash[SHA_DIGEST_LENGTH]; |
---|
166 | |
---|
167 | /* the name to use when deep logging is enabled */ |
---|
168 | char log_name[128]; |
---|
169 | } |
---|
170 | tr_announce_request; |
---|
171 | |
---|
172 | struct tr_pex; |
---|
173 | |
---|
174 | typedef struct |
---|
175 | { |
---|
176 | /* the torrent's info hash */ |
---|
177 | uint8_t info_hash[SHA_DIGEST_LENGTH]; |
---|
178 | |
---|
179 | /* whether or not we managed to connect to the tracker */ |
---|
180 | bool did_connect; |
---|
181 | |
---|
182 | /* whether or not the scrape timed out */ |
---|
183 | bool did_timeout; |
---|
184 | |
---|
185 | /* preferred interval between announces. |
---|
186 | * transmission treats this as the interval for periodic announces */ |
---|
187 | int interval; |
---|
188 | |
---|
189 | /* minimum interval between announces. (optional) |
---|
190 | * transmission treats this as the min interval for manual announces */ |
---|
191 | int min_interval; |
---|
192 | |
---|
193 | /* how many peers are seeding this torrent */ |
---|
194 | int seeders; |
---|
195 | |
---|
196 | /* how many peers are downloading this torrent */ |
---|
197 | int leechers; |
---|
198 | |
---|
199 | /* how many times this torrent has been downloaded */ |
---|
200 | int downloads; |
---|
201 | |
---|
202 | /* number of items in the 'pex' field */ |
---|
203 | size_t pex_count; |
---|
204 | |
---|
205 | /* IPv4 peers that we acquired from the tracker */ |
---|
206 | struct tr_pex * pex; |
---|
207 | |
---|
208 | /* number of items in the 'pex6' field */ |
---|
209 | size_t pex6_count; |
---|
210 | |
---|
211 | /* IPv6 peers that we acquired from the tracker */ |
---|
212 | struct tr_pex * pex6; |
---|
213 | |
---|
214 | /* human-readable error string on failure, or NULL */ |
---|
215 | char * errmsg; |
---|
216 | |
---|
217 | /* human-readable warning string or NULL */ |
---|
218 | char * warning; |
---|
219 | |
---|
220 | /* key generated by and returned from an http tracker. |
---|
221 | * if this is provided, subsequent http announces must include this. */ |
---|
222 | char * tracker_id_str; |
---|
223 | } |
---|
224 | tr_announce_response; |
---|
225 | |
---|
226 | typedef void tr_announce_response_func( const tr_announce_response * response, |
---|
227 | void * userdata ); |
---|
228 | |
---|
229 | void tr_tracker_http_announce( tr_session * session, |
---|
230 | const tr_announce_request * req, |
---|
231 | tr_announce_response_func response_func, |
---|
232 | void * user_data ); |
---|
233 | |
---|
234 | void tr_tracker_udp_announce( tr_session * session, |
---|
235 | const tr_announce_request * req, |
---|
236 | tr_announce_response_func response_func, |
---|
237 | void * user_data ); |
---|
238 | |
---|
239 | void tr_tracker_udp_start_shutdown( tr_session * session ); |
---|
240 | |
---|
241 | #endif /* _TR_ANNOUNCER_COMMON_H_ */ |
---|