#ifndef BITCOIN_NET_H
#define BITCOIN_NET_H
+#include <limits>
#include <deque>
#ifndef Q_MOC_RUN
#include <boost/array.hpp>
class CBlockIndex;
extern int nBestHeight;
+const uint16_t nSocksDefault = 9050;
+const uint16_t nPortZero = 0;
-inline unsigned int ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
-inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
+inline uint64_t ReceiveBufferSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
+inline uint64_t SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
void AddOneShot(std::string strDest);
bool RecvLine(SOCKET hSocket, std::string& strLine);
CNode* FindNode(const CNetAddr& ip);
CNode* FindNode(const CService& ip);
CNode* ConnectNode(CAddress addrConnect, const char *strDest = NULL, int64_t nTimeout=0);
+bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
void MapPort();
unsigned short GetListenPort();
bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string()));
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=)
THREAD_OPENCONNECTIONS,
THREAD_MESSAGEHANDLER,
THREAD_RPCLISTENER,
- THREAD_UPNP,
THREAD_DNSSEED,
THREAD_ADDEDCONNECTIONS,
THREAD_DUMPADDRESS,
THREAD_RPCHANDLER,
THREAD_MINTER,
THREAD_SCRIPTCHECK,
+ THREAD_NTP,
THREAD_MAX
};
extern bool fClient;
extern bool fDiscover;
-extern bool fUseUPnP;
extern uint64_t nLocalServices;
extern uint64_t nLocalHostNonce;
extern CAddress addrSeenByPeer;
extern std::vector<CNode*> vNodes;
extern CCriticalSection cs_vNodes;
+extern std::vector<std::string> vAddedNodes;
+extern CCriticalSection cs_vAddedNodes;
extern std::map<CInv, CDataStream> mapRelay;
extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
extern CCriticalSection cs_mapRelay;
int64_t nLastRecv;
int64_t nTimeConnected;
std::string addrName;
- int nVersion;
+ int32_t nVersion;
std::string strSubVer;
bool fInbound;
int64_t nReleaseTime;
- int nStartingHeight;
- int nMisbehavior;
+ int32_t nStartingHeight;
+ int32_t nMisbehavior;
uint64_t nSendBytes;
uint64_t nRecvBytes;
bool fSyncNode;
int64_t nLastRecv;
int64_t nLastSendEmpty;
int64_t nTimeConnected;
- int nHeaderStart;
- unsigned int nMessageStart;
+ int32_t nHeaderStart;
+ uint32_t nMessageStart;
CAddress addr;
std::string addrName;
CService addrLocal;
- int nVersion;
+ int32_t nVersion;
std::string strSubVer;
bool fOneShot;
bool fClient;
uint256 hashContinue;
CBlockIndex* pindexLastGetBlocksBegin;
uint256 hashLastGetBlocksEnd;
- int nStartingHeight;
+ int32_t nStartingHeight;
bool fStartSync;
// flood relay
nLastSendEmpty = GetTime();
nTimeConnected = GetTime();
nHeaderStart = -1;
- nMessageStart = -1;
+ nMessageStart = std::numeric_limits<uint32_t>::max();
addr = addrIn;
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
nVersion = 0;
fGetAddr = false;
nMisbehavior = 0;
hashCheckpointKnown = 0;
- setInventoryKnown.max_size(SendBufferSize() / 1000);
+ setInventoryKnown.max_size((size_t)SendBufferSize() / 1000);
// Be shy and don't send version until we hear
if (hSocket != INVALID_SOCKET && !fInbound)
ENTER_CRITICAL_SECTION(cs_vSend);
if (nHeaderStart != -1)
AbortMessage();
- nHeaderStart = vSend.size();
+ nHeaderStart = (int32_t)vSend.size();
vSend << CMessageHeader(pszCommand, 0);
- nMessageStart = vSend.size();
+ nMessageStart = (uint32_t)vSend.size();
if (fDebug)
printf("sending: %s ", pszCommand);
}
return;
vSend.resize(nHeaderStart);
nHeaderStart = -1;
- nMessageStart = -1;
+ nMessageStart = std::numeric_limits<uint32_t>::max();
LEAVE_CRITICAL_SECTION(cs_vSend);
if (fDebug)
return;
// Set the size
- unsigned int nSize = vSend.size() - nMessageStart;
+ uint32_t nSize = (uint32_t) vSend.size() - nMessageStart;
memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::MESSAGE_SIZE_OFFSET, &nSize, sizeof(nSize));
// Set the checksum
uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end());
- unsigned int nChecksum = 0;
+ uint32_t nChecksum = 0;
memcpy(&nChecksum, &hash, sizeof(nChecksum));
assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum));
}
nHeaderStart = -1;
- nMessageStart = -1;
+ nMessageStart = std::numeric_limits<uint32_t>::max();
LEAVE_CRITICAL_SECTION(cs_vSend);
}
{
if (nHeaderStart < 0)
return;
- int nSize = vSend.size() - nMessageStart;
+ int nSize = (int) vSend.size() - nMessageStart;
if (nSize > 0)
EndMessage();
else