Limit ipv6 udp replies to an amount that does not create too large UDP packets. Credits to anonymous donor

master
Dirk Engling 9 months ago
parent a3251ffac7
commit 5b98dcf3a3

@ -141,9 +141,9 @@ int handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
/* We do only want to know, if it is zero */ /* We do only want to know, if it is zero */
left = inpacket[64/4] | inpacket[68/4]; 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] ); 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] ); event = ntohl( inpacket[80/4] );
port = *(uint16_t*)( ((char*)inpacket) + 96 ); port = *(uint16_t*)( ((char*)inpacket) + 96 );

@ -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 /* Compiles a list of random peers for a torrent
* reply must have enough space to hold 92+6*amount bytes * Reply must have enough space to hold:
* does not yet check not to return self * 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 ) { 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; ot_peerlist *peer_list = torrent->peer_list;

@ -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 ) ) #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 /* If WANT_MODEST_FULLSCRAPES is on, ip addresses may not
fullscrape more frequently than this amount in seconds */ fullscrape more frequently than this amount in seconds */
#define OT_MODEST_PEER_TIMEOUT (60*5) #define OT_MODEST_PEER_TIMEOUT (60*5)

Loading…
Cancel
Save