Skip to content

Commit afdc413

Browse files
committed
Verify that outbound connections have expected services
1 parent 644b2c5 commit afdc413

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4543,6 +4543,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
45434543
{
45444544
addrman.SetServices(pfrom->addr, pfrom->nServices);
45454545
}
4546+
if (pfrom->nServicesExpected & ~pfrom->nServices)
4547+
{
4548+
LogPrint("net", "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom->id, pfrom->nServices, pfrom->nServicesExpected);
4549+
pfrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_NONSTANDARD,
4550+
strprintf("Expected to offer services %08x", pfrom->nServicesExpected));
4551+
pfrom->fDisconnect = true;
4552+
}
4553+
45464554
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
45474555
{
45484556
// disconnect from peers older than this proto version

src/net.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ namespace {
7171

7272
const static std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
7373

74+
/** Services this node implementation cares about */
75+
static const uint64_t nRelevantServices = NODE_NETWORK;
76+
7477
//
7578
// Global state variables
7679
//
@@ -414,6 +417,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
414417
vNodes.push_back(pnode);
415418
}
416419

420+
pnode->nServicesExpected = addrConnect.nServices & nRelevantServices;
417421
pnode->nTimeConnected = GetTime();
418422

419423
return pnode;
@@ -2345,6 +2349,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
23452349
filterInventoryKnown(50000, 0.000001)
23462350
{
23472351
nServices = 0;
2352+
nServicesExpected = 0;
23482353
hSocket = hSocketIn;
23492354
nRecvVersion = INIT_PROTO_VERSION;
23502355
nLastSend = 0;

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ class CNode
319319
public:
320320
// socket
321321
uint64_t nServices;
322+
uint64_t nServicesExpected;
322323
SOCKET hSocket;
323324
CDataStream ssSend;
324325
size_t nSendSize; // total size of all vSendMsg entries

0 commit comments

Comments
 (0)