Bitcoin Core  0.19.99
P2P Digital Currency
net.h
Go to the documentation of this file.
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 <uint256.h>
25 #include <threadinterrupt.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 
44 static const bool DEFAULT_WHITELISTRELAY = true;
46 static const bool DEFAULT_WHITELISTFORCERELAY = false;
47 
49 static const int PING_INTERVAL = 2 * 60;
51 static const int TIMEOUT_INTERVAL = 20 * 60;
53 static const int FEELER_INTERVAL = 120;
55 static const unsigned int MAX_INV_SZ = 50000;
57 static const unsigned int MAX_LOCATOR_SZ = 101;
59 static const unsigned int MAX_ADDR_TO_SEND = 1000;
61 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
63 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
67 static const int MAX_ADDNODE_CONNECTIONS = 8;
69 static const int MAX_BLOCKS_ONLY_CONNECTIONS = 2;
71 static const bool DEFAULT_LISTEN = true;
73 #ifdef USE_UPNP
74 static const bool DEFAULT_UPNP = USE_UPNP;
75 #else
76 static const bool DEFAULT_UPNP = false;
77 #endif
78 
79 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
81 static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
83 static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24;
85 static const bool DEFAULT_BLOCKSONLY = false;
87 static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
88 
89 static const bool DEFAULT_FORCEDNSSEED = false;
90 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
91 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
92 
93 typedef int64_t NodeId;
94 
96 {
97  std::string strAddedNode;
99  bool fConnected;
100  bool fInbound;
101 };
102 
103 class CNodeStats;
104 class CClientUIInterface;
105 
107 {
108  CSerializedNetMsg() = default;
110  CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default;
111  // No copying, only moves.
112  CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
113  CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;
114 
115  std::vector<unsigned char> data;
116  std::string command;
117 };
118 
119 
120 class NetEventsInterface;
121 class CConnman
122 {
123 public:
124 
127  CONNECTIONS_IN = (1U << 0),
128  CONNECTIONS_OUT = (1U << 1),
130  };
131 
132  struct Options
133  {
134  ServiceFlags nLocalServices = NODE_NONE;
135  int nMaxConnections = 0;
136  int m_max_outbound_full_relay = 0;
137  int m_max_outbound_block_relay = 0;
138  int nMaxAddnode = 0;
139  int nMaxFeeler = 0;
140  int nBestHeight = 0;
142  NetEventsInterface* m_msgproc = nullptr;
143  BanMan* m_banman = nullptr;
144  unsigned int nSendBufferMaxSize = 0;
145  unsigned int nReceiveFloodSize = 0;
146  uint64_t nMaxOutboundTimeframe = 0;
147  uint64_t nMaxOutboundLimit = 0;
148  int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
149  std::vector<std::string> vSeedNodes;
150  std::vector<NetWhitelistPermissions> vWhitelistedRange;
151  std::vector<NetWhitebindPermissions> vWhiteBinds;
152  std::vector<CService> vBinds;
153  bool m_use_addrman_outgoing = true;
154  std::vector<std::string> m_specified_outgoing;
155  std::vector<std::string> m_added_nodes;
156  std::vector<bool> m_asmap;
157  };
158 
159  void Init(const Options& connOptions) {
160  nLocalServices = connOptions.nLocalServices;
161  nMaxConnections = connOptions.nMaxConnections;
162  m_max_outbound_full_relay = std::min(connOptions.m_max_outbound_full_relay, connOptions.nMaxConnections);
163  m_max_outbound_block_relay = connOptions.m_max_outbound_block_relay;
164  m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
165  nMaxAddnode = connOptions.nMaxAddnode;
166  nMaxFeeler = connOptions.nMaxFeeler;
167  m_max_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + nMaxFeeler;
168  nBestHeight = connOptions.nBestHeight;
169  clientInterface = connOptions.uiInterface;
170  m_banman = connOptions.m_banman;
171  m_msgproc = connOptions.m_msgproc;
172  nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
173  nReceiveFloodSize = connOptions.nReceiveFloodSize;
174  m_peer_connect_timeout = connOptions.m_peer_connect_timeout;
175  {
176  LOCK(cs_totalBytesSent);
177  nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
178  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
179  }
180  vWhitelistedRange = connOptions.vWhitelistedRange;
181  {
182  LOCK(cs_vAddedNodes);
183  vAddedNodes = connOptions.m_added_nodes;
184  }
185  }
186 
187  CConnman(uint64_t seed0, uint64_t seed1);
188  ~CConnman();
189  bool Start(CScheduler& scheduler, const Options& options);
190 
191  // TODO: Remove NO_THREAD_SAFETY_ANALYSIS. Lock cs_vNodes before reading the variable vNodes.
192  //
193  // When removing NO_THREAD_SAFETY_ANALYSIS be aware of the following lock order requirements:
194  // * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraOutboundCount
195  // which locks cs_vNodes.
196  // * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
197  // locks cs_vNodes.
198  //
199  // Thus the implicit locking order requirement is: (1) cs_main, (2) g_cs_orphans, (3) cs_vNodes.
200  void Stop() NO_THREAD_SAFETY_ANALYSIS;
201 
202  void Interrupt();
203  bool GetNetworkActive() const { return fNetworkActive; };
204  bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
205  void SetNetworkActive(bool active);
206  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);
207  bool CheckIncomingNonce(uint64_t nonce);
208 
209  bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
210 
211  void PushMessage(CNode* pnode, CSerializedNetMsg&& msg);
212 
213  template<typename Callable>
214  void ForEachNode(Callable&& func)
215  {
216  LOCK(cs_vNodes);
217  for (auto&& node : vNodes) {
218  if (NodeFullyConnected(node))
219  func(node);
220  }
221  };
222 
223  template<typename Callable>
224  void ForEachNode(Callable&& func) const
225  {
226  LOCK(cs_vNodes);
227  for (auto&& node : vNodes) {
228  if (NodeFullyConnected(node))
229  func(node);
230  }
231  };
232 
233  template<typename Callable, typename CallableAfter>
234  void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
235  {
236  LOCK(cs_vNodes);
237  for (auto&& node : vNodes) {
238  if (NodeFullyConnected(node))
239  pre(node);
240  }
241  post();
242  };
243 
244  template<typename Callable, typename CallableAfter>
245  void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
246  {
247  LOCK(cs_vNodes);
248  for (auto&& node : vNodes) {
249  if (NodeFullyConnected(node))
250  pre(node);
251  }
252  post();
253  };
254 
255  // Addrman functions
256  size_t GetAddressCount() const;
257  void SetServices(const CService &addr, ServiceFlags nServices);
258  void MarkAddressGood(const CAddress& addr);
259  void AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
260  std::vector<CAddress> GetAddresses();
261 
262  // This allows temporarily exceeding m_max_outbound_full_relay, with the goal of finding
263  // a peer that is better than all our current peers.
264  void SetTryNewOutboundPeer(bool flag);
265  bool GetTryNewOutboundPeer();
266 
267  // Return the number of outbound peers we have in excess of our target (eg,
268  // if we previously called SetTryNewOutboundPeer(true), and have since set
269  // to false, we may have extra peers that we wish to disconnect). This may
270  // return a value less than (num_outbound_connections - num_outbound_slots)
271  // in cases where some outbound connections are not yet fully connected, or
272  // not yet fully disconnected.
273  int GetExtraOutboundCount();
274 
275  bool AddNode(const std::string& node);
276  bool RemoveAddedNode(const std::string& node);
277  std::vector<AddedNodeInfo> GetAddedNodeInfo();
278 
279  size_t GetNodeCount(NumConnections num);
280  void GetNodeStats(std::vector<CNodeStats>& vstats);
281  bool DisconnectNode(const std::string& node);
282  bool DisconnectNode(const CSubNet& subnet);
283  bool DisconnectNode(const CNetAddr& addr);
284  bool DisconnectNode(NodeId id);
285 
292  ServiceFlags GetLocalServices() const;
293 
295  void SetMaxOutboundTarget(uint64_t limit);
296  uint64_t GetMaxOutboundTarget();
297 
299  void SetMaxOutboundTimeframe(uint64_t timeframe);
300  uint64_t GetMaxOutboundTimeframe();
301 
305  bool OutboundTargetReached(bool historicalBlockServingLimit);
306 
309  uint64_t GetOutboundTargetBytesLeft();
310 
313  uint64_t GetMaxOutboundTimeLeftInCycle();
314 
315  uint64_t GetTotalBytesRecv();
316  uint64_t GetTotalBytesSent();
317 
318  void SetBestHeight(int height);
319  int GetBestHeight() const;
320 
322  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
323 
324  unsigned int GetReceiveFloodSize() const;
325 
326  void WakeMessageHandler();
327 
332  int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds);
333 
334  void SetAsmap(std::vector<bool> asmap) { addrman.m_asmap = std::move(asmap); }
335 
336 private:
337  struct ListenSocket {
338  public:
340  inline void AddSocketPermissionFlags(NetPermissionFlags& flags) const { NetPermissions::AddFlag(flags, m_permissions); }
341  ListenSocket(SOCKET socket_, NetPermissionFlags permissions_) : socket(socket_), m_permissions(permissions_) {}
342  private:
344  };
345 
346  bool BindListenPort(const CService& bindAddr, std::string& strError, NetPermissionFlags permissions);
347  bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
348  bool InitBinds(const std::vector<CService>& binds, const std::vector<NetWhitebindPermissions>& whiteBinds);
349  void ThreadOpenAddedConnections();
350  void AddOneShot(const std::string& strDest);
351  void ProcessOneShot();
352  void ThreadOpenConnections(std::vector<std::string> connect);
353  void ThreadMessageHandler();
354  void AcceptConnection(const ListenSocket& hListenSocket);
355  void DisconnectNodes();
357  void InactivityCheck(CNode *pnode);
358  bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
359  void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
360  void SocketHandler();
361  void ThreadSocketHandler();
362  void ThreadDNSAddressSeed();
363 
364  uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
365 
366  CNode* FindNode(const CNetAddr& ip);
367  CNode* FindNode(const CSubNet& subNet);
368  CNode* FindNode(const std::string& addrName);
369  CNode* FindNode(const CService& addr);
370 
371  bool AttemptToEvictConnection();
372  CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, bool manual_connection, bool block_relay_only);
373  void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const;
374 
375  void DeleteNode(CNode* pnode);
376 
377  NodeId GetNewNodeId();
378 
379  size_t SocketSendData(CNode *pnode) const;
380  void DumpAddresses();
381 
382  // Network stats
383  void RecordBytesRecv(uint64_t bytes);
384  void RecordBytesSent(uint64_t bytes);
385 
386  // Whether the node should be passed out in ForEach* callbacks
387  static bool NodeFullyConnected(const CNode* pnode);
388 
389  // Network usage totals
392  uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv) {0};
393  uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0};
394 
395  // outbound limit & stats
396  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
397  uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
398  uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
399  uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
400 
401  // P2P timeout in seconds
403 
404  // Whitelisted ranges. Any node connecting from these is automatically
405  // whitelisted (as well as those connecting to whitelisted binds).
406  std::vector<NetWhitelistPermissions> vWhitelistedRange;
407 
408  unsigned int nSendBufferMaxSize{0};
409  unsigned int nReceiveFloodSize{0};
410 
411  std::vector<ListenSocket> vhListenSocket;
412  std::atomic<bool> fNetworkActive{true};
413  bool fAddressesInitialized{false};
415  std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
417  std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
419  std::vector<CNode*> vNodes GUARDED_BY(cs_vNodes);
420  std::list<CNode*> vNodesDisconnected;
422  std::atomic<NodeId> nLastNodeId{0};
423  unsigned int nPrevNodeCount{0};
424 
438 
439  std::unique_ptr<CSemaphore> semOutbound;
440  std::unique_ptr<CSemaphore> semAddnode;
442 
443  // How many full-relay (tx, block, addr) outbound peers we want
445 
446  // How many block-relay only outbound peers we want
447  // We do not relay tx or addr messages with these peers
449 
454  std::atomic<int> nBestHeight;
458 
460  const uint64_t nSeed0, nSeed1;
461 
464 
465  std::condition_variable condMsgProc;
467  std::atomic<bool> flagInterruptMsgProc{false};
468 
470 
471  std::thread threadDNSAddressSeed;
472  std::thread threadSocketHandler;
475  std::thread threadMessageHandler;
476 
480  std::atomic_bool m_try_another_outbound_peer;
481 
482  std::atomic<int64_t> m_next_send_inv_to_incoming{0};
483 
484  friend struct CConnmanTest;
485 };
486 void Discover();
487 void StartMapPort();
488 void InterruptMapPort();
489 void StopMapPort();
490 unsigned short GetListenPort();
491 
493 {
494  typedef bool result_type;
495 
496  template<typename I>
497  bool operator()(I first, I last) const
498  {
499  while (first != last) {
500  if (!(*first)) return false;
501  ++first;
502  }
503  return true;
504  }
505 };
506 
511 {
512 public:
513  virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
514  virtual bool SendMessages(CNode* pnode) = 0;
515  virtual void InitializeNode(CNode* pnode) = 0;
516  virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
517 
518 protected:
523  ~NetEventsInterface() = default;
524 };
525 
526 enum
527 {
528  LOCAL_NONE, // unknown
529  LOCAL_IF, // address a local interface listens on
530  LOCAL_BIND, // address explicit bound to
531  LOCAL_UPNP, // address reported by UPnP
532  LOCAL_MANUAL, // address explicitly specified (-externalip=)
533 
535 };
536 
537 bool IsPeerAddrLocalGood(CNode *pnode);
538 void AdvertiseLocal(CNode *pnode);
539 
544 void SetReachable(enum Network net, bool reachable);
546 bool IsReachable(enum Network net);
548 bool IsReachable(const CNetAddr& addr);
549 
550 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
551 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
552 void RemoveLocal(const CService& addr);
553 bool SeenLocal(const CService& addr);
554 bool IsLocal(const CService& addr);
555 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
556 CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices);
557 
558 
559 extern bool fDiscover;
560 extern bool fListen;
561 extern bool g_relay_txes;
562 
564 extern std::string strSubVersion;
565 
567  int nScore;
568  int nPort;
569 };
570 
572 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost);
573 
574 extern const std::string NET_MESSAGE_COMMAND_OTHER;
575 typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
576 
578 {
579 public:
583  int64_t nLastSend;
584  int64_t nLastRecv;
585  int64_t nTimeConnected;
586  int64_t nTimeOffset;
587  std::string addrName;
588  int nVersion;
589  std::string cleanSubVer;
590  bool fInbound;
593  uint64_t nSendBytes;
594  mapMsgCmdSize mapSendBytesPerMsgCmd;
595  uint64_t nRecvBytes;
596  mapMsgCmdSize mapRecvBytesPerMsgCmd;
599  double dPingTime;
600  double dPingWait;
601  double dMinPing;
603  // Our address, as reported by the peer
604  std::string addrLocal;
605  // Address of this peer
607  // Bind address of our side of the connection
609  uint32_t m_mapped_as;
610 };
611 
612 
613 
618 class CNetMessage {
619 public:
620  CDataStream m_recv; // received message data
621  int64_t m_time = 0; // time (in microseconds) of message receipt.
622  bool m_valid_netmagic = false;
623  bool m_valid_header = false;
624  bool m_valid_checksum = false;
625  uint32_t m_message_size = 0; // size of the payload
626  uint32_t m_raw_message_size = 0; // used wire size of the message (including header/checksum)
627  std::string m_command;
628 
629  CNetMessage(CDataStream&& recv_in) : m_recv(std::move(recv_in)) {}
630 
631  void SetVersion(int nVersionIn)
632  {
633  m_recv.SetVersion(nVersionIn);
634  }
635 };
636 
642 public:
643  // returns true if the current deserialization is complete
644  virtual bool Complete() const = 0;
645  // set the serialization context version
646  virtual void SetVersion(int version) = 0;
647  // read and deserialize data
648  virtual int Read(const char *data, unsigned int bytes) = 0;
649  // decomposes a message from the context
650  virtual CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time) = 0;
652 };
653 
655 {
656 private:
657  mutable CHash256 hasher;
659  bool in_data; // parsing header (false) or data (true)
660  CDataStream hdrbuf; // partially received header
661  CMessageHeader hdr; // complete header
662  CDataStream vRecv; // received message data
663  unsigned int nHdrPos;
664  unsigned int nDataPos;
665 
666  const uint256& GetMessageHash() const;
667  int readHeader(const char *pch, unsigned int nBytes);
668  int readData(const char *pch, unsigned int nBytes);
669 
670  void Reset() {
671  vRecv.clear();
672  hdrbuf.clear();
673  hdrbuf.resize(24);
674  in_data = false;
675  nHdrPos = 0;
676  nDataPos = 0;
677  data_hash.SetNull();
678  hasher.Reset();
679  }
680 
681 public:
682 
683  V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
684  Reset();
685  }
686 
687  bool Complete() const override
688  {
689  if (!in_data)
690  return false;
691  return (hdr.nMessageSize == nDataPos);
692  }
693  void SetVersion(int nVersionIn) override
694  {
695  hdrbuf.SetVersion(nVersionIn);
696  vRecv.SetVersion(nVersionIn);
697  }
698  int Read(const char *pch, unsigned int nBytes) override {
699  int ret = in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
700  if (ret < 0) Reset();
701  return ret;
702  }
703  CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time) override;
704 };
705 
707 class CNode
708 {
709  friend class CConnman;
710 public:
711  std::unique_ptr<TransportDeserializer> m_deserializer;
712 
713  // socket
714  std::atomic<ServiceFlags> nServices{NODE_NONE};
715  SOCKET hSocket GUARDED_BY(cs_hSocket);
716  size_t nSendSize{0}; // total size of all vSendMsg entries
717  size_t nSendOffset{0}; // offset inside the first vSendMsg already sent
718  uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
719  std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
723 
725  std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
726  size_t nProcessQueueSize{0};
727 
729 
730  std::deque<CInv> vRecvGetData;
731  uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
732  std::atomic<int> nRecvVersion{INIT_PROTO_VERSION};
733 
734  std::atomic<int64_t> nLastSend{0};
735  std::atomic<int64_t> nLastRecv{0};
736  const int64_t nTimeConnected;
737  std::atomic<int64_t> nTimeOffset{0};
738  // Address of this peer
739  const CAddress addr;
740  // Bind address of our side of the connection
742  std::atomic<int> nVersion{0};
748  std::string cleanSubVer GUARDED_BY(cs_SubVer){};
749  bool m_prefer_evict{false}; // This peer is preferred for eviction.
750  bool HasPermission(NetPermissionFlags permission) const {
751  return NetPermissions::HasFlag(m_permissionFlags, permission);
752  }
753  // This boolean is unusued in actual processing, only present for backward compatibility at RPC/QT level
754  bool m_legacyWhitelisted{false};
755  bool fFeeler{false}; // If true this node is being used as a short lived feeler.
756  bool fOneShot{false};
757  bool m_manual_connection{false};
758  bool fClient{false}; // set by version message
759  bool m_limited_node{false}; //after BIP159, set by version message
760  const bool fInbound;
761  std::atomic_bool fSuccessfullyConnected{false};
762  // Setting fDisconnect to true will cause the node to be disconnected the
763  // next time DisconnectNodes() runs
764  std::atomic_bool fDisconnect{false};
765  bool fSentAddr{false};
767  std::atomic<int> nRefCount{0};
768 
769  const uint64_t nKeyedNetGroup;
770  std::atomic_bool fPauseRecv{false};
771  std::atomic_bool fPauseSend{false};
772 
773 protected:
774  mapMsgCmdSize mapSendBytesPerMsgCmd;
775  mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
776 
777 public:
779  std::atomic<int> nStartingHeight{-1};
780 
781  // flood relay
782  std::vector<CAddress> vAddrToSend;
783  const std::unique_ptr<CRollingBloomFilter> m_addr_known;
784  bool fGetAddr{false};
785  int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing){0};
786  int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing){0};
787 
788  bool IsAddrRelayPeer() const { return m_addr_known != nullptr; }
789 
790  // List of block ids we still have announce.
791  // There is no final sorting before sending, as they are always sent immediately
792  // and in the order requested.
793  std::vector<uint256> vInventoryBlockToSend GUARDED_BY(cs_inventory);
795 
796  struct TxRelay {
797  TxRelay() { pfilter = MakeUnique<CBloomFilter>(); }
799  // We use fRelayTxes for two purposes -
800  // a) it allows us to not relay tx invs before receiving the peer's version message
801  // b) the peer may tell us in its version message that we should not relay tx invs
802  // unless it loads a bloom filter.
803  bool fRelayTxes GUARDED_BY(cs_filter){false};
804  std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter);
805 
807  CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_tx_inventory){50000, 0.000001};
808  // Set of transaction ids we still have to announce.
809  // They are sorted by the mempool before relay, so the order is not important.
810  std::set<uint256> setInventoryTxToSend;
811  // Used for BIP35 mempool sending
812  bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
813  // Last time a "MEMPOOL" request was serviced.
814  std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
815  std::chrono::microseconds nNextInvSend{0};
816 
818  // Minimum fee rate with which to filter inv's to this node
819  CAmount minFeeFilter GUARDED_BY(cs_feeFilter){0};
820  CAmount lastSentFeeFilter{0};
821  int64_t nextSendTimeFeeFilter{0};
822  };
823 
824  // m_tx_relay == nullptr if we're not relaying transactions with this peer
825  std::unique_ptr<TxRelay> m_tx_relay;
826 
827  // Used for headers announcements - unfiltered blocks to relay
828  std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
829 
830  // Block and TXN accept times
831  std::atomic<int64_t> nLastBlockTime{0};
832  std::atomic<int64_t> nLastTXTime{0};
833 
834  // Ping time measurement:
835  // The pong reply we're expecting, or 0 if no pong expected.
836  std::atomic<uint64_t> nPingNonceSent{0};
837  // Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
838  std::atomic<int64_t> nPingUsecStart{0};
839  // Last measured round-trip time.
840  std::atomic<int64_t> nPingUsecTime{0};
841  // Best measured round-trip time.
842  std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()};
843  // Whether a ping is requested.
844  std::atomic<bool> fPingQueued{false};
845 
846  std::set<uint256> orphan_work_set;
847 
848  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);
849  ~CNode();
850  CNode(const CNode&) = delete;
851  CNode& operator=(const CNode&) = delete;
852 
853 private:
854  const NodeId id;
855  const uint64_t nLocalHostNonce;
856 
873 
874  const int nMyStartingHeight;
875  int nSendVersion{0};
876  NetPermissionFlags m_permissionFlags{ PF_NONE };
877  std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
878 
880  std::string addrName GUARDED_BY(cs_addrName);
881 
882  // Our address, as reported by the peer
883  CService addrLocal GUARDED_BY(cs_addrLocal);
885 public:
886 
887  NodeId GetId() const {
888  return id;
889  }
890 
891  uint64_t GetLocalNonce() const {
892  return nLocalHostNonce;
893  }
894 
895  int GetMyStartingHeight() const {
896  return nMyStartingHeight;
897  }
898 
899  int GetRefCount() const
900  {
901  assert(nRefCount >= 0);
902  return nRefCount;
903  }
904 
905  bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
906 
907  void SetRecvVersion(int nVersionIn)
908  {
909  nRecvVersion = nVersionIn;
910  }
911  int GetRecvVersion() const
912  {
913  return nRecvVersion;
914  }
915  void SetSendVersion(int nVersionIn);
916  int GetSendVersion() const;
917 
918  CService GetAddrLocal() const;
920  void SetAddrLocal(const CService& addrLocalIn);
921 
923  {
924  nRefCount++;
925  return this;
926  }
927 
928  void Release()
929  {
930  nRefCount--;
931  }
932 
933 
934 
935  void AddAddressKnown(const CAddress& _addr)
936  {
937  assert(m_addr_known);
938  m_addr_known->insert(_addr.GetKey());
939  }
940 
941  void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
942  {
943  // Known checking here is only to save space from duplicates.
944  // SendMessages will filter it again for knowns that were added
945  // after addresses were pushed.
946  assert(m_addr_known);
947  if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey())) {
948  if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
949  vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
950  } else {
951  vAddrToSend.push_back(_addr);
952  }
953  }
954  }
955 
956 
957  void AddInventoryKnown(const CInv& inv)
958  {
959  if (m_tx_relay != nullptr) {
960  LOCK(m_tx_relay->cs_tx_inventory);
961  m_tx_relay->filterInventoryKnown.insert(inv.hash);
962  }
963  }
964 
965  void PushInventory(const CInv& inv)
966  {
967  if (inv.type == MSG_TX && m_tx_relay != nullptr) {
968  LOCK(m_tx_relay->cs_tx_inventory);
969  if (!m_tx_relay->filterInventoryKnown.contains(inv.hash)) {
970  m_tx_relay->setInventoryTxToSend.insert(inv.hash);
971  }
972  } else if (inv.type == MSG_BLOCK) {
973  LOCK(cs_inventory);
974  vInventoryBlockToSend.push_back(inv.hash);
975  }
976  }
977 
978  void PushBlockHash(const uint256 &hash)
979  {
980  LOCK(cs_inventory);
981  vBlockHashesToAnnounce.push_back(hash);
982  }
983 
984  void CloseSocketDisconnect();
985 
986  void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap);
987 
989  {
990  return nLocalServices;
991  }
992 
993  std::string GetAddrName() const;
995  void MaybeSetAddrName(const std::string& addrNameIn);
996 };
997 
999 int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
1000 
1002 inline std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
1003 {
1004  return std::chrono::microseconds{PoissonNextSend(now.count(), average_interval.count())};
1005 }
1006 
1007 #endif // BITCOIN_NET_H
std::vector< CService > vBinds
Definition: net.h:152
int m_max_outbound_full_relay
Definition: net.h:136
uint256 data_hash
Definition: net.h:658
#define NO_THREAD_SAFETY_ANALYSIS
Definition: threadsafety.h:53
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent)
Definition: net.h:393
int nMaxFeeler
Definition: net.h:451
std::vector< bool > m_asmap
Definition: net.h:156
bool IsReachable(enum Network net)
Definition: net.cpp:255
int nStartingHeight
Definition: net.h:592
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable).
Definition: net.h:61
int64_t nNextLocalAddrSend GUARDED_BY(cs_sendProcessing)
Definition: net.h:786
int m_max_outbound
Definition: net.h:452
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:596
Definition: banman.h:38
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
bool fMsgProcWake
flag for waking the message processor.
Definition: net.h:463
ServiceFlags
nServices flags
Definition: protocol.h:239
static const uint64_t MAX_UPLOAD_TIMEFRAME
The default timeframe for -maxuploadtarget.
Definition: net.h:83
void SetNull()
Definition: uint256.h:38
RecursiveMutex cs_vNodes
Definition: net.h:421
std::string cleanSubVer GUARDED_BY(cs_SubVer)
cleanSubVer is a sanitized string of the user agent byte array we read from the wire.
Definition: net.h:748
int64_t nTimeOffset
Definition: net.h:586
bool fListen
Definition: net.cpp:86
int m_max_outbound_block_relay
Definition: net.h:137
uint32_t m_mapped_as
Definition: net.h:609
std::atomic< int > nBestHeight
Definition: net.h:454
bool fRelayTxes GUARDED_BY(cs_filter)
Definition: net.h:803
bool m_legacyWhitelisted
Definition: net.h:598
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:78
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(cs_mapLocalHost)
void SetVersion(int nVersionIn) override
Definition: net.h:693
BanMan * m_banman
Definition: net.h:143
Mutex mutexMsgProc
Definition: net.h:466
static const bool DEFAULT_FORCEDNSSEED
Definition: net.h:89
const uint64_t nKeyedNetGroup
Definition: net.h:769
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:267
int GetRecvVersion() const
Definition: net.h:911
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:774
CDataStream hdrbuf
Definition: net.h:660
void StartMapPort()
Definition: net.cpp:1546
void StopMapPort()
Definition: net.cpp:1554
std::vector< unsigned char > data
Definition: net.h:115
inv message data
Definition: protocol.h:375
RecursiveMutex cs_inventory
Definition: net.h:794
unsigned int nDataPos
Definition: net.h:664
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:406
CAmount minFeeFilter GUARDED_BY(cs_feeFilter)
Definition: net.h:819
unsigned int nReceiveFloodSize
Definition: net.h:145
RecursiveMutex cs_filter
Definition: net.h:798
int m_max_outbound_full_relay
Definition: net.h:444
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:594
CClientUIInterface * uiInterface
Definition: net.h:141
void resize(size_type n, value_type c=0)
Definition: streams.h:294
bool g_relay_txes
Definition: net.cpp:87
void SetAsmap(std::vector< bool > asmap)
Definition: net.h:334
ServiceFlags nServices
Definition: net.h:581
CDataStream m_recv
Definition: net.h:620
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:71
CNetMessage(CDataStream &&recv_in)
Definition: net.h:629
int nMaxAddnode
Definition: net.h:450
RAII-style semaphore lock.
Definition: sync.h:245
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:67
RecursiveMutex cs_vProcessMsg
Definition: net.h:724
std::string cleanSubVer
Definition: net.h:589
Interface for message handling.
Definition: net.h:510
void SetVersion(int nVersionIn)
Definition: net.h:631
RecursiveMutex cs_addrName
Definition: net.h:879
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set. ...
Definition: bloom.h:115
NetEventsInterface * m_msgproc
Definition: net.h:456
CAmount minFeeFilter
Definition: net.h:602
int nMaxConnections
Definition: net.h:135
int64_t nTimeConnected
Definition: net.h:585
void AdvertiseLocal(CNode *pnode)
Definition: net.cpp:182
int m_max_outbound_block_relay
Definition: net.h:448
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:201
uint32_t nMessageSize
Definition: protocol.h:58
A hasher class for Bitcoin&#39;s 256-bit hash (double SHA-256).
Definition: hash.h:22
uint64_t GetLocalNonce() const
Definition: net.h:891
std::unique_ptr< TransportDeserializer > m_deserializer
Definition: net.h:711
std::vector< CAddress > vAddrToSend
Definition: net.h:782
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
Definition: net.h:941
static const int FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes or 120 seconds.
Definition: net.h:53
RecursiveMutex cs_vRecv
Definition: net.h:722
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Definition: net.h:718
static const int TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:51
void SetRecvVersion(int nVersionIn)
Definition: net.h:907
Definition: net.h:534
Signals for UI communication.
Definition: ui_interface.h:29
std::list< CNetMessage > vRecvMsg
Definition: net.h:877
void PushInventory(const CInv &inv)
Definition: net.h:965
CAddrMan addrman
Definition: net.h:414
std::set< uint256 > orphan_work_set
Definition: net.h:846
static const int MAX_BLOCKS_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:69
std::deque< CInv > vRecvGetData
Definition: net.h:730
bool fConnected
Definition: net.h:99
virtual ~TransportDeserializer()
Definition: net.h:651
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:340
int GetRefCount() const
Definition: net.h:899
RecursiveMutex cs_sendProcessing
Definition: net.h:728
const std::unique_ptr< CRollingBloomFilter > m_addr_known
Definition: net.h:783
ServiceFlags nLocalServices
Services this instance offers.
Definition: net.h:437
bool IsValid() const
Definition: netaddress.cpp:248
bool operator()(I first, I last) const
Definition: net.h:497
static const unsigned int MAX_LOCATOR_SZ
The maximum number of entries in a locator.
Definition: net.h:57
bool m_manual_connection
Definition: net.h:591
CHash256 hasher
Definition: net.h:657
Stochastical (IP) address manager.
Definition: addrman.h:177
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool IsAddrRelayPeer() const
Definition: net.h:788
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:90
int GetMyStartingHeight() const
Definition: net.h:895
ServiceFlags GetLocalServices() const
Definition: net.h:988
int nVersion
Definition: net.h:588
RecursiveMutex cs_tx_inventory
Definition: net.h:806
void InterruptMapPort()
Definition: net.cpp:1550
void Release()
Definition: net.h:928
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:105
std::condition_variable condMsgProc
Definition: net.h:465
bool result_type
Definition: net.h:494
RecursiveMutex cs_vAddedNodes
Definition: net.h:418
void Interrupt(NodeContext &node)
Interrupt threads.
Definition: init.cpp:161
ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
Definition: net.h:341
std::thread threadOpenAddedConnections
Definition: net.h:473
#define LOCK(cs)
Definition: sync.h:179
RecursiveMutex cs_vOneShots
Definition: net.h:416
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:174
NetEventsInterface * m_msgproc
Definition: net.h:142
int type
Definition: protocol.h:396
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
Definition: version.h:15
std::string strAddedNode
Definition: net.h:97
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:150
Fast randomness source.
Definition: random.h:106
Transport protocol agnostic message container.
Definition: net.h:618
const CAddress addrBind
Definition: net.h:741
std::vector< std::string > vSeedNodes
Definition: net.h:149
std::vector< std::string > m_specified_outgoing
Definition: net.h:154
int64_t m_peer_connect_timeout
Definition: net.h:402
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:439
std::thread threadMessageHandler
Definition: net.h:475
static bool HasFlag(const NetPermissionFlags &flags, NetPermissionFlags f)
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
Definition: net.h:234
bool fInbound
Definition: net.h:590
A CService with information about it as peer.
Definition: protocol.h:318
uint64_t nRecvBytes
Definition: net.h:595
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:721
uint256 hash
Definition: protocol.h:397
int Read(const char *pch, unsigned int nBytes) override
Definition: net.h:698
RecursiveMutex cs_mapLocalHost
Definition: net.cpp:88
bool fInbound
Definition: net.h:100
double dPingTime
Definition: net.h:599
std::string addrName
Definition: net.h:587
int nMaxFeeler
Definition: net.h:139
Network
Definition: netaddress.h:19
std::atomic_bool m_try_another_outbound_peer
flag for deciding to connect to an extra outbound peer, in excess of m_max_outbound_full_relay This t...
Definition: net.h:480
int64_t NodeId
Definition: net.h:93
Definition: net.h:121
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:79
bool GetNetworkActive() const
Definition: net.h:203
NumConnections
Definition: net.h:125
CClientUIInterface * clientInterface
Definition: net.h:455
V1TransportDeserializer(const CMessageHeader::MessageStartChars &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:683
NodeId GetId() const
Definition: net.h:887
uint64_t nSendBytes
Definition: net.h:593
int nMaxConnections
Definition: net.h:441
NetPermissionFlags
void ForEachNode(Callable &&func)
Definition: net.h:214
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:731
void Discover()
Definition: net.cpp:2127
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:37
RecursiveMutex cs_SubVer
Definition: net.h:743
unsigned int SOCKET
Definition: compat.h:48
NetPermissionFlags m_permissions
Definition: net.h:343
const CAddress addr
Definition: net.h:739
bool Complete() const override
Definition: net.h:687
CDataStream vRecv
Definition: net.h:662
const int64_t nTimeConnected
Definition: net.h:736
CMessageHeader hdr
Definition: net.h:661
int flags
Definition: bitcoin-tx.cpp:508
uint64_t nMaxOutboundTimeframe
Definition: net.h:146
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netaddress.h:31
RecursiveMutex cs_feeFilter
Definition: net.h:817
std::list< CNode * > vNodesDisconnected
Definition: net.h:420
256-bit opaque blob.
Definition: uint256.h:120
void RemoveLocal(const CService &addr)
Definition: net.cpp:240
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:150
void AddInventoryKnown(const CInv &inv)
Definition: net.h:957
int nScore
Definition: net.h:567
static const unsigned int MAX_ADDR_TO_SEND
The maximum number of new addresses to accumulate before announcing.
Definition: net.h:59
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: net.h:46
int nMaxAddnode
Definition: net.h:138
int64_t nNextAddrSend GUARDED_BY(cs_sendProcessing)
Definition: net.h:785
void ForEachNode(Callable &&func) const
Definition: net.h:224
BanMan * m_banman
Definition: net.h:457
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:91
CAddress addrBind
Definition: net.h:608
const bool fInbound
Definition: net.h:760
bool fSendMempool GUARDED_BY(cs_tx_inventory)
Definition: net.h:812
CService resolvedAddress
Definition: net.h:98
std::thread threadOpenConnections
Definition: net.h:474
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:81
CSemaphoreGrant grantOutbound
Definition: net.h:766
The TransportDeserializer takes care of holding and deserializing the network receive buffer...
Definition: net.h:641
uint256 hashContinue
Definition: net.h:778
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:575
const NodeId id
Definition: net.h:854
std::string addrLocal
Definition: net.h:604
std::thread threadDNSAddressSeed
Definition: net.h:471
ServiceFlags nLocalServices
Definition: net.h:134
uint64_t nMaxOutboundLimit
Definition: net.h:147
std::vector< std::string > m_added_nodes
Definition: net.h:155
RecursiveMutex cs_vSend
Definition: net.h:720
int64_t PoissonNextSend(int64_t now, int average_interval_seconds)
Return a timestamp in the future (in microseconds) for exponentially distributed events.
Definition: net.cpp:2781
std::vector< ListenSocket > vhListenSocket
Definition: net.h:411
double dMinPing
Definition: net.h:601
void PushBlockHash(const uint256 &hash)
Definition: net.h:978
std::string command
Definition: net.h:116
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
Definition: net.h:245
SipHash-2-4.
Definition: siphash.h:13
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
Definition: net.h:63
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv)
Definition: net.h:392
static const bool DEFAULT_UPNP
-upnp default
Definition: net.h:76
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:87
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:85
const uint64_t nLocalHostNonce
Definition: net.h:855
unsigned int nSendBufferMaxSize
Definition: net.h:144
static const int PING_INTERVAL
Time between pings automatically sent out for latency probing and keepalive (in seconds).
Definition: net.h:49
std::string m_command
Definition: net.h:627
void clear()
Definition: streams.h:298
const ServiceFlags nLocalServices
Services offered to this peer.
Definition: net.h:872
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: net.h:44
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we&#39;ll relay everything (blocks, tx, addrs, etc)
Definition: net.h:65
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:91
CClientUIInterface uiInterface
Definition: net.h:529
Information about a peer.
Definition: net.h:707
std::thread threadSocketHandler
Definition: net.h:472
RecursiveMutex cs_totalBytesRecv
Definition: net.h:390
void SetReachable(enum Network net, bool reachable)
Mark a network as reachable or unreachable (no automatic connects to it)
Definition: net.cpp:247
NetPermissionFlags m_permissionFlags
Definition: net.h:597
RecursiveMutex cs_addrLocal
Definition: net.h:884
bool fDiscover
Definition: net.cpp:85
void SetVersion(int n)
Definition: streams.h:394
void AddAddressKnown(const CAddress &_addr)
Definition: net.h:935
CNode * AddRef()
Definition: net.h:922
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:440
double dPingWait
Definition: net.h:600
void Init(const Options &connOptions)
Definition: net.h:159
CThreadInterrupt interruptNet
Definition: net.h:469
unsigned int nHdrPos
Definition: net.h:663
static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections)
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:750
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:154
static const unsigned int MAX_INV_SZ
The maximum number of entries in an &#39;inv&#39; protocol message.
Definition: net.h:55
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:209
const uint64_t nSeed1
Definition: net.h:460
bool m_use_addrman_outgoing
Definition: net.h:153
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:151
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:280
CHash256 & Reset()
Definition: hash.h:39
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
Definition: random.h:173
bool GetUseAddrmanOutgoing() const
Definition: net.h:204
bool fRelayTxes
Definition: net.h:582
int64_t nLastSend
Definition: net.h:583
RecursiveMutex cs_hSocket
Definition: net.h:721
unsigned short GetListenPort()
Definition: net.cpp:99
const int nMyStartingHeight
Definition: net.h:874
bool m_use_addrman_outgoing
Definition: net.h:453
int nBestHeight
Definition: net.h:140
NodeId nodeid
Definition: net.h:580
int64_t nLastRecv
Definition: net.h:584
RecursiveMutex cs_totalBytesSent
Definition: net.h:391
#define PT_GUARDED_BY(x)
Definition: threadsafety.h:40
std::unique_ptr< TxRelay > m_tx_relay
Definition: net.h:825
CAddress addr
Definition: net.h:606
Message header.
Definition: protocol.h:27
int64_t m_peer_connect_timeout
Definition: net.h:148