#ifndef BITCOIN_NET_H
#define BITCOIN_NET_H
-#include <limits>
-#include <deque>
-#ifndef Q_MOC_RUN
-#include <boost/array.hpp>
-#include <boost/foreach.hpp>
-#endif
+#include "mruset.h"
+#include "netbase.h"
+#include "addrman.h"
+#include "hash.h"
+#include "streams.h"
+
#include <openssl/rand.h>
#ifndef WIN32
#include <arpa/inet.h>
#endif
-#include "mruset.h"
-#include "netbase.h"
-#include "protocol.h"
-#include "addrman.h"
-#include "hash.h"
+#include <limits>
+#include <deque>
+
class CRequestTracker;
class CNode;
LOCAL_MAX
};
+
+bool IsPeerAddrLocalGood(CNode *pnode);
+void AdvertiseLocal(CNode *pnode);
void SetLimited(enum Network net, bool fLimited = true);
bool IsLimited(enum Network net);
bool IsLimited(const CNetAddr& addr);
enum
{
MSG_TX = 1,
- MSG_BLOCK,
+ MSG_BLOCK
};
class CRequestTracker
THREAD_MINTER,
THREAD_SCRIPTCHECK,
THREAD_NTP,
+ THREAD_IPCOLLECTOR,
THREAD_MAX
};
extern bool fClient;
extern bool fDiscover;
+extern bool fNoListen;
+
+extern bool fDiscover;
extern uint64_t nLocalServices;
extern uint64_t nLocalHostNonce;
extern CAddress addrSeenByPeer;
-extern boost::array<int, THREAD_MAX> vnThreadsRunning;
+extern std::array<int, THREAD_MAX> vnThreadsRunning;
extern CAddrMan addrman;
extern std::vector<CNode*> vNodes;
bool fGetAddr;
std::set<uint256> setKnown;
uint256 hashCheckpointKnown; // ppcoin: known sent sync-checkpoint
+ int64_t nNextAddrSend;
+ int64_t nNextLocalAddrSend;
+ int64_t nNextInvSend;
// inventory based relay
mruset<CInv> setInventoryKnown;
nHeaderStart = -1;
nMessageStart = std::numeric_limits<uint32_t>::max();
addr = addrIn;
- addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
+ addrName = addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn;
nVersion = 0;
- strSubVer = "";
+ strSubVer.clear();
fOneShot = false;
fClient = false; // set by version message
fInbound = fInboundIn;
pindexLastGetBlocksBegin = 0;
hashLastGetBlocksEnd = 0;
nStartingHeight = -1;
+ nNextLocalAddrSend = 0;
+ nNextAddrSend = 0;
+ nNextInvSend = 0;
fStartSync = false;
fGetAddr = false;
nMisbehavior = 0;
return;
}
- if (nHeaderStart < 0)
+ if (nHeaderStart < 0) {
+ LEAVE_CRITICAL_SECTION(cs_vSend);
return;
+ }
// Set the size
uint32_t nSize = (uint32_t) vSend.size() - nMessageStart;
}
}
- template<typename T1>
- void PushMessage(const char* pszCommand, const T1& a1)
- {
- try
- {
- BeginMessage(pszCommand);
- vSend << a1;
- EndMessage();
- }
- catch (...)
- {
- AbortMessage();
- throw;
- }
- }
-
- template<typename T1, typename T2>
- void PushMessage(const char* pszCommand, const T1& a1, const T2& a2)
- {
- try
- {
- BeginMessage(pszCommand);
- vSend << a1 << a2;
- EndMessage();
- }
- catch (...)
- {
- AbortMessage();
- throw;
- }
- }
-
- template<typename T1, typename T2, typename T3>
- void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3)
- {
- try
- {
- BeginMessage(pszCommand);
- vSend << a1 << a2 << a3;
- EndMessage();
- }
- catch (...)
- {
- AbortMessage();
- throw;
- }
- }
-
- template<typename T1, typename T2, typename T3, typename T4>
- void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4)
- {
- try
- {
- BeginMessage(pszCommand);
- vSend << a1 << a2 << a3 << a4;
- EndMessage();
- }
- catch (...)
- {
- AbortMessage();
- throw;
- }
- }
-
- template<typename T1, typename T2, typename T3, typename T4, typename T5>
- void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5)
- {
- try
- {
- BeginMessage(pszCommand);
- vSend << a1 << a2 << a3 << a4 << a5;
- EndMessage();
- }
- catch (...)
- {
- AbortMessage();
- throw;
- }
- }
-
- template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
- void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6)
- {
- try
- {
- BeginMessage(pszCommand);
- vSend << a1 << a2 << a3 << a4 << a5 << a6;
- EndMessage();
- }
- catch (...)
- {
- AbortMessage();
- throw;
- }
- }
-
- template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
- void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7)
- {
- try
- {
- BeginMessage(pszCommand);
- vSend << a1 << a2 << a3 << a4 << a5 << a6 << a7;
- EndMessage();
- }
- catch (...)
- {
- AbortMessage();
- throw;
- }
- }
-
- template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
- void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8)
- {
- try
- {
- BeginMessage(pszCommand);
- vSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8;
- EndMessage();
- }
- catch (...)
- {
- AbortMessage();
- throw;
- }
- }
-
- template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
- void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8, const T9& a9)
+ template<typename ...Args>
+ void PushMessage(const char* pszCommand, const Args&... args)
{
try
{
BeginMessage(pszCommand);
- vSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9;
+ (vSend << ... << args);
EndMessage();
}
catch (...)
}
}
-
void PushRequest(const char* pszCommand,
void (*fn)(void*, CDataStream&), void* param1)
{
// Put on lists to offer to the other nodes
{
LOCK(cs_vNodes);
- BOOST_FOREACH(CNode* pnode, vNodes)
+ for (CNode* pnode : vNodes)
pnode->PushInventory(inv);
}
}
void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataStream& ss);
+/** Return a timestamp in the future (in microseconds) for exponentially distributed events. */
+int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds);
+
#endif