diff options
author | Dirk Engling <erdgeist@erdgeist.org> | 2021-04-20 03:48:50 +0200 |
---|---|---|
committer | Dirk Engling <erdgeist@erdgeist.org> | 2021-04-20 03:48:50 +0200 |
commit | 616119ee22fec0f0db7a4c89a6a8f649d5926891 (patch) | |
tree | 0b32171a1f16b389d80f050838aa52b5e38f0cce /trackerlogic.h | |
parent | 0695b488708f3beaa17456c2b132b211a6fb5332 (diff) |
Turn random() to nrand48 in inner loop where it is not cryptographically relevant to avoid futex storm. Thanks and credits to Bart Smienk
Diffstat (limited to 'trackerlogic.h')
-rw-r--r-- | trackerlogic.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/trackerlogic.h b/trackerlogic.h index 721ba6e..33dccbe 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <sys/time.h> | 10 | #include <sys/time.h> |
11 | #include <time.h> | 11 | #include <time.h> |
12 | #include <stdint.h> | 12 | #include <stdint.h> |
13 | #include <stdlib.h> | ||
13 | 14 | ||
14 | typedef uint8_t ot_hash[20]; | 15 | typedef uint8_t ot_hash[20]; |
15 | typedef time_t ot_time; | 16 | typedef time_t ot_time; |
@@ -34,7 +35,7 @@ typedef struct { ot_ip6 address; int bits; } | |||
34 | #define OT_TORRENT_TIMEOUT_HOURS 24 | 35 | #define OT_TORRENT_TIMEOUT_HOURS 24 |
35 | #define OT_TORRENT_TIMEOUT (60*OT_TORRENT_TIMEOUT_HOURS) | 36 | #define OT_TORRENT_TIMEOUT (60*OT_TORRENT_TIMEOUT_HOURS) |
36 | 37 | ||
37 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) | 38 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION ) ) |
38 | 39 | ||
39 | /* If WANT_MODEST_FULLSCRAPES is on, ip addresses may not | 40 | /* If WANT_MODEST_FULLSCRAPES is on, ip addresses may not |
40 | fullscrape more frequently than this amount in seconds */ | 41 | fullscrape more frequently than this amount in seconds */ |
@@ -131,6 +132,10 @@ struct ot_workstruct { | |||
131 | ssize_t header_size; | 132 | ssize_t header_size; |
132 | char *reply; | 133 | char *reply; |
133 | ssize_t reply_size; | 134 | ssize_t reply_size; |
135 | |||
136 | /* Entropy state for rand48 function so that threads don't need to acquire mutexes for | ||
137 | global random() or arc4random() state, which causes heavy load on linuxes */ | ||
138 | uint16_t rand48_state[3]; | ||
134 | }; | 139 | }; |
135 | 140 | ||
136 | /* | 141 | /* |