Commit graph

801 commits

Author SHA1 Message Date
Wladimir J. van der Laan ef3758d1ef
Merge #10696: Remove redundant nullptr checks before deallocation
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-09 13:38:48 +01:00
Wladimir J. van der Laan 5ef3b6967b
Merge #11524: [net] De-duplicate connection eviction logic
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-08 08:46:50 +01:00
Thomas Snider 5ce7cb9518 [net] De-duplicate connection eviction logic 2017-11-07 15:33:15 -08:00
Suhas Daftuar ac7b37cd2b Connect to an extra outbound peer if our tip is stale
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-02 12:39:14 -04:00
Suhas Daftuar 2d4327db19 net: Allow connecting to extra outbound peers 2017-11-01 13:13:43 -04:00
Matt Corallo 15f5d3b172 Switch DNSSeed-needed metric to any-automatic-nodes, not services 2017-10-13 13:29:25 -04:00
Matt Corallo 57edc0b0c8 Rename fAddnode to a more-descriptive "manual_connection" 2017-10-13 13:25:58 -04:00
Matt Corallo 44407100ff Replace relevant services logic with a function suite.
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-13 13:25:57 -04:00
practicalswift 680bc2cbb3 Use range-based for loops (C++11) when looping over map elements
Before this commit:

  for (std::map<T1, T2>::iterator x = y.begin(); x != y.end(); ++x) {
  }

After this commit:

  for (auto& x : y) {
  }
2017-10-09 21:31:58 +02:00
Wladimir J. van der Laan 9d31ed2e69
Merge #10663: net: split resolve out of connect
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-28 17:05:47 +02:00
Pieter Wuille 8776787108
Merge #11301: add m_added_nodes to connman options
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-22 16:05:50 -07:00
practicalswift 9ad6746ccd Use static_cast instead of C-style casts for non-fundamental types
A C-style cast is equivalent to try casting in the following order:

1. const_cast(...)
2. static_cast(...)
3. const_cast(static_cast(...))
4. reinterpret_cast(...)
5. const_cast(reinterpret_cast(...))

