LCOV - code coverage report
Current view: top level - src - net.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 99 178 55.6 %
Date: 2020-06-05 16:23:38 Functions: 19 41 46.3 %
Legend: Lines: hit, modifiedhit, not modified not hit, modifiednot hit, not modified

          Line data    Source code
#       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2             : // Copyright (c) 2009-2020 The Bitcoin Core developers
#       3             : // Distributed under the MIT software license, see the accompanying
#       4             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       5             : 
#       6             : #ifndef BITCOIN_NET_H
#       7             : #define BITCOIN_NET_H
#       8             : 
#       9             : #include <addrdb.h>
#      10             : #include <addrman.h>
#      11             : #include <amount.h>
#      12             : #include <bloom.h>
#      13             : #include <compat.h>
#      14             : #include <crypto/siphash.h>
#      15             : #include <hash.h>
#      16             : #include <limitedmap.h>
#      17             : #include <netaddress.h>
#      18             : #include <net_permissions.h>
#      19             : #include <policy/feerate.h>
#      20             : #include <protocol.h>
#      21             : #include <random.h>
#      22             : #include <streams.h>
#      23             : #include <sync.h>
#      24             : #include <threadinterrupt.h>
#      25             : #include <uint256.h>
#      26             : 
#      27             : #include <atomic>
#      28             : #include <deque>
#      29             : #include <stdint.h>
#      30             : #include <thread>
#      31             : #include <memory>
#      32             : #include <condition_variable>
#      33             : 
#      34             : #ifndef WIN32
#      35             : #include <arpa/inet.h>
#      36             : #endif
#      37             : 
#      38             : 
#      39             : class CScheduler;
#      40             : class CNode;
#      41             : class BanMan;
#      42             : struct bilingual_str;
#      43             : 
#      44             : /** Default for -whitelistrelay. */
#      45             : static const bool DEFAULT_WHITELISTRELAY = true;
#      46             : /** Default for -whitelistforcerelay. */
#      47             : static const bool DEFAULT_WHITELISTFORCERELAY = false;
#      48             : 
#      49             : /** Time after which to disconnect, after waiting for a ping response (or inactivity). */
#      50             : static const int TIMEOUT_INTERVAL = 20 * 60;
#      51             : /** Run the feeler connection loop once every 2 minutes or 120 seconds. **/
#      52             : static const int FEELER_INTERVAL = 120;
#      53             : /** The maximum number of new addresses to accumulate before announcing. */
#      54             : static const unsigned int MAX_ADDR_TO_SEND = 1000;
#      55             : /** Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable). */
#      56             : static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
#      57             : /** Maximum length of the user agent string in `version` message */
#      58             : static const unsigned int MAX_SUBVERSION_LENGTH = 256;
#      59             : /** Maximum number of automatic outgoing nodes over which we'll relay everything (blocks, tx, addrs, etc) */
#      60             : static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 8;
#      61             : /** Maximum number of addnode outgoing nodes */
#      62             : static const int MAX_ADDNODE_CONNECTIONS = 8;
#      63             : /** Maximum number of block-relay-only outgoing connections */
#      64             : static const int MAX_BLOCKS_ONLY_CONNECTIONS = 2;
#      65             : /** Maximum number of feeler connections */
#      66             : static const int MAX_FEELER_CONNECTIONS = 1;
#      67             : /** -listen default */
#      68             : static const bool DEFAULT_LISTEN = true;
#      69             : /** -upnp default */
#      70             : #ifdef USE_UPNP
#      71             : static const bool DEFAULT_UPNP = USE_UPNP;
#      72             : #else
#      73             : static const bool DEFAULT_UPNP = false;
#      74             : #endif
#      75             : /** The maximum number of peer connections to maintain. */
#      76             : static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
#      77             : /** The default for -maxuploadtarget. 0 = Unlimited */
#      78             : static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
#      79             : /** The default timeframe for -maxuploadtarget. 1 day. */
#      80             : static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24;
#      81             : /** Default for blocks only*/
#      82             : static const bool DEFAULT_BLOCKSONLY = false;
#      83             : /** -peertimeout default */
#      84             : static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
#      85             : 
#      86             : static const bool DEFAULT_FORCEDNSSEED = false;
#      87             : static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
#      88             : static const size_t DEFAULT_MAXSENDBUFFER    = 1 * 1000;
#      89             : 
#      90             : typedef int64_t NodeId;
#      91             : 
#      92             : struct AddedNodeInfo
#      93             : {
#      94             :     std::string strAddedNode;
#      95             :     CService resolvedAddress;
#      96             :     bool fConnected;
#      97             :     bool fInbound;
#      98             : };
#      99             : 
#     100             : class CNodeStats;
#     101             : class CClientUIInterface;
#     102             : 
#     103             : struct CSerializedNetMsg
#     104             : {
#     105          38 :     CSerializedNetMsg() = default;
#     106             :     CSerializedNetMsg(CSerializedNetMsg&&) = default;
#     107             :     CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default;
#     108             :     // No copying, only moves.
#     109             :     CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
#     110             :     CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;
#     111             : 
#     112             :     std::vector<unsigned char> data;
#     113             :     std::string command;
#     114             : };
#     115             : 
#     116             : 
#     117             : class NetEventsInterface;
#     118             : class CConnman
#     119             : {
#     120             : public:
#     121             : 
#     122             :     enum NumConnections {
#     123             :         CONNECTIONS_NONE = 0,
#     124             :         CONNECTIONS_IN = (1U << 0),
#     125             :         CONNECTIONS_OUT = (1U << 1),
#     126             :         CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
#     127             :     };
#     128             : 
#     129             :     struct Options
#     130             :     {
#     131             :         ServiceFlags nLocalServices = NODE_NONE;
#     132             :         int nMaxConnections = 0;
#     133             :         int m_max_outbound_full_relay = 0;
#     134             :         int m_max_outbound_block_relay = 0;
#     135             :         int nMaxAddnode = 0;
#     136             :         int nMaxFeeler = 0;
#     137             :         int nBestHeight = 0;
#     138             :         CClientUIInterface* uiInterface = nullptr;
#     139             :         NetEventsInterface* m_msgproc = nullptr;
#     140             :         BanMan* m_banman = nullptr;
#     141             :         unsigned int nSendBufferMaxSize = 0;
#     142             :         unsigned int nReceiveFloodSize = 0;
#     143             :         uint64_t nMaxOutboundTimeframe = 0;
#     144             :         uint64_t nMaxOutboundLimit = 0;
#     145             :         int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
#     146             :         std::vector<std::string> vSeedNodes;
#     147             :         std::vector<NetWhitelistPermissions> vWhitelistedRange;
#     148             :         std::vector<NetWhitebindPermissions> vWhiteBinds;
#     149             :         std::vector<CService> vBinds;
#     150             :         bool m_use_addrman_outgoing = true;
#     151             :         std::vector<std::string> m_specified_outgoing;
#     152             :         std::vector<std::string> m_added_nodes;
#     153             :         std::vector<bool> m_asmap;
#     154             :     };
#     155             : 
#     156         310 :     void Init(const Options& connOptions) {
#     157         310 :         nLocalServices = connOptions.nLocalServices;
#     158         310 :         nMaxConnections = connOptions.nMaxConnections;
#     159         310 :         m_max_outbound_full_relay = std::min(connOptions.m_max_outbound_full_relay, connOptions.nMaxConnections);
#     160         310 :         m_max_outbound_block_relay = connOptions.m_max_outbound_block_relay;
#     161         310 :         m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
#     162         310 :         nMaxAddnode = connOptions.nMaxAddnode;
#     163         310 :         nMaxFeeler = connOptions.nMaxFeeler;
#     164         310 :         m_max_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + nMaxFeeler;
#     165         310 :         nBestHeight = connOptions.nBestHeight;
#     166         310 :         clientInterface = connOptions.uiInterface;
#     167         310 :         m_banman = connOptions.m_banman;
#     168         310 :         m_msgproc = connOptions.m_msgproc;
#     169         310 :         nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
#     170         310 :         nReceiveFloodSize = connOptions.nReceiveFloodSize;
#     171         310 :         m_peer_connect_timeout = connOptions.m_peer_connect_timeout;
#     172         310 :         {
#     173         310 :             LOCK(cs_totalBytesSent);
#     174         310 :             nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
#     175         310 :             nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
#     176         310 :         }
#     177         310 :         vWhitelistedRange = connOptions.vWhitelistedRange;
#     178         310 :         {
#     179         310 :             LOCK(cs_vAddedNodes);
#     180         310 :             vAddedNodes = connOptions.m_added_nodes;
#     181         310 :         }
#     182         310 :     }
#     183             : 
#     184             :     CConnman(uint64_t seed0, uint64_t seed1);
#     185             :     ~CConnman();
#     186             :     bool Start(CScheduler& scheduler, const Options& options);
#     187             : 
#     188             :     void StopThreads();
#     189             :     void StopNodes();
#     190             :     void Stop()
#     191         159 :     {
#     192         159 :         StopThreads();
#     193         159 :         StopNodes();
#     194         159 :     };
#     195             : 
#     196             :     void Interrupt();
#     197          15 :     bool GetNetworkActive() const { return fNetworkActive; };
#     198           5 :     bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
#     199             :     void SetNetworkActive(bool active);
#     200             :     void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, bool fOneShot = false, bool fFeeler = false, bool manual_connection = false, bool block_relay_only = false);
#     201             :     bool CheckIncomingNonce(uint64_t nonce);
#     202             : 
#     203             :     bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
#     204             : 
#     205             :     void PushMessage(CNode* pnode, CSerializedNetMsg&& msg);
#     206             : 
#     207             :     template<typename Callable>
#     208             :     void ForEachNode(Callable&& func)
#     209           4 :     {
#     210           4 :         LOCK(cs_vNodes);
#     211          36 :         for (auto&& node : vNodes) {
#     212          36 :             if (NodeFullyConnected(node))
#     213          36 :                 func(node);
#     214          36 :         }
#     215           4 :     };
#     216             : 
#     217             :     template<typename Callable>
#     218             :     void ForEachNode(Callable&& func) const
#     219           0 :     {
#     220           0 :         LOCK(cs_vNodes);
#     221           0 :         for (auto&& node : vNodes) {
#     222           0 :             if (NodeFullyConnected(node))
#     223           0 :                 func(node);
#     224           0 :         }
#     225           0 :     };
#     226             : 
#     227             :     template<typename Callable, typename CallableAfter>
#     228             :     void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
#     229             :     {
#     230             :         LOCK(cs_vNodes);
#     231             :         for (auto&& node : vNodes) {
#     232             :             if (NodeFullyConnected(node))
#     233             :                 pre(node);
#     234             :         }
#     235             :         post();
#     236             :     };
#     237             : 
#     238             :     template<typename Callable, typename CallableAfter>
#     239             :     void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
#     240           0 :     {
#     241           0 :         LOCK(cs_vNodes);
#     242           0 :         for (auto&& node : vNodes) {
#     243           0 :             if (NodeFullyConnected(node))
#     244           0 :                 pre(node);
#     245           0 :         }
#     246           0 :         post();
#     247           0 :     };
#     248             : 
#     249             :     // Addrman functions
#     250             :     size_t GetAddressCount() const;
#     251             :     void SetServices(const CService &addr, ServiceFlags nServices);
#     252             :     void MarkAddressGood(const CAddress& addr);
#     253             :     void AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
#     254             :     std::vector<CAddress> GetAddresses();
#     255             : 
#     256             :     // This allows temporarily exceeding m_max_outbound_full_relay, with the goal of finding
#     257             :     // a peer that is better than all our current peers.
#     258             :     void SetTryNewOutboundPeer(bool flag);
#     259             :     bool GetTryNewOutboundPeer();
#     260             : 
#     261             :     // Return the number of outbound peers we have in excess of our target (eg,
#     262             :     // if we previously called SetTryNewOutboundPeer(true), and have since set
#     263             :     // to false, we may have extra peers that we wish to disconnect). This may
#     264             :     // return a value less than (num_outbound_connections - num_outbound_slots)
#     265             :     // in cases where some outbound connections are not yet fully connected, or
#     266             :     // not yet fully disconnected.
#     267             :     int GetExtraOutboundCount();
#     268             : 
#     269             :     bool AddNode(const std::string& node);
#     270             :     bool RemoveAddedNode(const std::string& node);
#     271             :     std::vector<AddedNodeInfo> GetAddedNodeInfo();
#     272             : 
#     273             :     size_t GetNodeCount(NumConnections num);
#     274             :     void GetNodeStats(std::vector<CNodeStats>& vstats);
#     275             :     bool DisconnectNode(const std::string& node);
#     276             :     bool DisconnectNode(const CSubNet& subnet);
#     277             :     bool DisconnectNode(const CNetAddr& addr);
#     278             :     bool DisconnectNode(NodeId id);
#     279             : 
#     280             :     //! Used to convey which local services we are offering peers during node
#     281             :     //! connection.
#     282             :     //!
#     283             :     //! The data returned by this is used in CNode construction,
#     284             :     //! which is used to advertise which services we are offering
#     285             :     //! that peer during `net_processing.cpp:PushNodeVersion()`.
#     286             :     ServiceFlags GetLocalServices() const;
#     287             : 
#     288             :     //!set the max outbound target in bytes
#     289             :     void SetMaxOutboundTarget(uint64_t limit);
#     290             :     uint64_t GetMaxOutboundTarget();
#     291             : 
#     292             :     //!set the timeframe for the max outbound target
#     293             :     void SetMaxOutboundTimeframe(uint64_t timeframe);
#     294             :     uint64_t GetMaxOutboundTimeframe();
#     295             : 
#     296             :     //! check if the outbound target is reached
#     297             :     //! if param historicalBlockServingLimit is set true, the function will
#     298             :     //! response true if the limit for serving historical blocks has been reached
#     299             :     bool OutboundTargetReached(bool historicalBlockServingLimit);
#     300             : 
#     301             :     //! response the bytes left in the current max outbound cycle
#     302             :     //! in case of no limit, it will always response 0
#     303             :     uint64_t GetOutboundTargetBytesLeft();
#     304             : 
#     305             :     //! response the time in second left in the current max outbound cycle
#     306             :     //! in case of no limit, it will always response 0
#     307             :     uint64_t GetMaxOutboundTimeLeftInCycle();
#     308             : 
#     309             :     uint64_t GetTotalBytesRecv();
#     310             :     uint64_t GetTotalBytesSent();
#     311             : 
#     312             :     void SetBestHeight(int height);
#     313             :     int GetBestHeight() const;
#     314             : 
#     315             :     /** Get a unique deterministic randomizer. */
#     316             :     CSipHasher GetDeterministicRandomizer(uint64_t id) const;
#     317             : 
#     318             :     unsigned int GetReceiveFloodSize() const;
#     319             : 
#     320             :     void WakeMessageHandler();
#     321             : 
#     322             :     /** Attempts to obfuscate tx time through exponentially distributed emitting.
#     323             :         Works assuming that a single interval is used.
#     324             :         Variable intervals will result in privacy decrease.
#     325             :     */
#     326             :     int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds);
#     327             : 
#     328           0 :     void SetAsmap(std::vector<bool> asmap) { addrman.m_asmap = std::move(asmap); }
#     329             : 
#     330             : private:
#     331             :     struct ListenSocket {
#     332             :     public:
#     333             :         SOCKET socket;
#     334           0 :         inline void AddSocketPermissionFlags(NetPermissionFlags& flags) const { NetPermissions::AddFlag(flags, m_permissions); }
#     335           0 :         ListenSocket(SOCKET socket_, NetPermissionFlags permissions_) : socket(socket_), m_permissions(permissions_) {}
#     336             :     private:
#     337             :         NetPermissionFlags m_permissions;
#     338             :     };
#     339             : 
#     340             :     bool BindListenPort(const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
#     341             :     bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
#     342             :     bool InitBinds(const std::vector<CService>& binds, const std::vector<NetWhitebindPermissions>& whiteBinds);
#     343             :     void ThreadOpenAddedConnections();
#     344             :     void AddOneShot(const std::string& strDest);
#     345             :     void ProcessOneShot();
#     346             :     void ThreadOpenConnections(std::vector<std::string> connect);
#     347             :     void ThreadMessageHandler();
#     348             :     void AcceptConnection(const ListenSocket& hListenSocket);
#     349             :     void DisconnectNodes();
#     350             :     void NotifyNumConnectionsChanged();
#     351             :     void InactivityCheck(CNode *pnode);
#     352             :     bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
#     353             :     void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
#     354             :     void SocketHandler();
#     355             :     void ThreadSocketHandler();
#     356             :     void ThreadDNSAddressSeed();
#     357             : 
#     358             :     uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
#     359             : 
#     360             :     CNode* FindNode(const CNetAddr& ip);
#     361             :     CNode* FindNode(const CSubNet& subNet);
#     362             :     CNode* FindNode(const std::string& addrName);
#     363             :     CNode* FindNode(const CService& addr);
#     364             : 
#     365             :     bool AttemptToEvictConnection();
#     366             :     CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, bool manual_connection, bool block_relay_only);
#     367             :     void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const;
#     368             : 
#     369             :     void DeleteNode(CNode* pnode);
#     370             : 
#     371             :     NodeId GetNewNodeId();
#     372             : 
#     373             :     size_t SocketSendData(CNode *pnode) const;
#     374             :     void DumpAddresses();
#     375             : 
#     376             :     // Network stats
#     377             :     void RecordBytesRecv(uint64_t bytes);
#     378             :     void RecordBytesSent(uint64_t bytes);
#     379             : 
#     380             :     // Whether the node should be passed out in ForEach* callbacks
#     381             :     static bool NodeFullyConnected(const CNode* pnode);
#     382             : 
#     383             :     // Network usage totals
#     384             :     RecursiveMutex cs_totalBytesRecv;
#     385             :     RecursiveMutex cs_totalBytesSent;
#     386             :     uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv) {0};
#     387             :     uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0};
#     388             : 
#     389             :     // outbound limit & stats
#     390             :     uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
#     391             :     uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
#     392             :     uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
#     393             :     uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
#     394             : 
#     395             :     // P2P timeout in seconds
#     396             :     int64_t m_peer_connect_timeout;
#     397             : 
#     398             :     // Whitelisted ranges. Any node connecting from these is automatically
#     399             :     // whitelisted (as well as those connecting to whitelisted binds).
#     400             :     std::vector<NetWhitelistPermissions> vWhitelistedRange;
#     401             : 
#     402             :     unsigned int nSendBufferMaxSize{0};
#     403             :     unsigned int nReceiveFloodSize{0};
#     404             : 
#     405             :     std::vector<ListenSocket> vhListenSocket;
#     406             :     std::atomic<bool> fNetworkActive{true};
#     407             :     bool fAddressesInitialized{false};
#     408             :     CAddrMan addrman;
#     409             :     std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
#     410             :     RecursiveMutex cs_vOneShots;
#     411             :     std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
#     412             :     RecursiveMutex cs_vAddedNodes;
#     413             :     std::vector<CNode*> vNodes GUARDED_BY(cs_vNodes);
#     414             :     std::list<CNode*> vNodesDisconnected;
#     415             :     mutable RecursiveMutex cs_vNodes;
#     416             :     std::atomic<NodeId> nLastNodeId{0};
#     417             :     unsigned int nPrevNodeCount{0};
#     418             : 
#     419             :     /**
#     420             :      * Services this instance offers.
#     421             :      *
#     422             :      * This data is replicated in each CNode instance we create during peer
#     423             :      * connection (in ConnectNode()) under a member also called
#     424             :      * nLocalServices.
#     425             :      *
#     426             :      * This data is not marked const, but after being set it should not
#     427             :      * change. See the note in CNode::nLocalServices documentation.
#     428             :      *
#     429             :      * \sa CNode::nLocalServices
#     430             :      */
#     431             :     ServiceFlags nLocalServices;
#     432             : 
#     433             :     std::unique_ptr<CSemaphore> semOutbound;
#     434             :     std::unique_ptr<CSemaphore> semAddnode;
#     435             :     int nMaxConnections;
#     436             : 
#     437             :     // How many full-relay (tx, block, addr) outbound peers we want
#     438             :     int m_max_outbound_full_relay;
#     439             : 
#     440             :     // How many block-relay only outbound peers we want
#     441             :     // We do not relay tx or addr messages with these peers
#     442             :     int m_max_outbound_block_relay;
#     443             : 
#     444             :     int nMaxAddnode;
#     445             :     int nMaxFeeler;
#     446             :     int m_max_outbound;
#     447             :     bool m_use_addrman_outgoing;
#     448             :     std::atomic<int> nBestHeight;
#     449             :     CClientUIInterface* clientInterface;
#     450             :     NetEventsInterface* m_msgproc;
#     451             :     BanMan* m_banman;
#     452             : 
#     453             :     /** SipHasher seeds for deterministic randomness */
#     454             :     const uint64_t nSeed0, nSeed1;
#     455             : 
#     456             :     /** flag for waking the message processor. */
#     457             :     bool fMsgProcWake GUARDED_BY(mutexMsgProc);
#     458             : 
#     459             :     std::condition_variable condMsgProc;
#     460             :     Mutex mutexMsgProc;
#     461             :     std::atomic<bool> flagInterruptMsgProc{false};
#     462             : 
#     463             :     CThreadInterrupt interruptNet;
#     464             : 
#     465             :     std::thread threadDNSAddressSeed;
#     466             :     std::thread threadSocketHandler;
#     467             :     std::thread threadOpenAddedConnections;
#     468             :     std::thread threadOpenConnections;
#     469             :     std::thread threadMessageHandler;
#     470             : 
#     471             :     /** flag for deciding to connect to an extra outbound peer,
#     472             :      *  in excess of m_max_outbound_full_relay
#     473             :      *  This takes the place of a feeler connection */
#     474             :     std::atomic_bool m_try_another_outbound_peer;
#     475             : 
#     476             :     std::atomic<int64_t> m_next_send_inv_to_incoming{0};
#     477             : 
#     478             :     friend struct CConnmanTest;
#     479             :     friend struct ConnmanTestMsg;
#     480             : };
#     481             : void Discover();
#     482             : void StartMapPort();
#     483             : void InterruptMapPort();
#     484             : void StopMapPort();
#     485             : unsigned short GetListenPort();
#     486             : 
#     487             : struct CombinerAll
#     488             : {
#     489             :     typedef bool result_type;
#     490             : 
#     491             :     template<typename I>
#     492             :     bool operator()(I first, I last) const
#     493          10 :     {
#     494          12 :         while (first != last) {
#     495           6 :             if (!(*first)) return false;
#     496           2 :             ++first;
#     497           2 :         }
#     498          10 :         return true;
#     499          10 :     }
#     500             : };
#     501             : 
#     502             : /**
#     503             :  * Interface for message handling
#     504             :  */
#     505             : class NetEventsInterface
#     506             : {
#     507             : public:
#     508             :     virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
#     509             :     virtual bool SendMessages(CNode* pnode) = 0;
#     510             :     virtual void InitializeNode(CNode* pnode) = 0;
#     511             :     virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
#     512             : 
#     513             : protected:
#     514             :     /**
#     515             :      * Protected destructor so that instances can only be deleted by derived classes.
#     516             :      * If that restriction is no longer desired, this should be made public and virtual.
#     517             :      */
#     518             :     ~NetEventsInterface() = default;
#     519             : };
#     520             : 
#     521             : enum
#     522             : {
#     523             :     LOCAL_NONE,   // unknown
#     524             :     LOCAL_IF,     // address a local interface listens on
#     525             :     LOCAL_BIND,   // address explicit bound to
#     526             :     LOCAL_UPNP,   // address reported by UPnP
#     527             :     LOCAL_MANUAL, // address explicitly specified (-externalip=)
#     528             : 
#     529             :     LOCAL_MAX
#     530             : };
#     531             : 
#     532             : bool IsPeerAddrLocalGood(CNode *pnode);
#     533             : void AdvertiseLocal(CNode *pnode);
#     534             : 
#     535             : /**
#     536             :  * Mark a network as reachable or unreachable (no automatic connects to it)
#     537             :  * @note Networks are reachable by default
#     538             :  */
#     539             : void SetReachable(enum Network net, bool reachable);
#     540             : /** @returns true if the network is reachable, false otherwise */
#     541             : bool IsReachable(enum Network net);
#     542             : /** @returns true if the address is in a reachable network, false otherwise */
#     543             : bool IsReachable(const CNetAddr& addr);
#     544             : 
#     545             : bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
#     546             : bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
#     547             : void RemoveLocal(const CService& addr);
#     548             : bool SeenLocal(const CService& addr);
#     549             : bool IsLocal(const CService& addr);
#     550             : bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
#     551             : CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices);
#     552             : 
#     553             : 
#     554             : extern bool fDiscover;
#     555             : extern bool fListen;
#     556             : extern bool g_relay_txes;
#     557             : 
#     558             : /** Subversion as sent to the P2P network in `version` messages */
#     559             : extern std::string strSubVersion;
#     560             : 
#     561             : struct LocalServiceInfo {
#     562             :     int nScore;
#     563             :     int nPort;
#     564             : };
#     565             : 
#     566             : extern RecursiveMutex cs_mapLocalHost;
#     567             : extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost);
#     568             : 
#     569             : extern const std::string NET_MESSAGE_COMMAND_OTHER;
#     570             : typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
#     571             : 
#     572             : class CNodeStats
#     573             : {
#     574             : public:
#     575             :     NodeId nodeid;
#     576             :     ServiceFlags nServices;
#     577             :     bool fRelayTxes;
#     578             :     int64_t nLastSend;
#     579             :     int64_t nLastRecv;
#     580             :     int64_t nTimeConnected;
#     581             :     int64_t nTimeOffset;
#     582             :     std::string addrName;
#     583             :     int nVersion;
#     584             :     std::string cleanSubVer;
#     585             :     bool fInbound;
#     586             :     bool m_manual_connection;
#     587             :     int nStartingHeight;
#     588             :     uint64_t nSendBytes;
#     589             :     mapMsgCmdSize mapSendBytesPerMsgCmd;
#     590             :     uint64_t nRecvBytes;
#     591             :     mapMsgCmdSize mapRecvBytesPerMsgCmd;
#     592             :     NetPermissionFlags m_permissionFlags;
#     593             :     bool m_legacyWhitelisted;
#     594             :     int64_t m_ping_usec;
#     595             :     int64_t m_ping_wait_usec;
#     596             :     int64_t m_min_ping_usec;
#     597             :     CAmount minFeeFilter;
#     598             :     // Our address, as reported by the peer
#     599             :     std::string addrLocal;
#     600             :     // Address of this peer
#     601             :     CAddress addr;
#     602             :     // Bind address of our side of the connection
#     603             :     CAddress addrBind;
#     604             :     uint32_t m_mapped_as;
#     605             : };
#     606             : 
#     607             : 
#     608             : 
#     609             : /** Transport protocol agnostic message container.
#     610             :  * Ideally it should only contain receive time, payload,
#     611             :  * command and size.
#     612             :  */
#     613             : class CNetMessage {
#     614             : public:
#     615             :     CDataStream m_recv;                  // received message data
#     616             :     int64_t m_time = 0;                  // time (in microseconds) of message receipt.
#     617             :     bool m_valid_netmagic = false;
#     618             :     bool m_valid_header = false;
#     619             :     bool m_valid_checksum = false;
#     620             :     uint32_t m_message_size = 0;         // size of the payload
#     621             :     uint32_t m_raw_message_size = 0;     // used wire size of the message (including header/checksum)
#     622             :     std::string m_command;
#     623             : 
#     624           0 :     CNetMessage(CDataStream&& recv_in) : m_recv(std::move(recv_in)) {}
#     625             : 
#     626             :     void SetVersion(int nVersionIn)
#     627           0 :     {
#     628           0 :         m_recv.SetVersion(nVersionIn);
#     629           0 :     }
#     630             : };
#     631             : 
#     632             : /** The TransportDeserializer takes care of holding and deserializing the
#     633             :  * network receive buffer. It can deserialize the network buffer into a
#     634             :  * transport protocol agnostic CNetMessage (command & payload)
#     635             :  */
#     636             : class TransportDeserializer {
#     637             : public:
#     638             :     // returns true if the current deserialization is complete
#     639             :     virtual bool Complete() const = 0;
#     640             :     // set the serialization context version
#     641             :     virtual void SetVersion(int version) = 0;
#     642             :     // read and deserialize data
#     643             :     virtual int Read(const char *data, unsigned int bytes) = 0;
#     644             :     // decomposes a message from the context
#     645             :     virtual CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time) = 0;
#     646          68 :     virtual ~TransportDeserializer() {}
#     647             : };
#     648             : 
#     649             : class V1TransportDeserializer final : public TransportDeserializer
#     650             : {
#     651             : private:
#     652             :     mutable CHash256 hasher;
#     653             :     mutable uint256 data_hash;
#     654             :     bool in_data;                   // parsing header (false) or data (true)
#     655             :     CDataStream hdrbuf;             // partially received header
#     656             :     CMessageHeader hdr;             // complete header
#     657             :     CDataStream vRecv;              // received message data
#     658             :     unsigned int nHdrPos;
#     659             :     unsigned int nDataPos;
#     660             : 
#     661             :     const uint256& GetMessageHash() const;
#     662             :     int readHeader(const char *pch, unsigned int nBytes);
#     663             :     int readData(const char *pch, unsigned int nBytes);
#     664             : 
#     665          34 :     void Reset() {
#     666          34 :         vRecv.clear();
#     667          34 :         hdrbuf.clear();
#     668          34 :         hdrbuf.resize(24);
#     669          34 :         in_data = false;
#     670          34 :         nHdrPos = 0;
#     671          34 :         nDataPos = 0;
#     672          34 :         data_hash.SetNull();
#     673          34 :         hasher.Reset();
#     674          34 :     }
#     675             : 
#     676             : public:
#     677             : 
#     678          34 :     V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
#     679          34 :         Reset();
#     680          34 :     }
#     681             : 
#     682             :     bool Complete() const override
#     683           0 :     {
#     684           0 :         if (!in_data)
#     685           0 :             return false;
#     686           0 :         return (hdr.nMessageSize == nDataPos);
#     687           0 :     }
#     688             :     void SetVersion(int nVersionIn) override
#     689           0 :     {
#     690           0 :         hdrbuf.SetVersion(nVersionIn);
#     691           0 :         vRecv.SetVersion(nVersionIn);
#     692           0 :     }
#     693           0 :     int Read(const char *pch, unsigned int nBytes) override {
#     694           0 :         int ret = in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
#     695           0 :         if (ret < 0) Reset();
#     696           0 :         return ret;
#     697           0 :     }
#     698             :     CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time) override;
#     699             : };
#     700             : 
#     701             : /** The TransportSerializer prepares messages for the network transport
#     702             :  */
#     703             : class TransportSerializer {
#     704             : public:
#     705             :     // prepare message for transport (header construction, error-correction computation, payload encryption, etc.)
#     706             :     virtual void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) = 0;
#     707          68 :     virtual ~TransportSerializer() {}
#     708             : };
#     709             : 
#     710             : class V1TransportSerializer  : public TransportSerializer {
#     711             : public:
#     712             :     void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) override;
#     713             : };
#     714             : 
#     715             : /** Information about a peer */
#     716             : class CNode
#     717             : {
#     718             :     friend class CConnman;
#     719             :     friend struct ConnmanTestMsg;
#     720             : 
#     721             : public:
#     722             :     std::unique_ptr<TransportDeserializer> m_deserializer;
#     723             :     std::unique_ptr<TransportSerializer> m_serializer;
#     724             : 
#     725             :     // socket
#     726             :     std::atomic<ServiceFlags> nServices{NODE_NONE};
#     727             :     SOCKET hSocket GUARDED_BY(cs_hSocket);
#     728             :     size_t nSendSize{0}; // total size of all vSendMsg entries
#     729             :     size_t nSendOffset{0}; // offset inside the first vSendMsg already sent
#     730             :     uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
#     731             :     std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
#     732             :     RecursiveMutex cs_vSend;
#     733             :     RecursiveMutex cs_hSocket;
#     734             :     RecursiveMutex cs_vRecv;
#     735             : 
#     736             :     RecursiveMutex cs_vProcessMsg;
#     737             :     std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
#     738             :     size_t nProcessQueueSize{0};
#     739             : 
#     740             :     RecursiveMutex cs_sendProcessing;
#     741             : 
#     742             :     std::deque<CInv> vRecvGetData;
#     743             :     uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
#     744             :     std::atomic<int> nRecvVersion{INIT_PROTO_VERSION};
#     745             : 
#     746             :     std::atomic<int64_t> nLastSend{0};
#     747             :     std::atomic<int64_t> nLastRecv{0};
#     748             :     const int64_t nTimeConnected;
#     749             :     std::atomic<int64_t> nTimeOffset{0};
#     750             :     // Address of this peer
#     751             :     const CAddress addr;
#     752             :     // Bind address of our side of the connection
#     753             :     const CAddress addrBind;
#     754             :     std::atomic<int> nVersion{0};
#     755             :     RecursiveMutex cs_SubVer;
#     756             :     /**
#     757             :      * cleanSubVer is a sanitized string of the user agent byte array we read
#     758             :      * from the wire. This cleaned string can safely be logged or displayed.
#     759             :      */
#     760             :     std::string cleanSubVer GUARDED_BY(cs_SubVer){};
#     761             :     bool m_prefer_evict{false}; // This peer is preferred for eviction.
#     762          20 :     bool HasPermission(NetPermissionFlags permission) const {
#     763          20 :         return NetPermissions::HasFlag(m_permissionFlags, permission);
#     764          20 :     }
#     765             :     // This boolean is unusued in actual processing, only present for backward compatibility at RPC/QT level
#     766             :     bool m_legacyWhitelisted{false};
#     767             :     bool fFeeler{false}; // If true this node is being used as a short lived feeler.
#     768             :     bool fOneShot{false};
#     769             :     bool m_manual_connection{false};
#     770             :     bool fClient{false}; // set by version message
#     771             :     bool m_limited_node{false}; //after BIP159, set by version message
#     772             :     const bool fInbound;
#     773             :     std::atomic_bool fSuccessfullyConnected{false};
#     774             :     // Setting fDisconnect to true will cause the node to be disconnected the
#     775             :     // next time DisconnectNodes() runs
#     776             :     std::atomic_bool fDisconnect{false};
#     777             :     bool fSentAddr{false};
#     778             :     CSemaphoreGrant grantOutbound;
#     779             :     std::atomic<int> nRefCount{0};
#     780             : 
#     781             :     const uint64_t nKeyedNetGroup;
#     782             :     std::atomic_bool fPauseRecv{false};
#     783             :     std::atomic_bool fPauseSend{false};
#     784             : 
#     785             : protected:
#     786             :     mapMsgCmdSize mapSendBytesPerMsgCmd;
#     787             :     mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
#     788             : 
#     789             : public:
#     790             :     uint256 hashContinue;
#     791             :     std::atomic<int> nStartingHeight{-1};
#     792             : 
#     793             :     // flood relay
#     794             :     std::vector<CAddress> vAddrToSend;
#     795             :     const std::unique_ptr<CRollingBloomFilter> m_addr_known;
#     796             :     bool fGetAddr{false};
#     797             :     std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0};
#     798             :     std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0};
#     799             : 
#     800          24 :     bool IsAddrRelayPeer() const { return m_addr_known != nullptr; }
#     801             : 
#     802             :     // List of block ids we still have announce.
#     803             :     // There is no final sorting before sending, as they are always sent immediately
#     804             :     // and in the order requested.
#     805             :     std::vector<uint256> vInventoryBlockToSend GUARDED_BY(cs_inventory);
#     806             :     RecursiveMutex cs_inventory;
#     807             : 
#     808             :     struct TxRelay {
#     809             :         mutable RecursiveMutex cs_filter;
#     810             :         // We use fRelayTxes for two purposes -
#     811             :         // a) it allows us to not relay tx invs before receiving the peer's version message
#     812             :         // b) the peer may tell us in its version message that we should not relay tx invs
#     813             :         //    unless it loads a bloom filter.
#     814             :         bool fRelayTxes GUARDED_BY(cs_filter){false};
#     815             :         std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter){nullptr};
#     816             : 
#     817             :         mutable RecursiveMutex cs_tx_inventory;
#     818             :         CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_tx_inventory){50000, 0.000001};
#     819             :         // Set of transaction ids we still have to announce.
#     820             :         // They are sorted by the mempool before relay, so the order is not important.
#     821             :         std::set<uint256> setInventoryTxToSend;
#     822             :         // Used for BIP35 mempool sending
#     823             :         bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
#     824             :         // Last time a "MEMPOOL" request was serviced.
#     825             :         std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
#     826             :         std::chrono::microseconds nNextInvSend{0};
#     827             : 
#     828             :         RecursiveMutex cs_feeFilter;
#     829             :         // Minimum fee rate with which to filter inv's to this node
#     830             :         CAmount minFeeFilter GUARDED_BY(cs_feeFilter){0};
#     831             :         CAmount lastSentFeeFilter{0};
#     832             :         int64_t nextSendTimeFeeFilter{0};
#     833             :     };
#     834             : 
#     835             :     // m_tx_relay == nullptr if we're not relaying transactions with this peer
#     836             :     std::unique_ptr<TxRelay> m_tx_relay;
#     837             : 
#     838             :     // Used for headers announcements - unfiltered blocks to relay
#     839             :     std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
#     840             : 
#     841             :     // Block and TXN accept times
#     842             :     std::atomic<int64_t> nLastBlockTime{0};
#     843             :     std::atomic<int64_t> nLastTXTime{0};
#     844             : 
#     845             :     // Ping time measurement:
#     846             :     // The pong reply we're expecting, or 0 if no pong expected.
#     847             :     std::atomic<uint64_t> nPingNonceSent{0};
#     848             :     // Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
#     849             :     std::atomic<int64_t> nPingUsecStart{0};
#     850             :     // Last measured round-trip time.
#     851             :     std::atomic<int64_t> nPingUsecTime{0};
#     852             :     // Best measured round-trip time.
#     853             :     std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()};
#     854             :     // Whether a ping is requested.
#     855             :     std::atomic<bool> fPingQueued{false};
#     856             : 
#     857             :     std::set<uint256> orphan_work_set;
#     858             : 
#     859             :     CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn = "", bool fInboundIn = false, bool block_relay_only = false);
#     860             :     ~CNode();
#     861             :     CNode(const CNode&) = delete;
#     862             :     CNode& operator=(const CNode&) = delete;
#     863             : 
#     864             : private:
#     865             :     const NodeId id;
#     866             :     const uint64_t nLocalHostNonce;
#     867             : 
#     868             :     //! Services offered to this peer.
#     869             :     //!
#     870             :     //! This is supplied by the parent CConnman during peer connection
#     871             :     //! (CConnman::ConnectNode()) from its attribute of the same name.
#     872             :     //!
#     873             :     //! This is const because there is no protocol defined for renegotiating
#     874             :     //! services initially offered to a peer. The set of local services we
#     875             :     //! offer should not change after initialization.
#     876             :     //!
#     877             :     //! An interesting example of this is NODE_NETWORK and initial block
#     878             :     //! download: a node which starts up from scratch doesn't have any blocks
#     879             :     //! to serve, but still advertises NODE_NETWORK because it will eventually
#     880             :     //! fulfill this role after IBD completes. P2P code is written in such a
#     881             :     //! way that it can gracefully handle peers who don't make good on their
#     882             :     //! service advertisements.
#     883             :     const ServiceFlags nLocalServices;
#     884             : 
#     885             :     const int nMyStartingHeight;
#     886             :     int nSendVersion{0};
#     887             :     NetPermissionFlags m_permissionFlags{ PF_NONE };
#     888             :     std::list<CNetMessage> vRecvMsg;  // Used only by SocketHandler thread
#     889             : 
#     890             :     mutable RecursiveMutex cs_addrName;
#     891             :     std::string addrName GUARDED_BY(cs_addrName);
#     892             : 
#     893             :     // Our address, as reported by the peer
#     894             :     CService addrLocal GUARDED_BY(cs_addrLocal);
#     895             :     mutable RecursiveMutex cs_addrLocal;
#     896             : public:
#     897             : 
#     898         350 :     NodeId GetId() const {
#     899         350 :         return id;
#     900         350 :     }
#     901             : 
#     902          20 :     uint64_t GetLocalNonce() const {
#     903          20 :         return nLocalHostNonce;
#     904          20 :     }
#     905             : 
#     906          20 :     int GetMyStartingHeight() const {
#     907          20 :         return nMyStartingHeight;
#     908          20 :     }
#     909             : 
#     910             :     int GetRefCount() const
#     911           0 :     {
#     912           0 :         assert(nRefCount >= 0);
#     913           0 :         return nRefCount;
#     914           0 :     }
#     915             : 
#     916             :     bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
#     917             : 
#     918             :     void SetRecvVersion(int nVersionIn)
#     919           0 :     {
#     920           0 :         nRecvVersion = nVersionIn;
#     921           0 :     }
#     922             :     int GetRecvVersion() const
#     923           0 :     {
#     924           0 :         return nRecvVersion;
#     925           0 :     }
#     926             :     void SetSendVersion(int nVersionIn);
#     927             :     int GetSendVersion() const;
#     928             : 
#     929             :     CService GetAddrLocal() const;
#     930             :     //! May not be called more than once
#     931             :     void SetAddrLocal(const CService& addrLocalIn);
#     932             : 
#     933             :     CNode* AddRef()
#     934           0 :     {
#     935           0 :         nRefCount++;
#     936           0 :         return this;
#     937           0 :     }
#     938             : 
#     939             :     void Release()
#     940           0 :     {
#     941           0 :         nRefCount--;
#     942           0 :     }
#     943             : 
#     944             : 
#     945             : 
#     946             :     void AddAddressKnown(const CAddress& _addr)
#     947           0 :     {
#     948           0 :         assert(m_addr_known);
#     949           0 :         m_addr_known->insert(_addr.GetKey());
#     950           0 :     }
#     951             : 
#     952             :     void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
#     953           2 :     {
#     954           2 :         // Whether the peer supports the address in `_addr`. For example,
#     955           2 :         // nodes that do not implement BIP155 cannot receive Tor v3 addresses
#     956           2 :         // because they require ADDRv2 (BIP155) encoding.
#     957           2 :         const bool supported = (nServices & NODE_ADDRv2) || _addr.IsAddrV1Compatible();
#     958           2 : 
#     959           2 :         // Known checking here is only to save space from duplicates.
#     960           2 :         // SendMessages will filter it again for knowns that were added
#     961           2 :         // after addresses were pushed.
#     962           2 :         assert(m_addr_known);
#     963           2 :         if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey()) && supported) {
#     964           2 :             if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
#     965           0 :                 vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
#     966           2 :             } else {
#     967           2 :                 vAddrToSend.push_back(_addr);
#     968           2 :             }
#     969           2 :         }
#     970           2 :     }
#     971             : 
#     972             : 
#     973             :     void AddInventoryKnown(const CInv& inv)
#     974           0 :     {
#     975           0 :         if (m_tx_relay != nullptr) {
#     976           0 :             LOCK(m_tx_relay->cs_tx_inventory);
#     977           0 :             m_tx_relay->filterInventoryKnown.insert(inv.hash);
#     978           0 :         }
#     979           0 :     }
#     980             : 
#     981             :     void PushInventory(const CInv& inv)
#     982           0 :     {
#     983           0 :         if (inv.type == MSG_TX && m_tx_relay != nullptr) {
#     984           0 :             LOCK(m_tx_relay->cs_tx_inventory);
#     985           0 :             if (!m_tx_relay->filterInventoryKnown.contains(inv.hash)) {
#     986           0 :                 m_tx_relay->setInventoryTxToSend.insert(inv.hash);
#     987           0 :             }
#     988           0 :         } else if (inv.type == MSG_BLOCK) {
#     989           0 :             LOCK(cs_inventory);
#     990           0 :             vInventoryBlockToSend.push_back(inv.hash);
#     991           0 :         }
#     992           0 :     }
#     993             : 
#     994             :     void PushBlockHash(const uint256 &hash)
#     995           0 :     {
#     996           0 :         LOCK(cs_inventory);
#     997           0 :         vBlockHashesToAnnounce.push_back(hash);
#     998           0 :     }
#     999             : 
#    1000             :     void CloseSocketDisconnect();
#    1001             : 
#    1002             :     void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap);
#    1003             : 
#    1004             :     ServiceFlags GetLocalServices() const
#    1005          22 :     {
#    1006          22 :         return nLocalServices;
#    1007          22 :     }
#    1008             : 
#    1009             :     std::string GetAddrName() const;
#    1010             :     //! Sets the addrName only if it was not previously set
#    1011             :     void MaybeSetAddrName(const std::string& addrNameIn);
#    1012             : };
#    1013             : 
#    1014             : /** Return a timestamp in the future (in microseconds) for exponentially distributed events. */
#    1015             : int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
#    1016             : 
#    1017             : /** Wrapper to return mockable type */
#    1018             : inline std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
#    1019          18 : {
#    1020          18 :     return std::chrono::microseconds{PoissonNextSend(now.count(), average_interval.count())};
#    1021          18 : }
#    1022             : 
#    1023             : #endif // BITCOIN_NET_H

Generated by: LCOV version 1.14