Bitcoin Core  0.20.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 <threadinterrupt.h>
25 #include <uint256.h>
26 
27 #include <atomic>
28 #include <cstdint>
29 #include <deque>
30 #include <map>
31 #include <thread>
32 #include <memory>
33 #include <condition_variable>
34 
35 #ifndef WIN32
36 #include <arpa/inet.h>
37 #endif
38 
39 
40 class CScheduler;
41 class CNode;
42 class BanMan;
43 struct bilingual_str;
44 
46 static const bool DEFAULT_WHITELISTRELAY = true;
48 static const bool DEFAULT_WHITELISTFORCERELAY = false;
49 
51 static const int TIMEOUT_INTERVAL = 20 * 60;
53 static const int FEELER_INTERVAL = 120;
55 static const unsigned int MAX_ADDR_TO_SEND = 1000;
56 // TODO: remove ADDRMAN_GETADDR_MAX and let the caller specify this limit with MAX_ADDR_TO_SEND.
57 static_assert(MAX_ADDR_TO_SEND == ADDRMAN_GETADDR_MAX,
58  "Max allowed ADDR message size should be equal to the max number of records returned from AddrMan.");
60 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
62 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
66 static const int MAX_ADDNODE_CONNECTIONS = 8;
68 static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2;
70 static const int MAX_FEELER_CONNECTIONS = 1;
72 static const bool DEFAULT_LISTEN = true;
74 #ifdef USE_UPNP
75 static const bool DEFAULT_UPNP = USE_UPNP;
76 #else
77 static const bool DEFAULT_UPNP = false;
78 #endif
79 
80 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
82 static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
84 static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24;
86 static const bool DEFAULT_BLOCKSONLY = false;
88 static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
89 
90 static const bool DEFAULT_FORCEDNSSEED = false;
91 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
92 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
93 
94 typedef int64_t NodeId;
95 
97 {
98  std::string strAddedNode;
101  bool fInbound;
102 };
103 
104 class CNodeStats;
105 class CClientUIInterface;
106 
108 {
109  CSerializedNetMsg() = default;
111  CSerializedNetMsg& operator=(CSerializedNetMsg&&) = default;
112  // No copying, only moves.
113  CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
114  CSerializedNetMsg& operator=(const CSerializedNetMsg&) = delete;
115 
116  std::vector<unsigned char> data;
117  std::string m_type;
118 };
119 
120 
121 class NetEventsInterface;
122 class CConnman
123 {
124 public:
125 
128  CONNECTIONS_IN = (1U << 0),
129  CONNECTIONS_OUT = (1U << 1),
131  };
132 
133  struct Options
134  {
135  ServiceFlags nLocalServices = NODE_NONE;
136  int nMaxConnections = 0;
137  int m_max_outbound_full_relay = 0;
138  int m_max_outbound_block_relay = 0;
139  int nMaxAddnode = 0;
140  int nMaxFeeler = 0;
141  int nBestHeight = 0;
143  NetEventsInterface* m_msgproc = nullptr;
144  BanMan* m_banman = nullptr;
145  unsigned int nSendBufferMaxSize = 0;
146  unsigned int nReceiveFloodSize = 0;
147  uint64_t nMaxOutboundTimeframe = 0;
148  uint64_t nMaxOutboundLimit = 0;
149  int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
150  std::vector<std::string> vSeedNodes;
151  std::vector<NetWhitelistPermissions> vWhitelistedRange;
152  std::vector<NetWhitebindPermissions> vWhiteBinds;
153  std::vector<CService> vBinds;
154  bool m_use_addrman_outgoing = true;
155  std::vector<std::string> m_specified_outgoing;
156  std::vector<std::string> m_added_nodes;
157  std::vector<bool> m_asmap;
158  };
159 
160  void Init(const Options& connOptions) {
161  nLocalServices = connOptions.nLocalServices;
162  nMaxConnections = connOptions.nMaxConnections;
163  m_max_outbound_full_relay = std::min(connOptions.m_max_outbound_full_relay, connOptions.nMaxConnections);
164  m_max_outbound_block_relay = connOptions.m_max_outbound_block_relay;
165  m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
166  nMaxAddnode = connOptions.nMaxAddnode;
167  nMaxFeeler = connOptions.nMaxFeeler;
168  m_max_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + nMaxFeeler;
169  nBestHeight = connOptions.nBestHeight;
170  clientInterface = connOptions.uiInterface;
171  m_banman = connOptions.m_banman;
172  m_msgproc = connOptions.m_msgproc;
173  nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
174  nReceiveFloodSize = connOptions.nReceiveFloodSize;
175  m_peer_connect_timeout = connOptions.m_peer_connect_timeout;
176  {
177  LOCK(cs_totalBytesSent);
178  nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
179  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
180  }
181  vWhitelistedRange = connOptions.vWhitelistedRange;
182  {
183  LOCK(cs_vAddedNodes);
184  vAddedNodes = connOptions.m_added_nodes;
185  }
186  }
187 
188  CConnman(uint64_t seed0, uint64_t seed1, bool network_active = true);
189  ~CConnman();
190  bool Start(CScheduler& scheduler, const Options& options);
191 
192  void StopThreads();
193  void StopNodes();
194  void Stop()
195  {
196  StopThreads();
197  StopNodes();
198  };
199 
200  void Interrupt();
201  bool GetNetworkActive() const { return fNetworkActive; };
202  bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
203  void SetNetworkActive(bool active);
204  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);
205  bool CheckIncomingNonce(uint64_t nonce);
206 
207  bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
208 
209  void PushMessage(CNode* pnode, CSerializedNetMsg&& msg);
210 
211  template<typename Callable>
212  void ForEachNode(Callable&& func)
213  {
214  LOCK(cs_vNodes);
215  for (auto&& node : vNodes) {
216  if (NodeFullyConnected(node))
217  func(node);
218  }
219  };
220 
221  template<typename Callable>
222  void ForEachNode(Callable&& func) const
223  {
224  LOCK(cs_vNodes);
225  for (auto&& node : vNodes) {
226  if (NodeFullyConnected(node))
227  func(node);
228  }
229  };
230 
231  template<typename Callable, typename CallableAfter>
232  void ForEachNodeThen(Callable&& pre, CallableAfter&& post)
233  {
234  LOCK(cs_vNodes);
235  for (auto&& node : vNodes) {
236  if (NodeFullyConnected(node))
237  pre(node);
238  }
239  post();
240  };
241 
242  template<typename Callable, typename CallableAfter>
243  void ForEachNodeThen(Callable&& pre, CallableAfter&& post) const
244  {
245  LOCK(cs_vNodes);
246  for (auto&& node : vNodes) {
247  if (NodeFullyConnected(node))
248  pre(node);
249  }
250  post();
251  };
252 
253  // Addrman functions
254  void SetServices(const CService &addr, ServiceFlags nServices);
255  void MarkAddressGood(const CAddress& addr);
256  void AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
257  std::vector<CAddress> GetAddresses();
264  std::vector<CAddress> GetAddresses(Network requestor_network);
265 
266  // This allows temporarily exceeding m_max_outbound_full_relay, with the goal of finding
267  // a peer that is better than all our current peers.
268  void SetTryNewOutboundPeer(bool flag);
269  bool GetTryNewOutboundPeer();
270 
271  // Return the number of outbound peers we have in excess of our target (eg,
272  // if we previously called SetTryNewOutboundPeer(true), and have since set
273  // to false, we may have extra peers that we wish to disconnect). This may
274  // return a value less than (num_outbound_connections - num_outbound_slots)
275  // in cases where some outbound connections are not yet fully connected, or
276  // not yet fully disconnected.
277  int GetExtraOutboundCount();
278 
279  bool AddNode(const std::string& node);
280  bool RemoveAddedNode(const std::string& node);
281  std::vector<AddedNodeInfo> GetAddedNodeInfo();
282 
283  size_t GetNodeCount(NumConnections num);
284  void GetNodeStats(std::vector<CNodeStats>& vstats);
285  bool DisconnectNode(const std::string& node);
286  bool DisconnectNode(const CSubNet& subnet);
287  bool DisconnectNode(const CNetAddr& addr);
288  bool DisconnectNode(NodeId id);
289 
296  ServiceFlags GetLocalServices() const;
297 
299  void SetMaxOutboundTarget(uint64_t limit);
300  uint64_t GetMaxOutboundTarget();
301 
303  void SetMaxOutboundTimeframe(uint64_t timeframe);
304  uint64_t GetMaxOutboundTimeframe();
305 
309  bool OutboundTargetReached(bool historicalBlockServingLimit);
310 
313  uint64_t GetOutboundTargetBytesLeft();
314 
317  uint64_t GetMaxOutboundTimeLeftInCycle();
318 
319  uint64_t GetTotalBytesRecv();
320  uint64_t GetTotalBytesSent();
321 
322  void SetBestHeight(int height);
323  int GetBestHeight() const;
324 
326  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
327 
328  unsigned int GetReceiveFloodSize() const;
329 
330  void WakeMessageHandler();
331 
336  int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds);
337 
338  void SetAsmap(std::vector<bool> asmap) { addrman.m_asmap = std::move(asmap); }
339 
340 private:
341  struct ListenSocket {
342  public:
344  inline void AddSocketPermissionFlags(NetPermissionFlags& flags) const { NetPermissions::AddFlag(flags, m_permissions); }
345  ListenSocket(SOCKET socket_, NetPermissionFlags permissions_) : socket(socket_), m_permissions(permissions_) {}
346  private:
348  };
349 
350  bool BindListenPort(const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
351  bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
352  bool InitBinds(const std::vector<CService>& binds, const std::vector<NetWhitebindPermissions>& whiteBinds);
353  void ThreadOpenAddedConnections();
354  void AddOneShot(const std::string& strDest);
355  void ProcessOneShot();
356  void ThreadOpenConnections(std::vector<std::string> connect);
357  void ThreadMessageHandler();
358  void AcceptConnection(const ListenSocket& hListenSocket);
359  void DisconnectNodes();
361  void InactivityCheck(CNode *pnode);
362  bool GenerateSelectSet(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
363  void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set, std::set<SOCKET> &error_set);
364  void SocketHandler();
365  void ThreadSocketHandler();
366  void ThreadDNSAddressSeed();
367 
368  uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
369 
370  CNode* FindNode(const CNetAddr& ip);
371  CNode* FindNode(const CSubNet& subNet);
372  CNode* FindNode(const std::string& addrName);
373  CNode* FindNode(const CService& addr);
374 
375  bool AttemptToEvictConnection();
376  CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, bool manual_connection, bool block_relay_only);
377  void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const;
378 
379  void DeleteNode(CNode* pnode);
380 
381  NodeId GetNewNodeId();
382 
383  size_t SocketSendData(CNode *pnode) const;
384  void DumpAddresses();
385 
386  // Network stats
387  void RecordBytesRecv(uint64_t bytes);
388  void RecordBytesSent(uint64_t bytes);
389 
390  // Whether the node should be passed out in ForEach* callbacks
391  static bool NodeFullyConnected(const CNode* pnode);
392 
393  // Network usage totals
396  uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv) {0};
397  uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0};
398 
399  // outbound limit & stats
400  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
401  uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
402  uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
403  uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
404 
405  // P2P timeout in seconds
407 
408  // Whitelisted ranges. Any node connecting from these is automatically
409  // whitelisted (as well as those connecting to whitelisted binds).
410  std::vector<NetWhitelistPermissions> vWhitelistedRange;
411 
412  unsigned int nSendBufferMaxSize{0};
413  unsigned int nReceiveFloodSize{0};
414 
415  std::vector<ListenSocket> vhListenSocket;
416  std::atomic<bool> fNetworkActive{true};
417  bool fAddressesInitialized{false};
419  std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
421  std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
423  std::vector<CNode*> vNodes GUARDED_BY(cs_vNodes);
424  std::list<CNode*> vNodesDisconnected;
426  std::atomic<NodeId> nLastNodeId{0};
427  unsigned int nPrevNodeCount{0};
428 
436  std::vector<CAddress> m_addrs_response_cache;
437  std::chrono::microseconds m_update_addr_response{0};
438  };
439 
450  std::map<Network, CachedAddrResponse> m_addr_response_caches;
451 
465 
466  std::unique_ptr<CSemaphore> semOutbound;
467  std::unique_ptr<CSemaphore> semAddnode;
469 
470  // How many full-relay (tx, block, addr) outbound peers we want
472 
473  // How many block-relay only outbound peers we want
474  // We do not relay tx or addr messages with these peers
476 
481  std::atomic<int> nBestHeight;
486 
488  const uint64_t nSeed0, nSeed1;
489 
491  bool fMsgProcWake GUARDED_BY(mutexMsgProc);
492 
493  std::condition_variable condMsgProc;
495  std::atomic<bool> flagInterruptMsgProc{false};
496 
498 
499  std::thread threadDNSAddressSeed;
500  std::thread threadSocketHandler;
503  std::thread threadMessageHandler;
504 
508  std::atomic_bool m_try_another_outbound_peer;
509 
510  std::atomic<int64_t> m_next_send_inv_to_incoming{0};
511 
512  friend struct CConnmanTest;
513  friend struct ConnmanTestMsg;
514 };
515 void Discover();
516 void StartMapPort();
517 void InterruptMapPort();
518 void StopMapPort();
519 uint16_t GetListenPort();
520 
522 {
523  typedef bool result_type;
524 
525  template<typename I>
526  bool operator()(I first, I last) const
527  {
528  while (first != last) {
529  if (!(*first)) return false;
530  ++first;
531  }
532  return true;
533  }
534 };
535 
540 {
541 public:
542  virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
543  virtual bool SendMessages(CNode* pnode) = 0;
544  virtual void InitializeNode(CNode* pnode) = 0;
545  virtual void FinalizeNode(NodeId id, bool& update_connection_time) = 0;
546 
547 protected:
552  ~NetEventsInterface() = default;
553 };
554 
555 enum
556 {
557  LOCAL_NONE, // unknown
558  LOCAL_IF, // address a local interface listens on
559  LOCAL_BIND, // address explicit bound to
560  LOCAL_UPNP, // address reported by UPnP
561  LOCAL_MANUAL, // address explicitly specified (-externalip=)
562 
564 };
565 
566 bool IsPeerAddrLocalGood(CNode *pnode);
567 void AdvertiseLocal(CNode *pnode);
568 
573 void SetReachable(enum Network net, bool reachable);
575 bool IsReachable(enum Network net);
577 bool IsReachable(const CNetAddr& addr);
578 
579 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
580 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
581 void RemoveLocal(const CService& addr);
582 bool SeenLocal(const CService& addr);
583 bool IsLocal(const CService& addr);
584 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
585 CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices);
586 
587 
588 extern bool fDiscover;
589 extern bool fListen;
590 extern bool g_relay_txes;
591 
593 extern std::string strSubVersion;
594 
596  int nScore;
597  int nPort;
598 };
599 
601 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost);
602 
603 extern const std::string NET_MESSAGE_COMMAND_OTHER;
604 typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
605 
607 {
608 public:
612  int64_t nLastSend;
613  int64_t nLastRecv;
614  int64_t nTimeConnected;
615  int64_t nTimeOffset;
616  std::string addrName;
617  int nVersion;
618  std::string cleanSubVer;
619  bool fInbound;
622  uint64_t nSendBytes;
623  mapMsgCmdSize mapSendBytesPerMsgCmd;
624  uint64_t nRecvBytes;
625  mapMsgCmdSize mapRecvBytesPerMsgCmd;
628  int64_t m_ping_usec;
632  // Our address, as reported by the peer
633  std::string addrLocal;
634  // Address of this peer
636  // Bind address of our side of the connection
638  uint32_t m_mapped_as;
639 };
640 
641 
642 
647 class CNetMessage {
648 public:
650  std::chrono::microseconds m_time{0};
651  bool m_valid_netmagic = false;
652  bool m_valid_header = false;
653  bool m_valid_checksum = false;
654  uint32_t m_message_size{0};
655  uint32_t m_raw_message_size{0};
656  std::string m_command;
657 
658  CNetMessage(CDataStream&& recv_in) : m_recv(std::move(recv_in)) {}
659 
660  void SetVersion(int nVersionIn)
661  {
662  m_recv.SetVersion(nVersionIn);
663  }
664 };
665 
671 public:
672  // returns true if the current deserialization is complete
673  virtual bool Complete() const = 0;
674  // set the serialization context version
675  virtual void SetVersion(int version) = 0;
676  // read and deserialize data
677  virtual int Read(const char *data, unsigned int bytes) = 0;
678  // decomposes a message from the context
679  virtual CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, std::chrono::microseconds time) = 0;
681 };
682 
684 {
685 private:
686  mutable CHash256 hasher;
688  bool in_data; // parsing header (false) or data (true)
689  CDataStream hdrbuf; // partially received header
690  CMessageHeader hdr; // complete header
691  CDataStream vRecv; // received message data
692  unsigned int nHdrPos;
693  unsigned int nDataPos;
694 
695  const uint256& GetMessageHash() const;
696  int readHeader(const char *pch, unsigned int nBytes);
697  int readData(const char *pch, unsigned int nBytes);
698 
699  void Reset() {
700  vRecv.clear();
701  hdrbuf.clear();
702  hdrbuf.resize(24);
703  in_data = false;
704  nHdrPos = 0;
705  nDataPos = 0;
706  data_hash.SetNull();
707  hasher.Reset();
708  }
709 
710 public:
711 
712  V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
713  Reset();
714  }
715 
716  bool Complete() const override
717  {
718  if (!in_data)
719  return false;
720  return (hdr.nMessageSize == nDataPos);
721  }
722  void SetVersion(int nVersionIn) override
723  {
724  hdrbuf.SetVersion(nVersionIn);
725  vRecv.SetVersion(nVersionIn);
726  }
727  int Read(const char *pch, unsigned int nBytes) override {
728  int ret = in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
729  if (ret < 0) Reset();
730  return ret;
731  }
732  CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, std::chrono::microseconds time) override;
733 };
734 
738 public:
739  // prepare message for transport (header construction, error-correction computation, payload encryption, etc.)
740  virtual void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) = 0;
741  virtual ~TransportSerializer() {}
742 };
743 
745 public:
746  void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) override;
747 };
748 
750 class CNode
751 {
752  friend class CConnman;
753  friend struct ConnmanTestMsg;
754 
755 public:
756  std::unique_ptr<TransportDeserializer> m_deserializer;
757  std::unique_ptr<TransportSerializer> m_serializer;
758 
759  // socket
760  std::atomic<ServiceFlags> nServices{NODE_NONE};
761  SOCKET hSocket GUARDED_BY(cs_hSocket);
762  size_t nSendSize{0}; // total size of all vSendMsg entries
763  size_t nSendOffset{0}; // offset inside the first vSendMsg already sent
764  uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
765  std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
769 
771  std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
772  size_t nProcessQueueSize{0};
773 
775 
776  std::deque<CInv> vRecvGetData;
777  uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
778  std::atomic<int> nRecvVersion{INIT_PROTO_VERSION};
779 
780  std::atomic<int64_t> nLastSend{0};
781  std::atomic<int64_t> nLastRecv{0};
782  const int64_t nTimeConnected;
783  std::atomic<int64_t> nTimeOffset{0};
784  // Address of this peer
785  const CAddress addr;
786  // Bind address of our side of the connection
788  std::atomic<int> nVersion{0};
794  std::string cleanSubVer GUARDED_BY(cs_SubVer){};
795  bool m_prefer_evict{false}; // This peer is preferred for eviction.
796  bool HasPermission(NetPermissionFlags permission) const {
797  return NetPermissions::HasFlag(m_permissionFlags, permission);
798  }
799  // This boolean is unusued in actual processing, only present for backward compatibility at RPC/QT level
800  bool m_legacyWhitelisted{false};
801  bool fFeeler{false}; // If true this node is being used as a short lived feeler.
802  bool fOneShot{false};
803  bool m_manual_connection{false};
804  bool fClient{false}; // set by version message
805  bool m_limited_node{false}; //after BIP159, set by version message
806  const bool fInbound;
807  std::atomic_bool fSuccessfullyConnected{false};
808  // Setting fDisconnect to true will cause the node to be disconnected the
809  // next time DisconnectNodes() runs
810  std::atomic_bool fDisconnect{false};
811  bool fSentAddr{false};
813  std::atomic<int> nRefCount{0};
814 
815  const uint64_t nKeyedNetGroup;
816  std::atomic_bool fPauseRecv{false};
817  std::atomic_bool fPauseSend{false};
818 
819 protected:
820  mapMsgCmdSize mapSendBytesPerMsgCmd;
821  mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
822 
823 public:
825  std::atomic<int> nStartingHeight{-1};
826 
827  // flood relay
828  std::vector<CAddress> vAddrToSend;
829  const std::unique_ptr<CRollingBloomFilter> m_addr_known;
830  bool fGetAddr{false};
831  std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0};
832  std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0};
833 
834  bool IsAddrRelayPeer() const { return m_addr_known != nullptr; }
835 
836  // List of block ids we still have announce.
837  // There is no final sorting before sending, as they are always sent immediately
838  // and in the order requested.
839  std::vector<uint256> vInventoryBlockToSend GUARDED_BY(cs_inventory);
841 
842  struct TxRelay {
844  // We use fRelayTxes for two purposes -
845  // a) it allows us to not relay tx invs before receiving the peer's version message
846  // b) the peer may tell us in its version message that we should not relay tx invs
847  // unless it loads a bloom filter.
848  bool fRelayTxes GUARDED_BY(cs_filter){false};
849  std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter){nullptr};
850 
851  mutable RecursiveMutex cs_tx_inventory;
852  CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_tx_inventory){50000, 0.000001};
853  // Set of transaction ids we still have to announce.
854  // They are sorted by the mempool before relay, so the order is not important.
855  std::set<uint256> setInventoryTxToSend;
856  // Used for BIP35 mempool sending
857  bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
858  // Last time a "MEMPOOL" request was serviced.
859  std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
860  std::chrono::microseconds nNextInvSend{0};
861 
863  // Minimum fee rate with which to filter inv's to this node
864  CAmount minFeeFilter GUARDED_BY(cs_feeFilter){0};
865  CAmount lastSentFeeFilter{0};
866  int64_t nextSendTimeFeeFilter{0};
867  };
868 
869  // m_tx_relay == nullptr if we're not relaying transactions with this peer
870  std::unique_ptr<TxRelay> m_tx_relay;
871 
872  // Used for headers announcements - unfiltered blocks to relay
873  std::vector<uint256> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
874 
875  // Block and TXN accept times
876  std::atomic<int64_t> nLastBlockTime{0};
877  std::atomic<int64_t> nLastTXTime{0};
878 
879  // Ping time measurement:
880  // The pong reply we're expecting, or 0 if no pong expected.
881  std::atomic<uint64_t> nPingNonceSent{0};
883  std::atomic<std::chrono::microseconds> m_ping_start{std::chrono::microseconds{0}};
884  // Last measured round-trip time.
885  std::atomic<int64_t> nPingUsecTime{0};
886  // Best measured round-trip time.
887  std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()};
888  // Whether a ping is requested.
889  std::atomic<bool> fPingQueued{false};
890 
891  std::set<uint256> orphan_work_set;
892 
893  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);
894  ~CNode();
895  CNode(const CNode&) = delete;
896  CNode& operator=(const CNode&) = delete;
897 
898 private:
899  const NodeId id;
900  const uint64_t nLocalHostNonce;
901 
918 
919  const int nMyStartingHeight;
920  int nSendVersion{0};
921  NetPermissionFlags m_permissionFlags{ PF_NONE };
922  std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
923 
925  std::string addrName GUARDED_BY(cs_addrName);
926 
927  // Our address, as reported by the peer
928  CService addrLocal GUARDED_BY(cs_addrLocal);
930 public:
931 
932  NodeId GetId() const {
933  return id;
934  }
935 
936  uint64_t GetLocalNonce() const {
937  return nLocalHostNonce;
938  }
939 
940  int GetMyStartingHeight() const {
941  return nMyStartingHeight;
942  }
943 
944  int GetRefCount() const
945  {
946  assert(nRefCount >= 0);
947  return nRefCount;
948  }
949 
950  bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
951 
952  void SetRecvVersion(int nVersionIn)
953  {
954  nRecvVersion = nVersionIn;
955  }
956  int GetRecvVersion() const
957  {
958  return nRecvVersion;
959  }
960  void SetSendVersion(int nVersionIn);
961  int GetSendVersion() const;
962 
963  CService GetAddrLocal() const;
965  void SetAddrLocal(const CService& addrLocalIn);
966 
968  {
969  nRefCount++;
970  return this;
971  }
972 
973  void Release()
974  {
975  nRefCount--;
976  }
977 
978 
979 
980  void AddAddressKnown(const CAddress& _addr)
981  {
982  assert(m_addr_known);
983  m_addr_known->insert(_addr.GetKey());
984  }
985 
986  void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
987  {
988  // Known checking here is only to save space from duplicates.
989  // SendMessages will filter it again for knowns that were added
990  // after addresses were pushed.
991  assert(m_addr_known);
992  if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey())) {
993  if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
994  vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
995  } else {
996  vAddrToSend.push_back(_addr);
997  }
998  }
999  }
1000 
1001 
1002  void AddKnownTx(const uint256& hash)
1003  {
1004  if (m_tx_relay != nullptr) {
1005  LOCK(m_tx_relay->cs_tx_inventory);
1006  m_tx_relay->filterInventoryKnown.insert(hash);
1007  }
1008  }
1009 
1010  void PushTxInventory(const uint256& hash)
1011  {
1012  if (m_tx_relay == nullptr) return;
1013  LOCK(m_tx_relay->cs_tx_inventory);
1014  if (!m_tx_relay->filterInventoryKnown.contains(hash)) {
1015  m_tx_relay->setInventoryTxToSend.insert(hash);
1016  }
1017  }
1018 
1019  void CloseSocketDisconnect();
1020 
1021  void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap);
1022 
1024  {
1025  return nLocalServices;
1026  }
1027 
1028  std::string GetAddrName() const;
1030  void MaybeSetAddrName(const std::string& addrNameIn);
1031 };
1032 
1034 int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
1035 
1037 inline std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
1038 {
1039  return std::chrono::microseconds{PoissonNextSend(now.count(), average_interval.count())};
1040 }
1041 
1042 #endif // BITCOIN_NET_H
std::vector< CService > vBinds
Definition: net.h:153
int m_max_outbound_full_relay
Definition: net.h:137
uint256 data_hash
Definition: net.h:687
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:436
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:68
std::string m_type
Definition: net.h:117
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent)
Definition: net.h:397
int nMaxFeeler
Definition: net.h:478
std::vector< bool > m_asmap
Definition: net.h:157
bool IsReachable(enum Network net)
Definition: net.cpp:270
int nStartingHeight
Definition: net.h:621
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:60
int m_max_outbound
Definition: net.h:479
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:625
Definition: banman.h:57
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
ServiceFlags
nServices flags
Definition: protocol.h:257
static const uint64_t MAX_UPLOAD_TIMEFRAME
The default timeframe for -maxuploadtarget.
Definition: net.h:84
void SetNull()
Definition: uint256.h:38
std::unique_ptr< TransportSerializer > m_serializer
Definition: net.h:757
RecursiveMutex cs_vNodes
Definition: net.h:425
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:794
int64_t nTimeOffset
Definition: net.h:615
int64_t m_ping_usec
Definition: net.h:628
bool fListen
Definition: net.cpp:101
int m_max_outbound_block_relay
Definition: net.h:138
uint32_t m_mapped_as
Definition: net.h:638
std::atomic< int > nBestHeight
Definition: net.h:481
bool fRelayTxes GUARDED_BY(cs_filter)
Definition: net.h:848
bool m_legacyWhitelisted
Definition: net.h:627
Bilingual messages:
Definition: translation.h:16
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:93
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(cs_mapLocalHost)
void SetVersion(int nVersionIn) override
Definition: net.h:722
void PushTxInventory(const uint256 &hash)
Definition: net.h:1010
BanMan * m_banman
Definition: net.h:144
Mutex mutexMsgProc
Definition: net.h:494
static const bool DEFAULT_FORCEDNSSEED
Definition: net.h:90
const uint64_t nKeyedNetGroup
Definition: net.h:815
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:282
int GetRecvVersion() const
Definition: net.h:956
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:820
CDataStream hdrbuf
Definition: net.h:689
void StartMapPort()
Definition: net.cpp:1579
void StopMapPort()
Definition: net.cpp:1587
std::vector< unsigned char > data
Definition: net.h:116
unsigned int nDataPos
Definition: net.h:693
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:410
CAmount minFeeFilter GUARDED_BY(cs_feeFilter)
Definition: net.h:864
unsigned int nReceiveFloodSize
Definition: net.h:146
uint16_t GetListenPort()
Definition: net.cpp:114
RecursiveMutex cs_filter
Definition: net.h:843
int m_max_outbound_full_relay
Definition: net.h:471
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:623
CClientUIInterface * uiInterface
Definition: net.h:142
void resize(size_type n, value_type c=0)
Definition: streams.h:294
bool g_relay_txes
Definition: net.cpp:102
void SetAsmap(std::vector< bool > asmap)
Definition: net.h:338
ServiceFlags nServices
Definition: net.h:610
Mutex cs_inventory
Definition: net.h:840
CDataStream m_recv
received message data
Definition: net.h:649
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:72
CNetMessage(CDataStream &&recv_in)
Definition: net.h:658
int nMaxAddnode
Definition: net.h:477
RAII-style semaphore lock.
Definition: sync.h:294
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:66
RecursiveMutex cs_vProcessMsg
Definition: net.h:770
std::string cleanSubVer
Definition: net.h:618
Interface for message handling.
Definition: net.h:539
void SetVersion(int nVersionIn)
Definition: net.h:660
RecursiveMutex cs_addrName
Definition: net.h:924
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set. ...
Definition: bloom.h:99
NetEventsInterface * m_msgproc
Definition: net.h:483
CAmount minFeeFilter
Definition: net.h:631
int nMaxConnections
Definition: net.h:136
int64_t nTimeConnected
Definition: net.h:614
void AdvertiseLocal(CNode *pnode)
Definition: net.cpp:197
int m_max_outbound_block_relay
Definition: net.h:475
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:201
uint32_t nMessageSize
Definition: protocol.h:54
A hasher class for Bitcoin&#39;s 256-bit hash (double SHA-256).
Definition: hash.h:22
uint64_t GetLocalNonce() const
Definition: net.h:936
std::unique_ptr< TransportDeserializer > m_deserializer
Definition: net.h:756
std::vector< CAddress > vAddrToSend
Definition: net.h:828
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
Definition: net.h:986
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:768
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Definition: net.h:764
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:952
Definition: net.h:563
Signals for UI communication.
Definition: ui_interface.h:24
std::list< CNetMessage > vRecvMsg
Definition: net.h:922
CAddrMan addrman
Definition: net.h:418
std::set< uint256 > orphan_work_set
Definition: net.h:891
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:70
std::deque< CInv > vRecvGetData
Definition: net.h:776
bool fConnected
Definition: net.h:100
virtual ~TransportDeserializer()
Definition: net.h:680
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:344
int GetRefCount() const
Definition: net.h:944
RecursiveMutex cs_sendProcessing
Definition: net.h:774
const std::unique_ptr< CRollingBloomFilter > m_addr_known
Definition: net.h:829
ServiceFlags nLocalServices
Services this instance offers.
Definition: net.h:464
bool IsValid() const
Definition: netaddress.cpp:267
bool operator()(I first, I last) const
Definition: net.h:526
bool m_manual_connection
Definition: net.h:620
CHash256 hasher
Definition: net.h:686
Stochastical (IP) address manager.
Definition: addrman.h:176
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool IsAddrRelayPeer() const
Definition: net.h:834
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:91
int GetMyStartingHeight() const
Definition: net.h:940
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing)
Definition: net.h:832
ServiceFlags GetLocalServices() const
Definition: net.h:1023
int nVersion
Definition: net.h:617
void InterruptMapPort()
Definition: net.cpp:1583
int64_t m_ping_wait_usec
Definition: net.h:629
void Release()
Definition: net.h:973
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:120
std::condition_variable condMsgProc
Definition: net.h:493
bool result_type
Definition: net.h:523
RecursiveMutex cs_vAddedNodes
Definition: net.h:422
void Interrupt(NodeContext &node)
Interrupt threads.
Definition: init.cpp:160
ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
Definition: net.h:345
std::thread threadOpenAddedConnections
Definition: net.h:501
#define LOCK(cs)
Definition: sync.h:228
RecursiveMutex cs_vOneShots
Definition: net.h:420
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:189
NetEventsInterface * m_msgproc
Definition: net.h:143
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:98
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:196
Fast randomness source.
Definition: random.h:119
Transport protocol agnostic message container.
Definition: net.h:647
const CAddress addrBind
Definition: net.h:787
std::vector< std::string > vSeedNodes
Definition: net.h:150
std::map< Network, CachedAddrResponse > m_addr_response_caches
Addr responses stored in different caches per network prevent cross-network node identification.
Definition: net.h:450
std::vector< std::string > m_specified_outgoing
Definition: net.h:155
int64_t m_peer_connect_timeout
Definition: net.h:406
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:466
std::thread threadMessageHandler
Definition: net.h:503
static bool HasFlag(const NetPermissionFlags &flags, NetPermissionFlags f)
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
Definition: net.h:232
bool fInbound
Definition: net.h:619
A CService with information about it as peer.
Definition: protocol.h:345
uint64_t nRecvBytes
Definition: net.h:624
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:734
int Read(const char *pch, unsigned int nBytes) override
Definition: net.h:727
RecursiveMutex cs_mapLocalHost
Definition: net.cpp:103
bool fInbound
Definition: net.h:101
std::string addrName
Definition: net.h:616
int nMaxFeeler
Definition: net.h:140
Network
A network type.
Definition: netaddress.h:28
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:508
int64_t NodeId
Definition: net.h:94
Definition: net.h:122
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:80
bool GetNetworkActive() const
Definition: net.h:201
NumConnections
Definition: net.h:126
CClientUIInterface * clientInterface
Definition: net.h:482
V1TransportDeserializer(const CMessageHeader::MessageStartChars &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:712
NodeId GetId() const
Definition: net.h:932
uint64_t nSendBytes
Definition: net.h:622
int nMaxConnections
Definition: net.h:468
The TransportSerializer prepares messages for the network transport.
Definition: net.h:737
NetPermissionFlags
void ForEachNode(Callable &&func)
Definition: net.h:212
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:777
void Discover()
Definition: net.cpp:2203
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:38
RecursiveMutex cs_SubVer
Definition: net.h:789
unsigned int SOCKET
Definition: compat.h:48
NetPermissionFlags m_permissions
Definition: net.h:347
const CAddress addr
Definition: net.h:785
bool Complete() const override
Definition: net.h:716
CDataStream vRecv
Definition: net.h:691
const int64_t nTimeConnected
Definition: net.h:782
CMessageHeader hdr
Definition: net.h:690
virtual ~TransportSerializer()
Definition: net.h:741
int flags
Definition: bitcoin-tx.cpp:509
uint64_t nMaxOutboundTimeframe
Definition: net.h:147
Network address.
Definition: netaddress.h:55
RecursiveMutex cs_feeFilter
Definition: net.h:862
std::list< CNode * > vNodesDisconnected
Definition: net.h:424
#define ADDRMAN_GETADDR_MAX
the maximum number of nodes to return in a getaddr call
Definition: addrman.h:160
256-bit opaque blob.
Definition: uint256.h:123
void RemoveLocal(const CService &addr)
Definition: net.cpp:255
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:151
int nScore
Definition: net.h:596
static const unsigned int MAX_ADDR_TO_SEND
The maximum number of new addresses to accumulate before announcing.
Definition: net.h:55
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: net.h:48
int nMaxAddnode
Definition: net.h:139
void ForEachNode(Callable &&func) const
Definition: net.h:222
void AddKnownTx(const uint256 &hash)
Definition: net.h:1002
BanMan * m_banman
Pointer to this node&#39;s banman.
Definition: net.h:485
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:92
CAddress addrBind
Definition: net.h:637
const bool fInbound
Definition: net.h:806
bool fSendMempool GUARDED_BY(cs_tx_inventory)
Definition: net.h:857
CService resolvedAddress
Definition: net.h:99
std::thread threadOpenConnections
Definition: net.h:502
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:82
CSemaphoreGrant grantOutbound
Definition: net.h:812
The TransportDeserializer takes care of holding and deserializing the network receive buffer...
Definition: net.h:670
uint256 hashContinue
Definition: net.h:824
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:604
const NodeId id
Definition: net.h:899
std::string addrLocal
Definition: net.h:633
std::thread threadDNSAddressSeed
Definition: net.h:499
ServiceFlags nLocalServices
Definition: net.h:135
uint64_t nMaxOutboundLimit
Definition: net.h:148
std::vector< std::string > m_added_nodes
Definition: net.h:156
RecursiveMutex cs_vSend
Definition: net.h:766
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:2871
std::vector< ListenSocket > vhListenSocket
Definition: net.h:415
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
Definition: net.h:243
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:62
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv)
Definition: net.h:396
static const bool DEFAULT_UPNP
-upnp default
Definition: net.h:77
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:88
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:86
const uint64_t nLocalHostNonce
Definition: net.h:900
unsigned int nSendBufferMaxSize
Definition: net.h:145
std::string m_command
Definition: net.h:656
void clear()
Definition: streams.h:298
const ServiceFlags nLocalServices
Services offered to this peer.
Definition: net.h:917
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: net.h:46
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:64
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:106
CClientUIInterface uiInterface
Definition: net.h:558
Information about a peer.
Definition: net.h:750
std::thread threadSocketHandler
Definition: net.h:500
Simple class for background tasks that should be run periodically or once "after a while"...
Definition: scheduler.h:32
RecursiveMutex cs_totalBytesRecv
Definition: net.h:394
void SetReachable(enum Network net, bool reachable)
Mark a network as reachable or unreachable (no automatic connects to it)
Definition: net.cpp:262
NetPermissionFlags m_permissionFlags
Definition: net.h:626
RecursiveMutex cs_addrLocal
Definition: net.h:929
bool fDiscover
Definition: net.cpp:100
void SetVersion(int n)
Definition: streams.h:394
void AddAddressKnown(const CAddress &_addr)
Definition: net.h:980
CNode * AddRef()
Definition: net.h:967
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:467
void Init(const Options &connOptions)
Definition: net.h:160
CThreadInterrupt interruptNet
Definition: net.h:497
unsigned int nHdrPos
Definition: net.h:692
static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections)
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:796
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:169
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:224
const uint64_t nSeed1
Definition: net.h:488
void Stop()
Definition: net.h:194
bool m_use_addrman_outgoing
Definition: net.h:154
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:152
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:295
CHash256 & Reset()
Definition: hash.h:40
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
Definition: random.h:190
bool GetUseAddrmanOutgoing() const
Definition: net.h:202
bool fRelayTxes
Definition: net.h:611
int64_t nLastSend
Definition: net.h:612
RecursiveMutex cs_hSocket
Definition: net.h:767
int64_t m_min_ping_usec
Definition: net.h:630
const int nMyStartingHeight
Definition: net.h:919
bool m_use_addrman_outgoing
Definition: net.h:480
Cache responses to addr requests to minimize privacy leak.
Definition: net.h:435
int nBestHeight
Definition: net.h:141
NodeId nodeid
Definition: net.h:609
int64_t nLastRecv
Definition: net.h:613
RecursiveMutex cs_totalBytesSent
Definition: net.h:395
std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing)
Definition: net.h:831
std::unique_ptr< TxRelay > m_tx_relay
Definition: net.h:870
CAddress addr
Definition: net.h:635
Message header.
Definition: protocol.h:28
int64_t m_peer_connect_timeout
Definition: net.h:149
std::unique_ptr< CBloomFilter > pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter)
Definition: net.h:849