By using static_cast<T>(...) explicitly we avoid the possibility
of an unintentional and dangerous reinterpret_cast. Furthermore
static_cast<T>(...) allows for easier grepping of casts.
2017-09-22 14:59:27 +02:00
Cory Fields 45fd75453e net: remove now-superfluous numeric resolve
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-18 13:47:47 -04:00
Cory Fields 2416dd7cc9 net: separate resolving and conecting
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-18 13:47:47 -04:00
Marko Bencun 05cae8aefd range-based loops and const qualifications in net.cpp
Plus a use of std::copy() instead of manual copying.
2017-09-12 09:11:22 +02:00
Marko Bencun 605918272c add m_added_nodes to connman options 2017-09-11 16:17:01 +02:00
Cory Fields 80e2e9d0ce net: drop unused connman param
The copy in PeerLogicValidation can be used instead.
2017-09-06 19:32:04 -04:00
Cory Fields 8ad663c1fa net: use an interface class rather than signals for message processing
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-06 19:32:04 -04:00
Cory Fields 28f11e9406 net: pass CConnman via pointer rather than reference
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-06 19:03:39 -04:00
Wladimir J. van der Laan 6866b4912b
Merge #10596: Add vConnect to CConnman::Options
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-09-06 02:03:48 +02:00
practicalswift 36d326e8b0 Use nullptr instead of zero (0) as the null pointer constant 2017-08-16 10:24:18 +02:00
practicalswift b109a1c396 Remove redundant nullptr checks before deallocation
Rationale:
* delete ptr is a no-op if ptr is nullptr
2017-08-14 17:45:15 +02:00
Marko Bencun bb81e17355 scripted-diff: stop using the gArgs wrappers
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-14 17:02:10 +02:00
practicalswift 90d4d89230 scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal 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-07 07:36:37 +02:00
practicalswift 11dd29b658 [net] Fix use of uninitialized value in getnetworkinfo(const JSONRPCRequest& 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.
2017-08-02 23:28:15 +02:00
Wladimir J. van der Laan 8a99fe053a
Merge #10501: remove some unused functions
f228b8e remove some unused functions (Marko Bencun)

Pull request description:

  Identified with `cppcheck --enable=unusedFunction .`.

   - GetSendBufferSize()'s last use removed in
     991955e
   - SetPort()'s last use removed in
     7e195e8
   - GetfLargeWorkInvalidChainFound() was introduced in
     e3ba0ef and never used

Tree-SHA512: ea8e5498bec981e42e1342c171c37723c2f5e575c7d6c1a524d9c6cd9b332bdd0d84fddf9e14ca011bb49fb82bd037386382c9afc546b3c2231ae548358bd4f4
2017-07-27 13:19:32 +02:00
Wladimir J. van der Laan 9dd6a2be41
Merge #10824: Avoid unnecessary work in SetNetworkActive
a2420ae Avoid unnecessary work in SetNetworkActive (João Barbosa)

Pull request description:

  This PR adds an early return to avoid unnecessary notifications when the status doesn't change.

Tree-SHA512: 85d05ca6fa36cb581f94bc154d08bd72cd53f6a857173c6fb2f184058f9c0208c4cf5e5d196825a78339902d8f256688eb6793f99abc7be9c7cfac85136180d9
2017-07-26 11:11:42 +02:00
Marko Bencun f228b8e163 remove some unused functions
Identified with `cppcheck --enable=unusedFunction .`.

 - GetSendBufferSize()'s last use removed in
   991955ee81
 - SetPort()'s last use removed in
   7e195e8459
 - GetfLargeWorkInvalidChainFound() was introduced in
   e3ba0ef956 and never used
2017-07-22 09:55:57 +02:00
Dag Robole 05e023f2ec Move CloseSocket out of SetSocketNonBlocking and pass SOCKET by const reference in SetSocket* functions 2017-07-22 09:11:55 +02:00
Marko Bencun 352d582ba2 Add vConnect to CConnman::Options
Split the "-connect" argument parsing out of CConnman and put it into
AppInitMain().
2017-07-19 23:34:50 +02:00
João Barbosa a2420ae2f1 Avoid unnecessary work in SetNetworkActive 2017-07-14 15:01:05 +01:00
Jeremy Rubin e0451e3e2a Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector 2017-07-08 13:31:47 -07:00
Jorge Timón 506b700dcb
Util: Remove redundant calls to gArgs.IsArgSet()
Return empty std::vector<std::string> with ArgsManager::GetArgs if
nothing is set for that string
2017-06-27 02:54:19 +02:00
Wladimir J. van der Laan 22a0aca329
Merge #10496: Add Binds, WhiteBinds, Whitelistedrange to CConnman::Options
07b2afe add Binds, WhiteBinds to CConnman::Options (Marko Bencun)
ce79f32 add WhitelistedRange to CConnman::Options (Marko Bencun)

Tree-SHA512: c23a6f317c955338af531fa3e53e3c42e995f88c6e1939bbc2ad119fa5b786c54b3dad3d2e9b3f830b7292c0c63a02fcff66a89907d0fa8d7c83aefade01af45
2017-06-26 15:04:54 +02:00
Wladimir J. van der Laan 2772dc9f21
Merge #10446: net: avoid extra dns query per seed
c1be285 chainparams: make supported service bits option explicit (Cory Fields)
d5c7c1c net: use an internal address for fixed seeds (Cory Fields)
6cdc488 net: switch to dummy internal ip for dns seed source (Cory Fields)
6d0bd5b net: do not allow resolving to an internal address (Cory Fields)
7f31762 net: add an internal subnet for representing unresolved hostnames (Cory Fields)

Tree-SHA512: 9bf1042bef546ac3ef0e0d3a9a5555eb21628ff2674a0cf8c6367194b22bfdab477adf452c0e7c56f44e0fb37debc5e14bdb623452e076fb9c492c7702601d7a
2017-06-24 12:25:13 +02:00
Cory Fields d5c7c1cfe3 net: use an internal address for fixed seeds 2017-06-22 15:21:22 -04:00
Marko Bencun 07b2afef10 add Binds, WhiteBinds to CConnman::Options
Part of a series of changes to clean up the instantiation of connman
by decoupling the command line arguments.

We also now abort with an error when explicit binds are set with
-listen=0.
2017-06-15 23:07:14 +02:00
Marko Bencun ce79f32518 add WhitelistedRange to CConnman::Options
Part of a series of changes to clean up the instantiation of connman
by decoupling the command line arguments.
2017-06-15 23:06:12 +02:00
Cory Fields 6cdc488e36 net: switch to dummy internal ip for dns seed source
This addresss the TODO to avoid resolving twice.
2017-06-14 18:05:01 -04:00
Cory Fields 7f31762cb6 net: add an internal subnet for representing unresolved hostnames
We currently do two resolves for dns seeds: one for the results, and one to
serve in addrman as the source for those addresses.

There's no requirement that the source hostname resolves to the stored
identifier, only that the mapping is unique. So rather than incurring the
second lookup, combine a private subnet with a hash of the hostname.

The resulting v6 ip is guaranteed not to be publicy routable, and has only a
negligible chance of colliding with a user's internal network (which would be
of no consequence anyway).
2017-06-14 18:05:00 -04:00
Pieter Wuille 1ad3d4e126
Merge #10502: scripted-diff: Remove BOOST_FOREACH, Q_FOREACH and PAIRTYPE
1238f13cf scripted-diff: Remove PAIRTYPE (Jorge Timón)
18dc3c396 scripted-diff: Remove Q_FOREACH (Jorge Timón)
7c00c2672 scripted-diff: Fully remove BOOST_FOREACH (Jorge Timón)
a5410ac5e Small preparations for Q_FOREACH, PAIRTYPE and #include <boost/foreach.hpp> removal (Jorge Timón)

Tree-SHA512: d3ab4a173366402e7dcef31608977b757d4aa07abbbad2ee1bcbcfa311e994a4552f24e5a55272cb22c2dcf89a4b0495e02e9d9aceae4b08c0bab668f20e324c
2017-06-13 18:05:58 -07:00
Gregory Maxwell bf376eaccc Return early in IsBanned.
I am not aware of any reason that we'd try to stop a ban-list timing
 side-channel and the prior code wouldn't be enough if we were.
2017-06-09 02:05:53 +00:00
Jorge Timón 7c00c26726
scripted-diff: Fully remove BOOST_FOREACH
-BEGIN VERIFY SCRIPT-
sed -i 's/BOOST_FOREACH *(\(.*\),/for (\1 :/' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp ;
-END VERIFY SCRIPT-
2017-06-05 20:10:50 +02:00
Wladimir J. van der Laan a7e3c2814c rpc: Add listen address to incoming connections in getpeerinfo
This adds the listening address on which incoming connections were received to the
CNode and CNodeStats structures.

The address is reported in `getpeerinfo`.

