|
|
@ -164,8 +164,9 @@ int GetnScore(const CService& addr) |
|
|
|
// Is our peer's addrLocal potentially useful as an external IP source?
|
|
|
|
// Is our peer's addrLocal potentially useful as an external IP source?
|
|
|
|
bool IsPeerAddrLocalGood(CNode *pnode) |
|
|
|
bool IsPeerAddrLocalGood(CNode *pnode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return fDiscover && pnode->addr.IsRoutable() && pnode->addrLocal.IsRoutable() && |
|
|
|
CService addrLocal = pnode->GetAddrLocal(); |
|
|
|
!IsLimited(pnode->addrLocal.GetNetwork()); |
|
|
|
return fDiscover && pnode->addr.IsRoutable() && addrLocal.IsRoutable() && |
|
|
|
|
|
|
|
!IsLimited(addrLocal.GetNetwork()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// pushes our own address to a peer
|
|
|
|
// pushes our own address to a peer
|
|
|
@ -180,7 +181,7 @@ void AdvertiseLocal(CNode *pnode) |
|
|
|
if (IsPeerAddrLocalGood(pnode) && (!addrLocal.IsRoutable() || |
|
|
|
if (IsPeerAddrLocalGood(pnode) && (!addrLocal.IsRoutable() || |
|
|
|
GetRand((GetnScore(addrLocal) > LOCAL_MANUAL) ? 8:2) == 0)) |
|
|
|
GetRand((GetnScore(addrLocal) > LOCAL_MANUAL) ? 8:2) == 0)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
addrLocal.SetIP(pnode->addrLocal); |
|
|
|
addrLocal.SetIP(pnode->GetAddrLocal()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (addrLocal.IsRoutable()) |
|
|
|
if (addrLocal.IsRoutable()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -307,9 +308,11 @@ CNode* CConnman::FindNode(const CSubNet& subNet) |
|
|
|
CNode* CConnman::FindNode(const std::string& addrName) |
|
|
|
CNode* CConnman::FindNode(const std::string& addrName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) { |
|
|
|
if (pnode->addrName == addrName) |
|
|
|
if (pnode->GetAddrName() == addrName) { |
|
|
|
return (pnode); |
|
|
|
return (pnode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -373,9 +376,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo |
|
|
|
CNode* pnode = FindNode((CService)addrConnect); |
|
|
|
CNode* pnode = FindNode((CService)addrConnect); |
|
|
|
if (pnode) |
|
|
|
if (pnode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (pnode->addrName.empty()) { |
|
|
|
pnode->MaybeSetAddrName(std::string(pszDest)); |
|
|
|
pnode->addrName = std::string(pszDest); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
CloseSocket(hSocket); |
|
|
|
CloseSocket(hSocket); |
|
|
|
LogPrintf("Failed to open new connection, already connected\n"); |
|
|
|
LogPrintf("Failed to open new connection, already connected\n"); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
@ -389,7 +390,6 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo |
|
|
|
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize(); |
|
|
|
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize(); |
|
|
|
CNode* pnode = new CNode(id, nLocalServices, GetBestHeight(), hSocket, addrConnect, CalculateKeyedNetGroup(addrConnect), nonce, pszDest ? pszDest : "", false); |
|
|
|
CNode* pnode = new CNode(id, nLocalServices, GetBestHeight(), hSocket, addrConnect, CalculateKeyedNetGroup(addrConnect), nonce, pszDest ? pszDest : "", false); |
|
|
|
pnode->nServicesExpected = ServiceFlags(addrConnect.nServices & nRelevantServices); |
|
|
|
pnode->nServicesExpected = ServiceFlags(addrConnect.nServices & nRelevantServices); |
|
|
|
pnode->nTimeConnected = GetSystemTimeInSeconds(); |
|
|
|
|
|
|
|
pnode->AddRef(); |
|
|
|
pnode->AddRef(); |
|
|
|
|
|
|
|
|
|
|
|
return pnode; |
|
|
|
return pnode; |
|
|
@ -594,6 +594,33 @@ void CConnman::AddWhitelistedRange(const CSubNet &subnet) { |
|
|
|
vWhitelistedRange.push_back(subnet); |
|
|
|
vWhitelistedRange.push_back(subnet); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string CNode::GetAddrName() const { |
|
|
|
|
|
|
|
LOCK(cs_addrName); |
|
|
|
|
|
|
|
return addrName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CNode::MaybeSetAddrName(const std::string& addrNameIn) { |
|
|
|
|
|
|
|
LOCK(cs_addrName); |
|
|
|
|
|
|
|
if (addrName.empty()) { |
|
|
|
|
|
|
|
addrName = addrNameIn; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CService CNode::GetAddrLocal() const { |
|
|
|
|
|
|
|
LOCK(cs_addrLocal); |
|
|
|
|
|
|
|
return addrLocal; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CNode::SetAddrLocal(const CService& addrLocalIn) { |
|
|
|
|
|
|
|
LOCK(cs_addrLocal); |
|
|
|
|
|
|
|
if (addrLocal.IsValid()) { |
|
|
|
|
|
|
|
error("Addr local already set for node: %i. Refusing to change from %s to %s", id, addrLocal.ToString(), addrLocalIn.ToString()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
addrLocal = addrLocalIn; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#undef X |
|
|
|
#undef X |
|
|
|
#define X(name) stats.name = name |
|
|
|
#define X(name) stats.name = name |
|
|
|
void CNode::copyStats(CNodeStats &stats) |
|
|
|
void CNode::copyStats(CNodeStats &stats) |
|
|
@ -601,21 +628,33 @@ void CNode::copyStats(CNodeStats &stats) |
|
|
|
stats.nodeid = this->GetId(); |
|
|
|
stats.nodeid = this->GetId(); |
|
|
|
X(nServices); |
|
|
|
X(nServices); |
|
|
|
X(addr); |
|
|
|
X(addr); |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_filter); |
|
|
|
X(fRelayTxes); |
|
|
|
X(fRelayTxes); |
|
|
|
|
|
|
|
} |
|
|
|
X(nLastSend); |
|
|
|
X(nLastSend); |
|
|
|
X(nLastRecv); |
|
|
|
X(nLastRecv); |
|
|
|
X(nTimeConnected); |
|
|
|
X(nTimeConnected); |
|
|
|
X(nTimeOffset); |
|
|
|
X(nTimeOffset); |
|
|
|
X(addrName); |
|
|
|
stats.addrName = GetAddrName(); |
|
|
|
X(nVersion); |
|
|
|
X(nVersion); |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_SubVer); |
|
|
|
X(cleanSubVer); |
|
|
|
X(cleanSubVer); |
|
|
|
|
|
|
|
} |
|
|
|
X(fInbound); |
|
|
|
X(fInbound); |
|
|
|
X(fAddnode); |
|
|
|
X(fAddnode); |
|
|
|
X(nStartingHeight); |
|
|
|
X(nStartingHeight); |
|
|
|
X(nSendBytes); |
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_vSend); |
|
|
|
X(mapSendBytesPerMsgCmd); |
|
|
|
X(mapSendBytesPerMsgCmd); |
|
|
|
X(nRecvBytes); |
|
|
|
X(nSendBytes); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_vRecv); |
|
|
|
X(mapRecvBytesPerMsgCmd); |
|
|
|
X(mapRecvBytesPerMsgCmd); |
|
|
|
|
|
|
|
X(nRecvBytes); |
|
|
|
|
|
|
|
} |
|
|
|
X(fWhitelisted); |
|
|
|
X(fWhitelisted); |
|
|
|
|
|
|
|
|
|
|
|
// It is common for nodes with good ping times to suddenly become lagged,
|
|
|
|
// It is common for nodes with good ping times to suddenly become lagged,
|
|
|
@ -635,7 +674,8 @@ void CNode::copyStats(CNodeStats &stats) |
|
|
|
stats.dPingWait = (((double)nPingUsecWait) / 1e6); |
|
|
|
stats.dPingWait = (((double)nPingUsecWait) / 1e6); |
|
|
|
|
|
|
|
|
|
|
|
// Leave string empty if addrLocal invalid (not filled in yet)
|
|
|
|
// Leave string empty if addrLocal invalid (not filled in yet)
|
|
|
|
stats.addrLocal = addrLocal.IsValid() ? addrLocal.ToString() : ""; |
|
|
|
CService addrLocalUnlocked = GetAddrLocal(); |
|
|
|
|
|
|
|
stats.addrLocal = addrLocalUnlocked.IsValid() ? addrLocalUnlocked.ToString() : ""; |
|
|
|
} |
|
|
|
} |
|
|
|
#undef X |
|
|
|
#undef X |
|
|
|
|
|
|
|
|
|
|
@ -643,6 +683,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete |
|
|
|
{ |
|
|
|
{ |
|
|
|
complete = false; |
|
|
|
complete = false; |
|
|
|
int64_t nTimeMicros = GetTimeMicros(); |
|
|
|
int64_t nTimeMicros = GetTimeMicros(); |
|
|
|
|
|
|
|
LOCK(cs_vRecv); |
|
|
|
nLastRecv = nTimeMicros / 1000000; |
|
|
|
nLastRecv = nTimeMicros / 1000000; |
|
|
|
nRecvBytes += nBytes; |
|
|
|
nRecvBytes += nBytes; |
|
|
|
while (nBytes > 0) { |
|
|
|
while (nBytes > 0) { |
|
|
@ -1786,8 +1827,9 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() |
|
|
|
if (pnode->addr.IsValid()) { |
|
|
|
if (pnode->addr.IsValid()) { |
|
|
|
mapConnected[pnode->addr] = pnode->fInbound; |
|
|
|
mapConnected[pnode->addr] = pnode->fInbound; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!pnode->addrName.empty()) { |
|
|
|
std::string addrName = pnode->GetAddrName(); |
|
|
|
mapConnectedByName[pnode->addrName] = std::make_pair(pnode->fInbound, static_cast<const CService&>(pnode->addr)); |
|
|
|
if (!addrName.empty()) { |
|
|
|
|
|
|
|
mapConnectedByName[std::move(addrName)] = std::make_pair(pnode->fInbound, static_cast<const CService&>(pnode->addr)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -2414,9 +2456,8 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) |
|
|
|
vstats.reserve(vNodes.size()); |
|
|
|
vstats.reserve(vNodes.size()); |
|
|
|
for(std::vector<CNode*>::iterator it = vNodes.begin(); it != vNodes.end(); ++it) { |
|
|
|
for(std::vector<CNode*>::iterator it = vNodes.begin(); it != vNodes.end(); ++it) { |
|
|
|
CNode* pnode = *it; |
|
|
|
CNode* pnode = *it; |
|
|
|
CNodeStats stats; |
|
|
|
vstats.emplace_back(); |
|
|
|
pnode->copyStats(stats); |
|
|
|
pnode->copyStats(vstats.back()); |
|
|
|
vstats.push_back(stats); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2568,6 +2609,7 @@ unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; } |
|
|
|
unsigned int CConnman::GetSendBufferSize() const{ return nSendBufferMaxSize; } |
|
|
|
unsigned int CConnman::GetSendBufferSize() const{ return nSendBufferMaxSize; } |
|
|
|
|
|
|
|
|
|
|
|
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const std::string& addrNameIn, bool fInboundIn) : |
|
|
|
CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const std::string& addrNameIn, bool fInboundIn) : |
|
|
|
|
|
|
|
nTimeConnected(GetSystemTimeInSeconds()), |
|
|
|
addr(addrIn), |
|
|
|
addr(addrIn), |
|
|
|
fInbound(fInboundIn), |
|
|
|
fInbound(fInboundIn), |
|
|
|
id(idIn), |
|
|
|
id(idIn), |
|
|
@ -2587,7 +2629,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn |
|
|
|
nLastRecv = 0; |
|
|
|
nLastRecv = 0; |
|
|
|
nSendBytes = 0; |
|
|
|
nSendBytes = 0; |
|
|
|
nRecvBytes = 0; |
|
|
|
nRecvBytes = 0; |
|
|
|
nTimeConnected = GetSystemTimeInSeconds(); |
|
|
|
|
|
|
|
nTimeOffset = 0; |
|
|
|
nTimeOffset = 0; |
|
|
|
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; |
|
|
|
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn; |
|
|
|
nVersion = 0; |
|
|
|
nVersion = 0; |
|
|
|