@@ -1792,21 +1792,21 @@ void CConnman::DandelionShuffle() {
1792
1792
LogPrint (BCLog::DANDELION, " After Dandelion shuffle:\n %s" , GetDandelionRoutingDataDebugString ());
1793
1793
}
1794
1794
1795
- void CConnman::ThreadDandelionShuffle () {
1796
- auto current_time = GetTime<std::chrono::microseconds>();
1797
- auto next_dandelion_shuffle = PoissonNextSend (current_time, DANDELION_SHUFFLE_INTERVAL);
1795
+ void CConnman::CheckDandelionShuffle ()
1796
+ {
1797
+ {
1798
+ LOCK (cs_vNodes);
1799
+ if (!vNodes.size ())
1800
+ return ;
1801
+ }
1798
1802
1799
- while (!interruptNet) {
1800
- current_time = GetTime<std::chrono::microseconds>();
1801
- if (current_time > next_dandelion_shuffle) {
1802
- DandelionShuffle ();
1803
- next_dandelion_shuffle = PoissonNextSend (current_time, DANDELION_SHUFFLE_INTERVAL);
1804
- // Sleep until the next shuffle time
1805
- auto sleep_ms = std::chrono::duration_cast<std::chrono::milliseconds>((next_dandelion_shuffle - current_time) / 1000 );
1806
- if (!interruptNet.sleep_for (sleep_ms)) {
1807
- return ;
1808
- }
1809
- }
1803
+ // ! next_dandelion_shuffle static to avoid needing a global
1804
+ auto current_time = GetTime<std::chrono::milliseconds>();
1805
+ static auto next_dandelion_shuffle = PoissonNextSend (current_time, DANDELION_SHUFFLE_INTERVAL);
1806
+
1807
+ if (current_time > next_dandelion_shuffle) {
1808
+ DandelionShuffle ();
1809
+ next_dandelion_shuffle = PoissonNextSend (current_time, DANDELION_SHUFFLE_INTERVAL);
1810
1810
}
1811
1811
}
1812
1812
@@ -2927,9 +2927,6 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
2927
2927
std::thread (&util::TraceThread, " i2paccept" , [this ] { ThreadI2PAcceptIncoming (); });
2928
2928
}
2929
2929
2930
- // Dandelion shuffle
2931
- threadDandelionShuffle = std::thread (&util::TraceThread, " dandelion" , [this ] { ThreadDandelionShuffle (); });
2932
-
2933
2930
// Dump network addresses
2934
2931
scheduler.scheduleEvery ([this ] { DumpAddresses (); }, DUMP_PEERS_INTERVAL);
2935
2932
@@ -2977,9 +2974,8 @@ void CConnman::Interrupt()
2977
2974
2978
2975
void CConnman::StopThreads ()
2979
2976
{
2980
- if (threadI2PAcceptIncoming.joinable ()) {
2977
+ if (threadI2PAcceptIncoming.joinable ())
2981
2978
threadI2PAcceptIncoming.join ();
2982
- }
2983
2979
if (threadMessageHandler.joinable ())
2984
2980
threadMessageHandler.join ();
2985
2981
if (threadOpenConnections.joinable ())
@@ -2990,8 +2986,6 @@ void CConnman::StopThreads()
2990
2986
threadDNSAddressSeed.join ();
2991
2987
if (threadSocketHandler.joinable ())
2992
2988
threadSocketHandler.join ();
2993
- if (threadDandelionShuffle.joinable ())
2994
- threadDandelionShuffle.join ();
2995
2989
}
2996
2990
2997
2991
void CConnman::StopNodes ()
0 commit comments