Skip to content

Commit 0c23c01

Browse files
sipaFuzzbawls
authored andcommitted
Keep addrman's nService bits consistent with outbound observations
1 parent 8ec6bbe commit 0c23c01

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/addrman.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,24 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)
503503
info.nTime = nTime;
504504
}
505505

506+
void CAddrMan::SetServices_(const CService& addr, uint64_t nServices)
507+
{
508+
CAddrInfo* pinfo = Find(addr);
509+
510+
// if not found, bail out
511+
if (!pinfo)
512+
return;
513+
514+
CAddrInfo& info = *pinfo;
515+
516+
// check whether we are talking about the exact same CService (including same port)
517+
if (info != addr)
518+
return;
519+
520+
// update info
521+
info.nServices = nServices;
522+
}
523+
506524
int CAddrMan::RandomInt(int nMax){
507525
return GetRandInt(nMax);
508526
}

src/addrman.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2012 Pieter Wuille
2-
// Copyright (c) 2012-2014 The Bitcoin developers
2+
// Copyright (c) 2012-2015 The Bitcoin developers
33
// Copyright (c) 2017-2020 The PIVX developers
44
// Distributed under the MIT software license, see the accompanying
55
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -264,6 +264,9 @@ class CAddrMan
264264
//! Mark an entry as currently-connected-to.
265265
void Connected_(const CService& addr, int64_t nTime);
266266

267+
//! Update an entry's service bits.
268+
void SetServices_(const CService& addr, uint64_t nServices);
269+
267270
public:
268271
/**
269272
* serialized format:
@@ -589,6 +592,14 @@ class CAddrMan
589592
Check();
590593
}
591594
}
595+
596+
void SetServices(const CService& addr, uint64_t nServices)
597+
{
598+
LOCK(cs);
599+
Check();
600+
SetServices_(addr, nServices);
601+
Check();
602+
}
592603
};
593604

594605
#endif // BITCOIN_ADDRMAN_H

src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5234,6 +5234,9 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
52345234
CAddress addrFrom;
52355235
uint64_t nNonce = 1;
52365236
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
5237+
if (!pfrom->fInbound) {
5238+
addrman.SetServices(pfrom->addr, pfrom->nServices);
5239+
}
52375240
if (pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand))
52385241
return false;
52395242

0 commit comments

Comments
 (0)