@@ -603,8 +603,8 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
603
603
stats.minFeeFilter = 0 ;
604
604
}
605
605
606
- stats. m_ping_usec = m_last_ping_time;
607
- stats. m_min_ping_usec = m_min_ping_time;
606
+ X ( m_last_ping_time) ;
607
+ X ( m_min_ping_time) ;
608
608
609
609
// Leave string empty if addrLocal invalid (not filled in yet)
610
610
CService addrLocalUnlocked = GetAddrLocal ();
@@ -1761,12 +1761,11 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1761
1761
}
1762
1762
1763
1763
// Initiate network connections
1764
- auto start = GetTime<std::chrono::seconds >();
1764
+ auto start = GetTime<std::chrono::microseconds >();
1765
1765
1766
1766
// Minimum time before next feeler connection (in microseconds).
1767
-
1768
- int64_t nNextFeeler = PoissonNextSend (count_microseconds (start), FEELER_INTERVAL);
1769
- int64_t nNextExtraBlockRelay = PoissonNextSend (count_microseconds (start), EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
1767
+ auto next_feeler = PoissonNextSend (start, FEELER_INTERVAL);
1768
+ auto next_extra_block_relay = PoissonNextSend (start, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
1770
1769
const bool dnsseed = gArgs .GetBoolArg (" -dnsseed" , DEFAULT_DNSSEED);
1771
1770
bool add_fixed_seeds = gArgs .GetBoolArg (" -fixedseeds" , DEFAULT_FIXEDSEEDS);
1772
1771
@@ -1849,7 +1848,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1849
1848
}
1850
1849
1851
1850
ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
1852
- int64_t nTime = GetTimeMicros ();
1851
+ auto now = GetTime<std::chrono::microseconds> ();
1853
1852
bool anchor = false ;
1854
1853
bool fFeeler = false ;
1855
1854
@@ -1861,7 +1860,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1861
1860
// GetTryNewOutboundPeer() gets set when a stale tip is detected, so we
1862
1861
// try opening an additional OUTBOUND_FULL_RELAY connection. If none of
1863
1862
// these conditions are met, check to see if it's time to try an extra
1864
- // block-relay-only peer (to confirm our tip is current, see below) or the nNextFeeler
1863
+ // block-relay-only peer (to confirm our tip is current, see below) or the next_feeler
1865
1864
// timer to decide if we should open a FEELER.
1866
1865
1867
1866
if (!m_anchors.empty () && (nOutboundBlockRelay < m_max_outbound_block_relay)) {
@@ -1873,7 +1872,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1873
1872
conn_type = ConnectionType::BLOCK_RELAY;
1874
1873
} else if (GetTryNewOutboundPeer ()) {
1875
1874
// OUTBOUND_FULL_RELAY
1876
- } else if (nTime > nNextExtraBlockRelay && m_start_extra_block_relay_peers) {
1875
+ } else if (now > next_extra_block_relay && m_start_extra_block_relay_peers) {
1877
1876
// Periodically connect to a peer (using regular outbound selection
1878
1877
// methodology from addrman) and stay connected long enough to sync
1879
1878
// headers, but not much else.
@@ -1895,10 +1894,10 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1895
1894
// Because we can promote these connections to block-relay-only
1896
1895
// connections, they do not get their own ConnectionType enum
1897
1896
// (similar to how we deal with extra outbound peers).
1898
- nNextExtraBlockRelay = PoissonNextSend (nTime , EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
1897
+ next_extra_block_relay = PoissonNextSend (now , EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
1899
1898
conn_type = ConnectionType::BLOCK_RELAY;
1900
- } else if (nTime > nNextFeeler ) {
1901
- nNextFeeler = PoissonNextSend (nTime , FEELER_INTERVAL);
1899
+ } else if (now > next_feeler ) {
1900
+ next_feeler = PoissonNextSend (now , FEELER_INTERVAL);
1902
1901
conn_type = ConnectionType::FEELER;
1903
1902
fFeeler = true ;
1904
1903
} else {
@@ -2983,20 +2982,21 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
2983
2982
return found != nullptr && NodeFullyConnected (found) && func (found);
2984
2983
}
2985
2984
2986
- int64_t CConnman::PoissonNextSendInbound (int64_t now, int average_interval_seconds )
2985
+ std::chrono::microseconds CConnman::PoissonNextSendInbound (std::chrono::microseconds now, std::chrono::seconds average_interval )
2987
2986
{
2988
- if (m_next_send_inv_to_incoming < now) {
2987
+ if (m_next_send_inv_to_incoming. load () < now) {
2989
2988
// If this function were called from multiple threads simultaneously
2990
2989
// it would possible that both update the next send variable, and return a different result to their caller.
2991
2990
// This is not possible in practice as only the net processing thread invokes this function.
2992
- m_next_send_inv_to_incoming = PoissonNextSend (now, average_interval_seconds );
2991
+ m_next_send_inv_to_incoming = PoissonNextSend (now, average_interval );
2993
2992
}
2994
2993
return m_next_send_inv_to_incoming;
2995
2994
}
2996
2995
2997
- int64_t PoissonNextSend (int64_t now, int average_interval_seconds )
2996
+ std::chrono::microseconds PoissonNextSend (std::chrono::microseconds now, std::chrono::seconds average_interval )
2998
2997
{
2999
- return now + (int64_t )(log1p (GetRand (1ULL << 48 ) * -0.0000000000000035527136788 /* -1/2^48 */ ) * average_interval_seconds * -1000000.0 + 0.5 );
2998
+ double unscaled = -log1p (GetRand (1ULL << 48 ) * -0.0000000000000035527136788 /* -1/2^48 */ );
2999
+ return now + std::chrono::duration_cast<std::chrono::microseconds>(unscaled * average_interval + 0 .5us);
3000
3000
}
3001
3001
3002
3002
CSipHasher CConnman::GetDeterministicRandomizer (uint64_t id) const
0 commit comments