diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2015-04-08 11:20:00 -0700 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-12-14 13:43:53 +0100 |
commit | 10b88be79856ee7ee66f69705c16b335941e396e (patch) | |
tree | 29766c79315ae9c569321e2ee607107be948dd5d /src/net.cpp | |
parent | 06c6a584635bb42c511baf505cebd7cdf77b89e9 (diff) | |
download | bitcoin-10b88be79856ee7ee66f69705c16b335941e396e.tar.xz |
Replace trickle nodes with per-node/message Poisson delays
We used to have a trickle node, a node which was chosen in each iteration of
the send loop that was privileged and allowed to send out queued up non-time
critical messages. Since the removal of the fixed sleeps in the network code,
this resulted in fast and attackable treatment of such broadcasts.
This pull request changes the 3 remaining trickle use cases by random delays:
* Local address broadcast (while also removing the the wiping of the seen filter)
* Address relay
* Inv relay (for transactions; blocks are always relayed immediately)
The code is based on older commits by Patrick Strateman.
Github-Pull: #7125
Rebased-From: 5400ef6bcb9d243b2b21697775aa6491115420f3
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/net.cpp b/src/net.cpp index e4db60aec4..3796256b4d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -36,6 +36,8 @@ #include <boost/filesystem.hpp> #include <boost/thread.hpp> +#include <math.h> + // Dump addresses to peers.dat every 15 minutes (900s) #define DUMP_ADDRESSES_INTERVAL 900 @@ -1720,11 +1722,6 @@ void ThreadMessageHandler() } } - // Poll the connected nodes for messages - CNode* pnodeTrickle = NULL; - if (!vNodesCopy.empty()) - pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())]; - bool fSleep = true; BOOST_FOREACH(CNode* pnode, vNodesCopy) @@ -1755,7 +1752,7 @@ void ThreadMessageHandler() { TRY_LOCK(pnode->cs_vSend, lockSend); if (lockSend) - g_signals.SendMessages(pnode, pnode == pnodeTrickle || pnode->fWhitelisted); + g_signals.SendMessages(pnode); } boost::this_thread::interruption_point(); } @@ -2371,6 +2368,9 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa nStartingHeight = -1; filterInventoryKnown.reset(); fGetAddr = false; + nNextLocalAddrSend = 0; + nNextAddrSend = 0; + nNextInvSend = 0; fRelayTxes = false; pfilter = new CBloomFilter(); nPingNonceSent = 0; @@ -2615,3 +2615,7 @@ void DumpBanlist() LogPrint("net", "Flushed %d banned node ips/subnets to banlist.dat %dms\n", banmap.size(), GetTimeMillis() - nStart); } + +int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) { + return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5); +} |