From acb08f053aa80e96531662d6fcb784285d8b1d19 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Sun, 20 Oct 2013 22:36:31 -0400 Subject: [PATCH] Add NODE_BLOOM service bit and bump protocol version Lets nodes advertise that they offer bloom filter support explicitly. The protocol version bump allows SPV nodes to assume that NODE_BLOOM is set if NODE_NETWORK is set for pre-70002 nodes. Also adds an undocumented option to turn bloom filter support off for testing purposes. Nodes attempting to use bloom filters are immediately dropped so as to not waste their bandwidth. ensure backward compatible service bits update protocol version to 70004 --- src/init.cpp | 6 ++++++ src/main.cpp | 9 +++++++++ src/protocol.h | 8 +++++++- src/util.cpp | 2 ++ src/util.h | 3 +++ src/version.h | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 21a566848..b8ef781a8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -321,6 +321,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), 1)); strUsage += HelpMessageOpt("-seednode=", _("Connect to a node to retrieve peer addresses, and disconnect")); strUsage += HelpMessageOpt("-timeout=", strprintf(_("Specify connection timeout in milliseconds (minimum: 1, default: %d)"), DEFAULT_CONNECT_TIMEOUT)); + strUsage += HelpMessageOpt("-bloomfilters", _("Allow peers to set bloom filters (default: 1)")); #ifdef USE_UPNP #if USE_UPNP strUsage += HelpMessageOpt("-upnp", _("Use UPnP to map the listening port (default: 1 when listening)")); @@ -669,6 +670,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) fLogTimestamps = GetBoolArg("-logtimestamps", true); fLogIPs = GetBoolArg("-logips", false); + fBloomFilters = GetBoolArg("-bloomfilters", true); + if (fBloomFilters) { + nLocalServices |= NODE_BLOOM; + } + // when specifying an explicit binding address, you want to listen on it // even when -connect or -proxy is specified if (mapArgs.count("-bind")) { diff --git a/src/main.cpp b/src/main.cpp index 5fffaa381..cec2cf18c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4684,6 +4684,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } } + else if (!fBloomFilters && + (strCommand == "filterload" || + strCommand == "filteradd" || + strCommand == "filterclear")) + { + pfrom->CloseSocketDisconnect(); + return error("peer %s attempted to set a bloom filter even though we do not advertise that service", + pfrom->addr.ToString().c_str()); + } else if (strCommand == "filterload") { diff --git a/src/protocol.h b/src/protocol.h index b5e65032a..b9e021990 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -71,10 +71,16 @@ enum { // set by all Bitcoin Core nodes, and is unset by SPV clients or other peers that just want // network services but don't provide them. NODE_NETWORK = (1 << 0), + + // NODE_BLOOM means the node is capable and willing to handle bloom-filtered connections. + // Dogecoin Core will continue to support this by default, but will allow disabling it + // with the -bloomfilters option. + NODE_BLOOM = (1 << 1), + // NODE_GETUTXO means the node is capable of responding to the getutxo protocol request. // Bitcoin Core does not support this but a patch set called Bitcoin XT does. // See BIP 64 for details on how this is implemented. - NODE_GETUTXO = (1 << 1), + NODE_GETUTXO = (1 << 2), // Bits 24-31 are reserved for temporary experiments. Just pick a bit that // isn't getting used, or one not being used much, and notify the diff --git a/src/util.cpp b/src/util.cpp index bfb95c904..4fbe66219 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -106,6 +106,8 @@ bool fPrintToDebugLog = true; bool fDaemon = false; bool fServer = false; string strMiscWarning; + +bool fBloomFilters = true; bool fLogTimestamps = false; bool fLogIPs = false; volatile bool fReopenDebugLog = false; diff --git a/src/util.h b/src/util.h index 4cc0faf4d..9b0088d49 100644 --- a/src/util.h +++ b/src/util.h @@ -43,6 +43,9 @@ extern bool fPrintToConsole; extern bool fPrintToDebugLog; extern bool fServer; extern std::string strMiscWarning; + + +extern bool fBloomFilters; extern bool fLogTimestamps; extern bool fLogIPs; extern volatile bool fReopenDebugLog; diff --git a/src/version.h b/src/version.h index 278ddb71e..02ccfd0e1 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 70003; +static const int PROTOCOL_VERSION = 70004; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209;