From 616119ee22fec0f0db7a4c89a6a8f649d5926891 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 20 Apr 2021 03:48:50 +0200 Subject: Turn random() to nrand48 in inner loop where it is not cryptographically relevant to avoid futex storm. Thanks and credits to Bart Smienk --- trackerlogic.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'trackerlogic.h') diff --git a/trackerlogic.h b/trackerlogic.h index 721ba6e..33dccbe 100644 --- a/trackerlogic.h +++ b/trackerlogic.h @@ -10,6 +10,7 @@ #include #include #include +#include typedef uint8_t ot_hash[20]; typedef time_t ot_time; @@ -34,7 +35,7 @@ typedef struct { ot_ip6 address; int bits; } #define OT_TORRENT_TIMEOUT_HOURS 24 #define OT_TORRENT_TIMEOUT (60*OT_TORRENT_TIMEOUT_HOURS) -#define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % 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 ) ) /* If WANT_MODEST_FULLSCRAPES is on, ip addresses may not fullscrape more frequently than this amount in seconds */ @@ -131,6 +132,10 @@ struct ot_workstruct { ssize_t header_size; char *reply; ssize_t reply_size; + + /* Entropy state for rand48 function so that threads don't need to acquire mutexes for + global random() or arc4random() state, which causes heavy load on linuxes */ + uint16_t rand48_state[3]; }; /* -- cgit v1.2.3