This can be useful for distinguishing connections received on different listening ports
(e.g. when using a different listening port for Tor hidden service connections)
or different networks.
2017-06-05 13:35:30 +02:00
Wladimir J. van der Laan cb1716acc7
Merge #10441: net: only enforce expected services for half of outgoing connections
b6fbfc2 net: only enforce the services required to connect (Cory Fields)

Tree-SHA512: 88943bff63213a734f3c96c45760cadaeb9ba18287c8a20c279851ebaf058a334c969028fb2180f155508e3eea4b838147382e4f2b655e7a9aa098eadc81d53e
2017-06-01 13:24:36 +02:00
Marko Bencun 5d67526026 add SeedNodes to CConnman::Options
Start of a series of changes to clean up the instantiation of connman
by decoupling the command line arguments.
2017-05-30 09:21:47 +02:00
Cory Fields b6fbfc2282 net: only enforce the services required to connect
also once half of all outgoing nodes have our preferred flags, require only
minimal flags from the rest.
2017-05-28 10:20:07 -04:00
Alex Morcos 307013469f Populate services in GetLocalAddress
Previously if we didn't have any local addresses, GetLocalAddress would return
0.0.0.0 and then we'd swap in a peer's notion of our address in AdvertiseLocal,
but then nServices would never get set.
2017-05-18 16:57:53 -04:00
Pieter Wuille ae786098bc
Merge #10061: [net] Added SetSocketNoDelay() utility function
ad415bc [net] Added SetSocketNoDelay() utility function (Thomas Snider)

Tree-SHA512: c19e3c9910b3fc2ef86f2434f3e91d343e9cd9e2116153941de9789e2a6fc0389bffe762d21b55cda4a4b1de993afee0564c6946e65d05cef9e866b58896f9af
2017-05-17 17:36:27 -07:00
Wladimir J. van der Laan 41987aa92f
Merge #9494: Introduce an ArgsManager class encapsulating cs_args, mapArgs and mapMultiArgs
78da882 Util: Small improvements in gArgs usage (Jorge Timón)
5292245 Util: Put mapMultiArgs inside ArgsManager (Jorge Timón)
b3cbd55 scripted-diff: Util: Encapsulate mapMultiArgs behind gArgs (Jorge Timón)
f2957ce Util: Create ArgsManager class... (Jorge Timón)

Tree-SHA512: 7d58250da440ad0f41745f46ab6021d6ecbb292035cab3d86fb08ce6bd822df604ac31b3ded6fd6914f7cfd12ba531cbc06a76eb500f629627f47ae6ac8350a7
2017-05-15 07:39:25 +02:00
Jorge Timón b3cbd554d9
scripted-diff: Util: Encapsulate mapMultiArgs behind gArgs
-BEGIN VERIFY SCRIPT-
sed -i 's/mapMultiArgs.count(/gArgs.IsArgSet(/g' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp ;
sed -i 's/mapMultiArgs.at("/gArgs.GetArgs("/g' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp ;
-END VERIFY SCRIPT-
2017-05-09 21:29:05 +02:00
Wladimir J. van der Laan 750c5a5b84
Merge #10189: devtools/net: add a verifier for scriptable changes. Use it to make CNode::id private.
0f3471f net: make CNode's id private (Cory Fields)
9ff0a51 scripted-diff: net: Use accessor rather than node's id directly (Cory Fields)
e50c33e devtools: add script to verify scriptable changes (Cory Fields)

Tree-SHA512: a0ff50f4e1d38a2b63109b4996546c91b3e02e00d92c0bf04f48792948f78b1f6d9227a15d25c823fd4723a0277fc6a32c2c1287c7abbb7e50fd82ffb0f8d994
2017-05-07 10:01:51 +02:00
Cory Fields 0f3471f3ad net: make CNode's id private 2017-05-04 01:04:47 -04:00
Cory Fields 9ff0a51164 scripted-diff: net: Use accessor rather than node's id directly
-BEGIN VERIFY SCRIPT-
sed -i "s/\(node\|to\|from\)->id/\1->GetId()/" src/net.cpp src/net_processing.cpp
-END VERIFY SCRIPT-
2017-05-04 01:04:47 -04:00
Wladimir J. van der Laan faf2dea5ea
Merge #10234: [net] listbanned RPC and QT should show correct banned subnets
d6732d8 [tests] update disconnect_ban.py test case to work with listbanned (John Newbery)
77c54b2 [net] listbanned RPC and QT should show correct banned subnets (John Newbery)

Tree-SHA512: edd0e43377d456260d2697213c2829f8483630f3a668b6707d52605faefa610d951d10e6f22a95eff483cbd14faa8ac9b69fa7d3c0b5735c5f3df23fd71282e0
2017-05-02 18:41:58 +02:00
John Newbery 77c54b270d [net] listbanned RPC and QT should show correct banned subnets 2017-04-28 11:24:33 -04:00
Wladimir J. van der Laan 9c94fb6c32
Merge #9930: Trivial: Correct indentation and bracing
31a14d4 Correct indentation and remove unnecessary braces (Matthias Grundmann)

Tree-SHA512: c0e827ec4474133c7674254dfd13f59608820cd639debc7759bddae71d73451645fcfe14384f343d08f74d69ac3922bafc12a514f3b790ae2bf9271aa67d5f36
2017-04-26 08:50:18 +02:00
Matt Corallo b2c9254205 Check interruptNet during dnsseed lookups 2017-04-14 16:52:42 -04:00
Thomas Snider ad415bc16a [net] Added SetSocketNoDelay() utility function 2017-04-05 11:31:43 -07:00
Matthias Grundmann 31a14d4909
Correct indentation and remove unnecessary braces 2017-04-02 14:41:38 +02:00
Gregory Maxwell 6b3bb3d9ba Change LogAcceptCategory to use uint32_t rather than sets of strings.
This changes the logging categories to boolean flags instead of strings.

