aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
AgeCommit message (Collapse)Author
2018-06-13Bugfix: Include <memory> for std::unique_ptrLuke Dashjr
GitHub-Pull: #12859 Rebased-From: a5bca13
2018-04-26Limit the number of IPs we use from each DNS seedere0
A risk exists where a malicious DNS seeder eclipses a node by returning an enormous number of IP addresses. In this commit we mitigate this risk by limiting the number of IP addresses addrman learns to 256 per DNS seeder. GitHub-Pull: #12626 Rebased-From: 46e7f80
2018-02-02net: don't retry failed oneshot connections foreverCory Fields
Github-Pull: #12329 Rebased-From: 660f5f19ae74cc81b83540fcb95a33ec437834c8 Tree-SHA512: 7e7401b0ade3a2482dd246cc92c795230b37001a13fd7d050847ea532b619106dfdfc113e95c2891c689d421b3dd775d1833789061cd90dc094f13c4f5f6b278
2018-02-01net: initialize socket to avoid closing random fd'sCory Fields
Github-Pull: #12326 Rebased-From: 96dbd381cf0ded169406bab3b1ba911a13d563c5 Tree-SHA512: 8b4a09974060e6d0992e7b9ec06c5de3ad2daf970c4484077fda803f37d3ed874dcb6fec226107b2aa0fa64cfe4116604ca4f90599430fcc622bbb805be55e1b
2018-01-24Merge #11512: Use GetDesireableServiceFlags in seeds, dnsseeds, fixing ↵Wladimir J. van der Laan
static seed adding 2b839ab Update chainparams comment for more info on service bits per dnsseed (Matt Corallo) 62e7642 Fall back to oneshot for DNS Seeds which don't support filtering. (Matt Corallo) 51ae766 Use GetDesireableServiceFlags in static seeds, document this. (Matt Corallo) fb6f6b1 bluematt's testnet-seed now supports x9 (and is just a static list) (Matt Corallo) Pull request description: 4440710 broke inserting entries into addrman from dnsseeds which did not support service bits, as well as static seeds. Static seeds were already being filtered by UA for 0.13.1+ (ie NODE_WITNESS), so simply changing the default service bits to include NODE_WITNESS (and updating docs appropriately) is sufficient. For DNS Seeds, not supporting NODE_WITNESS is no longer useful, so instead use non-filtering seeds as oneshot hosts irrespective of named proxy. I've set my testnet-seed to also support x9, though because it is simply a static host, it may be useful to leave the support off so that it is used as a oneshot to get addresses from a live node instead. I'm fine with either. Tree-SHA512: 3f17d4d2b0b84d876981c962d2b44cb0c8f95f52c56a48c6b35fd882f6d7a40805f320ec452985a1c0b34aebddb1922709156c3ceccd1b9f8363fd7cb537d21d
2018-01-19Fall back to oneshot for DNS Seeds which don't support filtering.Matt Corallo
This allows us to not have to update the chainparams whenever a DNS Seed changes its filtering support, as well fixes a bug introduced in 44407100f where returned nodes will never be attempted.
2018-01-19Use GetDesireableServiceFlags in static seeds, document this.Matt Corallo
44407100f broke inserting entries into addrman from static seeds (as well as dnsseeds which did not support service bits). Static seeds were already being filtered by UA for 0.13.1+ (ie NODE_WITNESS), so simply changing the default service bits to include NODE_WITNESS (and updating docs appropriately) is sufficient. For DNS Seeds, we will later fix by falling back to oneshot if a seed does not support filtering.
2018-01-03Increment MIT Licence copyright header year on files modified in 2017Akira Takizawa
2017-12-15Merge #11616: Update ban-state in case of dirty-state during periodic sweepWladimir J. van der Laan
57ac471 Call BannedListChanged outside of cs_setBanned lock (Jonas Schnelli) c853812 Update ban-state in case of dirty-state during periodic sweep (Jonas Schnelli) Pull request description: We do currently not update the UI during periodic ban list sweeps (via dump banlist). Fixes #11612 Tree-SHA512: bffbdcc03c63042177bdd511b0a9187c211c2b5011178481e8ee3e43a71eef1e4cd6b72f73672babab142b644f62f8b56f0aac1d26d3f19372b1f8644fec9395
2017-12-13Merge #11363: net: Split socket create/connectWladimir J. van der Laan
3830b6e net: use CreateSocket for binds (Cory Fields) df3bcf8 net: pass socket closing responsibility up to caller for outgoing connections (Cory Fields) 9e3b2f5 net: Move IsSelectableSocket check into socket creation (Cory Fields) 1729c29 net: split socket creation out of connection (Cory Fields) Pull request description: Requirement for #11227. We'll need to create sockets and perform the actual connect in separate steps, so break them up. #11227 adds an RAII wrapper around connection attempts, as a belt-and-suspenders in case a CloseSocket is missed. Tree-SHA512: de675bb718cc56d68893c303b8057ca062c7431eaa17ae7c4829caed119fa3f15b404d8f52aca22a6bca6e73a26fb79e898b335d090ab015bf6456cf417fc694
2017-12-12net: use CreateSocket for bindsCory Fields
2017-12-12net: Move IsSelectableSocket check into socket creationCory Fields
We use select in ConnectSocketDirectly, so this check needs to happen before that. IsSelectableSocket will not be relevant after upcoming changes to remove select.
2017-12-12net: split socket creation out of connectionCory Fields
Also, check for the correct error during socket creation
2017-12-12Merge #10574: Remove includes in .cpp files for things the corresponding .h ↵Wladimir J. van der Laan
file already included a720b92 Remove includes in .cpp files for things the corresponding .h file already included (practicalswift) Pull request description: Remove includes in .cpp files for things the corresponding .h file already included. Example case: * `addrdb.cpp` includes `addrdb.h` and `fs.h` * `addrdb.h` includes `fs.h` Then remove the direct inclusion of `fs.h` in `addrman.cpp` and rely on the indirect inclusion of `fs.h` via the included `addrdb.h`. In line with the header include guideline (see #10575). Tree-SHA512: 8704b9de3011a4c234db336a39f7d2c139e741cf0f7aef08a5d3e05197e1e18286b863fdab25ae9638af4ff86b3d52e5cab9eed66bfa2476063aa5c79f9b0346
2017-12-11Merge #11583: Do not make it trivial for inbound peers to generate log entriesWladimir J. van der Laan
be9f38c Do not make it trivial for inbound peers to generate log entries (Matt Corallo) Pull request description: Based on #11580 because I'm lazy. We should generally avoid writing to debug.log unconditionally for inbound peers which misbehave (the peer being about to be banned being an exception, since they cannot do this twice). Tree-SHA512: 8e59c8d08d00b1527951b30f4842d010a4c2fc440503ade112baa2c1b9afd0e0d1c5c2df83dde25183a242af45089cf9b9f873b71796771232ffb6c5fc6cc0cc
2017-11-30Merge #10493: Use range-based for loops (C++11) when looping over map elementsMarcoFalke
680bc2cbb Use range-based for loops (C++11) when looping over map elements (practicalswift) Pull request description: Before this commit: ```c++ for (std::map<T1, T2>::iterator x = y.begin(); x != y.end(); ++x) { T1 z = (*x).first; … } ``` After this commit: ```c++ for (auto& x : y) { T1 z = x.first; … } ``` Tree-SHA512: 954b136b7f5e6df09f39248a6b530fd9baa9ab59d7c2c7eb369fd4afbb591b7a52c92ee25f87f1745f47b41d6828b7abfd395b43daf84a55b4e6a3d45015e3a0
2017-11-21net: Add missing locks in net.{cpp,h}practicalswift
* writing variable 'nTotalBytesRecv' requires holding mutex 'cs_totalBytesRecv' exclusively * writing variables 'nTotalBytesSent'/'nMaxOutboundTotalBytesSentInCycle'/'nMaxOutboundCycleStartTime' require holding mutex 'cs_totalBytesSent' exclusively * writing variable 'nMaxOutboundTimeframe'/'nMaxOutboundLimit' require holding mutex 'cs_totalBytesSent' exclusively * writing variable 'vAddedNodes' requires holding mutex 'cs_vAddedNodes' exclusively
2017-11-19Call BannedListChanged outside of cs_setBanned lockJonas Schnelli
2017-11-16Remove includes in .cpp files for things the corresponding .h file already ↵practicalswift
included
2017-11-16scripted-diff: Replace #include "" with #include <> (ryanofsky)MeshCollider
-BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT-
2017-11-09Do not make it trivial for inbound peers to generate log entriesMatt Corallo
We should generally avoid writing to debug.log unconditionally for inbound peers which misbehave (the peer being about to be banned being an exception, since they cannot do this twice). To avoid removing logs for outbound peers, a new log is added to notify users when a new outbound peer is connected which mimics the version print.
2017-11-09Update ban-state in case of dirty-state during periodic sweepJonas Schnelli
2017-11-09Use MakeUnique<T>(...) instead of std::unique_ptr<T>(new T(...))practicalswift
2017-11-09Use unique_ptr for pfilter (CBloomFilter)practicalswift
2017-11-09Use unique_ptr for sem{Addnode,Outbound} (CSemaphore)practicalswift
2017-11-09Use unique_ptr for upnp_thread (boost::thread)practicalswift
2017-11-09Merge #10696: Remove redundant nullptr checks before deallocationWladimir J. van der Laan
b109a1c Remove redundant nullptr checks before deallocation (practicalswift) Pull request description: Rationale: * `delete ptr` is a no-op if `ptr` is `nullptr` Tree-SHA512: c98ce769125c4912186a8403cc08a59cfba85b7141af645c709b4c4eb90dd9cbdd6ed8076d50099d1e4ec2bf75917d1af6844082ec42bbb4d94d229a710e051c
2017-11-08Merge #11524: [net] De-duplicate connection eviction logicWladimir J. van der Laan
5ce7cb9 [net] De-duplicate connection eviction logic (Thomas Snider) Pull request description: While reviewing the safeguards against deliberate node isolation on the network by malicious actors, I found a good de-duplication candidate. I think this form is much more legible (the type of `cutoffs` notwithstanding). ReverseCompareNodeTimeConnected is not included in the list since the cutoff size is a function of the remaining number of nodes in the candidate eviction set. Tree-SHA512: ed17999fa9250dcf8448329219324477117e4ecd2d41dedd72ad253e44630eef50b3232c420f1862ebbfb9b8c94efbba1a235b519e39ff5946865c7d69a75280
2017-11-07[net] De-duplicate connection eviction logicThomas Snider
2017-11-02Connect to an extra outbound peer if our tip is staleSuhas Daftuar
If our tip hasn't updated in a while, that may be because our peers are not relaying blocks to us that we would consider valid. Allow connection to an additional outbound peer in that circumstance. Also, periodically check to see if we are exceeding our target number of outbound peers, and disconnect the one which has least recently announced a new block to us (choosing the newest such peer in the case of tie).
2017-11-01net: Allow connecting to extra outbound peersSuhas Daftuar
2017-10-13Switch DNSSeed-needed metric to any-automatic-nodes, not servicesMatt Corallo
2017-10-13Rename fAddnode to a more-descriptive "manual_connection"Matt Corallo
2017-10-13Replace relevant services logic with a function suite.Matt Corallo
Adds HasAllRelevantServices and GetRelevantServices, which check for NETWORK|WITNESS. This changes the following: * Removes nRelevantServices from CConnman, disconnecting it a bit more from protocol-level logic. * Replaces our sometimes-connect-to-!WITNESS-nodes logic with simply always requiring WITNESS|NETWORK for outbound non-feeler connections (feelers still only require NETWORK). * This has the added benefit of removing nServicesExpected from CNode - instead letting net_processing's VERSION message handling simply check HasAllRelevantServices. * This implies we believe WITNESS nodes to continue to be a significant majority of nodes on the network, but also because we cannot sync properly from !WITNESS nodes, it is strange to continue using our valuable outbound slots on them. * In order to prevent this change from preventing connection to -connect= nodes which have !WITNESS, -connect nodes are now given the "addnode" flag. This also allows outbound connections to !NODE_NETWORK nodes for -connect nodes (which was already true of addnodes). * Has the (somewhat unintended) consequence of changing one of the eviction metrics from the same sometimes-connect-to-!WITNESS-nodes metric to requiring HasRelevantServices. This should make NODE_NETWORK_LIMITED much simpler to implement.
2017-10-09Use range-based for loops (C++11) when looping over map elementspracticalswift
Before this commit: for (std::map<T1, T2>::iterator x = y.begin(); x != y.end(); ++x) { } After this commit: for (auto& x : y) { }
2017-09-28Merge #10663: net: split resolve out of connectWladimir J. van der Laan
b887676 net: remove now-unused functions (Cory Fields) 45fd754 net: remove now-superfluous numeric resolve (Cory Fields) 2416dd7 net: separate resolving and conecting (Cory Fields) Pull request description: This is a greatly simplified version of #10285, which only aims to address async resolving. It essentially breaks up two wrapper functions for things only used in one place (ConnectSocketDirectly/ConnectThroughProxy) in favor of calling them directly. This allows us to fully handle resolves before attempting a connection, as is necessary for async connections. As a bonus, I believe the logic is now much easier to follow than before. Tree-SHA512: f03f618107379edf3efe2a9f3e3677e8f075017ab140a0b4fdc3b8263e6beff148d55256263ab10bc2125ef089ca68e0d8e865beeae176f1eca544e769c976d3
2017-09-22Merge #11301: add m_added_nodes to connman optionsPieter Wuille
35e5c2269 remove unused IsArgSet check (Marko Bencun) 605918272 add m_added_nodes to connman options (Marko Bencun) Pull request description: Tree-SHA512: ca4527a964dcda816b32d335e7fe4d0d8a668a83fbc5e4707ee452d00a7089fa59a88c9f2b1ecdf50e673f2a63fc364b23979e0153f91136525eceec10c2ede2
2017-09-18net: remove now-superfluous numeric resolveCory Fields
This was added in order to help OpenNetworkConnection avoid creating a connection that it would end up aborting. It was necessary because resolving was done as part of the connection process. Now that resolving is separated from connecting, this case is detected before the connection is attempted.
2017-09-18net: separate resolving and conectingCory Fields
ConnectSocketByName handled resolves as necessary, obscuring the connection process. With them separated, each can be handled asynchronously. Also, since proxies must be considered now anyway, go ahead and eliminate the ConnectSocket wrapper and use ConnectSocketDirectly... directly.
2017-09-12range-based loops and const qualifications in net.cppMarko Bencun
Plus a use of std::copy() instead of manual copying.
2017-09-11add m_added_nodes to connman optionsMarko Bencun
2017-09-06net: drop unused connman paramCory Fields
The copy in PeerLogicValidation can be used instead.
2017-09-06net: use an interface class rather than signals for message processingCory Fields
Drop boost signals in favor of a stateful class. This will allow the message processing loop to actually move to net_processing in a future step.
2017-09-06net: pass CConnman via pointer rather than referenceCory Fields
There are a few too many edge-cases here to make this a scripted diff. The following commits will move a few functions into PeerLogicValidation, where the local connman instance can be used. This change prepares for that usage.
2017-09-06Merge #10596: Add vConnect to CConnman::OptionsWladimir J. van der Laan
352d582ba Add vConnect to CConnman::Options (Marko Bencun) Pull request description: Split the "-connect" argument parsing out of CConnman and put it into AppInitMain(). Tree-SHA512: f2d3efc4e2c5808ff98696ea20dd96df599bc472ed5afc9c3eea305d94c36a6ab50c632aa05396c7c34d1917d91b1e7ccd725656ff2631e2a36d9eac477455dc
2017-08-16Use nullptr instead of zero (0) as the null pointer constantpracticalswift
2017-08-14Remove redundant nullptr checks before deallocationpracticalswift
Rationale: * delete ptr is a no-op if ptr is nullptr
2017-08-14scripted-diff: stop using the gArgs wrappersMarko Bencun
They were temporary additions to ease the transition. -BEGIN VERIFY SCRIPT- find src/ -name "*.cpp" ! -wholename "src/util.h" ! -wholename "src/util.cpp" | xargs perl -i -pe 's/(?<!\.)(ParseParameters|ReadConfigFile|IsArgSet|(Soft|Force)?(Get|Set)(|Bool|)Arg(s)?)\(/gArgs.\1(/g' -END VERIFY SCRIPT-
2017-08-07scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal ↵practicalswift
instead of the macro NULL -BEGIN VERIFY SCRIPT- sed -i 's/\<NULL\>/nullptr/g' src/*.cpp src/*.h src/*/*.cpp src/*/*.h src/qt/*/*.cpp src/qt/*/*.h src/wallet/*/*.cpp src/wallet/*/*.h src/support/allocators/*.h sed -i 's/Prefer nullptr, otherwise SAFECOOKIE./Prefer NULL, otherwise SAFECOOKIE./g' src/torcontrol.cpp sed -i 's/tor: Using nullptr authentication/tor: Using NULL authentication/g' src/torcontrol.cpp sed -i 's/METHODS=nullptr/METHODS=NULL/g' src/test/torcontrol_tests.cpp src/torcontrol.cpp sed -i 's/nullptr certificates/NULL certificates/g' src/qt/paymentserver.cpp sed -i 's/"nullptr"/"NULL"/g' src/torcontrol.cpp src/test/torcontrol_tests.cpp -END VERIFY SCRIPT-
2017-08-02[net] Fix use of uninitialized value in getnetworkinfo(const JSONRPCRequest& ↵practicalswift
request) When running test_bitcoin under Valgrind I found the following issue: ``` $ valgrind src/test/test_bitcoin ... ==10465== Use of uninitialised value of size 8 ==10465== at 0x6D09B61: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21) ==10465== by 0x6D0B1BB: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<unsigned long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, unsigned long) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21) ==10465== by 0x6D0B36C: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, unsigned long) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21) ==10465== by 0x6D17699: std::ostream& std::ostream::_M_insert<unsigned long>(unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21) ==10465== by 0x4CAAD7: operator<< (ostream:171) ==10465== by 0x4CAAD7: formatValue<ServiceFlags> (tinyformat.h:345) ==10465== by 0x4CAAD7: void tinyformat::detail::FormatArg::formatImpl<ServiceFlags>(std::ostream&, char const*, char const*, int, void const*) (tinyformat.h:523) ==10465== by 0x1924D4: format (tinyformat.h:510) ==10465== by 0x1924D4: tinyformat::detail::formatImpl(std::ostream&, char const*, tinyformat::detail::FormatArg const*, int) (tinyformat.h:803) ==10465== by 0x553A55: vformat (tinyformat.h:947) ==10465== by 0x553A55: format<ServiceFlags> (tinyformat.h:957) ==10465== by 0x553A55: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > tinyformat::format<ServiceFlags>(char const*, ServiceFlags const&) (tinyformat.h:966) ==10465== by 0x54C952: getnetworkinfo(JSONRPCRequest const&) (net.cpp:462) ==10465== by 0x28EDB5: CallRPC(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (rpc_tests.cpp:31) ==10465== by 0x293947: rpc_tests::rpc_togglenetwork::test_method() (rpc_tests.cpp:88) ==10465== by 0x2950E5: rpc_tests::rpc_togglenetwork_invoker() (rpc_tests.cpp:84) ==10465== by 0x182496: invoke<void (*)()> (callback.hpp:56) ==10465== by 0x182496: boost::unit_test::ut_detail::callback0_impl_t<boost::unit_test::ut_detail::unused, void (*)()>::invoke() (callback.hpp:89) ... ``` The read of the uninitialized variable nLocalServices is triggered by g_connman->GetLocalServices() in getnetworkinfo(const JSONRPCRequest& request) (net.cpp:462): ```c++ UniValue getnetworkinfo(const JSONRPCRequest& request) { ... if(g_connman) obj.push_back(Pair("localservices", strprintf("%016x", g_connman->GetLocalServices()))); ... } ``` The reason for the uninitialized nLocalServices is that CConnman::Start(...) is not called by the tests, and hence the initialization normally performed by CConnman::Start(...) is not done. This commit adds a method Init(const Options& connOptions) which is called by both the constructor and CConnman::Start(...). This method initializes nLocalServices and the other relevant values from the supplied Options object.