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 <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 
45 static const bool DEFAULT_WHITELISTRELAY = true;
47 static const bool DEFAULT_WHITELISTFORCERELAY = false;
48 
50 static const int TIMEOUT_INTERVAL = 20 * 60;
52 static const int FEELER_INTERVAL = 120;
54 static const unsigned int MAX_ADDR_TO_SEND = 1000;
56 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
58 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
62 static const int MAX_ADDNODE_CONNECTIONS = 8;
64 static const int MAX_BLOCKS_ONLY_CONNECTIONS = 2;
66 static const int MAX_FEELER_CONNECTIONS = 1;
68 static const bool DEFAULT_LISTEN = true;
70 #ifdef USE_UPNP
71 static const bool DEFAULT_UPNP = USE_UPNP;
72 #else
73 static const bool DEFAULT_UPNP = false;
74 #endif
75 
76 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
78 static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
80 static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24;
82 static const bool DEFAULT_BLOCKSONLY = false;
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 
93 {
94  std::string strAddedNode;
96  bool fConnected;
97  bool fInbound;
98 };
99 
100 class CNodeStats;
101 class CClientUIInterface;
102 
104 {
105  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 
124  CONNECTIONS_IN = (1U << 0),
125  CONNECTIONS_OUT = (1U << 1),
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;
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  void Init(const Options& connOptions) {
157  nLocalServices = connOptions.nLocalServices;
158  nMaxConnections = connOptions.nMaxConnections;
159  m_max_outbound_full_relay = std::min(connOptions.m_max_outbound_full_relay, connOptions.nMaxConnections);
160  m_max_outbound_block_relay = connOptions.m_max_outbound_block_relay;
161  m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
162  nMaxAddnode = connOptions.nMaxAddnode;
163  nMaxFeeler = connOptions.nMaxFeeler;
164  m_max_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + nMaxFeeler;
165  nBestHeight = connOptions.nBestHeight;
166  clientInterface = connOptions.uiInterface;
167  m_banman = connOptions.m_banman;
168  m_msgproc = connOptions.m_msgproc;
169  nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
170  nReceiveFloodSize = connOptions.nReceiveFloodSize;
171  m_peer_connect_timeout = connOptions.m_peer_connect_timeout;
172  {
173  LOCK(cs_totalBytesSent);
174  nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
175  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
176  }
177  vWhitelistedRange = connOptions.vWhitelistedRange;
178  {
179  LOCK(cs_vAddedNodes);
180  vAddedNodes = connOptions.m_added_nodes;
181  }
182  }
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  {
192  StopThreads();
193  StopNodes();
194  };
195 
196  void Interrupt();
197  bool GetNetworkActive() const { return fNetworkActive; };
198  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  {
210  LOCK(cs_vNodes);
211  for (auto&& node : vNodes) {
212  if (NodeFullyConnected(node))
213  func(node);
214  }
215  };
216 
217  template<typename Callable>
218  void ForEachNode(Callable&& func) const
219  {
220  LOCK(cs_vNodes);
221  for (auto&& node : vNodes) {
222  if (NodeFullyConnected(node))
223  func(node);
224  }
225  };
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  {
241  LOCK(cs_vNodes);
242  for (auto&& node : vNodes) {
243  if (NodeFullyConnected(node))
244  pre(node);
245  }
246  post();
247  };
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 
286  ServiceFlags GetLocalServices() const;
287 
289  void SetMaxOutboundTarget(uint64_t limit);
290  uint64_t GetMaxOutboundTarget();
291 
293  void SetMaxOutboundTimeframe(uint64_t timeframe);
294  uint64_t GetMaxOutboundTimeframe();
295 
299  bool OutboundTargetReached(bool historicalBlockServingLimit);
300 
303  uint64_t GetOutboundTargetBytesLeft();
304 
307  uint64_t GetMaxOutboundTimeLeftInCycle();
308 
309  uint64_t GetTotalBytesRecv();
310  uint64_t GetTotalBytesSent();
311 
312  void SetBestHeight(int height);
313  int GetBestHeight() const;
314 
316  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
317 
318  unsigned int GetReceiveFloodSize() const;
319 
320  void WakeMessageHandler();
321 
326  int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds);
327 
328  void SetAsmap(std::vector<bool> asmap) { addrman.m_asmap = std::move(asmap); }
329 
330 private:
331  struct ListenSocket {
332  public:
334  inline void AddSocketPermissionFlags(NetPermissionFlags& flags) const { NetPermissions::AddFlag(flags, m_permissions); }
335  ListenSocket(SOCKET socket_, NetPermissionFlags permissions_) : socket(socket_), m_permissions(permissions_) {}
336  private:
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();
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
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
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};
409  std::deque<std::string> vOneShots GUARDED_BY(cs_vOneShots);
411  std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
413  std::vector<CNode*> vNodes GUARDED_BY(cs_vNodes);
414  std::list<CNode*> vNodesDisconnected;
416  std::atomic<NodeId> nLastNodeId{0};
417  unsigned int nPrevNodeCount{0};
418 
432 
433  std::unique_ptr<CSemaphore> semOutbound;
434  std::unique_ptr<CSemaphore> semAddnode;
436 
437  // How many full-relay (tx, block, addr) outbound peers we want
439 
440  // How many block-relay only outbound peers we want
441  // We do not relay tx or addr messages with these peers
443 
448  std::atomic<int> nBestHeight;
452 
454  const uint64_t nSeed0, nSeed1;
455 
457  bool fMsgProcWake GUARDED_BY(mutexMsgProc);
458 
459  std::condition_variable condMsgProc;
461  std::atomic<bool> flagInterruptMsgProc{false};
462 
464 
465  std::thread threadDNSAddressSeed;
466  std::thread threadSocketHandler;
469  std::thread threadMessageHandler;
470 
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 
488 {
489  typedef bool result_type;
490 
491  template<typename I>
492  bool operator()(I first, I last) const
493  {
494  while (first != last) {
495  if (!(*first)) return false;
496  ++first;
497  }
498  return true;
499  }
500 };
501 
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:
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 
530 };
531 
532 bool IsPeerAddrLocalGood(CNode *pnode);
533 void AdvertiseLocal(CNode *pnode);
534 
539 void SetReachable(enum Network net, bool reachable);
541 bool IsReachable(enum Network net);
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 
559 extern std::string strSubVersion;
560 
562  int nScore;
563  int nPort;
564 };
565 
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 
573 {
574 public:
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;
588  uint64_t nSendBytes;
589  mapMsgCmdSize mapSendBytesPerMsgCmd;
590  uint64_t nRecvBytes;
591  mapMsgCmdSize mapRecvBytesPerMsgCmd;
594  int64_t m_ping_usec;
598  // Our address, as reported by the peer
599  std::string addrLocal;
600  // Address of this peer
602  // Bind address of our side of the connection
604  uint32_t m_mapped_as;
605 };
606 
607 
608 
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  CNetMessage(CDataStream&& recv_in) : m_recv(std::move(recv_in)) {}
625 
626  void SetVersion(int nVersionIn)
627  {
628  m_recv.SetVersion(nVersionIn);
629  }
630 };
631 
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;
647 };
648 
650 {
651 private:
652  mutable CHash256 hasher;
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  void Reset() {
666  vRecv.clear();
667  hdrbuf.clear();
668  hdrbuf.resize(24);
669  in_data = false;
670  nHdrPos = 0;
671  nDataPos = 0;
672  data_hash.SetNull();
673  hasher.Reset();
674  }
675 
676 public:
677 
678  V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) {
679  Reset();
680  }
681 
682  bool Complete() const override
683  {
684  if (!in_data)
685  return false;
686  return (hdr.nMessageSize == nDataPos);
687  }
688  void SetVersion(int nVersionIn) override
689  {
690  hdrbuf.SetVersion(nVersionIn);
691  vRecv.SetVersion(nVersionIn);
692  }
693  int Read(const char *pch, unsigned int nBytes) override {
694  int ret = in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
695  if (ret < 0) Reset();
696  return ret;
697  }
698  CNetMessage GetMessage(const CMessageHeader::MessageStartChars& message_start, int64_t time) override;
699 };
700 
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  virtual ~TransportSerializer() {}
708 };
709 
711 public:
712  void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) override;
713 };
714 
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);
735 
737  std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
738  size_t nProcessQueueSize{0};
739 
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
754  std::atomic<int> nVersion{0};
760  std::string cleanSubVer GUARDED_BY(cs_SubVer){};
761  bool m_prefer_evict{false}; // This peer is preferred for eviction.
762  bool HasPermission(NetPermissionFlags permission) const {
763  return NetPermissions::HasFlag(m_permissionFlags, permission);
764  }
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};
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:
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  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);
807 
808  struct TxRelay {
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 
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 
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 
891  std::string addrName GUARDED_BY(cs_addrName);
892 
893  // Our address, as reported by the peer
894  CService addrLocal GUARDED_BY(cs_addrLocal);
896 public:
897 
898  NodeId GetId() const {
899  return id;
900  }
901 
902  uint64_t GetLocalNonce() const {
903  return nLocalHostNonce;
904  }
905 
906  int GetMyStartingHeight() const {
907  return nMyStartingHeight;
908  }
909 
910  int GetRefCount() const
911  {
912  assert(nRefCount >= 0);
913  return nRefCount;
914  }
915 
916  bool ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete);
917 
918  void SetRecvVersion(int nVersionIn)
919  {
920  nRecvVersion = nVersionIn;
921  }
922  int GetRecvVersion() const
923  {
924  return nRecvVersion;
925  }
926  void SetSendVersion(int nVersionIn);
927  int GetSendVersion() const;
928 
929  CService GetAddrLocal() const;
931  void SetAddrLocal(const CService& addrLocalIn);
932 
934  {
935  nRefCount++;
936  return this;
937  }
938 
939  void Release()
940  {
941  nRefCount--;
942  }
943 
944 
945 
946  void AddAddressKnown(const CAddress& _addr)
947  {
948  assert(m_addr_known);
949  m_addr_known->insert(_addr.GetKey());
950  }
951 
952  void PushAddress(const CAddress& _addr, FastRandomContext &insecure_rand)
953  {
954  // Known checking here is only to save space from duplicates.
955  // SendMessages will filter it again for knowns that were added
956  // after addresses were pushed.
957  assert(m_addr_known);
958  if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey())) {
959  if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
960  vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] = _addr;
961  } else {
962  vAddrToSend.push_back(_addr);
963  }
964  }
965  }
966 
967 
968  void AddInventoryKnown(const CInv& inv)
969  {
970  if (m_tx_relay != nullptr) {
971  LOCK(m_tx_relay->cs_tx_inventory);
972  m_tx_relay->filterInventoryKnown.insert(inv.hash);
973  }
974  }
975 
976  void PushInventory(const CInv& inv)
977  {
978  if (inv.type == MSG_TX && m_tx_relay != nullptr) {
979  LOCK(m_tx_relay->cs_tx_inventory);
980  if (!m_tx_relay->filterInventoryKnown.contains(inv.hash)) {
981  m_tx_relay->setInventoryTxToSend.insert(inv.hash);
982  }
983  } else if (inv.type == MSG_BLOCK) {
984  LOCK(cs_inventory);
985  vInventoryBlockToSend.push_back(inv.hash);
986  }
987  }
988 
989  void PushBlockHash(const uint256 &hash)
990  {
991  LOCK(cs_inventory);
992  vBlockHashesToAnnounce.push_back(hash);
993  }
994 
995  void CloseSocketDisconnect();
996 
997  void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap);
998 
1000  {
1001  return nLocalServices;
1002  }
1003 
1004  std::string GetAddrName() const;
1006  void MaybeSetAddrName(const std::string& addrNameIn);
1007 };
1008 
1010 int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
1011 
1013 inline std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
1014 {
1015  return std::chrono::microseconds{PoissonNextSend(now.count(), average_interval.count())};
1016 }
1017 
1018 #endif // BITCOIN_NET_H
std::vector< CService > vBinds
Definition: net.h:149
int m_max_outbound_full_relay
Definition: net.h:133
uint256 data_hash
Definition: net.h:653
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent)
Definition: net.h:387
int nMaxFeeler
Definition: net.h:445
std::vector< bool > m_asmap
Definition: net.h:153
bool IsReachable(enum Network net)
Definition: net.cpp:262
int nStartingHeight
Definition: net.h:587
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:56
int m_max_outbound
Definition: net.h:446
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:591
Definition: banman.h:41
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
ServiceFlags
nServices flags
Definition: protocol.h:259
static const uint64_t MAX_UPLOAD_TIMEFRAME
The default timeframe for -maxuploadtarget.
Definition: net.h:80
void SetNull()
Definition: uint256.h:38
std::unique_ptr< TransportSerializer > m_serializer
Definition: net.h:723
RecursiveMutex cs_vNodes
Definition: net.h:415
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:760
int64_t nTimeOffset
Definition: net.h:581
int64_t m_ping_usec
Definition: net.h:594
bool fListen
Definition: net.cpp:93
int m_max_outbound_block_relay
Definition: net.h:134
uint32_t m_mapped_as
Definition: net.h:604
std::atomic< int > nBestHeight
Definition: net.h:448
bool fRelayTxes GUARDED_BY(cs_filter)
Definition: net.h:814
bool m_legacyWhitelisted
Definition: net.h:593
Bilingual messages:
Definition: translation.h:16
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:85
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(cs_mapLocalHost)
void SetVersion(int nVersionIn) override
Definition: net.h:688
BanMan * m_banman
Definition: net.h:140
Mutex mutexMsgProc
Definition: net.h:460
static const bool DEFAULT_FORCEDNSSEED
Definition: net.h:86
const uint64_t nKeyedNetGroup
Definition: net.h:781
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:274
int GetRecvVersion() const
Definition: net.h:922
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:786
CDataStream hdrbuf
Definition: net.h:655
void StartMapPort()
Definition: net.cpp:1566
void StopMapPort()
Definition: net.cpp:1574
std::vector< unsigned char > data
Definition: net.h:112
inv message data
Definition: protocol.h:396
RecursiveMutex cs_inventory
Definition: net.h:806
unsigned int nDataPos
Definition: net.h:659
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:400
CAmount minFeeFilter GUARDED_BY(cs_feeFilter)
Definition: net.h:830
unsigned int nReceiveFloodSize
Definition: net.h:142
RecursiveMutex cs_filter
Definition: net.h:809
int m_max_outbound_full_relay
Definition: net.h:438
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:589
CClientUIInterface * uiInterface
Definition: net.h:138
void resize(size_type n, value_type c=0)
Definition: streams.h:294
bool g_relay_txes
Definition: net.cpp:94
void SetAsmap(std::vector< bool > asmap)
Definition: net.h:328
ServiceFlags nServices
Definition: net.h:576
CDataStream m_recv
Definition: net.h:615
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:68
CNetMessage(CDataStream &&recv_in)
Definition: net.h:624
int nMaxAddnode
Definition: net.h:444
RAII-style semaphore lock.
Definition: sync.h:286
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:62
RecursiveMutex cs_vProcessMsg
Definition: net.h:736
std::string cleanSubVer
Definition: net.h:584
Interface for message handling.
Definition: net.h:505
void SetVersion(int nVersionIn)
Definition: net.h:626
RecursiveMutex cs_addrName
Definition: net.h:890
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set. ...
Definition: bloom.h:99
NetEventsInterface * m_msgproc
Definition: net.h:450
CAmount minFeeFilter
Definition: net.h:597
int nMaxConnections
Definition: net.h:132
int64_t nTimeConnected
Definition: net.h:580
void AdvertiseLocal(CNode *pnode)
Definition: net.cpp:189
int m_max_outbound_block_relay
Definition: net.h:442
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:201
uint32_t nMessageSize
Definition: protocol.h:53
A hasher class for Bitcoin&#39;s 256-bit hash (double SHA-256).
Definition: hash.h:22
uint64_t GetLocalNonce() const
Definition: net.h:902
std::unique_ptr< TransportDeserializer > m_deserializer
Definition: net.h:722
std::vector< CAddress > vAddrToSend
Definition: net.h:794
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
Definition: net.h:952
static const int FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes or 120 seconds.
Definition: net.h:52
RecursiveMutex cs_vRecv
Definition: net.h:734
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Definition: net.h:730
static const int TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:50
void SetRecvVersion(int nVersionIn)
Definition: net.h:918
Definition: net.h:529
Signals for UI communication.
Definition: ui_interface.h:32
std::list< CNetMessage > vRecvMsg
Definition: net.h:888
void PushInventory(const CInv &inv)
Definition: net.h:976
CAddrMan addrman
Definition: net.h:408
std::set< uint256 > orphan_work_set
Definition: net.h:857
static const int MAX_BLOCKS_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:64
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:66
std::deque< CInv > vRecvGetData
Definition: net.h:742
bool fConnected
Definition: net.h:96
virtual ~TransportDeserializer()
Definition: net.h:646
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:334
int GetRefCount() const
Definition: net.h:910
RecursiveMutex cs_sendProcessing
Definition: net.h:740
const std::unique_ptr< CRollingBloomFilter > m_addr_known
Definition: net.h:795
ServiceFlags nLocalServices
Services this instance offers.
Definition: net.h:431
bool IsValid() const
Definition: netaddress.cpp:253
bool operator()(I first, I last) const
Definition: net.h:492
bool m_manual_connection
Definition: net.h:586
CHash256 hasher
Definition: net.h:652
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:800
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:87
int GetMyStartingHeight() const
Definition: net.h:906
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing)
Definition: net.h:798
ServiceFlags GetLocalServices() const
Definition: net.h:999
int nVersion
Definition: net.h:583
void InterruptMapPort()
Definition: net.cpp:1570
int64_t m_ping_wait_usec
Definition: net.h:595
void Release()
Definition: net.h:939
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:112
std::condition_variable condMsgProc
Definition: net.h:459
bool result_type
Definition: net.h:489
RecursiveMutex cs_vAddedNodes
Definition: net.h:412
void Interrupt(NodeContext &node)
Interrupt threads.
Definition: init.cpp:158
ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
Definition: net.h:335
std::thread threadOpenAddedConnections
Definition: net.h:467
#define LOCK(cs)
Definition: sync.h:220
RecursiveMutex cs_vOneShots
Definition: net.h:410
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:181
NetEventsInterface * m_msgproc
Definition: net.h:139
int type
Definition: protocol.h:409
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:94
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:138
Fast randomness source.
Definition: random.h:119
Transport protocol agnostic message container.
Definition: net.h:613
const CAddress addrBind
Definition: net.h:753
std::vector< std::string > vSeedNodes
Definition: net.h:146
std::vector< std::string > m_specified_outgoing
Definition: net.h:151
int64_t m_peer_connect_timeout
Definition: net.h:396
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:433
std::thread threadMessageHandler
Definition: net.h:469
static bool HasFlag(const NetPermissionFlags &flags, NetPermissionFlags f)
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
Definition: net.h:228
bool fInbound
Definition: net.h:585
A CService with information about it as peer.
Definition: protocol.h:347
uint64_t nRecvBytes
Definition: net.h:590
std::vector< unsigned char > GetKey() const
Definition: netaddress.cpp:726
uint256 hash
Definition: protocol.h:410
int Read(const char *pch, unsigned int nBytes) override
Definition: net.h:693
RecursiveMutex cs_mapLocalHost
Definition: net.cpp:95
bool fInbound
Definition: net.h:97
std::string addrName
Definition: net.h:582
int nMaxFeeler
Definition: net.h:136
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:474
int64_t NodeId
Definition: net.h:90
Definition: net.h:118
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:76
bool GetNetworkActive() const
Definition: net.h:197
NumConnections
Definition: net.h:122
CClientUIInterface * clientInterface
Definition: net.h:449
V1TransportDeserializer(const CMessageHeader::MessageStartChars &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:678
NodeId GetId() const
Definition: net.h:898
uint64_t nSendBytes
Definition: net.h:588
int nMaxConnections
Definition: net.h:435
The TransportSerializer prepares messages for the network transport.
Definition: net.h:703
NetPermissionFlags
void ForEachNode(Callable &&func)
Definition: net.h:208
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:743
void Discover()
Definition: net.cpp:2182
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:37
RecursiveMutex cs_SubVer
Definition: net.h:755
unsigned int SOCKET
Definition: compat.h:48
NetPermissionFlags m_permissions
Definition: net.h:337
const CAddress addr
Definition: net.h:751
bool Complete() const override
Definition: net.h:682
CDataStream vRecv
Definition: net.h:657
const int64_t nTimeConnected
Definition: net.h:748
CMessageHeader hdr
Definition: net.h:656
virtual ~TransportSerializer()
Definition: net.h:707
int flags
Definition: bitcoin-tx.cpp:509
uint64_t nMaxOutboundTimeframe
Definition: net.h:143
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netaddress.h:31
RecursiveMutex cs_feeFilter
Definition: net.h:828
std::list< CNode * > vNodesDisconnected
Definition: net.h:414
256-bit opaque blob.
Definition: uint256.h:120
void RemoveLocal(const CService &addr)
Definition: net.cpp:247
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:147
void AddInventoryKnown(const CInv &inv)
Definition: net.h:968
int nScore
Definition: net.h:562
static const unsigned int MAX_ADDR_TO_SEND
The maximum number of new addresses to accumulate before announcing.
Definition: net.h:54
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: net.h:47
int nMaxAddnode
Definition: net.h:135
void ForEachNode(Callable &&func) const
Definition: net.h:218
BanMan * m_banman
Definition: net.h:451
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:88
CAddress addrBind
Definition: net.h:603
const bool fInbound
Definition: net.h:772
bool fSendMempool GUARDED_BY(cs_tx_inventory)
Definition: net.h:823
CService resolvedAddress
Definition: net.h:95
std::thread threadOpenConnections
Definition: net.h:468
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:78
CSemaphoreGrant grantOutbound
Definition: net.h:778
The TransportDeserializer takes care of holding and deserializing the network receive buffer...
Definition: net.h:636
uint256 hashContinue
Definition: net.h:790
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:570
const NodeId id
Definition: net.h:865
std::string addrLocal
Definition: net.h:599
std::thread threadDNSAddressSeed
Definition: net.h:465
ServiceFlags nLocalServices
Definition: net.h:131
uint64_t nMaxOutboundLimit
Definition: net.h:144
std::vector< std::string > m_added_nodes
Definition: net.h:152
RecursiveMutex cs_vSend
Definition: net.h:732
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:2836
std::vector< ListenSocket > vhListenSocket
Definition: net.h:405
void PushBlockHash(const uint256 &hash)
Definition: net.h:989
std::string command
Definition: net.h:113
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
Definition: net.h:239
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:58
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv)
Definition: net.h:386
static const bool DEFAULT_UPNP
-upnp default
Definition: net.h:73
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:84
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:82
const uint64_t nLocalHostNonce
Definition: net.h:866
unsigned int nSendBufferMaxSize
Definition: net.h:141
std::string m_command
Definition: net.h:622
void clear()
Definition: streams.h:298
const ServiceFlags nLocalServices
Services offered to this peer.
Definition: net.h:883
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: net.h:45
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:60
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:98
CClientUIInterface uiInterface
Definition: net.h:524
Information about a peer.
Definition: net.h:716
std::thread threadSocketHandler
Definition: net.h:466
RecursiveMutex cs_totalBytesRecv
Definition: net.h:384
void SetReachable(enum Network net, bool reachable)
Mark a network as reachable or unreachable (no automatic connects to it)
Definition: net.cpp:254
NetPermissionFlags m_permissionFlags
Definition: net.h:592
RecursiveMutex cs_addrLocal
Definition: net.h:895
bool fDiscover
Definition: net.cpp:92
void SetVersion(int n)
Definition: streams.h:394
void AddAddressKnown(const CAddress &_addr)
Definition: net.h:946
CNode * AddRef()
Definition: net.h:933
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:434
void Init(const Options &connOptions)
Definition: net.h:156
CThreadInterrupt interruptNet
Definition: net.h:463
unsigned int nHdrPos
Definition: net.h:658
static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections)
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:762
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:161
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:216
const uint64_t nSeed1
Definition: net.h:454
void Stop()
Definition: net.h:190
bool m_use_addrman_outgoing
Definition: net.h:150
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:148
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:287
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:190
bool GetUseAddrmanOutgoing() const
Definition: net.h:198
bool fRelayTxes
Definition: net.h:577
int64_t nLastSend
Definition: net.h:578
RecursiveMutex cs_hSocket
Definition: net.h:733
int64_t m_min_ping_usec
Definition: net.h:596
unsigned short GetListenPort()
Definition: net.cpp:106
const int nMyStartingHeight
Definition: net.h:885
bool m_use_addrman_outgoing
Definition: net.h:447
int nBestHeight
Definition: net.h:137
NodeId nodeid
Definition: net.h:575
int64_t nLastRecv
Definition: net.h:579
RecursiveMutex cs_totalBytesSent
Definition: net.h:385
std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing)
Definition: net.h:797
std::unique_ptr< TxRelay > m_tx_relay
Definition: net.h:836
CAddress addr
Definition: net.h:601
Message header.
Definition: protocol.h:27
int64_t m_peer_connect_timeout
Definition: net.h:145
std::unique_ptr< CBloomFilter > pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter)
Definition: net.h:815