Browse Source

Keep addrman's nService bits consistent with outbound observations

0.13
Pieter Wuille 9 years ago
parent
commit
3764dec36c
  1. 18
      src/addrman.cpp
  2. 11
      src/addrman.h
  3. 4
      src/main.cpp

18
src/addrman.cpp

@ -502,6 +502,24 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime) @@ -502,6 +502,24 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)
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);
}

11
src/addrman.h

@ -256,6 +256,9 @@ protected: @@ -256,6 +256,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:
@ -589,6 +592,14 @@ public: @@ -589,6 +592,14 @@ public:
}
}
void SetServices(const CService &addr, uint64_t nServices)
{
LOCK(cs);
Check();
SetServices_(addr, nServices);
Check();
}
};
#endif // BITCOIN_ADDRMAN_H

4
src/main.cpp

@ -4612,6 +4612,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, @@ -4612,6 +4612,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

Loading…
Cancel
Save