Browse Source

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

master
Dirk Engling 3 months ago
parent
commit
5b98dcf3a3
  1. 4
      ot_udp.c
  2. 8
      trackerlogic.c
  3. 7
      trackerlogic.h

4
ot_udp.c

@ -141,9 +141,9 @@ int handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { @@ -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 );

8
trackerlogic.c

@ -259,8 +259,12 @@ static size_t return_peers_selection( struct ot_workstruct *ws, ot_peerlist *pee @@ -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;

7
trackerlogic.h

@ -44,6 +44,13 @@ typedef struct { ot_ip6 address; int bits; } @@ -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)

Loading…
Cancel
Save