This simplifies the acceptance testing by avoiding accessing a scoped
 static thread local pointer to a thread local set of strings.  It
 eliminates the only use of boost::thread_specific_ptr outside of
 lockorder debugging.

This change allows log entries to be directed to multiple categories
 and makes it easy to change the logging flags at runtime (e.g. via
 an RPC, though that isn't done by this commit.)

It also eliminates the fDebug global.

Configuration of unknown logging categories now produces a warning.
2017-04-01 18:53:29 +00:00
Wladimir J. van der Laan aab1e55860
Merge #9987: Remove unused code
8dc957a Remove unused code (practicalswift)

Tree-SHA512: c7bb286e3b92e42fec8aa1ac2491fd38be36602efca16b4bdc4e9d5ada75c11d99e7713092ec13794abd69d5ef2c732b86209a6d01710e5ebf6fc51b8a65c92a
2017-03-18 10:10:33 +01:00
practicalswift 8dc957ae06 Remove unused code 2017-03-17 04:37:43 +01:00
Wladimir J. van der Laan 8b789d8141
Merge #9921: build: Probe MSG_DONTWAIT in the same way as MSG_NOSIGNAL
a4d1c9f compat: use `unsigned int` instead of `u_int` (Wladimir J. van der Laan)
25da1ee build: cleanup: define MSG_DONTWAIT/MSG_NO_SIGNAL locally (Wladimir J. van der Laan)
c459d50 build: Probe MSG_DONTWAIT in the same way as MSG_NOSIGNAL (Wladimir J. van der Laan)

Tree-SHA512: 60d79d69439bb181465e4244aa5ddc28bbd84f69c0ca0c753956b3798c9022394e29d791bc085fe7ffb1268c64c789a57e24797daad63525bb776088188ff9ae
2017-03-16 12:03:00 +01:00
Matt Corallo 819b513a54 Add missing braces in semaphore posts in net 2017-03-08 14:55:28 -05:00
Matt Corallo e007b243c4 Fix shutdown hang with >= 8 -addnodes set
We previously would block waiting for a CSemaphoreGrant in
ThreadOpenAddedConnections, when we did not need to. This would
block as the posts in CConnman shutdown were both to the wrong
semaphore and in the wrong location.
2017-03-08 14:41:57 -05:00
Matt Corallo 73296f54d6 CScheduler boost->std::function, use millisecs for times, not secs 2017-03-06 18:33:50 -05:00
Wladimir J. van der Laan 25da1ee36c build: cleanup: define MSG_DONTWAIT/MSG_NO_SIGNAL locally
Define MSG_DONTWAIT and MSG_NO_SIGNAL in the implementation files that
use them (`net.cpp` and `netbase.cpp`), instead of compat.h which is
included all over the place.

This avoids putting them in the global namespace, as defining them as 0
is a hack that works for our specific usage, but it is not a general
solution.

Also makes sure they are defined only once so the `!defined(MSG_x)` guard can go.
2017-03-05 09:47:29 +00:00
keystrike 6d37ee8314 Trivial: Debug log ambiguity fix for peer addrs
This line can be misinterpreted as loading wallet addresses which is confusing, especially when the wallet is disabled.
2017-02-28 22:14:24 -03:00
Wladimir J. van der Laan b08656e343
Merge #9715: Disconnect peers which we do not receive VERACKs from within 60 sec
66f861a Add a test for P2P inactivity timeouts (Matt Corallo)
b436f92 qa: Expose on-connection to mininode listeners (Matt Corallo)
8aaba7a qa: mininode learns when a socket connects, not its first action (Matt Corallo)
2cbd119 Disconnect peers which we do not receive VERACKs from within 60 sec (Matt Corallo)
2017-02-14 14:35:15 +01:00
Matt Corallo db2dc7a58c Move CNode::addrLocal access behind locked accessors 2017-02-10 11:32:41 -05:00
Matt Corallo 036073bf87 Move CNode::addrName accesses behind locked accessors 2017-02-10 11:32:41 -05:00
Matt Corallo 22b4966a29 Move [clean|str]SubVer writes/copyStats into a lock 2017-02-10 11:32:41 -05:00
Matt Corallo 512731bed0 Access fRelayTxes with cs_filter lock in copyStats 2017-02-10 11:32:40 -05:00
Matt Corallo ae683c1b19 Avoid copying CNodeStats to make helgrind OK with buggy std::string 2017-02-10 11:32:40 -05:00
Matt Corallo 644f1234e2 Make nTimeConnected const in CNode 2017-02-10 11:32:40 -05:00
Cory Fields 321d0fc6b6 net: fix a few races. Credit @TheBlueMatt
These are (afaik) all long-standing races or concurrent accesses. Going
forward, we can clean these up so that they're not all individual atomic
accesses.

- Reintroduce cs_vRecv to guard receive-specific vars
- Lock vRecv/vSend for CNodeStats
- Make some vars atomic.
- Only set the connection time in CNode's constructor so that it doesn't change
2017-02-10 11:32:39 -05:00
Wladimir J. van der Laan 2447c1024e
Merge #9698: net: fix socket close race
9a0b784 net: add a lock around hSocket (Cory Fields)
45e2e08 net: rearrange so that socket accesses can be grouped together (Cory Fields)
2017-02-10 12:42:53 +01:00
Wladimir J. van der Laan dd163f5788
Merge #9674: Always enforce strict lock ordering (try or not)
618ee92 Further-enforce lockordering by enforcing directly after TRY_LOCKs (Matt Corallo)
2a962d4 Fixup style a bit by moving { to the same line as if statements (Matt Corallo)
8465631 Always enforce lock strict lock ordering (try or not) (Matt Corallo)
fd13eca Lock cs_vSend and cs_inventory in a consistent order even in TRY (Matt Corallo)
2017-02-08 14:46:43 +01:00
Matt Corallo 2cbd1196b7 Disconnect peers which we do not receive VERACKs from within 60 sec 2017-02-07 17:44:46 -05:00
Cory Fields 9a0b784dea net: add a lock around hSocket 2017-02-06 14:48:50 -05:00
Cory Fields 45e2e08561 net: rearrange so that socket accesses can be grouped together 2017-02-06 14:48:50 -05:00
Wladimir J. van der Laan 09e0c28f85
Merge #9659: Net: Turn some methods and params/variables const
0729102 Net: pass interruptMsgProc as const where possible (Jorge Timón)
fc7f2ff Net: Make CNetMsgMaker more const (Jorge Timón)
d45955f Net: CConnman: Make some methods const (Jorge Timón)
2017-02-06 14:34:53 +01:00
Matt Corallo 2a962d4540 Fixup style a bit by moving { to the same line as if statements 2017-02-04 16:44:05 -05:00
Wladimir J. van der Laan 7821db30e1
Merge #9671: Fix super-unlikely race introduced in 236618061a
885cfdd Fix super-unlikely race introduced in 236618061a (Matt Corallo)
2017-02-04 11:39:17 +01:00
Matt Corallo fd13eca147 Lock cs_vSend and cs_inventory in a consistent order even in TRY 2017-02-02 20:03:46 -05:00
Cory Fields 08bb6f4ed4 net: log an error rather than asserting if send version is misused
Also cleaned up the comments and moved from the header to the .cpp so that
logging headers aren't needed from net.h
2017-02-02 16:14:16 -05:00
Cory Fields 12752af0cc net: don't run callbacks on nodes that haven't completed the version handshake
Since ForEach* are can be used to send messages to  all nodes, the caller may
end up sending a message before the version handshake is complete. To limit
this, filter out these nodes. While we're at it, may as well filter out
disconnected nodes as well.

Delete unused methods rather than updating them.
2017-02-02 16:14:16 -05:00
Matt Corallo 885cfdd217 Fix super-unlikely race introduced in 236618061a
Once the CNode has been added to vNodes, it is possible that it is
disconnected+deleted in the socket handler thread. However, after
that we now call InitializeNode, which accesses the pnode.

helgrind managed to tickle this case (somehow), but I suspect it
requires in immensely braindead scheduler.
2017-02-02 13:51:57 -05:00
Jorge Timón d45955fa09
Net: CConnman: Make some methods const 2017-01-31 23:20:26 +01:00
Wladimir J. van der Laan 36966a1c0e
Merge #9626: Clean up a few CConnman cs_vNodes/CNode things
2366180 Do not add to vNodes until fOneShot/fFeeler/fAddNode have been set (Matt Corallo)
3c37dc4 Ensure cs_vNodes is held when using the return value from FindNode (Matt Corallo)
5be0190 Delete some unused (and broken) functions in CConnman (Matt Corallo)
2017-01-30 12:48:43 +01:00
Wladimir J. van der Laan 3f9f9629cc
Merge #9606: net: Consistently use GetTimeMicros() for inactivity checks
99464bc net: Consistently use GetTimeMicros() for inactivity checks (Suhas Daftuar)
2017-01-26 09:57:45 +01:00
Matt Corallo 236618061a Do not add to vNodes until fOneShot/fFeeler/fAddNode have been set 2017-01-25 18:59:16 -05:00
Suhas Daftuar 99464bc38e net: Consistently use GetTimeMicros() for inactivity checks
The use of mocktime in test logic means that comparisons between
GetTime() and GetTimeMicros()/1000000 are unreliable since the former
can use mocktime values while the latter always gets the system clock;
this changes the networking code's inactivity checks to consistently
use the system clock for inactivity comparisons.

Also remove some hacks from setmocktime() that are no longer needed,
now that we're using the system clock for nLastSend and nLastRecv.
2017-01-25 09:48:14 -05:00
Matt Corallo 3c37dc40d3 Ensure cs_vNodes is held when using the return value from FindNode 2017-01-24 17:01:45 -05:00
Matt Corallo 5be01906e5 Delete some unused (and broken) functions in CConnman 2017-01-24 17:01:43 -05:00
Matt Corallo 376b3c2c6e Make the cs_sendProcessing a LOCK instead of a TRY_LOCK
Technically cs_sendProcessing is entirely useless now because it
is only ever taken on the one MessageHandler thread, but because
there may be multiple of those in the future, it is left in place
2017-01-13 10:34:38 -08:00
Matt Corallo d7c58ad514 Split CNode::cs_vSend: message processing and message sending
cs_vSend is used for two purposes - to lock the datastructures used
to queue messages to place on the wire and to only call
SendMessages once at a time per-node. I believe SendMessages used
to access some of the vSendMsg stuff, but it doesn't anymore, so
these locks do not need to be on the same mutex, and also make
deadlocking much more likely.
2017-01-13 10:34:37 -08:00
Pieter Wuille 8b66bf74e2
Merge #9441: Net: Massive speedup. Net locks overhaul
e60360e net: remove cs_vRecvMsg (Cory Fields)
991955e net: add a flag to indicate when a node's send buffer is full (Cory Fields)
c6e8a9b net: add a flag to indicate when a node's process queue is full (Cory Fields)
4d712e3 net: add a new message queue for the message processor (Cory Fields)
c5a8b1b net: rework the way that the messagehandler sleeps (Cory Fields)
c72cc88 net: remove useless comments (Cory Fields)
ef7b5ec net: Add a simple function for waking the message handler (Cory Fields)
f5c36d1 net: record bytes written before notifying the message processor (Cory Fields)
60befa3 net: handle message accounting in ReceiveMsgBytes (Cory Fields)
56212e2 net: set message deserialization version when it's actually time to deserialize (Cory Fields)
0e973d9 net: remove redundant max sendbuffer size check (Cory Fields)
6042587 net: wait until the node is destroyed to delete its recv buffer (Cory Fields)
f6315e0 net: only disconnect if fDisconnect has been set (Cory Fields)
5b4a8ac net: make GetReceiveFloodSize public (Cory Fields)
e5bcd9c net: make vRecvMsg a list so that we can use splice() (Cory Fields)
53ad9a1 net: fix typo causing the wrong receive buffer size (Cory Fields)
2017-01-13 10:02:18 -08:00
Cory Fields e60360e139 net: remove cs_vRecvMsg
vRecvMsg is now only touched by the socket handler thread.

The accounting vars (nRecvBytes/nLastRecv/mapRecvBytesPerMsgCmd) are also
only used by the socket handler thread, with the exception of queries from
rpc/gui. These accesses are not threadsafe, but they never were. This needs to
be addressed separately.

Also, update comment describing data flow
2017-01-12 23:08:08 -05:00
Cory Fields 991955ee81 net: add a flag to indicate when a node's send buffer is full
Similar to the recv flag, but this one indicates whether or not the net's send
buffer is full.

The socket handler checks the send queue when a new message is added and pauses
if necessary, and possibly unpauses after each message is drained from its buffer.
2017-01-12 23:05:59 -05:00
Cory Fields c6e8a9bcff net: add a flag to indicate when a node's process queue is full
Messages are dumped very quickly from the socket handler to the processor, so
it's the depth of the processing queue that's interesting.

The socket handler checks the process queue's size during the brief message
hand-off and pauses if necessary, and the processor possibly unpauses each time
a message is popped off of its queue.
2017-01-12 23:05:47 -05:00
Cory Fields 4d712e366c net: add a new message queue for the message processor
This separates the storage of messages from the net and queued messages for
processing, allowing the locks to be split.
2017-01-12 23:05:25 -05:00
Cory Fields c5a8b1b946 net: rework the way that the messagehandler sleeps
In order to sleep accurately, the message handler needs to know if _any_ node
has more processing that it should do before the entire thread sleeps.

Rather than returning a value that represents whether ProcessMessages
encountered a message that should trigger a disconnnect, interpret the return
value as whether or not that node has more work to do.

Also, use a global fProcessWake value that can be set by other threads,
which takes precedence (for one cycle) over the messagehandler's decision.

Note that the previous behavior was to only process one message per loop
(except in the case of a bad checksum or invalid header). That was changed in
PR #3180.

The only change here in that regard is that the current node now falls to the
back of the processing queue for the bad checksum/invalid header cases.
2017-01-12 23:05:24 -05:00
Cory Fields ef7b5ecbb7 net: Add a simple function for waking the message handler
This may be used publicly in the future
2017-01-12 23:05:09 -05:00
Cory Fields f5c36d19b6 net: record bytes written before notifying the message processor 2017-01-12 23:05:09 -05:00
Cory Fields 60befa3997 net: handle message accounting in ReceiveMsgBytes
This allows locking to be pushed down to only where it's needed

Also reuse the current time rather than checking multiple times.
2017-01-12 23:05:09 -05:00
Douglas Roark cc0589639c
Remove stray semicolon (Fix empty body warning)
Empty body introduced by commit #9319 should not be empty.
2017-01-07 09:49:14 -08:00
Gregory Maxwell 032ba3f066 RPC help documentation for addnode peerinfo.
Also adds a comment about the netgroup exclusion behavior.
2017-01-05 19:02:15 +00:00
Gregory Maxwell 50bd12ce0c Break addnode out from the outbound connection limits.
Previously addnodes were in competition with outbound connections
 for access to the eight outbound slots.

One result of this is that frequently a node with several addnode
 configured peers would end up connected to none of them, because
 while the addnode loop was in its two minute sleep the automatic
 connection logic would fill any free slots with random peers.
 This is particularly unwelcome to users trying to maintain links
 to specific nodes for fast block relay or purposes.

Another result is that a group of nine or more nodes which are
 have addnode configured towards each other can become partitioned
 from the public network.

This commit introduces a new limit of eight connections just for
 addnode peers which is not subject to any of the other connection
 limitations (including maxconnections).

The choice of eight is sufficient so that under no condition would
 a user find themselves connected to fewer addnoded peers than
 previously.  It is also low enough that users who are confused
 about the significance of more connections and have gotten too
 copy-and-paste happy will not consume more than twice the slot
 usage of a typical user.

Any additional load on the network resulting from this will likely
 be offset by a reduction in users applying even more wasteful
 workaround for the prior behavior.

The retry delays are reduced to avoid nodes sitting around without
 their added peers up, but are still sufficient to prevent overly
 aggressive repeated connections.  The reduced delays also make
 the system much more responsive to the addnode RPC.

Ban-disconnects are also exempted for peers added via addnode since
 the outbound addnode logic ignores bans.  Previously it would ban
 an addnode then immediately reconnect to it.

A minor change was also made to CSemaphoreGrant so that it is
 possible to re-acquire via an object whos grant was moved.
2017-01-05 19:02:09 +00:00
Cory Fields 56212e20ac net: set message deserialization version when it's actually time to deserialize
We'll soon no longer have access to vRecvMsg, and this is more intuitive anyway.
2017-01-04 10:10:35 -05:00
Cory Fields 60425870d7 net: wait until the node is destroyed to delete its recv buffer
when vRecvMsg becomes a private buffer, it won't make sense to allow other
threads to mess with it anymore.
2017-01-04 09:29:14 -05:00
Cory Fields f6315e07f9 net: only disconnect if fDisconnect has been set
These conditions are problematic to check without locking, and we shouldn't be
relying on the refcount to disconnect.
2017-01-04 09:29:14 -05:00
Cory Fields e5bcd9c84f net: make vRecvMsg a list so that we can use splice() 2017-01-04 09:29:14 -05:00
Cory Fields 53ad9a133a net: fix typo causing the wrong receive buffer size
Surprisingly this hasn't been causing me any issues while testing, probably
because it requires lots of large blocks to be flying around.

Send/Recv corks need tests!
2017-01-04 09:29:14 -05:00
Wladimir J. van der Laan d9ae1cefa0
Merge #9289: net: drop boost::thread_group
67ee4ec net: misc header cleanups (Cory Fields)
8b3159e net: make proxy receives interruptible (Cory Fields)
5cb0fce net: remove thread_interrupted catch (Cory Fields)
d3d7056 net: make net processing interruptible (Cory Fields)
0985052 net: make net interruptible (Cory Fields)
799df91 net: add CThreadInterrupt and InterruptibleSleep (Cory Fields)
7325b15 net: a few small cleanups before replacing boost threads (Cory Fields)
2017-01-04 12:21:53 +01:00
Cory Fields 67ee4ec901 net: misc header cleanups 2017-01-03 17:56:21 -05:00
Cory Fields 8b3159ef0a net: make proxy receives interruptible 2017-01-03 17:56:21 -05:00
Cory Fields d3d7056d2a net: make net processing interruptible 2017-01-03 17:56:20 -05:00
Cory Fields 0985052319 net: make net interruptible
Also now that net threads are interruptible, switch them to use std
threads/binds/mutexes/condvars.
2017-01-03 17:53:09 -05:00
Cory Fields 7325b15566 net: a few small cleanups before replacing boost threads
- Drop the interruption point directly after the pnode allocation. This would
    be leaky if hit.
- Rearrange thread creation so that the socket handler comes first
2017-01-03 17:53:09 -05:00
isle2983 27765b6403 Increment MIT Licence copyright header year on files modified in 2016
Edited via:

$ contrib/devtools/copyright_header.py update .
2016-12-31 11:01:21 -07:00
Matt Corallo 2b5f085ad1 Fix non-const mapMultiArgs[] access after init.
Swap mapMultiArgs for a const-reference to a _mapMultiArgs which is
only accessed in util.cpp
2016-12-23 21:30:15 -05:00
Pieter Wuille 3bf06e9bac
Merge #9226: Remove fNetworkNode and pnodeLocalHost.
bdb922b Remove pnodeLocalHost. (Gregory Maxwell)
083f203 Remove fNetworkNode. (Gregory Maxwell)
2016-11-30 17:15:58 -08:00
Wladimir J. van der Laan 5488514b90
Merge #9225: Fix some benign races
dfed983 Fix unlocked access to vNodes.size() (Matt Corallo)
3033522 Remove double brackets in addrman (Matt Corallo)
dbfaade Fix AddrMan locking (Matt Corallo)
047ea10 Make fImporting an std::atomic (Matt Corallo)
42071ca Make fDisconnect an std::atomic (Matt Corallo)
2016-11-29 12:39:33 +01:00
Gregory Maxwell bdb922b34c Remove pnodeLocalHost.
Mostly a legacy of the long removed pub/sub system.
2016-11-27 04:19:37 +00:00
Gregory Maxwell 083f203698 Remove fNetworkNode.
Matt pointed out to me that this appeared to be doing nothing (except involving itself in data races).
2016-11-27 04:13:54 +00:00
Matt Corallo dfed983f19 Fix unlocked access to vNodes.size() 2016-11-26 15:42:55 -08:00
Cory Fields c7be56dcef net: push only raw data into CConnman
This fixes one of the last major layer violations in the networking stack.

The network side is no longer in charge of message serialization, so it is now
decoupled from Bitcoin structures. Only the header is serialized and attached
to the payload.
2016-11-25 12:37:33 -05:00
Jonas Schnelli ab914a6530
Merge #8996: Network activity toggle
19f46f1 Qt: New network_disabled icon (Luke Dashjr)
54cf997 RPC/Net: Use boolean consistently for networkactive, and remove from getinfo (Luke Dashjr)
b2b33d9 Overhaul network activity toggle (Jonas Schnelli)
32efa79 Qt: Add GUI feedback and control of network activity state. (Jon Lund Steffensen)
e38993b RPC: Add "togglenetwork" method to toggle network activity temporarily (Jon Lund Steffensen)
7c9a98a Allow network activity to be temporarily suspended. (Jon Lund Steffensen)
2016-11-11 11:16:40 +01:00
Pieter Wuille 9f554e03eb
Merge #9045: Hash P2P messages as they are received instead of at process-time
fe1dc62 Hash P2P messages as they are received instead of at process-time (Matt Corallo)
2016-11-07 14:19:44 -08:00
Wladimir J. van der Laan c113a651f1
Merge #9052: Use RelevantServices instead of node_network in AttemptToEvict.
d32036a Use RelevantServices instead of node_network in AttemptToEvict. (Gregory Maxwell)
2016-11-07 13:14:04 +01:00
Cory Fields 902768099c net: handle version push in InitializeNode 2016-11-03 13:35:54 -07:00
Cory Fields 440f1d3e4c net: remove now-unused ssSend and Fuzz 2016-11-03 13:35:54 -07:00
Cory Fields 5c2169cc3f drop the optimistic write counter hack
This is now handled properly in realtime.
2016-11-03 13:35:54 -07:00
Cory Fields ea3326891d net: switch all callers to connman for pushing messages
Drop all of the old stuff.
2016-11-03 13:35:53 -07:00
Cory Fields 3e32cd09f6 connman is in charge of pushing messages
The changes here are dense and subtle, but hopefully all is more explicit
than before.

- CConnman is now in charge of sending data rather than the nodes themselves.
  This is necessary because many decisions need to be made with all nodes in
  mind, and a model that requires the nodes calling up to their manager quickly
  turns to spaghetti.

- The per-node-serializer (ssSend) has been replaced with a (quasi-)const
  send-version. Since the send version for serialization can only change once
  per connection, we now explicitly tag messages with INIT_PROTO_VERSION if
  they are sent before the handshake. With this done, there's no need to lock
  for access to nSendVersion.

  Also, a new stream is used for each message, so there's no need to lock
  during the serialization process.

- This takes care of accounting for optimistic sends, so the
  nOptimisticBytesWritten hack can be removed.

- -dropmessagestest and -fuzzmessagestest have not been preserved, as I suspect
  they haven't been used in years.
2016-11-03 13:32:09 -07:00
Gregory Maxwell d32036a47d Use RelevantServices instead of node_network in AttemptToEvict.
Use of node_network here is really meant to be a proxy of "likely to
 send us blocks in the future".  RelevantServices is the right criteria
 now.
2016-11-01 00:11:52 +00:00
Cory Fields 59ac5c5b72 net: Use deterministic randomness for CNode's nonce, and make it const 2016-10-31 17:17:18 -04:00
Cory Fields aff6584e09 net: constify a few CNode vars to indicate that they're threadsafe 2016-10-31 17:17:18 -04:00
Matt Corallo fe1dc62cef Hash P2P messages as they are received instead of at process-time 2016-10-30 18:04:57 -04:00
Wladimir J. van der Laan f14f07cb94
Merge #9008: [net] Remove assert(nMaxInbound > 0)
fa1c3c2 [net] Remove assert(nMaxInbound > 0) (MarcoFalke)
2016-10-25 12:37:05 +02:00
Gregory Maxwell 515e2642eb Make connect=0 disable automatic outbound connections.
Otherwise it just responds to this obvious bit of configuration by
 trying to connect to "0" in a loop.
2016-10-25 06:17:43 +00:00
MarcoFalke fa1c3c2eb0 [net] Remove assert(nMaxInbound > 0)
nMaxInbound might very well be 0 or -1, if the user prefers to keep
a small number of maxconnections.

Note: nMaxInbound of -1 means that the user set maxconnections
to 8 or less, but we still want to keep an additional slot for
the feeler connection.
2016-10-24 22:12:48 +02:00
Jon Lund Steffensen 32efa79e0e Qt: Add GUI feedback and control of network activity state.
Add getNetworkActive()/setNetworkActive() method to client model.
Send network active status through NotifyNetworkActiveChanged.
Indicate in tool tip of gui status bar network indicator whether network activity is disabled.
Indicate in debug window whether network activity is disabled and add button to allow user to toggle network activity state.
2016-10-24 10:23:58 +00:00
Jon Lund Steffensen 7c9a98aac8 Allow network activity to be temporarily suspended.
Added the function SetNetworkActive() which when called with argument set to false disconnects all nodes and sets the flag fNetworkActive to false. As long as this flag is false no new connections are attempted and no incoming connections are accepted. Network activity is reenabled by calling the function with argument true.
2016-10-24 10:23:58 +00:00
Wladimir J. van der Laan e44753c067
Merge #8949: Be more agressive in getting connections to peers with relevant services.
4630479 Make dnsseed's definition of acute need include relevant services. (Gregory Maxwell)
9583477 Be more aggressive in connecting to peers with relevant services. (Gregory Maxwell)
2016-10-19 10:43:54 +02:00
Gregory Maxwell 4630479135 Make dnsseed's definition of acute need include relevant services.
We normally prefer to connect to peers offering the relevant services.

If we're not connected to enough peers with relevant services, we
 probably don't know about them and could use dnsseed's help.
2016-10-19 08:07:02 +00:00
Wladimir J. van der Laan cdfb7755a6
Merge #8914: Kill insecure_random and associated global state
5eaaa83 Kill insecure_random and associated global state (Wladimir J. van der Laan)
2016-10-18 15:44:57 +02:00
Wladimir J. van der Laan f628d9a29a
Merge #8925: qt: Display minimum ping in debug window.
1724a40 Display minimum ping in debug window. (R E Broadley)
2016-10-18 15:16:39 +02:00