X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fnet.h;h=bede389de0c3f9b873b1149fc15732a3fc6964bd;hb=60cf27d9500deb3bc80ffa8ce5dc3e8284a4c658;hp=7306d136b63967e40345c63280bf43322dc9c042;hpb=92948780909cc9e3349409d6102dbe5adf1d5a10;p=novacoin.git diff --git a/src/net.h b/src/net.h index 7306d13..bede389 100644 --- a/src/net.h +++ b/src/net.h @@ -5,28 +5,28 @@ #ifndef BITCOIN_NET_H #define BITCOIN_NET_H -#include -#ifndef Q_MOC_RUN -#include -#include -#endif +#include "mruset.h" +#include "netbase.h" +#include "addrman.h" +#include "hash.h" + #include #ifndef WIN32 #include #endif -#include "mruset.h" -#include "netbase.h" -#include "protocol.h" -#include "addrman.h" -#include "hash.h" +#include +#include + class CRequestTracker; class CNode; class CBlockIndex; extern int nBestHeight; +const uint16_t nSocksDefault = 9050; +const uint16_t nPortZero = 0; inline uint64_t ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); } @@ -51,7 +51,6 @@ enum LOCAL_NONE, // unknown LOCAL_IF, // address a local interface listens on LOCAL_BIND, // address explicit bound to - LOCAL_UPNP, // address reported by UPnP LOCAL_IRC, // address reported by IRC (deprecated) LOCAL_HTTP, // address reported by whatismyip.com and similar LOCAL_MANUAL, // address explicitly specified (-externalip=) @@ -59,6 +58,9 @@ enum 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); @@ -75,7 +77,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL); enum { MSG_TX = 1, - MSG_BLOCK, + MSG_BLOCK }; class CRequestTracker @@ -104,24 +106,27 @@ enum threadId THREAD_OPENCONNECTIONS, THREAD_MESSAGEHANDLER, THREAD_RPCLISTENER, - THREAD_UPNP, THREAD_DNSSEED, THREAD_ADDEDCONNECTIONS, THREAD_DUMPADDRESS, THREAD_RPCHANDLER, THREAD_MINTER, THREAD_SCRIPTCHECK, + THREAD_NTP, + THREAD_IPCOLLECTOR, THREAD_MAX }; extern bool fClient; extern bool fDiscover; -extern bool fUseUPnP; +extern bool fNoListen; + +extern bool fDiscover; extern uint64_t nLocalServices; extern uint64_t nLocalHostNonce; extern CAddress addrSeenByPeer; -extern boost::array vnThreadsRunning; +extern std::array vnThreadsRunning; extern CAddrMan addrman; extern std::vector vNodes; @@ -215,6 +220,9 @@ public: bool fGetAddr; std::set setKnown; uint256 hashCheckpointKnown; // ppcoin: known sent sync-checkpoint + int64_t nNextAddrSend; + int64_t nNextLocalAddrSend; + int64_t nNextInvSend; // inventory based relay mruset setInventoryKnown; @@ -233,11 +241,11 @@ public: nLastSendEmpty = GetTime(); nTimeConnected = GetTime(); nHeaderStart = -1; - nMessageStart = UINT_MAX; + nMessageStart = std::numeric_limits::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; @@ -250,6 +258,9 @@ public: pindexLastGetBlocksBegin = 0; hashLastGetBlocksEnd = 0; nStartingHeight = -1; + nNextLocalAddrSend = 0; + nNextAddrSend = 0; + nNextInvSend = 0; fStartSync = false; fGetAddr = false; nMisbehavior = 0; @@ -265,8 +276,7 @@ public: { if (hSocket != INVALID_SOCKET) { - closesocket(hSocket); - hSocket = INVALID_SOCKET; + CloseSocket(hSocket); } } @@ -375,7 +385,7 @@ public: return; vSend.resize(nHeaderStart); nHeaderStart = -1; - nMessageStart = UINT_MAX; + nMessageStart = std::numeric_limits::max(); LEAVE_CRITICAL_SECTION(cs_vSend); if (fDebug) @@ -391,8 +401,10 @@ public: return; } - if (nHeaderStart < 0) + if (nHeaderStart < 0) { + LEAVE_CRITICAL_SECTION(cs_vSend); return; + } // Set the size uint32_t nSize = (uint32_t) vSend.size() - nMessageStart; @@ -410,7 +422,7 @@ public: } nHeaderStart = -1; - nMessageStart = UINT_MAX; + nMessageStart = std::numeric_limits::max(); LEAVE_CRITICAL_SECTION(cs_vSend); } @@ -444,93 +456,13 @@ public: } } - template - void PushMessage(const char* pszCommand, const T1& a1) - { - try - { - BeginMessage(pszCommand); - vSend << a1; - EndMessage(); - } - catch (...) - { - AbortMessage(); - throw; - } - } - - template - void PushMessage(const char* pszCommand, const T1& a1, const T2& a2) - { - try - { - BeginMessage(pszCommand); - vSend << a1 << a2; - EndMessage(); - } - catch (...) - { - AbortMessage(); - throw; - } - } - - template - 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 - 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 - 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 - void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6) + template + void PushMessage(const char* pszCommand, const Args&... args) { try { BeginMessage(pszCommand); - vSend << a1 << a2 << a3 << a4 << a5 << a6; + (vSend << ... << args); EndMessage(); } catch (...) @@ -540,55 +472,6 @@ public: } } - template - 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 - 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 - 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) - { - try - { - BeginMessage(pszCommand); - vSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9; - EndMessage(); - } - catch (...) - { - AbortMessage(); - throw; - } - } - - void PushRequest(const char* pszCommand, void (*fn)(void*, CDataStream&), void* param1) { @@ -674,7 +557,7 @@ inline void RelayInventory(const CInv& inv) // Put on lists to offer to the other nodes { LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) + for (CNode* pnode : vNodes) pnode->PushInventory(inv); } } @@ -684,4 +567,7 @@ void RelayTransaction(const CTransaction& tx, const uint256& hash); 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