X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fnet.h;h=093ba85cfd6c2f8d3fc7cd01ec083bc052ddab2a;hb=5098ea454db9132aa0f576921ca9d1a69429d146;hp=7306d136b63967e40345c63280bf43322dc9c042;hpb=92948780909cc9e3349409d6102dbe5adf1d5a10;p=novacoin.git diff --git a/src/net.h b/src/net.h index 7306d13..093ba85 100644 --- a/src/net.h +++ b/src/net.h @@ -5,10 +5,10 @@ #ifndef BITCOIN_NET_H #define BITCOIN_NET_H +#include #include #ifndef Q_MOC_RUN #include -#include #endif #include @@ -18,7 +18,6 @@ #include "mruset.h" #include "netbase.h" -#include "protocol.h" #include "addrman.h" #include "hash.h" @@ -27,6 +26,8 @@ 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 +52,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 +59,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 +78,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL); enum { MSG_TX = 1, - MSG_BLOCK, + MSG_BLOCK }; class CRequestTracker @@ -104,20 +107,23 @@ 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; @@ -215,6 +221,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 +242,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 +259,9 @@ public: pindexLastGetBlocksBegin = 0; hashLastGetBlocksEnd = 0; nStartingHeight = -1; + nNextLocalAddrSend = 0; + nNextAddrSend = 0; + nNextInvSend = 0; fStartSync = false; fGetAddr = false; nMisbehavior = 0; @@ -265,8 +277,7 @@ public: { if (hSocket != INVALID_SOCKET) { - closesocket(hSocket); - hSocket = INVALID_SOCKET; + CloseSocket(hSocket); } } @@ -375,7 +386,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 +402,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 +423,7 @@ public: } nHeaderStart = -1; - nMessageStart = UINT_MAX; + nMessageStart = std::numeric_limits::max(); LEAVE_CRITICAL_SECTION(cs_vSend); } @@ -444,13 +457,13 @@ public: } } - template - void PushMessage(const char* pszCommand, const T1& a1) + template + void PushMessage(const char* pszCommand, const Args&... args) { try { BeginMessage(pszCommand); - vSend << a1; + (vSend << ... << args); EndMessage(); } catch (...) @@ -460,135 +473,6 @@ public: } } - 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) - { - try - { - BeginMessage(pszCommand); - vSend << a1 << a2 << a3 << a4 << a5 << a6; - 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) - { - 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 +558,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 +568,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