Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 2,735 Lines • ▼ Show 20 Lines | for (auto &&pnode : vNodes) { | ||||
if (pnode->GetId() == id) { | if (pnode->GetId() == id) { | ||||
found = pnode; | found = pnode; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return found != nullptr && NodeFullyConnected(found) && func(found); | return found != nullptr && NodeFullyConnected(found) && func(found); | ||||
} | } | ||||
int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) { | int64_t CConnman::PoissonNextSendInbound(int64_t now, | ||||
return nNow + int64_t(log1p(GetRand(1ULL << 48) * | int average_interval_seconds) { | ||||
if (m_next_send_inv_to_incoming < now) { | |||||
// If this function were called from multiple threads simultaneously | |||||
// it would be possible that both update the next send variable, and | |||||
// return a different result to their caller. This is not possible in | |||||
// practice as only the net processing thread invokes this function. | |||||
m_next_send_inv_to_incoming = | |||||
PoissonNextSend(now, average_interval_seconds); | |||||
} | |||||
return m_next_send_inv_to_incoming; | |||||
} | |||||
int64_t PoissonNextSend(int64_t now, int average_interval_seconds) { | |||||
return now + int64_t(log1p(GetRand(1ULL << 48) * | |||||
-0.0000000000000035527136788 /* -1/2^48 */) * | -0.0000000000000035527136788 /* -1/2^48 */) * | ||||
average_interval_seconds * -1000000.0 + | average_interval_seconds * -1000000.0 + | ||||
0.5); | 0.5); | ||||
} | } | ||||
CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const { | CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const { | ||||
return CSipHasher(nSeed0, nSeed1).Write(id); | return CSipHasher(nSeed0, nSeed1).Write(id); | ||||
} | } | ||||
uint64_t CConnman::CalculateKeyedNetGroup(const CAddress &ad) const { | uint64_t CConnman::CalculateKeyedNetGroup(const CAddress &ad) const { | ||||
std::vector<uint8_t> vchNetGroup(ad.GetGroup()); | std::vector<uint8_t> vchNetGroup(ad.GetGroup()); | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |