diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ot_udp.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/ot_udp.c b/src/ot_udp.c index 9e8e3c4..2755766 100644 --- a/src/ot_udp.c +++ b/src/ot_udp.c | |||
| @@ -19,6 +19,9 @@ | |||
| 19 | #include "ot_udp.h" | 19 | #include "ot_udp.h" |
| 20 | #include "trackerlogic.h" | 20 | #include "trackerlogic.h" |
| 21 | 21 | ||
| 22 | /* BEP 15: "Up to about 74 torrents can be scraped at once" */ | ||
| 23 | #define OT_MAX_SCRAPE_UDP 74 | ||
| 24 | |||
| 22 | static uint32_t g_rijndael_round_key[44] = {0}; | 25 | static uint32_t g_rijndael_round_key[44] = {0}; |
| 23 | static volatile uint32_t g_key_of_the_hour[2] = {0}; | 26 | static volatile uint32_t g_key_of_the_hour[2] = {0}; |
| 24 | static volatile ot_time g_hour_of_the_key; | 27 | static volatile ot_time g_hour_of_the_key; |
| @@ -70,7 +73,9 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) { | |||
| 70 | uint32_t connid[2]; | 73 | uint32_t connid[2]; |
| 71 | uint32_t action; | 74 | uint32_t action; |
| 72 | uint16_t port, remoteport; | 75 | uint16_t port, remoteport; |
| 73 | size_t byte_count, scrape_count; | 76 | size_t byte_count, scrape_count, i; |
| 77 | ot_hash *hashes; | ||
| 78 | char *reply; | ||
| 74 | 79 | ||
| 75 | ssize_t result = socket_recv(serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport); | 80 | ssize_t result = socket_recv(serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport); |
| 76 | if (result <= 0) | 81 | if (result <= 0) |
| @@ -193,14 +198,20 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) { | |||
| 193 | stats_issue_event(ws, EVENT_ANNOUNCE, FLAG_UDP, ws->reply_size); | 198 | stats_issue_event(ws, EVENT_ANNOUNCE, FLAG_UDP, ws->reply_size); |
| 194 | break; | 199 | break; |
| 195 | 200 | ||
| 196 | case 2: /* This is a scrape action */ | 201 | case 2: /* This is a scrape action */ |
| 202 | scrape_count = (byte_count - 16) / sizeof(ot_hash); | ||
| 203 | if (scrape_count > OT_MAX_SCRAPE_UDP) | ||
| 204 | scrape_count = OT_MAX_SCRAPE_UDP; | ||
| 205 | |||
| 197 | outpacket[0] = htonl(2); /* scrape action */ | 206 | outpacket[0] = htonl(2); /* scrape action */ |
| 198 | outpacket[1] = inpacket[12 / 4]; | 207 | outpacket[1] = inpacket[12 / 4]; |
| 199 | 208 | ||
| 200 | for (scrape_count = 0; (scrape_count * 20 < byte_count - 16) && (scrape_count <= 74); scrape_count++) | 209 | hashes = (ot_hash *)(ws->inbuf + 16); |
| 201 | return_udp_scrape_for_torrent(*(ot_hash *)(((char *)inpacket) + 16 + 20 * scrape_count), ((char *)outpacket) + 8 + 12 * scrape_count); | 210 | reply = ws->outbuf + 8; |
| 211 | for (i = 0; i < scrape_count; ++i) | ||
| 212 | reply += return_udp_scrape_for_torrent(hashes[i], reply); | ||
| 202 | 213 | ||
| 203 | socket_send(serversocket, ws->outbuf, 8 + 12 * scrape_count, remoteip, remoteport); | 214 | socket_send(serversocket, ws->outbuf, reply - ws->outbuf, remoteip, remoteport); |
| 204 | stats_issue_event(ws, EVENT_SCRAPE, FLAG_UDP, scrape_count); | 215 | stats_issue_event(ws, EVENT_SCRAPE, FLAG_UDP, scrape_count); |
| 205 | break; | 216 | break; |
| 206 | } | 217 | } |
