source: trunk/libtransmission/announcer-common.h

Last change on this file was 14724, checked in by jordan, 5 years ago

use '#pragma once' instead of #ifndef..#define..#endif guards

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