From 5b98dcf3a36f43bf335f6888d9515bdb614cbd6d Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 30 Mar 2024 00:34:28 +0100 Subject: [PATCH] Limit ipv6 udp replies to an amount that does not create too large UDP packets. Credits to anonymous donor --- ot_udp.c | 4 ++-- trackerlogic.c | 8 ++++++-- trackerlogic.h | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ot_udp.c b/ot_udp.c index edbaca8..8309660 100644 --- a/ot_udp.c +++ b/ot_udp.c @@ -141,9 +141,9 @@ int handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { /* We do only want to know, if it is zero */ left = inpacket[64/4] | inpacket[68/4]; - /* Limit amount of peers to 200 */ + /* Limit amount of peers to OT_MAX_PEERS_UDP */ numwant = ntohl( inpacket[92/4] ); - if (numwant > 200) numwant = 200; + if (numwant > OT_MAX_PEERS_UDP) numwant = OT_MAX_PEERS_UDP; event = ntohl( inpacket[80/4] ); 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 } /* Compiles a list of random peers for a torrent - * reply must have enough space to hold 92+6*amount bytes - * does not yet check not to return self + * Reply must have enough space to hold: + * 92 + 6 * amount bytes for TCP/IPv4 + * 92 + 18 * amount bytes for TCP/IPv6 + * 12 + 6 * amount bytes for UDP/IPv4 + * 12 + 18 * amount bytes for UDP/IPv6 + * Does not yet check not to return self */ size_t return_peers_for_torrent( struct ot_workstruct * ws, ot_torrent *torrent, size_t amount, char *reply, PROTO_FLAG proto ) { 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; } #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION ) ) +/* List of peers should fit in a single UDP packet (around 1200 bytes) */ +#ifdef WANT_V6 +#define OT_MAX_PEERS_UDP 66 +#else +#define OT_MAX_PEERS_UDP 200 +#endif + /* If WANT_MODEST_FULLSCRAPES is on, ip addresses may not fullscrape more frequently than this amount in seconds */ #define OT_MODEST_PEER_TIMEOUT (60*5)