aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
AgeCommit message (Collapse)Author
2017-01-05Break addnode out from the outbound connection limits.Gregory Maxwell
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-04Merge #9289: net: drop boost::thread_groupWladimir J. van der Laan
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-03net: make net processing interruptibleCory Fields
2017-01-03net: make net interruptibleCory Fields
Also now that net threads are interruptible, switch them to use std threads/binds/mutexes/condvars.
2016-12-31Increment MIT Licence copyright header year on files modified in 2016isle2983
Edited via: $ contrib/devtools/copyright_header.py update .
2016-11-30Merge #9226: Remove fNetworkNode and pnodeLocalHost.Pieter Wuille
bdb922b Remove pnodeLocalHost. (Gregory Maxwell) 083f203 Remove fNetworkNode. (Gregory Maxwell)
2016-11-29Merge #9225: Fix some benign racesWladimir J. van der Laan
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-27Remove fNetworkNode.Gregory Maxwell
Matt pointed out to me that this appeared to be doing nothing (except involving itself in data races).
2016-11-25Make fDisconnect an std::atomicMatt Corallo
2016-11-25net: push only raw data into CConnmanCory Fields
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-25net: add CVectorWriter and CNetMsgMakerCory Fields
CVectorWriter is useful for overwriting or appending an existing byte vector. CNetMsgMaker is a shortcut for creating messages on-the-fly which are suitable for pushing to CConnman.
2016-11-11fNetworkActive is not protected by a lock, use an atomicJonas Schnelli
2016-11-11Merge #8996: Network activity toggleJonas Schnelli
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-09Merge #9039: Various serialization simplifcations and optimizationsWladimir J. van der Laan
d59a518 Use fixed preallocation instead of costly GetSerializeSize (Pieter Wuille) 25a211a Add optimized CSizeComputer serializers (Pieter Wuille) a2929a2 Make CSerAction's ForRead() constexpr (Pieter Wuille) a603925 Avoid -Wshadow errors (Pieter Wuille) 5284721 Get rid of nType and nVersion (Pieter Wuille) 657e05a Make GetSerializeSize a wrapper on top of CSizeComputer (Pieter Wuille) fad9b66 Make nType and nVersion private and sometimes const (Pieter Wuille) c2c5d42 Make streams' read and write return void (Pieter Wuille) 50e8a9c Remove unused ReadVersion and WriteVersion (Pieter Wuille)
2016-11-07Merge #9045: Hash P2P messages as they are received instead of at process-timePieter Wuille
fe1dc62 Hash P2P messages as they are received instead of at process-time (Matt Corallo)
2016-11-07Get rid of nType and nVersionPieter Wuille
Remove the nType and nVersion as parameters to all serialization methods and functions. There is only one place where it's read and has an impact (in CAddress), and even there it does not impact any of the recursively invoked serializers. Instead, the few places that need nType or nVersion are changed to read it directly from the stream object, through GetType() and GetVersion() methods which are added to all stream classes.
2016-11-07Make nType and nVersion private and sometimes constPieter Wuille
Make the various stream implementations' nType and nVersion private and const (except in CDataStream where we really need a setter).
2016-11-03net: handle version push in InitializeNodeCory Fields
2016-11-03net: remove now-unused ssSend and FuzzCory Fields
2016-11-03drop the optimistic write counter hackCory Fields
This is now handled properly in realtime.
2016-11-03net: switch all callers to connman for pushing messagesCory Fields
Drop all of the old stuff.
2016-11-03connman is in charge of pushing messagesCory Fields
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-10-31net: Use deterministic randomness for CNode's nonce, and make it constCory Fields
2016-10-31net: constify a few CNode vars to indicate that they're threadsafeCory Fields
2016-10-30Hash P2P messages as they are received instead of at process-timeMatt Corallo
2016-10-24RPC: Add "togglenetwork" method to toggle network activity temporarilyJon Lund Steffensen
RPC command "togglenetwork" toggles network and returns new state after command. RPC command "getinfo" returns "networkactive" field in output.
2016-10-24Allow network activity to be temporarily suspended.Jon Lund Steffensen
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-18Merge #8914: Kill insecure_random and associated global stateWladimir J. van der Laan
5eaaa83 Kill insecure_random and associated global state (Wladimir J. van der Laan)
2016-10-17Kill insecure_random and associated global stateWladimir J. van der Laan
There are only a few uses of `insecure_random` outside the tests. This PR replaces uses of insecure_random (and its accompanying global state) in the core code with an FastRandomContext that is automatically seeded on creation. This is meant to be used for inner loops. The FastRandomContext can be in the outer scope, or the class itself, then rand32() is used inside the loop. Useful e.g. for pushing addresses in CNode or the fee rounding, or randomization for coin selection. As a context is created per purpose, thus it gets rid of cross-thread unprotected shared usage of a single set of globals, this should also get rid of the potential race conditions. - I'd say TxMempool::check is not called enough to warrant using a special fast random context, this is switched to GetRand() (open for discussion...) - The use of `insecure_rand` in ConnectThroughProxy has been replaced by an atomic integer counter. The only goal here is to have a different credentials pair for each connection to go on a different Tor circuit, it does not need to be random nor unpredictable. - To avoid having a FastRandomContext on every CNode, the context is passed into PushAddress as appropriate. There remains an insecure_random for test usage in `test_random.h`.
2016-10-15Display minimum ping in debug window.R E Broadley
2016-10-04gui: fix ban from qt consoleCory Fields
Rather than doing a circle and re-resolving the node's IP, just use the one from nodestats directly. This requires syncing the addr field from CNode.
2016-09-22Comment on CConnman::nLocalServices meaninginstagibbs
2016-09-19Merge #8688: Move static global randomizer seeds into CConnmanWladimir J. van der Laan
d9ff591 Move static global randomizer seeds into CConnman (Pieter Wuille)
2016-09-19Move static global randomizer seeds into CConnmanPieter Wuille
2016-09-14net: fix maxuploadtarget settingCory Fields
This was broken by 63cafa6329e1a. Note that while this fixes the settings, it doesn't fix the actual usage of -maxuploadtarget completely, as there is currently a bug in the nOptimisticBytesWritten accounting that causes a delayed response if the target is reached. That bug will be addressed separately.
2016-09-08net: move MAX_FEELER_CONNECTIONS into connmanCory Fields
2016-09-08Convert ForEachNode* functions to take a templated function argument rather ↵Jeremy Rubin
than a std::function to eliminate std::function overhead
2016-09-08Made the ForEachNode* functions in src/net.cpp more pragmatic and self ↵Jeremy Rubin
documenting
2016-09-08net: move vNodesDisconnected into CConnmanCory Fields
2016-09-08net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::OptionsCory Fields
2016-09-08net: Introduce CConnection::Options to avoid passing so many paramsCory Fields
2016-09-08net: Drop StartNode/StopNode and use CConnman directlyCory Fields
2016-09-08net: pass CClientUIInterface into CConnmanCory Fields
2016-09-08net: Pass best block known height into CConnmanCory Fields
CConnman then passes the current best height into CNode at creation time. This way CConnman/CNode have no dependency on main for height, and the signals only move in one direction. This also helps to prevent identity leakage a tiny bit. Before this change, an attacker could theoretically make 2 connections on different interfaces. They would connect fully on one, and only establish the initial connection on the other. Once they receive a new block, they would relay it to your first connection, and immediately commence the version handshake on the second. Since the new block height is reflected immediately, they could attempt to learn whether the two connections were correlated. This is, of course, incredibly unlikely to work due to the small timings involved and receipt from other senders. But it doesn't hurt to lock-in nBestHeight at the time of connection, rather than letting the remote choose the time.
2016-09-08net: move max/max-outbound to CConnmanCory Fields
2016-09-08net: move semOutbound to CConnmanCory Fields
2016-09-08net: move nLocalServices/nRelevantServices to CConnmanCory Fields
These are in-turn passed to CNode at connection time. This allows us to offer different services to different peers (or test the effects of doing so).
2016-09-08net: move SendBufferSize/ReceiveFloodSize to CConnmanCory Fields
2016-09-08net: move send/recv statistics to CConnmanCory Fields
2016-09-08net: SocketSendData returns written sizeCory Fields