aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2016-03-26 18:58:00 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2016-06-13 17:40:16 +0200
commit3764dec36c815267174951a4c64e17c07ee6302f (patch)
tree017bd6c2933f65f1b4ebbe34533e74c25e400dd0 /src
parent44c1b1c9bb54082625c7ad76af25473abf79f866 (diff)
downloadbitcoin-3764dec36c815267174951a4c64e17c07ee6302f.tar.xz
Keep addrman's nService bits consistent with outbound observations
Diffstat (limited to 'src')
-rw-r--r--src/addrman.cpp18
-rw-r--r--src/addrman.h11
-rw-r--r--src/main.cpp4
3 files changed, 33 insertions, 0 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 00f6fe99e0..d1e98d8ac0 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -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);
}
diff --git a/src/addrman.h b/src/addrman.h
index c5923e9417..7e36e2228f 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -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:
}
}
+ void SetServices(const CService &addr, uint64_t nServices)
+ {
+ LOCK(cs);
+ Check();
+ SetServices_(addr, nServices);
+ Check();
+ }
+
};
#endif // BITCOIN_ADDRMAN_H
diff --git a/src/main.cpp b/src/main.cpp
index 6092e7a12e..ac89945bf2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -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