1 | /****************************************************************************** |
---|
2 | * $Id: tracker.c 1234 2006-12-16 01:58:07Z livings124 $ |
---|
3 | * |
---|
4 | * Copyright (c) 2005-2006 Transmission authors and contributors |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
7 | * copy of this software and associated documentation files (the "Software"), |
---|
8 | * to deal in the Software without restriction, including without limitation |
---|
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
10 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
11 | * Software is furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
22 | * DEALINGS IN THE SOFTWARE. |
---|
23 | *****************************************************************************/ |
---|
24 | |
---|
25 | #include "transmission.h" |
---|
26 | |
---|
27 | typedef struct tr_announce_list_ptr_s tr_announce_list_ptr_t; |
---|
28 | struct tr_announce_list_ptr_s |
---|
29 | { |
---|
30 | tr_tracker_info_t * item; |
---|
31 | tr_announce_list_ptr_t * nextItem; |
---|
32 | }; |
---|
33 | |
---|
34 | struct tr_tracker_s |
---|
35 | { |
---|
36 | tr_torrent_t * tor; |
---|
37 | |
---|
38 | char * id; |
---|
39 | char * trackerid; |
---|
40 | |
---|
41 | const char * trackerAddress; |
---|
42 | int trackerPort; |
---|
43 | const char * trackerAnnounce; |
---|
44 | char trackerScrape[MAX_PATH_LENGTH]; |
---|
45 | int trackerCanScrape; |
---|
46 | |
---|
47 | tr_announce_list_ptr_t ** trackerAnnounceListPtr; |
---|
48 | |
---|
49 | #define TC_CHANGE_NO 0 |
---|
50 | #define TC_CHANGE_NEXT 1 |
---|
51 | #define TC_CHANGE_REDIRECT 2 |
---|
52 | int shouldChangeAnnounce; |
---|
53 | int announceTier; |
---|
54 | int announceTierLast; |
---|
55 | |
---|
56 | char * redirectAddress; |
---|
57 | int redirectAddressLen; |
---|
58 | char * redirectScrapeAddress; |
---|
59 | int redirectScrapeAddressLen; |
---|
60 | |
---|
61 | char started; |
---|
62 | char completed; |
---|
63 | char stopped; |
---|
64 | |
---|
65 | int interval; |
---|
66 | int minInterval; |
---|
67 | int scrapeInterval; |
---|
68 | int seeders; |
---|
69 | int leechers; |
---|
70 | int hasManyPeers; |
---|
71 | int complete; |
---|
72 | int randOffset; |
---|
73 | |
---|
74 | int completelyUnconnectable; |
---|
75 | |
---|
76 | uint64_t dateTry; |
---|
77 | uint64_t dateOk; |
---|
78 | uint64_t dateScrape; |
---|
79 | int lastScrapeFailed; |
---|
80 | |
---|
81 | #define TC_ATTEMPT_NOREACH 1 |
---|
82 | #define TC_ATTEMPT_ERROR 2 |
---|
83 | #define TC_ATTEMPT_OK 4 |
---|
84 | char lastAttempt; |
---|
85 | int scrapeNeeded; |
---|
86 | |
---|
87 | tr_http_t * http; |
---|
88 | tr_http_t * httpScrape; |
---|
89 | |
---|
90 | int bindPort; |
---|
91 | int newPort; |
---|
92 | }; |
---|
93 | |
---|
94 | static int announceToScrape ( char * announce, char * scrape ); |
---|
95 | static void setAnnounce ( tr_tracker_t * tc, tr_announce_list_ptr_t * announceItem ); |
---|
96 | static void failureAnnouncing( tr_tracker_t * tc ); |
---|
97 | static tr_http_t * getQuery ( tr_tracker_t * tc ); |
---|
98 | static tr_http_t * getScrapeQuery ( tr_tracker_t * tc ); |
---|
99 | static void readAnswer ( tr_tracker_t * tc, const char *, int ); |
---|
100 | static void readScrapeAnswer ( tr_tracker_t * tc, const char *, int ); |
---|
101 | static void killHttp ( tr_http_t ** http, tr_fd_t * fdlimit ); |
---|
102 | |
---|
103 | tr_tracker_t * tr_trackerInit( tr_torrent_t * tor ) |
---|
104 | { |
---|
105 | tr_info_t * inf = &tor->info; |
---|
106 | |
---|
107 | tr_tracker_t * tc; |
---|
108 | tr_announce_list_ptr_t * prev, * cur; |
---|
109 | int ii, jj; |
---|
110 | |
---|
111 | tc = calloc( 1, sizeof( tr_tracker_t ) ); |
---|
112 | tc->tor = tor; |
---|
113 | tc->id = tor->id; |
---|
114 | |
---|
115 | tc->started = 1; |
---|
116 | |
---|
117 | tc->shouldChangeAnnounce = TC_CHANGE_NO; |
---|
118 | tc->redirectAddress = NULL; |
---|
119 | |
---|
120 | tc->interval = 300; |
---|
121 | tc->scrapeInterval = 600; |
---|
122 | |
---|
123 | tc->lastAttempt = TC_ATTEMPT_NOREACH; |
---|
124 | |
---|
125 | tc->bindPort = *(tor->bindPort); |
---|
126 | tc->newPort = -1; |
---|
127 | |
---|
128 | tc->trackerAnnounceListPtr = calloc( sizeof( int ), inf->trackerTiers ); |
---|
129 | for( ii = 0; ii < inf->trackerTiers; ii++ ) |
---|
130 | { |
---|
131 | prev = NULL; |
---|
132 | for( jj = 0; jj < inf->trackerList[ii].count; jj++ ) |
---|
133 | { |
---|
134 | cur = calloc( sizeof( tr_announce_list_ptr_t ), 1 ); |
---|
135 | cur->item = &inf->trackerList[ii].list[jj]; |
---|
136 | if( NULL == prev ) |
---|
137 | { |
---|
138 | tc->trackerAnnounceListPtr[ii] = cur; |
---|
139 | } |
---|
140 | else |
---|
141 | { |
---|
142 | prev->nextItem = cur; |
---|
143 | } |
---|
144 | prev = cur; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | setAnnounce( tc, tc->trackerAnnounceListPtr[0] ); |
---|
149 | |
---|
150 | return tc; |
---|
151 | } |
---|
152 | |
---|
153 | static int announceToScrape( char * announce, char * scrape ) |
---|
154 | { |
---|
155 | char * slash, * nextSlash; |
---|
156 | int pre, post; |
---|
157 | |
---|
158 | slash = strchr( announce, '/' ); |
---|
159 | while( ( nextSlash = strchr( slash + 1, '/' ) ) ) |
---|
160 | { |
---|
161 | slash = nextSlash; |
---|
162 | } |
---|
163 | slash++; |
---|
164 | |
---|
165 | if( !strncmp( slash, "announce", 8 ) ) |
---|
166 | { |
---|
167 | pre = (long) slash - (long) announce; |
---|
168 | post = strlen( announce ) - pre - 8; |
---|
169 | memcpy( scrape, announce, pre ); |
---|
170 | sprintf( &scrape[pre], "scrape" ); |
---|
171 | memcpy( &scrape[pre+6], &announce[pre+8], post ); |
---|
172 | scrape[pre+6+post] = 0; |
---|
173 | |
---|
174 | return 1; |
---|
175 | } |
---|
176 | else |
---|
177 | { |
---|
178 | return 0; |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | static void setAnnounce( tr_tracker_t * tc, tr_announce_list_ptr_t * announcePtr ) |
---|
183 | { |
---|
184 | tr_tracker_info_t * announceItem = announcePtr->item; |
---|
185 | |
---|
186 | tc->trackerAddress = announceItem->address; |
---|
187 | tc->trackerPort = announceItem->port; |
---|
188 | tc->trackerAnnounce = announceItem->announce; |
---|
189 | |
---|
190 | tc->trackerCanScrape = announceToScrape( announceItem->announce, tc->trackerScrape ); |
---|
191 | |
---|
192 | /* Needs a new scrape */ |
---|
193 | tc->seeders = -1; |
---|
194 | tc->leechers = -1; |
---|
195 | tc->complete = -1; |
---|
196 | tc->dateScrape = 0; |
---|
197 | } |
---|
198 | |
---|
199 | static void failureAnnouncing( tr_tracker_t * tc ) |
---|
200 | { |
---|
201 | tr_info_t * inf = &tc->tor->info; |
---|
202 | |
---|
203 | tc->shouldChangeAnnounce = tc->announceTier + 1 < inf->trackerTiers |
---|
204 | || tc->announceTierLast + 1 < inf->trackerList[tc->announceTier].count |
---|
205 | ? TC_CHANGE_NEXT : TC_CHANGE_NO; |
---|
206 | |
---|
207 | if( tc->shouldChangeAnnounce == TC_CHANGE_NO ) |
---|
208 | { |
---|
209 | tc->completelyUnconnectable = 1; |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | static int shouldConnect( tr_tracker_t * tc ) |
---|
214 | { |
---|
215 | tr_torrent_t * tor = tc->tor; |
---|
216 | uint64_t now; |
---|
217 | |
---|
218 | /* Last tracker failed, try next */ |
---|
219 | if( tc->shouldChangeAnnounce != TC_CHANGE_NO ) |
---|
220 | { |
---|
221 | return 1; |
---|
222 | } |
---|
223 | |
---|
224 | now = tr_date(); |
---|
225 | |
---|
226 | /* Unreachable tracker, wait 10 seconds + random value before trying again */ |
---|
227 | if( tc->lastAttempt == TC_ATTEMPT_NOREACH && |
---|
228 | now < tc->dateTry + tc->randOffset + 10000 ) |
---|
229 | { |
---|
230 | return 0; |
---|
231 | } |
---|
232 | |
---|
233 | /* The tracker rejected us (like 4XX code, unauthorized IP...), |
---|
234 | don't hammer it - we'll probably get the same answer next time |
---|
235 | anyway */ |
---|
236 | if( tc->lastAttempt == TC_ATTEMPT_ERROR && |
---|
237 | now < tc->dateTry + 1000 * tc->interval + tc->randOffset ) |
---|
238 | { |
---|
239 | return 0; |
---|
240 | } |
---|
241 | |
---|
242 | /* Do we need to send an event? */ |
---|
243 | if( tc->started || tc->completed || tc->stopped || 0 < tc->newPort ) |
---|
244 | { |
---|
245 | return 1; |
---|
246 | } |
---|
247 | |
---|
248 | /* Should we try and get more peers? */ |
---|
249 | if( now > tc->dateOk + 1000 * tc->interval + tc->randOffset ) |
---|
250 | { |
---|
251 | return 1; |
---|
252 | } |
---|
253 | |
---|
254 | /* If there is quite a lot of people on this torrent, stress |
---|
255 | the tracker a bit until we get a decent number of peers */ |
---|
256 | if( tc->hasManyPeers && !tr_cpIsSeeding( tor->completion ) ) |
---|
257 | { |
---|
258 | /* reannounce in 10 seconds if we have less than 5 peers */ |
---|
259 | if( tor->peerCount < 5 ) |
---|
260 | { |
---|
261 | if( now > tc->dateOk + 1000 * MAX( 10, tc->minInterval ) ) |
---|
262 | { |
---|
263 | return 1; |
---|
264 | } |
---|
265 | } |
---|
266 | /* reannounce in 20 seconds if we have less than 10 peers */ |
---|
267 | else if( tor->peerCount < 10 ) |
---|
268 | { |
---|
269 | if( now > tc->dateOk + 1000 * MAX( 20, tc->minInterval ) ) |
---|
270 | { |
---|
271 | return 1; |
---|
272 | } |
---|
273 | } |
---|
274 | /* reannounce in 30 seconds if we have less than 15 peers */ |
---|
275 | else if( tor->peerCount < 15 ) |
---|
276 | { |
---|
277 | if( now > tc->dateOk + 1000 * MAX( 30, tc->minInterval ) ) |
---|
278 | { |
---|
279 | return 1; |
---|
280 | } |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | return 0; |
---|
285 | } |
---|
286 | |
---|
287 | static int shouldScrape( tr_tracker_t * tc ) |
---|
288 | { |
---|
289 | uint64_t now, interval; |
---|
290 | |
---|
291 | /* in process of changing tracker or scrape not supported */ |
---|
292 | if( tc->shouldChangeAnnounce != TC_CHANGE_NO || !tc->trackerCanScrape ) |
---|
293 | { |
---|
294 | return 0; |
---|
295 | } |
---|
296 | |
---|
297 | now = tr_date(); |
---|
298 | interval = 1000 * MAX( tc->scrapeInterval, 60 ); |
---|
299 | |
---|
300 | /* scrape half as often if there is no need to */ |
---|
301 | if( !tc->scrapeNeeded && !tc->lastScrapeFailed ) |
---|
302 | { |
---|
303 | interval *= 2; |
---|
304 | } |
---|
305 | |
---|
306 | return now > tc->dateScrape + interval; |
---|
307 | } |
---|
308 | |
---|
309 | void tr_trackerChangePort( tr_tracker_t * tc, int port ) |
---|
310 | { |
---|
311 | tc->newPort = port; |
---|
312 | } |
---|
313 | |
---|
314 | void tr_trackerPulse( tr_tracker_t * tc ) |
---|
315 | { |
---|
316 | tr_torrent_t * tor = tc->tor; |
---|
317 | tr_info_t * inf = &tor->info; |
---|
318 | const char * data; |
---|
319 | char * address, * announce; |
---|
320 | int len, i, port; |
---|
321 | tr_announce_list_ptr_t * announcePtr, * prevAnnouncePtr; |
---|
322 | |
---|
323 | if( ( NULL == tc->http ) && shouldConnect( tc ) ) |
---|
324 | { |
---|
325 | tc->completelyUnconnectable = 0; |
---|
326 | tc->randOffset = tr_rand( 60000 ); |
---|
327 | |
---|
328 | if( tr_fdSocketWillCreate( tor->fdlimit, 1 ) ) |
---|
329 | { |
---|
330 | return; |
---|
331 | } |
---|
332 | tc->dateTry = tr_date(); |
---|
333 | |
---|
334 | if( tc->shouldChangeAnnounce == TC_CHANGE_REDIRECT ) |
---|
335 | { |
---|
336 | /* Use redirected address */ |
---|
337 | if( !tr_httpParseUrl( tc->redirectAddress, tc->redirectAddressLen, |
---|
338 | &address, &port, &announce ) ) |
---|
339 | { |
---|
340 | tc->http = tr_httpClient( TR_HTTP_GET, address, port, announce ); |
---|
341 | |
---|
342 | free( address ); |
---|
343 | free( announce ); |
---|
344 | } |
---|
345 | |
---|
346 | tc->shouldChangeAnnounce = TC_CHANGE_NO; |
---|
347 | |
---|
348 | free( tc->redirectAddress ); |
---|
349 | tc->redirectAddress = NULL; |
---|
350 | } |
---|
351 | else |
---|
352 | { |
---|
353 | if( tc->shouldChangeAnnounce == TC_CHANGE_NEXT ) |
---|
354 | { |
---|
355 | tr_inf( "Tracker: failed to connect to %s, trying next", tc->trackerAddress ); |
---|
356 | |
---|
357 | if( tc->announceTierLast + 1 < inf->trackerList[tc->announceTier].count ) |
---|
358 | { |
---|
359 | prevAnnouncePtr = tc->trackerAnnounceListPtr[tc->announceTier]; |
---|
360 | announcePtr = prevAnnouncePtr->nextItem; |
---|
361 | for( i = 0; i < tc->announceTierLast; i++ ) |
---|
362 | { |
---|
363 | prevAnnouncePtr = announcePtr; |
---|
364 | announcePtr = announcePtr->nextItem; |
---|
365 | } |
---|
366 | |
---|
367 | /* Move address to front of tier in announce list */ |
---|
368 | prevAnnouncePtr->nextItem = announcePtr->nextItem; |
---|
369 | announcePtr->nextItem = tc->trackerAnnounceListPtr[tc->announceTier]; |
---|
370 | tc->trackerAnnounceListPtr[tc->announceTier] = announcePtr; |
---|
371 | |
---|
372 | tc->announceTierLast++; |
---|
373 | } |
---|
374 | else |
---|
375 | { |
---|
376 | tc->announceTierLast = 0; |
---|
377 | tc->announceTier++; |
---|
378 | } |
---|
379 | |
---|
380 | tr_inf( "Tracker: tracker address set to %s", tc->trackerAnnounceListPtr[tc->announceTier]->item->address ); |
---|
381 | setAnnounce( tc, tc->trackerAnnounceListPtr[tc->announceTier] ); |
---|
382 | tc->shouldChangeAnnounce = TC_CHANGE_NO; |
---|
383 | } |
---|
384 | else |
---|
385 | { |
---|
386 | if( tc->announceTier != 0 ) |
---|
387 | { |
---|
388 | setAnnounce( tc, tc->trackerAnnounceListPtr[0] ); |
---|
389 | tc->announceTier = 0; |
---|
390 | } |
---|
391 | tc->announceTierLast = 0; |
---|
392 | } |
---|
393 | |
---|
394 | tc->http = getQuery( tc ); |
---|
395 | |
---|
396 | tr_inf( "Tracker: connecting to %s:%d (%s)", |
---|
397 | tc->trackerAddress, tc->trackerPort, |
---|
398 | tc->started ? "sending 'started'" : |
---|
399 | ( tc->completed ? "sending 'completed'" : |
---|
400 | ( tc->stopped ? "sending 'stopped'" : |
---|
401 | ( 0 < tc->newPort ? "sending 'stopped' to change port" : |
---|
402 | "getting peers" ) ) ) ); |
---|
403 | } |
---|
404 | } |
---|
405 | |
---|
406 | if( NULL != tc->http ) |
---|
407 | { |
---|
408 | switch( tr_httpPulse( tc->http, &data, &len ) ) |
---|
409 | { |
---|
410 | case TR_WAIT: |
---|
411 | break; |
---|
412 | |
---|
413 | case TR_ERROR: |
---|
414 | killHttp( &tc->http, tor->fdlimit ); |
---|
415 | tc->dateTry = tr_date(); |
---|
416 | |
---|
417 | failureAnnouncing( tc ); |
---|
418 | if ( tc->shouldChangeAnnounce != TC_CHANGE_NO ) |
---|
419 | { |
---|
420 | tr_trackerPulse( tc ); |
---|
421 | return; |
---|
422 | } |
---|
423 | |
---|
424 | break; |
---|
425 | |
---|
426 | case TR_OK: |
---|
427 | readAnswer( tc, data, len ); |
---|
428 | killHttp( &tc->http, tor->fdlimit ); |
---|
429 | |
---|
430 | /* Something happened to need to try next address */ |
---|
431 | if ( tc->shouldChangeAnnounce != TC_CHANGE_NO ) |
---|
432 | { |
---|
433 | tr_trackerPulse( tc ); |
---|
434 | return; |
---|
435 | } |
---|
436 | |
---|
437 | break; |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | if( ( NULL == tc->httpScrape ) && shouldScrape( tc ) ) |
---|
442 | { |
---|
443 | if( tr_fdSocketWillCreate( tor->fdlimit, 1 ) ) |
---|
444 | { |
---|
445 | return; |
---|
446 | } |
---|
447 | tc->dateScrape = tr_date(); |
---|
448 | |
---|
449 | if ( tc->redirectScrapeAddress != NULL ) |
---|
450 | { |
---|
451 | /* Use redirected address */ |
---|
452 | if( !tr_httpParseUrl( tc->redirectScrapeAddress, tc->redirectScrapeAddressLen, |
---|
453 | &address, &port, &announce ) ) |
---|
454 | { |
---|
455 | tc->httpScrape = tr_httpClient( TR_HTTP_GET, address, port, announce ); |
---|
456 | |
---|
457 | free( address ); |
---|
458 | free( announce ); |
---|
459 | } |
---|
460 | |
---|
461 | free( tc->redirectScrapeAddress ); |
---|
462 | tc->redirectScrapeAddress = NULL; |
---|
463 | } |
---|
464 | else |
---|
465 | { |
---|
466 | tc->httpScrape = getScrapeQuery( tc ); |
---|
467 | tr_inf( "Scrape: sent HTTP request to %s:%d%s", tc->trackerAddress, tc->trackerPort, tc->trackerScrape ); |
---|
468 | } |
---|
469 | } |
---|
470 | |
---|
471 | if( NULL != tc->httpScrape ) |
---|
472 | { |
---|
473 | switch( tr_httpPulse( tc->httpScrape, &data, &len ) ) |
---|
474 | { |
---|
475 | case TR_WAIT: |
---|
476 | break; |
---|
477 | |
---|
478 | case TR_ERROR: |
---|
479 | killHttp( &tc->httpScrape, tor->fdlimit ); |
---|
480 | tc->lastScrapeFailed = 1; |
---|
481 | break; |
---|
482 | |
---|
483 | case TR_OK: |
---|
484 | readScrapeAnswer( tc, data, len ); |
---|
485 | killHttp( &tc->httpScrape, tor->fdlimit ); |
---|
486 | break; |
---|
487 | } |
---|
488 | } |
---|
489 | |
---|
490 | return; |
---|
491 | } |
---|
492 | |
---|
493 | void tr_trackerCompleted( tr_tracker_t * tc ) |
---|
494 | { |
---|
495 | tc->started = 0; |
---|
496 | tc->completed = 1; |
---|
497 | tc->stopped = 0; |
---|
498 | } |
---|
499 | |
---|
500 | void tr_trackerStopped( tr_tracker_t * tc ) |
---|
501 | { |
---|
502 | tr_torrent_t * tor = tc->tor; |
---|
503 | |
---|
504 | /* If we are already sending a query at the moment, we need to |
---|
505 | reconnect */ |
---|
506 | killHttp( &tc->http, tor->fdlimit ); |
---|
507 | |
---|
508 | tc->started = 0; |
---|
509 | tc->completed = 0; |
---|
510 | tc->stopped = 1; |
---|
511 | |
---|
512 | /* Even if we have connected recently, reconnect right now */ |
---|
513 | tc->dateTry = 0; |
---|
514 | } |
---|
515 | |
---|
516 | void tr_trackerClose( tr_tracker_t * tc ) |
---|
517 | { |
---|
518 | tr_torrent_t * tor = tc->tor; |
---|
519 | |
---|
520 | killHttp( &tc->http, tor->fdlimit ); |
---|
521 | killHttp( &tc->httpScrape, tor->fdlimit ); |
---|
522 | free( tc->trackerid ); |
---|
523 | free( tc ); |
---|
524 | } |
---|
525 | |
---|
526 | static tr_http_t * getQuery( tr_tracker_t * tc ) |
---|
527 | { |
---|
528 | tr_torrent_t * tor = tc->tor; |
---|
529 | |
---|
530 | char * event, * trackerid, * idparam; |
---|
531 | uint64_t left; |
---|
532 | uint64_t down; |
---|
533 | uint64_t up; |
---|
534 | char start; |
---|
535 | int numwant = 50; |
---|
536 | |
---|
537 | down = tor->downloadedCur; |
---|
538 | up = tor->uploadedCur; |
---|
539 | if( tc->started ) |
---|
540 | { |
---|
541 | event = "&event=started"; |
---|
542 | down = 0; |
---|
543 | up = 0; |
---|
544 | |
---|
545 | if( 0 < tc->newPort ) |
---|
546 | { |
---|
547 | tc->bindPort = tc->newPort; |
---|
548 | tc->newPort = -1; |
---|
549 | } |
---|
550 | } |
---|
551 | else if( tc->completed ) |
---|
552 | { |
---|
553 | event = "&event=completed"; |
---|
554 | } |
---|
555 | else if( tc->stopped || 0 < tc->newPort ) |
---|
556 | { |
---|
557 | event = "&event=stopped"; |
---|
558 | numwant = 0; |
---|
559 | } |
---|
560 | else |
---|
561 | { |
---|
562 | event = ""; |
---|
563 | } |
---|
564 | |
---|
565 | if( NULL == tc->trackerid ) |
---|
566 | { |
---|
567 | trackerid = ""; |
---|
568 | idparam = ""; |
---|
569 | } |
---|
570 | else |
---|
571 | { |
---|
572 | trackerid = tc->trackerid; |
---|
573 | idparam = "&trackerid="; |
---|
574 | } |
---|
575 | |
---|
576 | start = ( strchr( tc->trackerAnnounce, '?' ) ? '&' : '?' ); |
---|
577 | left = tr_cpLeftBytes( tor->completion ); |
---|
578 | |
---|
579 | return tr_httpClient( TR_HTTP_GET, tc->trackerAddress, tc->trackerPort, |
---|
580 | "%s%c" |
---|
581 | "info_hash=%s&" |
---|
582 | "peer_id=%s&" |
---|
583 | "port=%d&" |
---|
584 | "uploaded=%"PRIu64"&" |
---|
585 | "downloaded=%"PRIu64"&" |
---|
586 | "left=%"PRIu64"&" |
---|
587 | "compact=1&" |
---|
588 | "numwant=%d&" |
---|
589 | "key=%s" |
---|
590 | "%s%s" |
---|
591 | "%s", |
---|
592 | tc->trackerAnnounce, start, tor->escapedHashString, |
---|
593 | tc->id, tc->bindPort, up, down, left, numwant, |
---|
594 | tor->key, idparam, trackerid, event ); |
---|
595 | } |
---|
596 | |
---|
597 | static tr_http_t * getScrapeQuery( tr_tracker_t * tc ) |
---|
598 | { |
---|
599 | tr_torrent_t * tor = tc->tor; |
---|
600 | char start; |
---|
601 | |
---|
602 | start = ( strchr( tc->trackerScrape, '?' ) ? '&' : '?' ); |
---|
603 | |
---|
604 | return tr_httpClient( TR_HTTP_GET, tc->trackerAddress, tc->trackerPort, |
---|
605 | "%s%c" |
---|
606 | "info_hash=%s", |
---|
607 | tc->trackerScrape, start, tor->escapedHashString ); |
---|
608 | } |
---|
609 | |
---|
610 | static void readAnswer( tr_tracker_t * tc, const char * data, int len ) |
---|
611 | { |
---|
612 | tr_torrent_t * tor = tc->tor; |
---|
613 | int i; |
---|
614 | int code; |
---|
615 | benc_val_t beAll; |
---|
616 | benc_val_t * bePeers, * beFoo; |
---|
617 | const uint8_t * body; |
---|
618 | int bodylen, shouldfree, scrapeNeeded; |
---|
619 | |
---|
620 | tc->dateTry = tr_date(); |
---|
621 | code = tr_httpResponseCode( data, len ); |
---|
622 | |
---|
623 | if( 0 > code ) |
---|
624 | { |
---|
625 | /* We don't have a valid HTTP status line */ |
---|
626 | tr_inf( "Tracker: invalid HTTP status line" ); |
---|
627 | tc->lastAttempt = TC_ATTEMPT_NOREACH; |
---|
628 | failureAnnouncing( tc ); |
---|
629 | return; |
---|
630 | } |
---|
631 | |
---|
632 | if( code == 301 || code == 302 ) |
---|
633 | { |
---|
634 | tr_err( "Tracker: HTTP status code: %i", code ); |
---|
635 | |
---|
636 | tr_http_header_t hdr[] = { { "Location", NULL, 0 }, { NULL, NULL, 0 } }; |
---|
637 | |
---|
638 | tr_httpParse( data, len, hdr ); |
---|
639 | |
---|
640 | char * address = calloc( sizeof( char ), hdr->len+1 ); |
---|
641 | snprintf( address, hdr->len+1, "%s", hdr->data ); |
---|
642 | |
---|
643 | tr_err( "Tracker: redirected URL: %s", address ); |
---|
644 | |
---|
645 | tc->shouldChangeAnnounce = TC_CHANGE_REDIRECT; |
---|
646 | tc->redirectAddress = address; |
---|
647 | tc->redirectAddressLen = hdr->len; |
---|
648 | |
---|
649 | return; |
---|
650 | } |
---|
651 | |
---|
652 | if( !TR_HTTP_STATUS_OK( code ) ) |
---|
653 | { |
---|
654 | /* we didn't get a 2xx status code */ |
---|
655 | tr_err( "Tracker: invalid HTTP status code: %i", code ); |
---|
656 | tc->lastAttempt = TC_ATTEMPT_ERROR; |
---|
657 | failureAnnouncing( tc ); |
---|
658 | return; |
---|
659 | } |
---|
660 | |
---|
661 | /* find the end of the http headers */ |
---|
662 | body = (uint8_t *) tr_httpParse( data, len, NULL ); |
---|
663 | if( NULL == body ) |
---|
664 | { |
---|
665 | tr_err( "Tracker: could not find end of HTTP headers" ); |
---|
666 | tc->lastAttempt = TC_ATTEMPT_NOREACH; |
---|
667 | failureAnnouncing( tc ); |
---|
668 | return; |
---|
669 | } |
---|
670 | bodylen = len - ( body - (const uint8_t*)data ); |
---|
671 | |
---|
672 | /* Find and load the dictionary */ |
---|
673 | shouldfree = 0; |
---|
674 | for( i = 0; i < bodylen; i++ ) |
---|
675 | { |
---|
676 | if( !tr_bencLoad( &body[i], bodylen - i, &beAll, NULL ) ) |
---|
677 | { |
---|
678 | shouldfree = 1; |
---|
679 | break; |
---|
680 | } |
---|
681 | } |
---|
682 | |
---|
683 | if( i >= bodylen ) |
---|
684 | { |
---|
685 | if( tc->stopped || 0 < tc->newPort ) |
---|
686 | { |
---|
687 | tc->lastAttempt = TC_ATTEMPT_OK; |
---|
688 | goto nodict; |
---|
689 | } |
---|
690 | tr_err( "Tracker: no valid dictionary found in answer" ); |
---|
691 | tc->lastAttempt = TC_ATTEMPT_ERROR; |
---|
692 | failureAnnouncing( tc ); |
---|
693 | return; |
---|
694 | } |
---|
695 | |
---|
696 | // tr_bencPrint( &beAll ); |
---|
697 | |
---|
698 | if( ( bePeers = tr_bencDictFind( &beAll, "failure reason" ) ) ) |
---|
699 | { |
---|
700 | tr_err( "Tracker: Error - %s", bePeers->val.s.s ); |
---|
701 | tor->error |= TR_ETRACKER; |
---|
702 | snprintf( tor->trackerError, sizeof( tor->trackerError ), |
---|
703 | "%s", bePeers->val.s.s ); |
---|
704 | tc->lastAttempt = TC_ATTEMPT_ERROR; |
---|
705 | failureAnnouncing( tc ); |
---|
706 | goto cleanup; |
---|
707 | } |
---|
708 | else if( ( bePeers = tr_bencDictFind( &beAll, "warning message" ) ) ) |
---|
709 | { |
---|
710 | tr_err( "Tracker: Warning - %s", bePeers->val.s.s ); |
---|
711 | snprintf( tor->trackerError, sizeof( tor->trackerError ), |
---|
712 | "%s", bePeers->val.s.s ); |
---|
713 | } |
---|
714 | else |
---|
715 | { |
---|
716 | tor->trackerError[0] = '\0'; |
---|
717 | } |
---|
718 | |
---|
719 | tor->error &= ~TR_ETRACKER; |
---|
720 | tc->lastAttempt = TC_ATTEMPT_OK; |
---|
721 | |
---|
722 | /* Get the tracker interval, force to between |
---|
723 | 10 sec and 5 mins */ |
---|
724 | beFoo = tr_bencDictFind( &beAll, "interval" ); |
---|
725 | if( !beFoo || TYPE_INT != beFoo->type ) |
---|
726 | { |
---|
727 | tr_err( "Tracker: no 'interval' field" ); |
---|
728 | goto cleanup; |
---|
729 | } |
---|
730 | |
---|
731 | tc->interval = beFoo->val.i; |
---|
732 | tr_inf( "Tracker: interval = %d seconds", tc->interval ); |
---|
733 | |
---|
734 | tc->interval = MIN( tc->interval, 300 ); |
---|
735 | tc->interval = MAX( 10, tc->interval ); |
---|
736 | |
---|
737 | /* Get the tracker minimum interval, force to between |
---|
738 | 10 sec and 5 mins */ |
---|
739 | beFoo = tr_bencDictFind( &beAll, "min interval" ); |
---|
740 | if( beFoo && TYPE_INT == beFoo->type ) |
---|
741 | { |
---|
742 | tc->minInterval = beFoo->val.i; |
---|
743 | tr_inf( "Tracker: min interval = %d seconds", tc->minInterval ); |
---|
744 | |
---|
745 | tc->minInterval = MIN( tc->minInterval, 300 ); |
---|
746 | tc->minInterval = MAX( 10, tc->minInterval ); |
---|
747 | |
---|
748 | if( tc->interval < tc->minInterval ) |
---|
749 | { |
---|
750 | tc->interval = tc->minInterval; |
---|
751 | tr_inf( "Tracker: 'interval' less than 'min interval', " |
---|
752 | "using 'min interval'" ); |
---|
753 | } |
---|
754 | } |
---|
755 | else |
---|
756 | { |
---|
757 | tc->minInterval = 0; |
---|
758 | tr_inf( "Tracker: no 'min interval' field" ); |
---|
759 | } |
---|
760 | |
---|
761 | scrapeNeeded = 0; |
---|
762 | beFoo = tr_bencDictFind( &beAll, "complete" ); |
---|
763 | if( beFoo && TYPE_INT == beFoo->type ) |
---|
764 | { |
---|
765 | tc->seeders = beFoo->val.i; |
---|
766 | } |
---|
767 | else |
---|
768 | { |
---|
769 | scrapeNeeded = 1; |
---|
770 | } |
---|
771 | |
---|
772 | beFoo = tr_bencDictFind( &beAll, "incomplete" ); |
---|
773 | if( beFoo && TYPE_INT == beFoo->type ) |
---|
774 | { |
---|
775 | tc->leechers = beFoo->val.i; |
---|
776 | } |
---|
777 | else |
---|
778 | { |
---|
779 | scrapeNeeded = 1; |
---|
780 | } |
---|
781 | |
---|
782 | tc->scrapeNeeded = scrapeNeeded; |
---|
783 | if( !scrapeNeeded ) |
---|
784 | { |
---|
785 | tc->hasManyPeers = ( tc->seeders + tc->leechers >= 50 ); |
---|
786 | } |
---|
787 | |
---|
788 | beFoo = tr_bencDictFind( &beAll, "tracker id" ); |
---|
789 | if( beFoo ) |
---|
790 | { |
---|
791 | free( tc->trackerid ); |
---|
792 | tc->trackerid = strdup( beFoo->val.s.s ); |
---|
793 | tr_inf( "Tracker: tracker id = %s", tc->trackerid ); |
---|
794 | } |
---|
795 | |
---|
796 | bePeers = tr_bencDictFind( &beAll, "peers" ); |
---|
797 | if( !bePeers ) |
---|
798 | { |
---|
799 | if( tc->stopped || 0 < tc->newPort ) |
---|
800 | { |
---|
801 | goto nodict; |
---|
802 | } |
---|
803 | tr_err( "Tracker: no \"peers\" field" ); |
---|
804 | failureAnnouncing( tc ); |
---|
805 | goto cleanup; |
---|
806 | } |
---|
807 | |
---|
808 | if( bePeers->type & TYPE_LIST ) |
---|
809 | { |
---|
810 | char * ip; |
---|
811 | int port; |
---|
812 | |
---|
813 | /* Original protocol */ |
---|
814 | tr_inf( "Tracker: got %d peers", bePeers->val.l.count ); |
---|
815 | |
---|
816 | for( i = 0; i < bePeers->val.l.count; i++ ) |
---|
817 | { |
---|
818 | beFoo = tr_bencDictFind( &bePeers->val.l.vals[i], "ip" ); |
---|
819 | if( !beFoo ) |
---|
820 | continue; |
---|
821 | ip = beFoo->val.s.s; |
---|
822 | beFoo = tr_bencDictFind( &bePeers->val.l.vals[i], "port" ); |
---|
823 | if( !beFoo ) |
---|
824 | continue; |
---|
825 | port = beFoo->val.i; |
---|
826 | |
---|
827 | tr_peerAddOld( tor, ip, port ); |
---|
828 | } |
---|
829 | |
---|
830 | if( bePeers->val.l.count >= 50 ) |
---|
831 | { |
---|
832 | tc->hasManyPeers = 1; |
---|
833 | } |
---|
834 | } |
---|
835 | else if( bePeers->type & TYPE_STR ) |
---|
836 | { |
---|
837 | struct in_addr addr; |
---|
838 | in_port_t port; |
---|
839 | |
---|
840 | /* "Compact" extension */ |
---|
841 | if( bePeers->val.s.i % 6 ) |
---|
842 | { |
---|
843 | tr_err( "Tracker: \"peers\" of size %d", |
---|
844 | bePeers->val.s.i ); |
---|
845 | tr_lockUnlock( &tor->lock ); |
---|
846 | goto cleanup; |
---|
847 | } |
---|
848 | |
---|
849 | tr_inf( "Tracker: got %d peers", bePeers->val.s.i / 6 ); |
---|
850 | for( i = 0; i < bePeers->val.s.i / 6; i++ ) |
---|
851 | { |
---|
852 | memcpy( &addr, &bePeers->val.s.s[6*i], 4 ); |
---|
853 | memcpy( &port, &bePeers->val.s.s[6*i+4], 2 ); |
---|
854 | |
---|
855 | tr_peerAddCompact( tor, addr, port ); |
---|
856 | } |
---|
857 | |
---|
858 | if( bePeers->val.s.i / 6 >= 50 ) |
---|
859 | { |
---|
860 | tc->hasManyPeers = 1; |
---|
861 | } |
---|
862 | } |
---|
863 | |
---|
864 | nodict: |
---|
865 | /* Success */ |
---|
866 | tc->started = 0; |
---|
867 | tc->completed = 0; |
---|
868 | tc->dateOk = tr_date(); |
---|
869 | |
---|
870 | if( tc->stopped ) |
---|
871 | { |
---|
872 | tor->status = TR_STATUS_STOPPED; |
---|
873 | tc->stopped = 0; |
---|
874 | } |
---|
875 | else if( 0 < tc->newPort ) |
---|
876 | { |
---|
877 | tc->started = 1; |
---|
878 | } |
---|
879 | |
---|
880 | cleanup: |
---|
881 | if( shouldfree ) |
---|
882 | { |
---|
883 | tr_bencFree( &beAll ); |
---|
884 | } |
---|
885 | } |
---|
886 | |
---|
887 | static void readScrapeAnswer( tr_tracker_t * tc, const char * data, int len ) |
---|
888 | { |
---|
889 | int code; |
---|
890 | const uint8_t * body; |
---|
891 | int bodylen, ii; |
---|
892 | benc_val_t scrape, * val1, * val2; |
---|
893 | |
---|
894 | code = tr_httpResponseCode( data, len ); |
---|
895 | if( 0 > code ) |
---|
896 | { |
---|
897 | /* We don't have a valid HTTP status line */ |
---|
898 | tr_inf( "Scrape: invalid HTTP status line" ); |
---|
899 | tc->lastScrapeFailed = 1; |
---|
900 | return; |
---|
901 | } |
---|
902 | |
---|
903 | if( code == 301 || code == 302 ) |
---|
904 | { |
---|
905 | tr_err( "Scrape: HTTP status code: %i", code ); |
---|
906 | |
---|
907 | tr_http_header_t hdr[] = { { "Location", NULL, 0 }, { NULL, NULL, 0 } }; |
---|
908 | |
---|
909 | tr_httpParse( data, len, hdr ); |
---|
910 | |
---|
911 | char * address = calloc( sizeof( char ), hdr->len+1 ); |
---|
912 | snprintf( address, hdr->len+1, "%s", hdr->data ); |
---|
913 | |
---|
914 | tr_err( "Scrape: redirected URL: %s", address ); |
---|
915 | |
---|
916 | /* Needs a new scrape */ |
---|
917 | tc->dateScrape = 0; |
---|
918 | |
---|
919 | tc->redirectScrapeAddress = address; |
---|
920 | tc->redirectScrapeAddressLen = hdr->len; |
---|
921 | |
---|
922 | return; |
---|
923 | } |
---|
924 | |
---|
925 | if( !TR_HTTP_STATUS_OK( code ) ) |
---|
926 | { |
---|
927 | /* we didn't get a 2xx status code */ |
---|
928 | tr_err( "Scrape: invalid HTTP status code: %i", code ); |
---|
929 | if( TR_HTTP_STATUS_FAIL_CLIENT( code ) ) |
---|
930 | tc->trackerCanScrape = 0; |
---|
931 | tc->lastScrapeFailed = 1; |
---|
932 | return; |
---|
933 | } |
---|
934 | |
---|
935 | /* find the end of the http headers */ |
---|
936 | body = (uint8_t *) tr_httpParse( data, len, NULL ); |
---|
937 | if( NULL == body ) |
---|
938 | { |
---|
939 | tr_err( "Scrape: could not find end of HTTP headers" ); |
---|
940 | tc->lastScrapeFailed = 1; |
---|
941 | return; |
---|
942 | } |
---|
943 | |
---|
944 | tc->lastScrapeFailed = 0; |
---|
945 | bodylen = len - ( body - (const uint8_t*)data ); |
---|
946 | |
---|
947 | for( ii = 0; ii < bodylen; ii++ ) |
---|
948 | { |
---|
949 | if( !tr_bencLoad( body + ii, bodylen - ii, &scrape, NULL ) ) |
---|
950 | { |
---|
951 | break; |
---|
952 | } |
---|
953 | } |
---|
954 | if( ii >= bodylen ) |
---|
955 | { |
---|
956 | return; |
---|
957 | } |
---|
958 | |
---|
959 | val1 = tr_bencDictFind( &scrape, "files" ); |
---|
960 | if( !val1 ) |
---|
961 | { |
---|
962 | tr_bencFree( &scrape ); |
---|
963 | return; |
---|
964 | } |
---|
965 | val1 = &val1->val.l.vals[1]; |
---|
966 | if( !val1 ) |
---|
967 | { |
---|
968 | tr_bencFree( &scrape ); |
---|
969 | return; |
---|
970 | } |
---|
971 | |
---|
972 | val2 = tr_bencDictFind( val1, "complete" ); |
---|
973 | if( !val2 ) |
---|
974 | { |
---|
975 | tr_bencFree( &scrape ); |
---|
976 | return; |
---|
977 | } |
---|
978 | tc->seeders = val2->val.i; |
---|
979 | |
---|
980 | val2 = tr_bencDictFind( val1, "incomplete" ); |
---|
981 | if( !val2 ) |
---|
982 | { |
---|
983 | tr_bencFree( &scrape ); |
---|
984 | return; |
---|
985 | } |
---|
986 | tc->leechers = val2->val.i; |
---|
987 | |
---|
988 | val2 = tr_bencDictFind( val1, "downloaded" ); |
---|
989 | if( !val2 ) |
---|
990 | { |
---|
991 | tr_bencFree( &scrape ); |
---|
992 | return; |
---|
993 | } |
---|
994 | tc->complete = val2->val.i; |
---|
995 | |
---|
996 | val2 = tr_bencDictFind( val1, "flags" ); |
---|
997 | if( val2 ) |
---|
998 | { |
---|
999 | val2 = tr_bencDictFind( val2, "min_request_interval" ); |
---|
1000 | if( val2 ) |
---|
1001 | { |
---|
1002 | tc->scrapeInterval = val2->val.i; |
---|
1003 | } |
---|
1004 | } |
---|
1005 | |
---|
1006 | tc->hasManyPeers = ( tc->seeders + tc->leechers >= 50 ); |
---|
1007 | |
---|
1008 | tr_bencFree( &scrape ); |
---|
1009 | } |
---|
1010 | |
---|
1011 | int tr_trackerSeeders( tr_tracker_t * tc ) |
---|
1012 | { |
---|
1013 | if( !tc ) |
---|
1014 | { |
---|
1015 | return -1; |
---|
1016 | } |
---|
1017 | return tc->seeders; |
---|
1018 | } |
---|
1019 | |
---|
1020 | int tr_trackerLeechers( tr_tracker_t * tc ) |
---|
1021 | { |
---|
1022 | if( !tc ) |
---|
1023 | { |
---|
1024 | return -1; |
---|
1025 | } |
---|
1026 | return tc->leechers; |
---|
1027 | } |
---|
1028 | |
---|
1029 | int tr_trackerDownloaded( tr_tracker_t * tc ) |
---|
1030 | { |
---|
1031 | if( !tc ) |
---|
1032 | { |
---|
1033 | return -1; |
---|
1034 | } |
---|
1035 | return tc->complete; |
---|
1036 | } |
---|
1037 | |
---|
1038 | const char * tr_trackerAddress( tr_tracker_t * tc ) |
---|
1039 | { |
---|
1040 | if( !tc ) |
---|
1041 | { |
---|
1042 | return NULL; |
---|
1043 | } |
---|
1044 | return tc->trackerAddress; |
---|
1045 | } |
---|
1046 | |
---|
1047 | int tr_trackerPort( tr_tracker_t * tc ) |
---|
1048 | { |
---|
1049 | if( !tc ) |
---|
1050 | { |
---|
1051 | return 0; |
---|
1052 | } |
---|
1053 | return tc->trackerPort; |
---|
1054 | } |
---|
1055 | |
---|
1056 | const char * tr_trackerAnnounce( tr_tracker_t * tc ) |
---|
1057 | { |
---|
1058 | if( !tc ) |
---|
1059 | { |
---|
1060 | return NULL; |
---|
1061 | } |
---|
1062 | return tc->trackerAnnounce; |
---|
1063 | } |
---|
1064 | |
---|
1065 | int tr_trackerCannotConnecting( tr_tracker_t * tc ) |
---|
1066 | { |
---|
1067 | if( !tc ) |
---|
1068 | { |
---|
1069 | return 0; |
---|
1070 | } |
---|
1071 | return tc->completelyUnconnectable; |
---|
1072 | } |
---|
1073 | |
---|
1074 | /* Blocking version */ |
---|
1075 | int tr_trackerScrape( tr_torrent_t * tor, int * s, int * l, int * d ) |
---|
1076 | { |
---|
1077 | tr_tracker_t * tc; |
---|
1078 | tr_http_t * http; |
---|
1079 | const char * data; |
---|
1080 | int len; |
---|
1081 | int ret; |
---|
1082 | |
---|
1083 | tc = tr_trackerInit( tor ); |
---|
1084 | |
---|
1085 | if( !tc->trackerCanScrape ) |
---|
1086 | { |
---|
1087 | return 1; |
---|
1088 | } |
---|
1089 | |
---|
1090 | http = getScrapeQuery( tc ); |
---|
1091 | |
---|
1092 | for( data = NULL; !data; tr_wait( 10 ) ) |
---|
1093 | { |
---|
1094 | switch( tr_httpPulse( http, &data, &len ) ) |
---|
1095 | { |
---|
1096 | case TR_WAIT: |
---|
1097 | break; |
---|
1098 | |
---|
1099 | case TR_ERROR: |
---|
1100 | goto scrapeDone; |
---|
1101 | |
---|
1102 | case TR_OK: |
---|
1103 | readScrapeAnswer( tc, data, len ); |
---|
1104 | goto scrapeDone; |
---|
1105 | } |
---|
1106 | } |
---|
1107 | |
---|
1108 | scrapeDone: |
---|
1109 | tr_httpClose( http ); |
---|
1110 | |
---|
1111 | ret = 1; |
---|
1112 | if( tc->seeders > -1 && tc->leechers > -1 && tc->complete > -1 ) |
---|
1113 | { |
---|
1114 | *s = tc->seeders; |
---|
1115 | *l = tc->leechers; |
---|
1116 | *d = tc->complete; |
---|
1117 | ret = 0; |
---|
1118 | } |
---|
1119 | |
---|
1120 | tr_trackerClose( tc ); |
---|
1121 | return ret; |
---|
1122 | } |
---|
1123 | |
---|
1124 | static void killHttp( tr_http_t ** http, tr_fd_t * fdlimit ) |
---|
1125 | { |
---|
1126 | if( NULL != *http ) |
---|
1127 | { |
---|
1128 | tr_httpClose( *http ); |
---|
1129 | tr_fdSocketClosed( fdlimit, 1 ); |
---|
1130 | *http = NULL; |
---|
1131 | } |
---|
1132 | } |
---|