@@ -84,9 +84,6 @@ struct _HostCInternal {
8484 /* Lock protecting parts of shimSharedMemBlock. */
8585 ShimShmemHostLock * shimShmemHostLock ;
8686
87- /* random stream */
88- Random * random ;
89-
9087#ifdef USE_PERF_TIMERS
9188 /* track the time spent executing this host */
9289 GTimer * executionTimer ;
@@ -190,7 +187,6 @@ void hostc_setup(HostCInternal* host, DNS* dns, gulong rawCPUFreq, const gchar*
190187 g_mkdir_with_parents (host -> dataDirPath , 0775 );
191188 }
192189
193- host -> random = random_new (host -> params .nodeSeed );
194190 host -> cpu = cpu_new (host -> params .cpuFrequency , rawCPUFreq , host -> params .cpuThreshold ,
195191 host -> params .cpuPrecision );
196192
@@ -295,10 +291,6 @@ void hostc_shutdown(HostCInternal* host) {
295291 tracker_free (host -> tracker );
296292 }
297293
298- if (host -> random ) {
299- random_free (host -> random );
300- }
301-
302294 if (host -> params .pcapDir ) g_free ((gchar * )host -> params .pcapDir );
303295
304296 if (host -> dataDirPath ) {
@@ -459,11 +451,6 @@ in_addr_t hostc_getDefaultIP(HostCInternal* host) {
459451 return address_toNetworkIP (host -> defaultAddress );
460452}
461453
462- Random * hostc_getRandom (HostCInternal * host ) {
463- MAGIC_ASSERT (host );
464- return host -> random ;
465- }
466-
467454gboolean hostc_autotuneReceiveBuffer (HostCInternal * host ) {
468455 MAGIC_ASSERT (host );
469456 return host -> params .autotuneRecvBuf ;
@@ -596,8 +583,9 @@ in_port_t _hostc_incrementPort(in_port_t port, in_port_t port_on_overflow) {
596583 return htons (val );
597584}
598585
599- static in_port_t _hostc_getRandomPort (HostCInternal * host ) {
600- gdouble randomFraction = random_nextDouble (host -> random );
586+ static in_port_t _hostc_getRandomPort (const Host * rhost ) {
587+ HostCInternal * host = host_internal (rhost );
588+ gdouble randomFraction = host_rngDouble (rhost );
601589 gdouble numPotentialPorts = (gdouble )(UINT16_MAX - MIN_RANDOM_PORT );
602590
603591 gdouble randomPick = round (randomFraction * numPotentialPorts );
@@ -610,8 +598,9 @@ static in_port_t _hostc_getRandomPort(HostCInternal* host) {
610598 return htons (randomHostPort );
611599}
612600
613- in_port_t hostc_getRandomFreePort (HostCInternal * host , ProtocolType type , in_addr_t interfaceIP ,
601+ in_port_t hostc_getRandomFreePort (const Host * rhost , ProtocolType type , in_addr_t interfaceIP ,
614602 in_addr_t peerIP , in_port_t peerPort ) {
603+ HostCInternal * host = host_internal (rhost );
615604 MAGIC_ASSERT (host );
616605
617606 /* we need a random port that is free everywhere we need it to be.
@@ -622,7 +611,7 @@ in_port_t hostc_getRandomFreePort(HostCInternal* host, ProtocolType type, in_add
622611 /* if choosing randomly doesn't succeed within 10 tries, then we have already
623612 * allocated a lot of ports (>90% on average). then we fall back to linear search. */
624613 for (guint i = 0 ; i < 10 ; i ++ ) {
625- in_port_t randomPort = _hostc_getRandomPort (host );
614+ in_port_t randomPort = _hostc_getRandomPort (rhost );
626615
627616 /* this will check all interfaces in the case of INADDR_ANY */
628617 if (hostc_isInterfaceAvailable (host , type , interfaceIP , randomPort , peerIP , peerPort )) {
@@ -633,7 +622,7 @@ in_port_t hostc_getRandomFreePort(HostCInternal* host, ProtocolType type, in_add
633622 /* now if we tried too many times and still don't have a port, fall back
634623 * to a linear search to make sure we get a free port if we have one.
635624 * but start from a random port instead of the min. */
636- in_port_t start = _hostc_getRandomPort (host );
625+ in_port_t start = _hostc_getRandomPort (rhost );
637626 in_port_t next = _hostc_incrementPort (start , htons (MIN_RANDOM_PORT ));
638627 while (next != start ) {
639628 /* this will check all interfaces in the case of INADDR_ANY */
0 commit comments