From 31c45a927eaac934fb237433f156907092bf1d11 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 13 Oct 2017 21:17:51 -0700 Subject: Accept addresses with NODE_NETWORK_LIMITED flag --- src/net_processing.cpp | 2 +- src/protocol.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/net_processing.cpp b/src/net_processing.cpp index fc0ba82d8b..f633712912 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1801,7 +1801,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr // We only bother storing full nodes, though this may include // things which we would not make an outbound connection to, in // part because we may make feeler connections to them. - if (!MayHaveUsefulAddressDB(addr.nServices)) + if (!MayHaveUsefulAddressDB(addr.nServices) && !HasAllDesirableServiceFlags(addr.nServices)) continue; if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60) diff --git a/src/protocol.h b/src/protocol.h index 42eb57e4f0..ec5f55e4f6 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -316,10 +316,10 @@ static inline bool HasAllDesirableServiceFlags(ServiceFlags services) { /** * Checks if a peer with the given service flags may be capable of having a - * robust address-storage DB. Currently an alias for checking NODE_NETWORK. + * robust address-storage DB. */ static inline bool MayHaveUsefulAddressDB(ServiceFlags services) { - return services & NODE_NETWORK; + return (services & NODE_NETWORK) || (services & NODE_NETWORK_LIMITED); } /** A CService with information about it as peer */ -- cgit v1.2.3 From 6fe57bdaac17d49af9ec7f36c1414d5d2bcec564 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 13 Oct 2017 21:48:00 -0700 Subject: Connect to peers signaling NODE_NETWORK_LIMITED when out-of-IBD --- src/net.cpp | 1 + src/net.h | 1 + src/net_processing.cpp | 11 +++++++++-- src/protocol.cpp | 2 ++ src/protocol.h | 5 +++++ 5 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/net.cpp b/src/net.cpp index 03ed7e7fc1..b4b43c3bad 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2710,6 +2710,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn fOneShot = false; m_manual_connection = false; fClient = false; // set by version message + m_limited_node = false; // set by version message fFeeler = false; fSuccessfullyConnected = false; fDisconnect = false; diff --git a/src/net.h b/src/net.h index 0542ec1aaa..db0a1e62bb 100644 --- a/src/net.h +++ b/src/net.h @@ -643,6 +643,7 @@ public: bool fOneShot; bool m_manual_connection; bool fClient; + bool m_limited_node; //after BIP159 const bool fInbound; std::atomic_bool fSuccessfullyConnected; std::atomic_bool fDisconnect; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index f633712912..55d404d91e 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -892,6 +892,7 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB const int nNewHeight = pindexNew->nHeight; connman->SetBestHeight(nNewHeight); + g_initial_block_download_completed = !fInitialDownload; if (!fInitialDownload) { // Find the hashes of all blocks that weren't previously in the best chain. std::vector vHashes; @@ -1642,7 +1643,13 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr pfrom->cleanSubVer = cleanSubVer; } pfrom->nStartingHeight = nStartingHeight; - pfrom->fClient = !(nServices & NODE_NETWORK); + + // set nodes not relaying blocks and tx and not serving (parts) of the historical blockchain as "clients" + pfrom->fClient = (!(nServices & NODE_NETWORK) && !(nServices & NODE_NETWORK_LIMITED)); + + // set nodes not capable of serving the complete blockchain history as "limited nodes" + pfrom->m_limited_node = (!(nServices & NODE_NETWORK) && (nServices & NODE_NETWORK_LIMITED)); + { LOCK(pfrom->cs_filter); pfrom->fRelayTxes = fRelay; // set to true after we get the first filter* message @@ -3611,7 +3618,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic& interruptM // Message: getdata (blocks) // std::vector vGetData; - if (!pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { + if (!pto->fClient && ((fFetch && !pto->m_limited_node) || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { std::vector vToDownload; NodeId staller = -1; FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller, consensusParams); diff --git a/src/protocol.cpp b/src/protocol.cpp index c412ad9ffe..ea78ab6856 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -12,6 +12,8 @@ # include #endif +std::atomic g_initial_block_download_completed(false); + namespace NetMsgType { const char *VERSION="version"; const char *VERACK="verack"; diff --git a/src/protocol.h b/src/protocol.h index ec5f55e4f6..4907c38e5c 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -277,6 +278,7 @@ enum ServiceFlags : uint64_t { // BIP process. }; +extern std::atomic g_initial_block_download_completed; /** * Gets the set of service flags which are "desirable" for a given peer. * @@ -302,6 +304,9 @@ enum ServiceFlags : uint64_t { * should be updated appropriately to filter for the same nodes. */ static ServiceFlags GetDesirableServiceFlags(ServiceFlags services) { + if ((services & NODE_NETWORK_LIMITED) && g_initial_block_download_completed) { + return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS); + } return ServiceFlags(NODE_NETWORK | NODE_WITNESS); } -- cgit v1.2.3 From fa999affad115c09743f8b1f5812326c19753ba9 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Thu, 11 May 2017 14:59:57 +0200 Subject: [QA] Allow addrman loopback tests (add debug option -addrmantest) --- src/init.cpp | 1 + src/net.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index 84398d978c..79365d4935 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -447,6 +447,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-limitdescendantcount=", strprintf("Do not accept transactions if any ancestor would have or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT)); strUsage += HelpMessageOpt("-limitdescendantsize=", strprintf("Do not accept transactions if any ancestor would have more than kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT)); strUsage += HelpMessageOpt("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)"); + strUsage += HelpMessageOpt("-addrmantest", "Allows to test address relay on localhost"); } strUsage += HelpMessageOpt("-debug=", strprintf(_("Output debugging information (default: %u, supplying is optional)"), 0) + ". " + _("If is not supplied or if = 1, output all debugging information.") + " " + _(" can be:") + " " + ListLogCategories() + "."); diff --git a/src/net.cpp b/src/net.cpp index b4b43c3bad..ea6360f388 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -181,6 +181,10 @@ void AdvertiseLocal(CNode *pnode) if (fListen && pnode->fSuccessfullyConnected) { CAddress addrLocal = GetLocalAddress(&pnode->addr, pnode->GetLocalServices()); + if (gArgs.GetBoolArg("-addrmantest", false)) { + // use IPv4 loopback during addrmantest + addrLocal = CAddress(CService(LookupNumeric("127.0.0.1", GetListenPort())), pnode->GetLocalServices()); + } // If discovery is enabled, sometimes give our peer the address it // tells us that it sees us as in case it has a better idea of our // address than we do. @@ -189,7 +193,7 @@ void AdvertiseLocal(CNode *pnode) { addrLocal.SetIP(pnode->GetAddrLocal()); } - if (addrLocal.IsRoutable()) + if (addrLocal.IsRoutable() || gArgs.GetBoolArg("-addrmantest", false)) { LogPrint(BCLog::NET, "AdvertiseLocal: advertising address %s\n", addrLocal.ToString()); FastRandomContext insecure_rand; -- cgit v1.2.3 From eb9183535d5fc2dfe8c0e26378f2621d3473c303 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sat, 17 Feb 2018 21:28:50 +1100 Subject: Add setter for g_initial_block_download_completed --- src/net_processing.cpp | 2 +- src/protocol.cpp | 13 ++++++++++++- src/protocol.h | 11 ++++------- 3 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 55d404d91e..5a7c998af7 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -892,7 +892,7 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB const int nNewHeight = pindexNew->nHeight; connman->SetBestHeight(nNewHeight); - g_initial_block_download_completed = !fInitialDownload; + SetServiceFlagsIBDCache(!fInitialDownload); if (!fInitialDownload) { // Find the hashes of all blocks that weren't previously in the best chain. std::vector vHashes; diff --git a/src/protocol.cpp b/src/protocol.cpp index ea78ab6856..2ec26fbd3e 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -12,7 +12,7 @@ # include #endif -std::atomic g_initial_block_download_completed(false); +static std::atomic g_initial_block_download_completed(false); namespace NetMsgType { const char *VERSION="version"; @@ -129,6 +129,17 @@ bool CMessageHeader::IsValid(const MessageStartChars& pchMessageStartIn) const } +ServiceFlags GetDesirableServiceFlags(ServiceFlags services) { + if ((services & NODE_NETWORK_LIMITED) && g_initial_block_download_completed) { + return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS); + } + return ServiceFlags(NODE_NETWORK | NODE_WITNESS); +} + +void SetServiceFlagsIBDCache(bool state) { + g_initial_block_download_completed = state; +} + CAddress::CAddress() : CService() { diff --git a/src/protocol.h b/src/protocol.h index 4907c38e5c..e518d11944 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -278,7 +278,6 @@ enum ServiceFlags : uint64_t { // BIP process. }; -extern std::atomic g_initial_block_download_completed; /** * Gets the set of service flags which are "desirable" for a given peer. * @@ -303,12 +302,10 @@ extern std::atomic g_initial_block_download_completed; * If the NODE_NONE return value is changed, contrib/seeds/makeseeds.py * should be updated appropriately to filter for the same nodes. */ -static ServiceFlags GetDesirableServiceFlags(ServiceFlags services) { - if ((services & NODE_NETWORK_LIMITED) && g_initial_block_download_completed) { - return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS); - } - return ServiceFlags(NODE_NETWORK | NODE_WITNESS); -} +ServiceFlags GetDesirableServiceFlags(ServiceFlags services); + +/** Set the current IBD status in order to figure out the desirable service flags */ +void SetServiceFlagsIBDCache(bool status); /** * A shortcut for (services & GetDesirableServiceFlags(services)) -- cgit v1.2.3