From e7a64af74fee5734620e91e0045075c97197153a Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Sun, 20 Oct 2013 22:36:31 -0400 Subject: [PATCH 1/2] 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. --- src/init.cpp | 5 +++++ src/main.cpp | 9 +++++++++ src/protocol.h | 1 + src/util.cpp | 1 + src/util.h | 1 + src/version.h | 2 +- 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 72b53ebec..c8f0f4082 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -412,6 +412,11 @@ bool AppInit2(boost::thread_group& threadGroup) // ********************************************************* Step 2: parameter interactions + fBloomFilters = GetBoolArg("-bloomfilters", true); + if (fBloomFilters) { + nLocalServices |= NODE_BLOOM; + } + if (mapArgs.count("-bind")) { // when specifying an explicit binding address, you want to listen on it // even when -connect or -proxy is specified diff --git a/src/main.cpp b/src/main.cpp index 01a1babc7..bc34075c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3931,6 +3931,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 3d8eae55f..845c5fd63 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -60,6 +60,7 @@ class CMessageHeader enum { NODE_NETWORK = (1 << 0), + NODE_BLOOM = (1 << 1), }; /** A CService with information about it as peer */ diff --git a/src/util.cpp b/src/util.cpp index 71994587c..3897e3c97 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -79,6 +79,7 @@ bool fPrintToDebugger = false; bool fDaemon = false; bool fServer = false; string strMiscWarning; +bool fBloomFilters = true; bool fNoListen = false; bool fLogTimestamps = false; CMedianFilter vTimeOffsets(200,0); diff --git a/src/util.h b/src/util.h index 258910e2f..bfec63b6b 100644 --- a/src/util.h +++ b/src/util.h @@ -146,6 +146,7 @@ extern bool fPrintToDebugger; extern bool fDaemon; extern bool fServer; extern std::string strMiscWarning; +extern bool fBloomFilters; extern bool fNoListen; extern bool fLogTimestamps; extern volatile bool fReopenDebugLog; diff --git a/src/version.h b/src/version.h index f1e7c4cd7..281159b97 100644 --- a/src/version.h +++ b/src/version.h @@ -25,7 +25,7 @@ extern const std::string CLIENT_DATE; // network protocol versioning // -static const int PROTOCOL_VERSION = 70001; +static const int PROTOCOL_VERSION = 70002; // earlier versions not supported as of Feb 2012, and are disconnected static const int MIN_PROTO_VERSION = 209; From 63bd740c8ab8dd9a0a07fb038cd595528eb3d3aa Mon Sep 17 00:00:00 2001 From: Jannis Froese Date: Sun, 23 Mar 2014 22:04:17 +0100 Subject: [PATCH 2/2] document -bloomfilters option --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index c5e463d15..fdffca6f8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -219,6 +219,7 @@ std::string HelpMessage(HelpMessageMode hmm) strUsage += " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n"; strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; + strUsage += " -bloomfilters " + _("Allow peers to set bloom filters (default: 1)") + "\n" + #ifdef USE_UPNP #if USE_UPNP strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n";