Skip to content

Commit fc83f18

Browse files
committed
Verify that outbound connections have expected services
1 parent 3764dec commit fc83f18

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4616,6 +4616,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
46164616
{
46174617
addrman.SetServices(pfrom->addr, pfrom->nServices);
46184618
}
4619+
if (pfrom->nServicesExpected & ~pfrom->nServices)
4620+
{
4621+
LogPrint("net", "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom->id, pfrom->nServices, pfrom->nServicesExpected);
4622+
pfrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_NONSTANDARD,
4623+
strprintf("Expected to offer services %08x", pfrom->nServicesExpected));
4624+
pfrom->fDisconnect = true;
4625+
return false;
4626+
}
4627+
46194628
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
46204629
{
46214630
// 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
//
@@ -409,6 +412,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure
409412
vNodes.push_back(pnode);
410413
}
411414

415+
pnode->nServicesExpected = addrConnect.nServices & nRelevantServices;
412416
pnode->nTimeConnected = GetTime();
413417

414418
return pnode;
@@ -2325,6 +2329,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
23252329
filterInventoryKnown(50000, 0.000001)
23262330
{
23272331
nServices = 0;
2332+
nServicesExpected = 0;
23282333
hSocket = hSocketIn;
23292334
nRecvVersion = INIT_PROTO_VERSION;
23302335
nLastSend = 0;

src/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ class CNode
317317
public:
318318
// socket
319319
uint64_t nServices;
320+
uint64_t nServicesExpected;
320321
SOCKET hSocket;
321322
CDataStream ssSend;
322323
size_t nSendSize; // total size of all vSendMsg entries

0 commit comments

Comments
 (0)