Keep addrman's nService bits consistent with outbound observations

This commit is contained in:
Pieter Wuille
2016-03-26 18:58:00 +01:00
committed by lateminer
parent 1ee8436348
commit f1d80ea69b
3 changed files with 37 additions and 0 deletions

View File

@@ -500,3 +500,25 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)
if (nTime - info.nTime > nUpdateInterval)
info.nTime = nTime;
}
void CAddrMan::SetServices_(const CService& addr, uint64_t nServices)
{
CAddrInfo* pinfo = Find(addr);
// if not found, bail out
if (!pinfo)
return;
CAddrInfo& info = *pinfo;
// check whether we are talking about the exact same CService (including same port)
if (info != addr)
return;
// update info
info.nServices = nServices;
}
int CAddrMan::RandomInt(int nMax){
return GetRandInt(nMax);
}

View File

@@ -253,6 +253,9 @@ protected:
//! Mark an entry as currently-connected-to.
void Connected_(const CService &addr, int64_t nTime);
//! Update an entry's service bits.
void SetServices_(const CService &addr, uint64_t nServices);
public:
/**
* serialized format:
@@ -583,6 +586,14 @@ public:
nKey.SetNull(); //Do not use outside of tests.
}
void SetServices(const CService &addr, uint64_t nServices)
{
LOCK(cs);
Check();
SetServices_(addr, nServices);
Check();
}
};
#endif // BITCOIN_ADDRMAN_H

View File

@@ -4982,6 +4982,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CAddress addrFrom;
uint64_t nNonce = 1;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
if (!pfrom->fInbound)
{
addrman.SetServices(pfrom->addr, pfrom->nServices);
}
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
{
// disconnect from peers older than this proto version