diff options
Diffstat (limited to 'src/trackerlogic.c')
| -rw-r--r-- | src/trackerlogic.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/trackerlogic.c b/src/trackerlogic.c index 1f56a2c..0b032e1 100644 --- a/src/trackerlogic.c +++ b/src/trackerlogic.c | |||
| @@ -94,10 +94,11 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru | |||
| 94 | return strlen(invalid_hash); | 94 | return strlen(invalid_hash); |
| 95 | } | 95 | } |
| 96 | if (proto == FLAG_UDP) { | 96 | if (proto == FLAG_UDP) { |
| 97 | ((uint32_t *)ws->reply)[0] = htonl(OT_CLIENT_REJECT_INTERVAL_RANDOM); | 97 | char *r = ws->reply; |
| 98 | ((uint32_t *)ws->reply)[1] = 0; | 98 | pack_uint32(&r, OT_CLIENT_REJECT_INTERVAL_RANDOM); |
| 99 | ((uint32_t *)ws->reply)[2] = 0; | 99 | pack_uint32(&r, 0); |
| 100 | return 12; | 100 | pack_uint32(&r, 0); |
| 101 | return r - ws->reply; | ||
| 101 | } | 102 | } |
| 102 | return 0; | 103 | return 0; |
| 103 | } | 104 | } |
| @@ -297,10 +298,9 @@ static size_t return_peers_for_torrent_udp(struct ot_workstruct *ws, ot_torrent | |||
| 297 | if (amount > list_count) | 298 | if (amount > list_count) |
| 298 | amount = list_count; | 299 | amount = list_count; |
| 299 | 300 | ||
| 300 | *(uint32_t *)(r + 0) = htonl(OT_CLIENT_REQUEST_INTERVAL_RANDOM); | 301 | pack_uint32(&r, OT_CLIENT_REQUEST_INTERVAL_RANDOM); |
| 301 | *(uint32_t *)(r + 4) = htonl(peer_count - seed_count); | 302 | pack_uint32(&r, peer_count - seed_count); |
| 302 | *(uint32_t *)(r + 8) = htonl(seed_count); | 303 | pack_uint32(&r, seed_count); |
| 303 | r += 12; | ||
| 304 | 304 | ||
| 305 | if (amount) { | 305 | if (amount) { |
| 306 | if (amount == list_count) | 306 | if (amount == list_count) |
| @@ -400,23 +400,25 @@ size_t return_udp_scrape_for_torrent(ot_hash const hash, char *reply) { | |||
| 400 | ot_vector *torrents_list = mutex_bucket_lock_by_hash(hash); | 400 | ot_vector *torrents_list = mutex_bucket_lock_by_hash(hash); |
| 401 | ot_torrent *torrent = vector_binary_search(hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch); | 401 | ot_torrent *torrent = vector_binary_search(hash, torrents_list->data, torrents_list->size, sizeof(ot_torrent), OT_HASH_COMPARE_SIZE, &exactmatch); |
| 402 | 402 | ||
| 403 | if (!exactmatch) { | 403 | uint32_t seeders = 0, completed = 0, leechers = 0; |
| 404 | memset(reply, 0, 12); | 404 | char *r = reply; |
| 405 | } else { | ||
| 406 | uint32_t *r = (uint32_t *)reply; | ||
| 407 | 405 | ||
| 406 | if (exactmatch) { | ||
| 408 | if (clean_single_torrent(torrent)) { | 407 | if (clean_single_torrent(torrent)) { |
| 409 | vector_remove_torrent(torrents_list, torrent); | 408 | vector_remove_torrent(torrents_list, torrent); |
| 410 | memset(reply, 0, 12); | ||
| 411 | delta_torrentcount = -1; | 409 | delta_torrentcount = -1; |
| 412 | } else { | 410 | } else { |
| 413 | r[0] = htonl(torrent_seed_count(torrent)); | 411 | seeders = torrent_seed_count(torrent); |
| 414 | r[1] = htonl(torrent->down_count); | 412 | completed = torrent->down_count; |
| 415 | r[2] = htonl(torrent_peer_count(torrent) - torrent_seed_count(torrent)); | 413 | leechers = torrent_peer_count(torrent) - torrent_seed_count(torrent); |
| 416 | } | 414 | } |
| 417 | } | 415 | } |
| 418 | mutex_bucket_unlock_by_hash(hash, delta_torrentcount); | 416 | mutex_bucket_unlock_by_hash(hash, delta_torrentcount); |
| 419 | return 12; | 417 | |
| 418 | pack_uint32(&r, seeders); | ||
| 419 | pack_uint32(&r, completed); | ||
| 420 | pack_uint32(&r, leechers); | ||
| 421 | return r - reply; | ||
| 420 | } | 422 | } |
| 421 | 423 | ||
| 422 | /* Fetches scrape info for a specific torrent */ | 424 | /* Fetches scrape info for a specific torrent */ |
| @@ -485,10 +487,11 @@ size_t remove_peer_from_torrent(PROTO_FLAG proto, struct ot_workstruct *ws) { | |||
| 485 | 487 | ||
| 486 | /* Handle UDP reply */ | 488 | /* Handle UDP reply */ |
| 487 | if (proto == FLAG_UDP) { | 489 | if (proto == FLAG_UDP) { |
| 488 | ((uint32_t *)ws->reply)[2] = htonl(OT_CLIENT_REQUEST_INTERVAL_RANDOM); | 490 | char *r = ws->reply; |
| 489 | ((uint32_t *)ws->reply)[3] = htonl(peer_count - seed_count); | 491 | pack_uint32(&r, OT_CLIENT_REQUEST_INTERVAL_RANDOM); |
| 490 | ((uint32_t *)ws->reply)[4] = htonl(seed_count); | 492 | pack_uint32(&r, peer_count - seed_count); |
| 491 | ws->reply_size = 20; | 493 | pack_uint32(&r, seed_count); |
| 494 | ws->reply_size = r - ws->reply; | ||
| 492 | } | 495 | } |
| 493 | 496 | ||
| 494 | mutex_bucket_unlock_by_hash(*ws->hash, 0); | 497 | mutex_bucket_unlock_by_hash(*ws->hash, 0); |
