|
|
@ -173,7 +173,10 @@ public: |
|
|
|
// socket
|
|
|
|
// socket
|
|
|
|
uint64 nServices; |
|
|
|
uint64 nServices; |
|
|
|
SOCKET hSocket; |
|
|
|
SOCKET hSocket; |
|
|
|
CDataStream vSend; |
|
|
|
CDataStream ssSend; |
|
|
|
|
|
|
|
size_t nSendSize; // total size of all vSendMsg entries
|
|
|
|
|
|
|
|
size_t nSendOffset; // offset inside the first vSendMsg already sent
|
|
|
|
|
|
|
|
std::deque<CSerializeData> vSendMsg; |
|
|
|
CCriticalSection cs_vSend; |
|
|
|
CCriticalSection cs_vSend; |
|
|
|
|
|
|
|
|
|
|
|
std::deque<CNetMessage> vRecvMsg; |
|
|
|
std::deque<CNetMessage> vRecvMsg; |
|
|
@ -184,8 +187,6 @@ public: |
|
|
|
int64 nLastRecv; |
|
|
|
int64 nLastRecv; |
|
|
|
int64 nLastSendEmpty; |
|
|
|
int64 nLastSendEmpty; |
|
|
|
int64 nTimeConnected; |
|
|
|
int64 nTimeConnected; |
|
|
|
int nHeaderStart; |
|
|
|
|
|
|
|
unsigned int nMessageStart; |
|
|
|
|
|
|
|
CAddress addr; |
|
|
|
CAddress addr; |
|
|
|
std::string addrName; |
|
|
|
std::string addrName; |
|
|
|
CService addrLocal; |
|
|
|
CService addrLocal; |
|
|
@ -233,7 +234,7 @@ public: |
|
|
|
CCriticalSection cs_inventory; |
|
|
|
CCriticalSection cs_inventory; |
|
|
|
std::multimap<int64, CInv> mapAskFor; |
|
|
|
std::multimap<int64, CInv> mapAskFor; |
|
|
|
|
|
|
|
|
|
|
|
CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : vSend(SER_NETWORK, MIN_PROTO_VERSION) |
|
|
|
CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : ssSend(SER_NETWORK, MIN_PROTO_VERSION) |
|
|
|
{ |
|
|
|
{ |
|
|
|
nServices = 0; |
|
|
|
nServices = 0; |
|
|
|
hSocket = hSocketIn; |
|
|
|
hSocket = hSocketIn; |
|
|
@ -242,8 +243,6 @@ public: |
|
|
|
nLastRecv = 0; |
|
|
|
nLastRecv = 0; |
|
|
|
nLastSendEmpty = GetTime(); |
|
|
|
nLastSendEmpty = GetTime(); |
|
|
|
nTimeConnected = GetTime(); |
|
|
|
nTimeConnected = GetTime(); |
|
|
|
nHeaderStart = -1; |
|
|
|
|
|
|
|
nMessageStart = -1; |
|
|
|
|
|
|
|
addr = addrIn; |
|
|
|
addr = addrIn; |
|
|
|
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; |
|
|
|
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; |
|
|
|
nVersion = 0; |
|
|
|
nVersion = 0; |
|
|
@ -256,6 +255,8 @@ public: |
|
|
|
fDisconnect = false; |
|
|
|
fDisconnect = false; |
|
|
|
nRefCount = 0; |
|
|
|
nRefCount = 0; |
|
|
|
nReleaseTime = 0; |
|
|
|
nReleaseTime = 0; |
|
|
|
|
|
|
|
nSendSize = 0; |
|
|
|
|
|
|
|
nSendOffset = 0; |
|
|
|
hashContinue = 0; |
|
|
|
hashContinue = 0; |
|
|
|
pindexLastGetBlocksBegin = 0; |
|
|
|
pindexLastGetBlocksBegin = 0; |
|
|
|
hashLastGetBlocksEnd = 0; |
|
|
|
hashLastGetBlocksEnd = 0; |
|
|
@ -387,11 +388,8 @@ public: |
|
|
|
void BeginMessage(const char* pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSend) |
|
|
|
void BeginMessage(const char* pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSend) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ENTER_CRITICAL_SECTION(cs_vSend); |
|
|
|
ENTER_CRITICAL_SECTION(cs_vSend); |
|
|
|
if (nHeaderStart != -1) |
|
|
|
assert(ssSend.size() == 0); |
|
|
|
AbortMessage(); |
|
|
|
ssSend << CMessageHeader(pszCommand, 0); |
|
|
|
nHeaderStart = vSend.size(); |
|
|
|
|
|
|
|
vSend << CMessageHeader(pszCommand, 0); |
|
|
|
|
|
|
|
nMessageStart = vSend.size(); |
|
|
|
|
|
|
|
if (fDebug) |
|
|
|
if (fDebug) |
|
|
|
printf("sending: %s ", pszCommand); |
|
|
|
printf("sending: %s ", pszCommand); |
|
|
|
} |
|
|
|
} |
|
|
@ -399,11 +397,8 @@ public: |
|
|
|
// TODO: Document the precondition of this function. Is cs_vSend locked?
|
|
|
|
// TODO: Document the precondition of this function. Is cs_vSend locked?
|
|
|
|
void AbortMessage() UNLOCK_FUNCTION(cs_vSend) |
|
|
|
void AbortMessage() UNLOCK_FUNCTION(cs_vSend) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (nHeaderStart < 0) |
|
|
|
ssSend.clear(); |
|
|
|
return; |
|
|
|
|
|
|
|
vSend.resize(nHeaderStart); |
|
|
|
|
|
|
|
nHeaderStart = -1; |
|
|
|
|
|
|
|
nMessageStart = -1; |
|
|
|
|
|
|
|
LEAVE_CRITICAL_SECTION(cs_vSend); |
|
|
|
LEAVE_CRITICAL_SECTION(cs_vSend); |
|
|
|
|
|
|
|
|
|
|
|
if (fDebug) |
|
|
|
if (fDebug) |
|
|
@ -420,30 +415,32 @@ public: |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (nHeaderStart < 0) |
|
|
|
if (ssSend.size() == 0) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
// Set the size
|
|
|
|
// Set the size
|
|
|
|
unsigned int nSize = vSend.size() - nMessageStart; |
|
|
|
unsigned int nSize = ssSend.size() - CMessageHeader::HEADER_SIZE; |
|
|
|
memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::MESSAGE_SIZE_OFFSET, &nSize, sizeof(nSize)); |
|
|
|
memcpy((char*)&ssSend[CMessageHeader::MESSAGE_SIZE_OFFSET], &nSize, sizeof(nSize)); |
|
|
|
|
|
|
|
|
|
|
|
// Set the checksum
|
|
|
|
// Set the checksum
|
|
|
|
uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end()); |
|
|
|
uint256 hash = Hash(ssSend.begin() + CMessageHeader::HEADER_SIZE, ssSend.end()); |
|
|
|
unsigned int nChecksum = 0; |
|
|
|
unsigned int nChecksum = 0; |
|
|
|
memcpy(&nChecksum, &hash, sizeof(nChecksum)); |
|
|
|
memcpy(&nChecksum, &hash, sizeof(nChecksum)); |
|
|
|
assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum)); |
|
|
|
assert(ssSend.size () >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum)); |
|
|
|
memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum)); |
|
|
|
memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum)); |
|
|
|
|
|
|
|
|
|
|
|
if (fDebug) { |
|
|
|
if (fDebug) { |
|
|
|
printf("(%d bytes)\n", nSize); |
|
|
|
printf("(%d bytes)\n", nSize); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::deque<CSerializeData>::iterator it = vSendMsg.insert(vSendMsg.end(), CSerializeData()); |
|
|
|
|
|
|
|
ssSend.GetAndClear(*it); |
|
|
|
|
|
|
|
nSendSize += (*it).size(); |
|
|
|
|
|
|
|
|
|
|
|
// If write queue empty, attempt "optimistic write"
|
|
|
|
// If write queue empty, attempt "optimistic write"
|
|
|
|
if (nHeaderStart == 0) |
|
|
|
if (it == vSendMsg.begin()) |
|
|
|
SocketSendData(this); |
|
|
|
SocketSendData(this); |
|
|
|
|
|
|
|
|
|
|
|
nHeaderStart = -1; |
|
|
|
|
|
|
|
nMessageStart = -1; |
|
|
|
|
|
|
|
LEAVE_CRITICAL_SECTION(cs_vSend); |
|
|
|
LEAVE_CRITICAL_SECTION(cs_vSend); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -470,7 +467,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1; |
|
|
|
ssSend << a1; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
@ -486,7 +483,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1 << a2; |
|
|
|
ssSend << a1 << a2; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
@ -502,7 +499,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1 << a2 << a3; |
|
|
|
ssSend << a1 << a2 << a3; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
@ -518,7 +515,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1 << a2 << a3 << a4; |
|
|
|
ssSend << a1 << a2 << a3 << a4; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
@ -534,7 +531,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1 << a2 << a3 << a4 << a5; |
|
|
|
ssSend << a1 << a2 << a3 << a4 << a5; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
@ -550,7 +547,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1 << a2 << a3 << a4 << a5 << a6; |
|
|
|
ssSend << a1 << a2 << a3 << a4 << a5 << a6; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
@ -566,7 +563,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1 << a2 << a3 << a4 << a5 << a6 << a7; |
|
|
|
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
@ -582,7 +579,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8; |
|
|
|
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
@ -598,7 +595,7 @@ public: |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
BeginMessage(pszCommand); |
|
|
|
BeginMessage(pszCommand); |
|
|
|
vSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9; |
|
|
|
ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9; |
|
|
|
EndMessage(); |
|
|
|
EndMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (...) |
|
|
|
catch (...) |
|
|
|