diff options
| author | Pieter Wuille <[email protected]> | 2016-03-26 19:09:22 +0100 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2016-06-13 17:40:16 +0200 |
| commit | fc83f181530fb566726e5f3f4197fc5586d77fd8 (patch) | |
| tree | f30fb7b98a910a7f28f6317b32d35591cfaad1a7 /src | |
| parent | Keep addrman's nService bits consistent with outbound observations (diff) | |
| download | discoin-fc83f181530fb566726e5f3f4197fc5586d77fd8.tar.xz discoin-fc83f181530fb566726e5f3f4197fc5586d77fd8.zip | |
Verify that outbound connections have expected services
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 9 | ||||
| -rw-r--r-- | src/net.cpp | 5 | ||||
| -rw-r--r-- | src/net.h | 1 |
3 files changed, 15 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index ac89945bf..7818056d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4616,6 +4616,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { addrman.SetServices(pfrom->addr, pfrom->nServices); } + if (pfrom->nServicesExpected & ~pfrom->nServices) + { + LogPrint("net", "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom->id, pfrom->nServices, pfrom->nServicesExpected); + pfrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_NONSTANDARD, + strprintf("Expected to offer services %08x", pfrom->nServicesExpected)); + pfrom->fDisconnect = true; + return false; + } + if (pfrom->nVersion < MIN_PEER_PROTO_VERSION) { // disconnect from peers older than this proto version diff --git a/src/net.cpp b/src/net.cpp index 173eba57c..a0c2bd509 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -71,6 +71,9 @@ namespace { const static std::string NET_MESSAGE_COMMAND_OTHER = "*other*"; +/** Services this node implementation cares about */ +static const uint64_t nRelevantServices = NODE_NETWORK; + // // Global state variables // @@ -409,6 +412,7 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure vNodes.push_back(pnode); } + pnode->nServicesExpected = addrConnect.nServices & nRelevantServices; pnode->nTimeConnected = GetTime(); return pnode; @@ -2325,6 +2329,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa filterInventoryKnown(50000, 0.000001) { nServices = 0; + nServicesExpected = 0; hSocket = hSocketIn; nRecvVersion = INIT_PROTO_VERSION; nLastSend = 0; @@ -317,6 +317,7 @@ class CNode public: // socket uint64_t nServices; + uint64_t nServicesExpected; SOCKET hSocket; CDataStream ssSend; size_t nSendSize; // total size of all vSendMsg entries |