diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2024-03-30 00:34:28 +0100 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2024-03-30 00:34:28 +0100 |
commit | 5b98dcf3a36f43bf335f6888d9515bdb614cbd6d (patch) | |
tree | 2b30439cc44a34bc86ddc265db68eab1e7f151b8 | |
parent | a3251ffac76ea1211d52b97ee232b8171a47c13d (diff) |
Limit ipv6 udp replies to an amount that does not create too large UDP packets. Credits to anonymous donor
-rw-r--r-- | ot_udp.c | 4 | ||||
-rw-r--r-- | trackerlogic.c | 8 | ||||
-rw-r--r-- | trackerlogic.h | 7 |
3 files changed, 15 insertions, 4 deletions
@@ -141,9 +141,9 @@ int handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { | |||
141 | /* We do only want to know, if it is zero */ | 141 | /* We do only want to know, if it is zero */ |
142 | left = inpacket[64/4] | inpacket[68/4]; | 142 | left = inpacket[64/4] | inpacket[68/4]; |
143 | 143 | ||
144 | /* Limit amount of peers to 200 */ | 144 | /* Limit amount of peers to OT_MAX_PEERS_UDP */ |
145 | numwant = ntohl( inpacket[92/4] ); | 145 | numwant = ntohl( inpacket[92/4] ); |
146 | if (numwant > 200) numwant = 200; | 146 | if (numwant > OT_MAX_PEERS_UDP) numwant = OT_MAX_PEERS_UDP; |
147 | 147 | ||
148 | event = ntohl( inpacket[80/4] ); | 148 | event = ntohl( inpacket[80/4] ); |
149 | port = *(uint16_t*)( ((char*)inpacket) + 96 ); | 149 | port = *(uint16_t*)( ((char*)inpacket) + 96 ); |
diff --git a/trackerlogic.c b/trackerlogic.c index 719f8a2..47e0085 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -259,8 +259,12 @@ static size_t return_peers_selection( struct ot_workstruct *ws, ot_peerlist *pee | |||
259 | } | 259 | } |
260 | 260 | ||
261 | /* Compiles a list of random peers for a torrent | 261 | /* Compiles a list of random peers for a torrent |
262 | * reply must have enough space to hold 92+6*amount bytes | 262 | * Reply must have enough space to hold: |
263 | * does not yet check not to return self | 263 | * 92 + 6 * amount bytes for TCP/IPv4 |
264 | * 92 + 18 * amount bytes for TCP/IPv6 | ||
265 | * 12 + 6 * amount bytes for UDP/IPv4 | ||
266 | * 12 + 18 * amount bytes for UDP/IPv6 | ||
267 | * Does not yet check not to return self | ||
264 | */ | 268 | */ |
265 | size_t return_peers_for_torrent( struct ot_workstruct * ws, ot_torrent *torrent, size_t amount, char *reply, PROTO_FLAG proto ) { | 269 | size_t return_peers_for_torrent( struct ot_workstruct * ws, ot_torrent *torrent, size_t amount, char *reply, PROTO_FLAG proto ) { |
266 | ot_peerlist *peer_list = torrent->peer_list; | 270 | ot_peerlist *peer_list = torrent->peer_list; |
diff --git a/trackerlogic.h b/trackerlogic.h index ef59179..f235de8 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -44,6 +44,13 @@ typedef struct { ot_ip6 address; int bits; } | |||
44 | 44 | ||
45 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION ) ) | 45 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION ) ) |
46 | 46 | ||
47 | /* List of peers should fit in a single UDP packet (around 1200 bytes) */ | ||
48 | #ifdef WANT_V6 | ||
49 | #define OT_MAX_PEERS_UDP 66 | ||
50 | #else | ||
51 | #define OT_MAX_PEERS_UDP 200 | ||
52 | #endif | ||
53 | |||
47 | /* If WANT_MODEST_FULLSCRAPES is on, ip addresses may not | 54 | /* If WANT_MODEST_FULLSCRAPES is on, ip addresses may not |
48 | fullscrape more frequently than this amount in seconds */ | 55 | fullscrape more frequently than this amount in seconds */ |
49 | #define OT_MODEST_PEER_TIMEOUT (60*5) | 56 | #define OT_MODEST_PEER_TIMEOUT (60*5) |