Bitcoin ABC  0.24.7
P2P Digital Currency
net.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef BITCOIN_NET_H
8 #define BITCOIN_NET_H
9 
10 #include <addrdb.h>
11 #include <addrman.h>
12 #include <amount.h>
13 #include <avalanche/delegation.h>
14 #include <bloom.h>
15 #include <chainparams.h>
16 #include <compat.h>
17 #include <crypto/siphash.h>
18 #include <hash.h>
19 #include <net_permissions.h>
20 #include <netaddress.h>
21 #include <nodeid.h>
22 #include <protocol.h>
23 #include <random.h>
24 #include <streams.h>
25 #include <sync.h>
26 #include <threadinterrupt.h>
27 #include <uint256.h>
28 #include <util/check.h>
29 #include <validation.h> // For cs_main
30 
31 #include <atomic>
32 #include <condition_variable>
33 #include <cstdint>
34 #include <deque>
35 #include <map>
36 #include <memory>
37 #include <thread>
38 #include <vector>
39 
40 #ifndef WIN32
41 #include <arpa/inet.h>
42 #endif
43 
44 class BanMan;
45 class Config;
46 class CNode;
47 class CScheduler;
48 struct bilingual_str;
49 
51 static const bool DEFAULT_WHITELISTRELAY = true;
53 static const bool DEFAULT_WHITELISTFORCERELAY = false;
54 
59 static const int TIMEOUT_INTERVAL = 20 * 60;
61 static const int FEELER_INTERVAL = 120;
66 static constexpr size_t MAX_ADDR_TO_SEND = 1000;
68 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
75 static const int MAX_ADDNODE_CONNECTIONS = 8;
77 static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2;
79 static const int MAX_FEELER_CONNECTIONS = 1;
81 static const bool DEFAULT_LISTEN = true;
83 #ifdef USE_UPNP
84 static const bool DEFAULT_UPNP = USE_UPNP;
85 #else
86 static const bool DEFAULT_UPNP = false;
87 #endif
88 
93 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 4096;
95 static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
97 static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24;
99 static const bool DEFAULT_BLOCKSONLY = false;
101 static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
102 
103 static const bool DEFAULT_FORCEDNSSEED = false;
104 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
105 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
106 
108 static constexpr std::chrono::minutes AVALANCHE_STATISTICS_REFRESH_PERIOD{10};
110 static constexpr std::chrono::minutes AVALANCHE_STATISTICS_TIME_CONSTANT{10};
116  1. - std::exp(-1. * AVALANCHE_STATISTICS_REFRESH_PERIOD.count() /
118 
120  std::string strAddedNode;
123  bool fInbound;
124 };
125 
126 struct CNodeStats;
127 class CClientUIInterface;
128 
130  CSerializedNetMsg() = default;
131  CSerializedNetMsg(CSerializedNetMsg &&) = default;
133  // No copying, only moves.
134  CSerializedNetMsg(const CSerializedNetMsg &msg) = delete;
135  CSerializedNetMsg &operator=(const CSerializedNetMsg &) = delete;
136 
137  std::vector<uint8_t> data;
138  std::string m_type;
139 };
140 
141 const std::vector<std::string> CONNECTION_TYPE_DOC{
142  "outbound-full-relay (default automatic connections)",
143  "block-relay-only (does not relay transactions or addresses)",
144  "inbound (initiated by the peer)",
145  "manual (added via addnode RPC or -addnode/-connect configuration options)",
146  "addr-fetch (short-lived automatic connection for soliciting addresses)",
147  "feeler (short-lived automatic connection for testing addresses)"};
148 
154 enum class ConnectionType {
160  INBOUND,
161 
169 
176  MANUAL,
177 
194  FEELER,
195 
205  BLOCK_RELAY,
206 
213  ADDR_FETCH,
214 };
215 
216 namespace {
217 struct CConnmanTest;
218 }
219 
220 class NetEventsInterface;
221 class CConnman {
222 public:
225  CONNECTIONS_IN = (1U << 0),
226  CONNECTIONS_OUT = (1U << 1),
228  };
229 
230  struct Options {
235  int nMaxAddnode = 0;
236  int nMaxFeeler = 0;
237  int nBestHeight = 0;
240  BanMan *m_banman = nullptr;
241  unsigned int nSendBufferMaxSize = 0;
242  unsigned int nReceiveFloodSize = 0;
243  uint64_t nMaxOutboundTimeframe = 0;
244  uint64_t nMaxOutboundLimit = 0;
246  std::vector<std::string> vSeedNodes;
247  std::vector<NetWhitelistPermissions> vWhitelistedRange;
248  std::vector<NetWhitebindPermissions> vWhiteBinds;
249  std::vector<CService> vBinds;
250  std::vector<CService> onion_binds;
252  std::vector<std::string> m_specified_outgoing;
253  std::vector<std::string> m_added_nodes;
254  std::vector<bool> m_asmap;
255  };
256 
257  void Init(const Options &connOptions) {
258  nLocalServices = connOptions.nLocalServices;
259  nMaxConnections = connOptions.nMaxConnections;
261  nMaxAddnode = connOptions.nMaxAddnode;
262  nMaxFeeler = connOptions.nMaxFeeler;
263  {
264  // Lock cs_main to prevent a potential race with the peer validation
265  // logic thread.
266  LOCK(::cs_main);
268  std::min(connOptions.m_max_outbound_full_relay,
269  connOptions.nMaxConnections);
273  }
274  nBestHeight = connOptions.nBestHeight;
275  clientInterface = connOptions.uiInterface;
276  m_banman = connOptions.m_banman;
277  m_msgproc = connOptions.m_msgproc;
279  nReceiveFloodSize = connOptions.nReceiveFloodSize;
281  {
283  nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
284  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
285  }
286  vWhitelistedRange = connOptions.vWhitelistedRange;
287  {
289  vAddedNodes = connOptions.m_added_nodes;
290  }
291  m_onion_binds = connOptions.onion_binds;
292  }
293 
294  CConnman(const Config &configIn, uint64_t seed0, uint64_t seed1,
295  bool network_active = true);
296  ~CConnman();
297 
298  bool Start(CScheduler &scheduler, const Options &options);
299 
300  void StopThreads();
301  void StopNodes();
302  void Stop() {
303  StopThreads();
304  StopNodes();
305  };
306 
307  void Interrupt();
308  bool GetNetworkActive() const { return fNetworkActive; };
310  void SetNetworkActive(bool active);
311  void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure,
312  CSemaphoreGrant *grantOutbound,
313  const char *strDest, ConnectionType conn_type);
314  bool CheckIncomingNonce(uint64_t nonce);
315 
316  bool ForNode(NodeId id, std::function<bool(CNode *pnode)> func);
317 
318  void PushMessage(CNode *pnode, CSerializedNetMsg &&msg);
319 
320  using NodeFn = std::function<void(CNode *)>;
321  void ForEachNode(const NodeFn &func) {
322  LOCK(cs_vNodes);
323  for (auto &&node : vNodes) {
324  if (NodeFullyConnected(node)) {
325  func(node);
326  }
327  }
328  };
329 
330  void ForEachNode(const NodeFn &func) const {
331  LOCK(cs_vNodes);
332  for (auto &&node : vNodes) {
333  if (NodeFullyConnected(node)) {
334  func(node);
335  }
336  }
337  };
338 
339  template <typename Callable, typename CallableAfter>
340  void ForEachNodeThen(Callable &&pre, CallableAfter &&post) {
341  LOCK(cs_vNodes);
342  for (auto &&node : vNodes) {
343  if (NodeFullyConnected(node)) {
344  pre(node);
345  }
346  }
347  post();
348  };
349 
350  template <typename Callable, typename CallableAfter>
351  void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const {
352  LOCK(cs_vNodes);
353  for (auto &&node : vNodes) {
354  if (NodeFullyConnected(node)) {
355  pre(node);
356  }
357  }
358  post();
359  };
360 
361  // Addrman functions
362  void SetServices(const CService &addr, ServiceFlags nServices);
363  void MarkAddressGood(const CAddress &addr);
364  bool AddNewAddresses(const std::vector<CAddress> &vAddr,
365  const CAddress &addrFrom, int64_t nTimePenalty = 0);
366  std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct);
373  std::vector<CAddress> GetAddresses(CNode &requestor, size_t max_addresses,
374  size_t max_pct);
375 
376  // This allows temporarily exceeding m_max_outbound_full_relay, with the
377  // goal of finding a peer that is better than all our current peers.
378  void SetTryNewOutboundPeer(bool flag);
379  bool GetTryNewOutboundPeer();
380 
381  // Return the number of outbound peers we have in excess of our target (eg,
382  // if we previously called SetTryNewOutboundPeer(true), and have since set
383  // to false, we may have extra peers that we wish to disconnect). This may
384  // return a value less than (num_outbound_connections - num_outbound_slots)
385  // in cases where some outbound connections are not yet fully connected, or
386  // not yet fully disconnected.
387  int GetExtraOutboundCount();
388 
389  bool AddNode(const std::string &node);
390  bool RemoveAddedNode(const std::string &node);
391  std::vector<AddedNodeInfo> GetAddedNodeInfo();
392 
393  size_t GetNodeCount(NumConnections num);
394  void GetNodeStats(std::vector<CNodeStats> &vstats);
395  bool DisconnectNode(const std::string &node);
396  bool DisconnectNode(const CSubNet &subnet);
397  bool DisconnectNode(const CNetAddr &addr);
398  bool DisconnectNode(NodeId id);
399 
407 
409  void SetMaxOutboundTarget(uint64_t limit);
410  uint64_t GetMaxOutboundTarget();
411 
413  void SetMaxOutboundTimeframe(uint64_t timeframe);
414  uint64_t GetMaxOutboundTimeframe();
415 
419  bool OutboundTargetReached(bool historicalBlockServingLimit);
420 
423  uint64_t GetOutboundTargetBytesLeft();
424 
428 
429  uint64_t GetTotalBytesRecv();
430  uint64_t GetTotalBytesSent();
431 
432  void SetBestHeight(int height);
433  int GetBestHeight() const;
434 
436  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
437 
438  unsigned int GetReceiveFloodSize() const;
439 
440  void WakeMessageHandler();
441 
447  int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds);
448 
449  void SetAsmap(std::vector<bool> asmap) {
450  addrman.m_asmap = std::move(asmap);
451  }
452 
453 private:
454  struct ListenSocket {
455  public:
459  }
460  ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
461  : socket(socket_), m_permissions(permissions_) {}
462 
463  private:
465  };
466 
467  bool BindListenPort(const CService &bindAddr, bilingual_str &strError,
468  NetPermissionFlags permissions);
469  bool Bind(const CService &addr, unsigned int flags,
470  NetPermissionFlags permissions);
471  bool InitBinds(const std::vector<CService> &binds,
472  const std::vector<NetWhitebindPermissions> &whiteBinds,
473  const std::vector<CService> &onion_binds);
474 
476  void AddAddrFetch(const std::string &strDest);
477  void ProcessAddrFetch();
478  void ThreadOpenConnections(std::vector<std::string> connect);
479  void ThreadMessageHandler();
480  void AcceptConnection(const ListenSocket &hListenSocket);
481  void DisconnectNodes();
483  void InactivityCheck(CNode *pnode);
484  bool GenerateSelectSet(std::set<SOCKET> &recv_set,
485  std::set<SOCKET> &send_set,
486  std::set<SOCKET> &error_set);
487  void SocketEvents(std::set<SOCKET> &recv_set, std::set<SOCKET> &send_set,
488  std::set<SOCKET> &error_set);
489  void SocketHandler();
490  void ThreadSocketHandler();
491  void ThreadDNSAddressSeed();
492 
493  uint64_t CalculateKeyedNetGroup(const CAddress &ad) const;
494 
495  CNode *FindNode(const CNetAddr &ip);
496  CNode *FindNode(const CSubNet &subNet);
497  CNode *FindNode(const std::string &addrName);
498  CNode *FindNode(const CService &addr);
499 
501  CNode *ConnectNode(CAddress addrConnect, const char *pszDest,
502  bool fCountFailure, ConnectionType conn_type);
504  const CNetAddr &addr) const;
505 
506  void DeleteNode(CNode *pnode);
507 
509 
510  size_t SocketSendData(CNode *pnode) const;
511  void DumpAddresses();
512 
513  // Network stats
514  void RecordBytesRecv(uint64_t bytes);
515  void RecordBytesSent(uint64_t bytes);
516 
520  std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;
521 
522  // Whether the node should be passed out in ForEach* callbacks
523  static bool NodeFullyConnected(const CNode *pnode);
524 
525  const Config *config;
526 
527  // Network usage totals
530  uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv){0};
531  uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent){0};
532 
533  // outbound limit & stats
534  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
535  uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
536  uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
537  uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
538 
539  // P2P timeout in seconds
541 
542  // Whitelisted ranges. Any node connecting from these is automatically
543  // whitelisted (as well as those connecting to whitelisted binds).
544  std::vector<NetWhitelistPermissions> vWhitelistedRange;
545 
546  unsigned int nSendBufferMaxSize{0};
547  unsigned int nReceiveFloodSize{0};
548 
549  std::vector<ListenSocket> vhListenSocket;
550  std::atomic<bool> fNetworkActive{true};
553  std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
555  std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
557  std::vector<CNode *> vNodes GUARDED_BY(cs_vNodes);
558  std::list<CNode *> vNodesDisconnected;
560  std::atomic<NodeId> nLastNodeId{0};
561  unsigned int nPrevNodeCount{0};
562 
570  std::vector<CAddress> m_addrs_response_cache;
571  std::chrono::microseconds m_cache_entry_expiration{0};
572  };
573 
588  std::map<uint64_t, CachedAddrResponse> m_addr_response_caches;
589 
603 
604  std::unique_ptr<CSemaphore> semOutbound;
605  std::unique_ptr<CSemaphore> semAddnode;
607 
608  // How many full-relay (tx, block, addr) outbound peers we want
610 
611  // How many block-relay only outbound peers we want
612  // We do not relay tx or addr messages with these peers
614 
619  std::atomic<int> nBestHeight;
627 
632  std::vector<CAddress> m_anchors;
633 
635  const uint64_t nSeed0, nSeed1;
636 
638  bool fMsgProcWake GUARDED_BY(mutexMsgProc);
639 
640  std::condition_variable condMsgProc;
642  std::atomic<bool> flagInterruptMsgProc{false};
643 
645 
646  std::thread threadDNSAddressSeed;
647  std::thread threadSocketHandler;
650  std::thread threadMessageHandler;
651 
656  std::atomic_bool m_try_another_outbound_peer;
657 
658  std::atomic<int64_t> m_next_send_inv_to_incoming{0};
659 
664  std::vector<CService> m_onion_binds;
665 
666  friend struct ::CConnmanTest;
667  friend struct ConnmanTestMsg;
668 };
669 
670 void Discover();
671 void StartMapPort();
672 void InterruptMapPort();
673 void StopMapPort();
674 uint16_t GetListenPort();
675 
680 public:
681  virtual bool ProcessMessages(const Config &config, CNode *pnode,
682  std::atomic<bool> &interrupt) = 0;
683  virtual bool SendMessages(const Config &config, CNode *pnode,
684  std::atomic<bool> &interrupt) = 0;
685  virtual void InitializeNode(const Config &config, CNode *pnode) = 0;
686  virtual void FinalizeNode(const Config &config, NodeId id,
687  bool &update_connection_time) = 0;
688 
689 protected:
695  ~NetEventsInterface() = default;
696 };
697 
698 enum {
699  // unknown
701  // address a local interface listens on
703  // address explicit bound to
705  // address reported by UPnP
707  // address explicitly specified (-externalip=)
709 
711 };
712 
713 bool IsPeerAddrLocalGood(CNode *pnode);
714 void AdvertiseLocal(CNode *pnode);
715 
720 void SetReachable(enum Network net, bool reachable);
722 bool IsReachable(enum Network net);
724 bool IsReachable(const CNetAddr &addr);
725 
726 bool AddLocal(const CService &addr, int nScore = LOCAL_NONE);
727 bool AddLocal(const CNetAddr &addr, int nScore = LOCAL_NONE);
728 void RemoveLocal(const CService &addr);
729 bool SeenLocal(const CService &addr);
730 bool IsLocal(const CService &addr);
731 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
732 CAddress GetLocalAddress(const CNetAddr *paddrPeer,
733  ServiceFlags nLocalServices);
734 
735 extern bool fDiscover;
736 extern bool fListen;
737 extern bool g_relay_txes;
738 
740  int nScore;
741  int nPort;
742 };
743 
745 extern std::map<CNetAddr, LocalServiceInfo>
746  mapLocalHost GUARDED_BY(cs_mapLocalHost);
747 
748 extern const std::string NET_MESSAGE_COMMAND_OTHER;
749 // Command, total bytes
750 typedef std::map<std::string, uint64_t> mapMsgCmdSize;
751 
757 struct CNodeStats {
761  int64_t nLastSend;
762  int64_t nLastRecv;
763  int64_t nLastTXTime;
764  int64_t nLastProofTime;
765  int64_t nLastBlockTime;
766  int64_t nTimeConnected;
767  int64_t nTimeOffset;
768  std::string addrName;
769  int nVersion;
770  std::string cleanSubVer;
771  bool fInbound;
774  uint64_t nSendBytes;
776  uint64_t nRecvBytes;
780  int64_t m_ping_usec;
784  // Our address, as reported by the peer
785  std::string addrLocal;
786  // Address of this peer
788  // Bind address of our side of the connection
790  // Name of the network the peer connected through
791  std::string m_network;
792  uint32_t m_mapped_as;
793  std::string m_conn_type_string;
794 };
795 
801 class CNetMessage {
802 public:
806  std::chrono::microseconds m_time{0};
807  bool m_valid_netmagic = false;
808  bool m_valid_header = false;
809  bool m_valid_checksum = false;
811  uint32_t m_message_size{0};
813  uint32_t m_raw_message_size{0};
814  std::string m_command;
815 
816  CNetMessage(CDataStream &&recv_in) : m_recv(std::move(recv_in)) {}
817 
818  void SetVersion(int nVersionIn) { m_recv.SetVersion(nVersionIn); }
819 };
820 
827 public:
828  // returns true if the current deserialization is complete
829  virtual bool Complete() const = 0;
830  // set the serialization context version
831  virtual void SetVersion(int version) = 0;
832  // read and deserialize data
833  virtual int Read(const Config &config, const char *data,
834  uint32_t bytes) = 0;
835  // decomposes a message from the context
836  virtual CNetMessage GetMessage(const Config &config,
837  std::chrono::microseconds time) = 0;
839 };
840 
842 private:
843  mutable CHash256 hasher;
845 
846  // Parsing header (false) or data (true)
847  bool in_data;
848  // Partially received header.
850  // Complete header.
852  // Received message data.
854  uint32_t nHdrPos;
855  uint32_t nDataPos;
856 
857  const uint256 &GetMessageHash() const;
858  int readHeader(const Config &config, const char *pch, uint32_t nBytes);
859  int readData(const char *pch, uint32_t nBytes);
860 
861  void Reset() {
862  vRecv.clear();
863  hdrbuf.clear();
864  hdrbuf.resize(24);
865  in_data = false;
866  nHdrPos = 0;
867  nDataPos = 0;
868  data_hash.SetNull();
869  hasher.Reset();
870  }
871 
872 public:
874  const CMessageHeader::MessageMagic &pchMessageStartIn, int nTypeIn,
875  int nVersionIn)
876  : hdrbuf(nTypeIn, nVersionIn), hdr(pchMessageStartIn),
877  vRecv(nTypeIn, nVersionIn) {
878  Reset();
879  }
880 
881  bool Complete() const override {
882  if (!in_data) {
883  return false;
884  }
885 
886  return (hdr.nMessageSize == nDataPos);
887  }
888 
889  void SetVersion(int nVersionIn) override {
890  hdrbuf.SetVersion(nVersionIn);
891  vRecv.SetVersion(nVersionIn);
892  }
893  int Read(const Config &config, const char *pch, uint32_t nBytes) override {
894  int ret =
895  in_data ? readData(pch, nBytes) : readHeader(config, pch, nBytes);
896  if (ret < 0) {
897  Reset();
898  }
899  return ret;
900  }
901 
902  CNetMessage GetMessage(const Config &config,
903  std::chrono::microseconds time) override;
904 };
905 
910 public:
911  // prepare message for transport (header construction, error-correction
912  // computation, payload encryption, etc.)
913  virtual void prepareForTransport(const Config &config,
914  CSerializedNetMsg &msg,
915  std::vector<uint8_t> &header) = 0;
916  virtual ~TransportSerializer() {}
917 };
918 
920 public:
921  void prepareForTransport(const Config &config, CSerializedNetMsg &msg,
922  std::vector<uint8_t> &header) override;
923 };
924 
926 class CNode {
927  friend class CConnman;
928  friend struct ConnmanTestMsg;
929 
930 public:
931  std::unique_ptr<TransportDeserializer> m_deserializer;
932  std::unique_ptr<TransportSerializer> m_serializer;
933 
934  // socket
935  std::atomic<ServiceFlags> nServices{NODE_NONE};
936  SOCKET hSocket GUARDED_BY(cs_hSocket);
937  // Total size of all vSendMsg entries.
938  size_t nSendSize{0};
939  // Offset inside the first vSendMsg already sent.
940  size_t nSendOffset{0};
941  uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
942  std::deque<std::vector<uint8_t>> vSendMsg GUARDED_BY(cs_vSend);
946 
948  std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
949  size_t nProcessQueueSize{0};
950 
952 
953  uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
954 
955  std::atomic<int64_t> nLastSend{0};
956  std::atomic<int64_t> nLastRecv{0};
957  const int64_t nTimeConnected;
958  std::atomic<int64_t> nTimeOffset{0};
959  // Address of this peer
960  const CAddress addr;
961  // Bind address of our side of the connection
963  std::atomic<int> nVersion{0};
964  // The nonce provided by the remote host.
965  uint64_t nRemoteHostNonce{0};
966  // The extra entropy provided by the remote host.
967  uint64_t nRemoteExtraEntropy{0};
973  std::string cleanSubVer GUARDED_BY(cs_SubVer){};
974  // This peer is preferred for eviction.
975  bool m_prefer_evict{false};
976  bool HasPermission(NetPermissionFlags permission) const {
977  return NetPermissions::HasFlag(m_permissionFlags, permission);
978  }
979  // This boolean is unusued in actual processing, only present for backward
980  // compatibility at RPC/QT level
981  bool m_legacyWhitelisted{false};
982  // set by version message
983  bool fClient{false};
984  // after BIP159, set by version message
985  bool m_limited_node{false};
990  std::atomic_bool m_wants_addrv2{false};
991  std::atomic_bool fSuccessfullyConnected{false};
992  // Setting fDisconnect to true will cause the node to be disconnected the
993  // next time DisconnectNodes() runs
994  std::atomic_bool fDisconnect{false};
995  bool fSentAddr{false};
997  std::atomic<int> nRefCount{0};
998 
999  const uint64_t nKeyedNetGroup;
1000  std::atomic_bool fPauseRecv{false};
1001  std::atomic_bool fPauseSend{false};
1002 
1004  switch (m_conn_type) {
1007  return true;
1012  return false;
1013  } // no default case, so the compiler can warn about missing cases
1014 
1015  assert(false);
1016  }
1017 
1018  bool IsFullOutboundConn() const {
1020  }
1021 
1023 
1024  bool IsBlockOnlyConn() const {
1026  }
1027 
1029 
1030  bool IsAddrFetchConn() const {
1032  }
1033 
1034  bool IsInboundConn() const {
1036  }
1037 
1038  /* Whether we send addr messages over this connection */
1039  bool RelayAddrsWithConn() const {
1041  }
1042 
1043  bool ExpectServicesFromConn() const {
1044  switch (m_conn_type) {
1048  return false;
1052  return true;
1053  } // no default case, so the compiler can warn about missing cases
1054 
1055  assert(false);
1056  }
1057 
1070 
1071 protected:
1073  mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
1074 
1075 public:
1077  std::atomic<int> nStartingHeight{-1};
1078 
1079  // flood relay
1080  std::vector<CAddress> vAddrToSend;
1081  std::unique_ptr<CRollingBloomFilter> m_addr_known = nullptr;
1082  bool fGetAddr{false};
1083  std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing){0};
1084  std::chrono::microseconds
1085  m_next_local_addr_send GUARDED_BY(cs_sendProcessing){0};
1086 
1087  // List of block ids we still have to announce.
1088  // There is no final sorting before sending, as they are always sent
1089  // immediately and in the order requested.
1090  std::vector<BlockHash> vInventoryBlockToSend GUARDED_BY(cs_inventory);
1092 
1093  struct TxRelay {
1095  // We use fRelayTxes for two purposes -
1096  // a) it allows us to not relay tx invs before receiving the peer's
1097  // version message.
1098  // b) the peer may tell us in its version message that we should not
1099  // relay tx invs unless it loads a bloom filter.
1100  bool fRelayTxes GUARDED_BY(cs_filter){false};
1101  std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter)
1103 
1106  50000, 0.000001};
1107  // Set of transaction ids we still have to announce.
1108  // They are sorted by the mempool before relay, so the order is not
1109  // important.
1110  std::set<TxId> setInventoryTxToSend GUARDED_BY(cs_tx_inventory);
1111  // Used for BIP35 mempool sending
1112  bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
1113  // Last time a "MEMPOOL" request was serviced.
1114  std::atomic<std::chrono::seconds> m_last_mempool_req{
1115  std::chrono::seconds{0}};
1116  std::chrono::microseconds nNextInvSend{0};
1117 
1119  // Minimum fee rate with which to filter inv's to this node
1123  };
1124 
1125  // m_tx_relay == nullptr if we're not relaying transactions with this peer
1126  std::unique_ptr<TxRelay> m_tx_relay;
1127 
1128  struct ProofRelay {
1130  std::set<avalanche::ProofId>
1131  setInventoryProofToSend GUARDED_BY(cs_proof_inventory);
1132  // Prevent sending proof invs if the peer already knows about them
1134  10000, 0.000001};
1135  std::chrono::microseconds nextInvSend{0};
1136  };
1137 
1138  // m_proof_relay == nullptr if we're not relaying proofs with this peer
1139  std::unique_ptr<ProofRelay> m_proof_relay;
1140 
1147  std::atomic<uint64_t> invCounters;
1148 
1150  std::atomic<double> availabilityScore;
1151 
1157 
1158  public:
1160 
1162 
1164  void invsPolled(uint32_t count);
1165 
1167  void invsVoted(uint32_t count);
1168 
1185  void updateAvailabilityScore();
1186 
1187  double getAvailabilityScore() const;
1188  };
1189 
1190  // m_avalanche_state == nullptr if we're not using avalanche with this peer
1191  std::unique_ptr<AvalancheState> m_avalanche_state;
1192 
1193  // Used for headers announcements - unfiltered blocks to relay
1194  std::vector<BlockHash> vBlockHashesToAnnounce GUARDED_BY(cs_inventory);
1195 
1203  std::atomic<int64_t> nLastBlockTime{0};
1204 
1211  std::atomic<int64_t> nLastTXTime{0};
1212 
1219  std::atomic<int64_t> nLastProofTime{0};
1220 
1221  // Ping time measurement:
1222  // The pong reply we're expecting, or 0 if no pong expected.
1223  std::atomic<uint64_t> nPingNonceSent{0};
1225  std::atomic<std::chrono::microseconds> m_ping_start{
1226  std::chrono::microseconds{0}};
1227  // Last measured round-trip time.
1228  std::atomic<int64_t> nPingUsecTime{0};
1229  // Best measured round-trip time.
1230  std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()};
1231  // Whether a ping is requested.
1232  std::atomic<bool> fPingQueued{false};
1233 
1234  CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn,
1235  SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn,
1236  uint64_t nLocalHostNonceIn, uint64_t nLocalExtraEntropyIn,
1237  const CAddress &addrBindIn, const std::string &addrNameIn,
1238  ConnectionType conn_type_in, bool inbound_onion = false);
1239  ~CNode();
1240  CNode(const CNode &) = delete;
1241  CNode &operator=(const CNode &) = delete;
1242 
1243 private:
1244  const NodeId id;
1245  const uint64_t nLocalHostNonce;
1246  const uint64_t nLocalExtraEntropy;
1249 
1266 
1269  // Used only by SocketHandler thread
1270  std::list<CNetMessage> vRecvMsg;
1271 
1273  std::string addrName GUARDED_BY(cs_addrName);
1274 
1275  // Our address, as reported by the peer
1276  CService addrLocal GUARDED_BY(cs_addrLocal);
1278 
1280  const bool m_inbound_onion{false};
1281 
1282 public:
1283  NodeId GetId() const { return id; }
1284 
1285  uint64_t GetLocalNonce() const { return nLocalHostNonce; }
1286  uint64_t GetLocalExtraEntropy() const { return nLocalExtraEntropy; }
1287 
1288  int GetMyStartingHeight() const { return nMyStartingHeight; }
1289 
1290  int GetRefCount() const {
1291  assert(nRefCount >= 0);
1292  return nRefCount;
1293  }
1294 
1295  bool ReceiveMsgBytes(const Config &config, const char *pch, uint32_t nBytes,
1296  bool &complete);
1297 
1298  void SetCommonVersion(int greatest_common_version) {
1300  m_greatest_common_version = greatest_common_version;
1301  }
1303 
1304  CService GetAddrLocal() const;
1306  void SetAddrLocal(const CService &addrLocalIn);
1307 
1309  nRefCount++;
1310  return this;
1311  }
1312 
1313  void Release() { nRefCount--; }
1314 
1315  void AddAddressKnown(const CAddress &_addr) {
1316  assert(m_addr_known);
1317  m_addr_known->insert(_addr.GetKey());
1318  }
1319 
1320  void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand) {
1321  // Whether the peer supports the address in `_addr`. For example,
1322  // nodes that do not implement BIP155 cannot receive Tor v3 addresses
1323  // because they require ADDRv2 (BIP155) encoding.
1324  const bool addr_format_supported =
1326 
1327  // Known checking here is only to save space from duplicates.
1328  // SendMessages will filter it again for knowns that were added
1329  // after addresses were pushed.
1330  assert(m_addr_known);
1331  if (_addr.IsValid() && !m_addr_known->contains(_addr.GetKey()) &&
1332  addr_format_supported) {
1333  if (vAddrToSend.size() >= MAX_ADDR_TO_SEND) {
1334  vAddrToSend[insecure_rand.randrange(vAddrToSend.size())] =
1335  _addr;
1336  } else {
1337  vAddrToSend.push_back(_addr);
1338  }
1339  }
1340  }
1341 
1342  void AddKnownTx(const TxId &txid) {
1343  if (m_tx_relay != nullptr) {
1344  LOCK(m_tx_relay->cs_tx_inventory);
1345  m_tx_relay->filterInventoryKnown.insert(txid);
1346  }
1347  }
1348 
1349  void PushTxInventory(const TxId &txid) {
1350  if (m_tx_relay == nullptr) {
1351  return;
1352  }
1353  LOCK(m_tx_relay->cs_tx_inventory);
1354  if (!m_tx_relay->filterInventoryKnown.contains(txid)) {
1355  m_tx_relay->setInventoryTxToSend.insert(txid);
1356  }
1357  }
1358 
1359  void AddKnownProof(const avalanche::ProofId &proofid) {
1360  if (m_proof_relay != nullptr) {
1361  LOCK(m_proof_relay->cs_proof_inventory);
1362  m_proof_relay->filterProofKnown.insert(proofid);
1363  }
1364  }
1365 
1367  if (m_proof_relay == nullptr) {
1368  return;
1369  }
1370 
1371  LOCK(m_proof_relay->cs_proof_inventory);
1372  if (!m_proof_relay->filterProofKnown.contains(proofid)) {
1373  m_proof_relay->setInventoryProofToSend.insert(proofid);
1374  }
1375  }
1376 
1377  void CloseSocketDisconnect();
1378 
1379  void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap);
1380 
1382 
1383  std::string GetAddrName() const;
1385  void MaybeSetAddrName(const std::string &addrNameIn);
1386 
1387  std::string ConnectionTypeAsString() const;
1388 };
1389 
1394 int64_t PoissonNextSend(int64_t now, int average_interval_seconds);
1395 
1397 inline std::chrono::microseconds
1398 PoissonNextSend(std::chrono::microseconds now,
1399  std::chrono::seconds average_interval) {
1400  return std::chrono::microseconds{
1401  PoissonNextSend(now.count(), average_interval.count())};
1402 }
1403 
1404 std::string getSubVersionEB(uint64_t MaxBlockSize);
1405 std::string userAgent(const Config &config);
1406 
1413  int64_t nLastTXTime;
1417  uint64_t nKeyedNetGroup;
1421 };
1422 
1423 [[nodiscard]] std::optional<NodeId>
1424 SelectNodeToEvict(std::vector<NodeEvictionCandidate> &&vEvictionCandidates);
1425 
1426 #endif // BITCOIN_NET_H
V1TransportSerializer
Definition: net.h:919
CNode::AvalancheState::invCounters
std::atomic< uint64_t > invCounters
The inventories polled and voted couters since last score computation, stored as a pair of uint32_t w...
Definition: net.h:1147
CNode::mapSendBytesPerMsgCmd
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:1072
CConnman::SetTryNewOutboundPeer
void SetTryNewOutboundPeer(bool flag)
Definition: net.cpp:2039
CConnman::cs_totalBytesRecv
RecursiveMutex cs_totalBytesRecv
Definition: net.h:528
CNode::ConnmanTestMsg
friend struct ConnmanTestMsg
Definition: net.h:928
CConnman::DisconnectNode
bool DisconnectNode(const std::string &node)
Definition: net.cpp:3097
CNode::AvalancheState
Definition: net.h:1141
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:514
threadinterrupt.h
CConnman::SocketSendData
size_t SocketSendData(CNode *pnode) const
Definition: net.cpp:819
CNode::IsOutboundOrBlockRelayConn
bool IsOutboundOrBlockRelayConn() const
Definition: net.h:1003
CConnman::m_max_outbound
int m_max_outbound
Definition: net.h:617
CConnman::m_anchors
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
Definition: net.h:632
CNodeStats::nLastSend
int64_t nLastSend
Definition: net.h:761
CConnman::ConnectNode
CNode * ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type)
Definition: net.cpp:389
userAgent
std::string userAgent(const Config &config)
Definition: net.cpp:3444
CScheduler
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:35
CConnman::Options::vSeedNodes
std::vector< std::string > vSeedNodes
Definition: net.h:246
CConnman::vhListenSocket
std::vector< ListenSocket > vhListenSocket
Definition: net.h:549
V1TransportDeserializer::Complete
bool Complete() const override
Definition: net.h:881
CNode::ProofRelay
Definition: net.h:1128
LOCAL_UPNP
@ LOCAL_UPNP
Definition: net.h:706
CConnman::ThreadMessageHandler
void ThreadMessageHandler()
Definition: net.cpp:2444
delegation.h
count
static int count
Definition: tests.c:41
CNode::IsFeelerConn
bool IsFeelerConn() const
Definition: net.h:1028
CNode::GetRefCount
int GetRefCount() const
Definition: net.h:1290
TransportDeserializer
The TransportDeserializer takes care of holding and deserializing the network receive buffer.
Definition: net.h:826
NetEventsInterface
Interface for message handling.
Definition: net.h:679
CConnman::GUARDED_BY
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv)
Definition: net.h:530
CNode::nSendOffset
size_t nSendOffset
Definition: net.h:940
CConnman::Options::nMaxAddnode
int nMaxAddnode
Definition: net.h:235
check.h
CConnman::nSendBufferMaxSize
unsigned int nSendBufferMaxSize
Definition: net.h:546
CConnman::GetOutboundTargetBytesLeft
uint64_t GetOutboundTargetBytesLeft()
response the bytes left in the current max outbound cycle in case of no limit, it will always respons...
Definition: net.cpp:3213
CConnman::m_next_send_inv_to_incoming
std::atomic< int64_t > m_next_send_inv_to_incoming
Definition: net.h:658
CConnman::AttemptToEvictConnection
bool AttemptToEvictConnection()
Try to find a connection to evict when the node is full.
Definition: net.cpp:1119
CNode::fSentAddr
bool fSentAddr
Definition: net.h:995
CNode::nLastSend
std::atomic< int64_t > nLastSend
Definition: net.h:955
CNode::cs_vSend
Mutex cs_vSend
Definition: net.h:943
CConnman::CConnman
CConnman(const Config &configIn, uint64_t seed0, uint64_t seed1, bool network_active=true)
Definition: net.cpp:2641
CONNECTION_TYPE_DOC
const std::vector< std::string > CONNECTION_TYPE_DOC
Definition: net.h:141
CConnman::Interrupt
void Interrupt()
Definition: net.cpp:2863
CClientUIInterface
Signals for UI communication.
Definition: ui_interface.h:24
CConnman::GetMaxOutboundTimeframe
uint64_t GetMaxOutboundTimeframe()
Definition: net.cpp:3163
CNode::GetId
NodeId GetId() const
Definition: net.h:1283
CNodeStats::nTimeOffset
int64_t nTimeOffset
Definition: net.h:767
CConnman::condMsgProc
std::condition_variable condMsgProc
Definition: net.h:640
CConnman::nReceiveFloodSize
unsigned int nReceiveFloodSize
Definition: net.h:547
NodeEvictionCandidate::fBloomFilter
bool fBloomFilter
Definition: net.h:1416
CNode::ReceiveMsgBytes
bool ReceiveMsgBytes(const Config &config, const char *pch, uint32_t nBytes, bool &complete)
Definition: net.cpp:657
CNode::nMinPingUsecTime
std::atomic< int64_t > nMinPingUsecTime
Definition: net.h:1230
CMessageHeader::nMessageSize
uint32_t nMessageSize
Definition: protocol.h:74
flags
int flags
Definition: bitcoin-tx.cpp:532
CConnman::ThreadDNSAddressSeed
void ThreadDNSAddressSeed()
Definition: net.cpp:1871
streams.h
InterruptMapPort
void InterruptMapPort()
Definition: net.cpp:1863
CHash256::Reset
CHash256 & Reset()
Definition: hash.h:41
CConnman::Options::vBinds
std::vector< CService > vBinds
Definition: net.h:249
CNode::copyStats
void copyStats(CNodeStats &stats, const std::vector< bool > &m_asmap)
Definition: net.cpp:583
CNode::nRefCount
std::atomic< int > nRefCount
Definition: net.h:997
PF_NONE
@ PF_NONE
Definition: net_permissions.h:18
CNode::m_wants_addrv2
std::atomic_bool m_wants_addrv2
Whether the peer has signaled support for receiving ADDRv2 (BIP155) messages, implying a preference t...
Definition: net.h:990
CConnman::RecordBytesRecv
void RecordBytesRecv(uint64_t bytes)
Definition: net.cpp:3133
CNode::Release
void Release()
Definition: net.h:1313
CNodeStats::m_legacyWhitelisted
bool m_legacyWhitelisted
Definition: net.h:779
CConnman::WakeMessageHandler
void WakeMessageHandler()
Definition: net.cpp:1755
CNodeStats::nLastBlockTime
int64_t nLastBlockTime
Definition: net.h:765
CConnman::Bind
bool Bind(const CService &addr, unsigned int flags, NetPermissionFlags permissions)
Definition: net.cpp:2655
CNode::PushTxInventory
void PushTxInventory(const TxId &txid)
Definition: net.h:1349
CNode::nProcessQueueSize
size_t nProcessQueueSize
Definition: net.h:949
sync.h
CConnman::SocketEvents
void SocketEvents(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1534
CConnman::PoissonNextSendInbound
int64_t PoissonNextSendInbound(int64_t now, int average_interval_seconds)
Attempts to obfuscate tx time through exponentially distributed emitting.
Definition: net.cpp:3384
CConnman::m_max_outbound_full_relay
int m_max_outbound_full_relay
Definition: net.h:609
CNode::TxRelay::GUARDED_BY
CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_tx_inventory)
Definition: net.h:1105
CNodeStats::m_min_ping_usec
int64_t m_min_ping_usec
Definition: net.h:782
Discover
void Discover()
Definition: net.cpp:2577
CConnman::Options::nMaxOutboundLimit
uint64_t nMaxOutboundLimit
Definition: net.h:244
CNode::nLocalServices
const ServiceFlags nLocalServices
Services offered to this peer.
Definition: net.h:1265
CNode::nLastRecv
std::atomic< int64_t > nLastRecv
Definition: net.h:956
CConnman::OutboundTargetReached
bool OutboundTargetReached(bool historicalBlockServingLimit)
check if the outbound target is reached.
Definition: net.cpp:3192
NetEventsInterface::SendMessages
virtual bool SendMessages(const Config &config, CNode *pnode, std::atomic< bool > &interrupt)=0
CConnman::m_onion_binds
std::vector< CService > m_onion_binds
A vector of -bind=<address>:<port>=onion arguments each of which is an address and port that are desi...
Definition: net.h:664
CNode::m_limited_node
bool m_limited_node
Definition: net.h:985
CNodeStats::nodeid
NodeId nodeid
Definition: net.h:758
bilingual_str
Bilingual messages:
Definition: translation.h:17
CNetAddr
Network address.
Definition: netaddress.h:117
CConnman::GetAddresses
std::vector< CAddress > GetAddresses(size_t max_addresses, size_t max_pct)
Definition: net.cpp:2978
LocalServiceInfo::nPort
int nPort
Definition: net.h:741
CConnman::ProcessAddrFetch
void ProcessAddrFetch()
Definition: net.cpp:2017
uint256.h
NodeEvictionCandidate::fRelayTxes
bool fRelayTxes
Definition: net.h:1415
DEFAULT_MAX_PEER_CONNECTIONS
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:93
AddLocal
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:251
ConnectionType::OUTBOUND_FULL_RELAY
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
CNode
Information about a peer.
Definition: net.h:926
CNode::GUARDED_BY
SOCKET hSocket GUARDED_BY(cs_hSocket)
CConnman::GetMaxOutboundTarget
uint64_t GetMaxOutboundTarget()
Definition: net.cpp:3158
CNode::fPingQueued
std::atomic< bool > fPingQueued
Definition: net.h:1232
CConnman::GetTotalBytesRecv
uint64_t GetTotalBytesRecv()
Definition: net.cpp:3224
V1TransportDeserializer::nDataPos
uint32_t nDataPos
Definition: net.h:855
NodeEvictionCandidate::availabilityScore
double availabilityScore
Definition: net.h:1420
DEFAULT_MAXRECEIVEBUFFER
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:104
CConnman::Options::nLocalServices
ServiceFlags nLocalServices
Definition: net.h:231
CConnman::cs_vAddedNodes
RecursiveMutex cs_vAddedNodes
Definition: net.h:556
base_blob::SetNull
void SetNull()
Definition: uint256.h:39
CNode::m_serializer
std::unique_ptr< TransportSerializer > m_serializer
Definition: net.h:932
CNetMessage::m_command
std::string m_command
Definition: net.h:814
CConnman::AcceptConnection
void AcceptConnection(const ListenSocket &hListenSocket)
Definition: net.cpp:1175
CConnman::GetAddedNodeInfo
std::vector< AddedNodeInfo > GetAddedNodeInfo()
Definition: net.cpp:2311
CNode::TxRelay::nextSendTimeFeeFilter
int64_t nextSendTimeFeeFilter
Definition: net.h:1122
CNode::GetAddrName
std::string GetAddrName() const
Definition: net.cpp:551
avalanche::ProofId
Definition: proofid.h:17
CConnman::Options::m_added_nodes
std::vector< std::string > m_added_nodes
Definition: net.h:253
CConnman::GetLocalServices
ServiceFlags GetLocalServices() const
Used to convey which local services we are offering peers during node connection.
Definition: net.cpp:3234
CConnman::nBestHeight
std::atomic< int > nBestHeight
Definition: net.h:619
CConnman::m_addr_fetches_mutex
RecursiveMutex m_addr_fetches_mutex
Definition: net.h:554
AnnotatedMixin< std::recursive_mutex >
CConnman::cs_totalBytesSent
RecursiveMutex cs_totalBytesSent
Definition: net.h:529
CSerializedNetMsg::m_type
std::string m_type
Definition: net.h:138
CNetMessage::m_valid_header
bool m_valid_header
Definition: net.h:808
CConnman::Options::nMaxOutboundTimeframe
uint64_t nMaxOutboundTimeframe
Definition: net.h:243
PoissonNextSend
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:3397
ServiceFlags
ServiceFlags
nServices flags.
Definition: protocol.h:314
CConnman::CachedAddrResponse::m_addrs_response_cache
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:570
g_relay_txes
bool g_relay_txes
Definition: net.cpp:133
CNode::ExpectServicesFromConn
bool ExpectServicesFromConn() const
Definition: net.h:1043
MAX_ADDR_TO_SEND
static constexpr size_t MAX_ADDR_TO_SEND
The maximum number of addresses from our addrman to return in response to a getaddr message.
Definition: net.h:66
V1TransportDeserializer::vRecv
CDataStream vRecv
Definition: net.h:853
CNode::m_permissionFlags
NetPermissionFlags m_permissionFlags
Definition: net.h:1268
CConnman::ListenSocket::socket
SOCKET socket
Definition: net.h:456
CNode::nTimeOffset
std::atomic< int64_t > nTimeOffset
Definition: net.h:958
CNodeStats::m_mapped_as
uint32_t m_mapped_as
Definition: net.h:792
CNode::nServices
std::atomic< ServiceFlags > nServices
Definition: net.h:935
chainparams.h
CNetMessage::m_valid_netmagic
bool m_valid_netmagic
Definition: net.h:807
CNode::TxRelay::cs_filter
RecursiveMutex cs_filter
Definition: net.h:1094
CConnman::Start
bool Start(CScheduler &scheduler, const Options &options)
Definition: net.cpp:2708
CNode::GetMyStartingHeight
int GetMyStartingHeight() const
Definition: net.h:1288
CConnman::CalculateKeyedNetGroup
uint64_t CalculateKeyedNetGroup(const CAddress &ad) const
Definition: net.cpp:3408
V1TransportDeserializer::readData
int readData(const char *pch, uint32_t nBytes)
Definition: net.cpp:733
Network
Network
A network type.
Definition: netaddress.h:43
TransportSerializer::prepareForTransport
virtual void prepareForTransport(const Config &config, CSerializedNetMsg &msg, std::vector< uint8_t > &header)=0
CNode::nMyStartingHeight
const int nMyStartingHeight
Definition: net.h:1267
CConnman::StopThreads
void StopThreads()
Definition: net.cpp:2886
CNode::AvalancheState::invsPolled
void invsPolled(uint32_t count)
The node was polled for count invs.
Definition: net.cpp:3250
CConnman::NotifyNumConnectionsChanged
void NotifyNumConnectionsChanged()
Definition: net.cpp:1378
LOCAL_MAX
@ LOCAL_MAX
Definition: net.h:710
CNode::fDisconnect
std::atomic_bool fDisconnect
Definition: net.h:994
V1TransportDeserializer::data_hash
uint256 data_hash
Definition: net.h:844
MAX_UPLOAD_TIMEFRAME
static const uint64_t MAX_UPLOAD_TIMEFRAME
The default timeframe for -maxuploadtarget.
Definition: net.h:97
CNode::TxRelay::lastSentFeeFilter
Amount lastSentFeeFilter
Definition: net.h:1121
CSipHasher
SipHash-2-4.
Definition: siphash.h:13
CNode::AvalancheState::invsVoted
void invsVoted(uint32_t count)
The node voted for count invs.
Definition: net.cpp:3254
validation.h
CNode::hashContinue
BlockHash hashContinue
Definition: net.h:1076
CConnman::nPrevNodeCount
unsigned int nPrevNodeCount
Definition: net.h:561
AddedNodeInfo::fConnected
bool fConnected
Definition: net.h:122
ConnectionType::MANUAL
@ MANUAL
We open manual connections to addresses that users explicitly inputted via the addnode RPC,...
CConnman::AddAddrFetch
void AddAddrFetch(const std::string &strDest)
Definition: net.cpp:138
CNode::ProofRelay::cs_proof_inventory
RecursiveMutex cs_proof_inventory
Definition: net.h:1129
CNode::AvalancheState::updateAvailabilityScore
void updateAvailabilityScore()
The availability score is calculated using an exponentially weighted average.
Definition: net.cpp:3258
CNode::TxRelay::cs_tx_inventory
RecursiveMutex cs_tx_inventory
Definition: net.h:1102
CNodeStats::mapSendBytesPerMsgCmd
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:775
CNode::nLastProofTime
std::atomic< int64_t > nLastProofTime
UNIX epoch time of the last proof received from this peer that we had not yet seen (e....
Definition: net.h:1219
Amount::zero
static constexpr Amount zero()
Definition: amount.h:42
CNode::addr
const CAddress addr
Definition: net.h:960
CNodeStats::nTimeConnected
int64_t nTimeConnected
Definition: net.h:766
CNode::nPingUsecTime
std::atomic< int64_t > nPingUsecTime
Definition: net.h:1228
CConnman::OpenNetworkConnection
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
Definition: net.cpp:2399
CNode::TxRelay::cs_feeFilter
RecursiveMutex cs_feeFilter
Definition: net.h:1118
NodeEvictionCandidate::nKeyedNetGroup
uint64_t nKeyedNetGroup
Definition: net.h:1417
NetPermissions::HasFlag
static bool HasFlag(const NetPermissionFlags &flags, NetPermissionFlags f)
Definition: net_permissions.h:51
CNode::SetCommonVersion
void SetCommonVersion(int greatest_common_version)
Definition: net.h:1298
CNode::GetLocalServices
ServiceFlags GetLocalServices() const
Definition: net.h:1381
bloom.h
CNode::AvalancheState::pubkey
CPubKey pubkey
Definition: net.h:1159
CConnman::SetMaxOutboundTarget
void SetMaxOutboundTarget(uint64_t limit)
set the max outbound target in bytes.
Definition: net.cpp:3153
CNode::nTimeConnected
const int64_t nTimeConnected
Definition: net.h:957
Assume
#define Assume(val)
Assume is the identity function.
Definition: check.h:76
CConnman::FindNode
CNode * FindNode(const CNetAddr &ip)
Definition: net.cpp:322
ConnectionType::INBOUND
@ INBOUND
Inbound connections are those initiated by a peer.
addrdb.h
V1TransportDeserializer::hdr
CMessageHeader hdr
Definition: net.h:851
Config
Definition: config.h:17
CConnman::m_addr_response_caches
std::map< uint64_t, CachedAddrResponse > m_addr_response_caches
Addr responses stored in different caches per (network, local socket) prevent cross-network node iden...
Definition: net.h:588
siphash.h
CSemaphoreGrant
RAII-style semaphore lock.
Definition: sync.h:312
CNode::GetLocalExtraEntropy
uint64_t GetLocalExtraEntropy() const
Definition: net.h:1286
protocol.h
CNodeStats::addr
CAddress addr
Definition: net.h:787
MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition: net.h:73
random.h
CConnman::nMaxFeeler
int nMaxFeeler
Definition: net.h:616
CNode::m_deserializer
std::unique_ptr< TransportDeserializer > m_deserializer
Definition: net.h:931
CConnman::mutexMsgProc
Mutex mutexMsgProc
Definition: net.h:641
CConnman::ForEachNodeThen
void ForEachNodeThen(Callable &&pre, CallableAfter &&post)
Definition: net.h:340
SeenLocal
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:307
TransportSerializer::~TransportSerializer
virtual ~TransportSerializer()
Definition: net.h:916
CConnman::nLocalServices
ServiceFlags nLocalServices
Services this instance offers.
Definition: net.h:602
CConnman::ThreadSocketHandler
void ThreadSocketHandler()
Definition: net.cpp:1747
CConnman::ThreadOpenAddedConnections
void ThreadOpenAddedConnections()
Definition: net.cpp:2367
V1TransportDeserializer::in_data
bool in_data
Definition: net.h:847
getSubVersionEB
std::string getSubVersionEB(uint64_t MaxBlockSize)
This function convert MaxBlockSize from byte to MB with a decimal precision one digit rounded down E....
Definition: net.cpp:3430
CNodeStats::nSendBytes
uint64_t nSendBytes
Definition: net.h:774
DEFAULT_MAX_UPLOAD_TARGET
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:95
TransportDeserializer::GetMessage
virtual CNetMessage GetMessage(const Config &config, std::chrono::microseconds time)=0
CNodeStats::nLastRecv
int64_t nLastRecv
Definition: net.h:762
DEFAULT_MAXSENDBUFFER
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:105
NodeEvictionCandidate
Definition: net.h:1407
CNode::CNode
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, uint64_t nLocalExtraEntropyIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in, bool inbound_onion=false)
Definition: net.cpp:3278
LOCAL_MANUAL
@ LOCAL_MANUAL
Definition: net.h:708
CNodeStats::fRelayTxes
bool fRelayTxes
Definition: net.h:760
CNode::ConnectedThroughNetwork
Network ConnectedThroughNetwork() const
Get network the peer connected through.
Definition: net.cpp:579
CNode::TxRelay::m_last_mempool_req
std::atomic< std::chrono::seconds > m_last_mempool_req
Definition: net.h:1114
V1TransportDeserializer::GetMessage
CNetMessage GetMessage(const Config &config, std::chrono::microseconds time) override
Definition: net.cpp:759
CNode::cs_vRecv
Mutex cs_vRecv
Definition: net.h:945
CNode::AddKnownProof
void AddKnownProof(const avalanche::ProofId &proofid)
Definition: net.h:1359
CConnman::DumpAddresses
void DumpAddresses()
Definition: net.cpp:2007
CNode::TxRelay
Definition: net.h:1093
cs_main
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:103
CNode::AddAddressKnown
void AddAddressKnown(const CAddress &_addr)
Definition: net.h:1315
CConnman::vWhitelistedRange
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:544
CConnman::Options::vWhitelistedRange
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:247
AddedNodeInfo::strAddedNode
std::string strAddedNode
Definition: net.h:120
CNode::GetCommonVersion
int GetCommonVersion() const
Definition: net.h:1302
CNode::ProofRelay::GUARDED_BY
CRollingBloomFilter filterProofKnown GUARDED_BY(cs_proof_inventory)
Definition: net.h:1133
NodeEvictionCandidate::id
NodeId id
Definition: net.h:1408
CNode::AddRef
CNode * AddRef()
Definition: net.h:1308
CConnman::InactivityCheck
void InactivityCheck(CNode *pnode)
Definition: net.cpp:1392
CConnman::ForEachNodeThen
void ForEachNodeThen(Callable &&pre, CallableAfter &&post) const
Definition: net.h:351
CConnman::NumConnections
NumConnections
Definition: net.h:223
CConnman::SetAsmap
void SetAsmap(std::vector< bool > asmap)
Definition: net.h:449
CService::GetKey
std::vector< uint8_t > GetKey() const
Definition: netaddress.cpp:999
CConnman::NodeFn
std::function< void(CNode *)> NodeFn
Definition: net.h:320
CConnman::CONNECTIONS_ALL
@ CONNECTIONS_ALL
Definition: net.h:227
CConnman::m_banman
BanMan * m_banman
Pointer to this node's banman.
Definition: net.h:626
CNode::m_ping_start
std::atomic< std::chrono::microseconds > m_ping_start
When the last ping was sent, or 0 if no ping was ever sent.
Definition: net.h:1225
NetEventsInterface::FinalizeNode
virtual void FinalizeNode(const Config &config, NodeId id, bool &update_connection_time)=0
compat.h
NetEventsInterface::InitializeNode
virtual void InitializeNode(const Config &config, CNode *pnode)=0
CNode::fGetAddr
bool fGetAddr
Definition: net.h:1082
CNodeStats::addrName
std::string addrName
Definition: net.h:768
CConnman::threadOpenConnections
std::thread threadOpenConnections
Definition: net.h:649
CNode::m_tx_relay
std::unique_ptr< TxRelay > m_tx_relay
Definition: net.h:1126
CNode::m_avalanche_state
std::unique_ptr< AvalancheState > m_avalanche_state
Definition: net.h:1191
netaddress.h
CNode::m_conn_type
const ConnectionType m_conn_type
Definition: net.h:1247
CNode::GUARDED_BY
std::chrono::microseconds m_next_local_addr_send GUARDED_BY(cs_sendProcessing)
Definition: net.h:1085
SelectNodeToEvict
std::optional< NodeId > SelectNodeToEvict(std::vector< NodeEvictionCandidate > &&vEvictionCandidates)
Definition: net.cpp:1008
CConnman::ForNode
bool ForNode(NodeId id, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:3372
SetReachable
void SetReachable(enum Network net, bool reachable)
Mark a network as reachable or unreachable (no automatic connects to it)
Definition: net.cpp:289
CNetMessage::m_time
std::chrono::microseconds m_time
time of message receipt
Definition: net.h:806
AddedNodeInfo::fInbound
bool fInbound
Definition: net.h:123
CSerializedNetMsg
Definition: net.h:129
CNode::GUARDED_BY
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:953
StartMapPort
void StartMapPort()
Definition: net.cpp:1860
CNode::fSuccessfullyConnected
std::atomic_bool fSuccessfullyConnected
Definition: net.h:991
NetPermissionFlags
NetPermissionFlags
Definition: net_permissions.h:17
CConnman::Options::onion_binds
std::vector< CService > onion_binds
Definition: net.h:250
CConnman::CachedAddrResponse
Cache responses to addr requests to minimize privacy leak.
Definition: net.h:569
CNodeStats::m_permissionFlags
NetPermissionFlags m_permissionFlags
Definition: net.h:778
CNode::TxRelay::GUARDED_BY
Amount minFeeFilter GUARDED_BY(cs_feeFilter)
Definition: net.h:1120
CConnman::GetNewNodeId
NodeId GetNewNodeId()
Definition: net.cpp:2651
GetListenPort
uint16_t GetListenPort()
Definition: net.cpp:143
CConnman::fAddressesInitialized
bool fAddressesInitialized
Definition: net.h:551
CConnman::ListenSocket
Definition: net.h:454
AddedNodeInfo
Definition: net.h:119
CConnman::Options::m_peer_connect_timeout
int64_t m_peer_connect_timeout
Definition: net.h:245
TransportDeserializer::~TransportDeserializer
virtual ~TransportDeserializer()
Definition: net.h:838
CConnman::SetBestHeight
void SetBestHeight(int height)
Definition: net.cpp:3238
CConnman::Options::m_use_addrman_outgoing
bool m_use_addrman_outgoing
Definition: net.h:251
CNodeStats::m_ping_usec
int64_t m_ping_usec
Definition: net.h:780
CNetAddr::IsValid
bool IsValid() const
Definition: netaddress.cpp:438
CNetMessage::m_valid_checksum
bool m_valid_checksum
Definition: net.h:809
CConnman::Options::m_max_outbound_block_relay
int m_max_outbound_block_relay
Definition: net.h:234
AVALANCHE_STATISTICS_DECAY_FACTOR
static const double AVALANCHE_STATISTICS_DECAY_FACTOR
Pre-computed decay factor for the avalanche statistics computation.
Definition: net.h:115
CNodeStats::m_network
std::string m_network
Definition: net.h:791
CNodeStats::nStartingHeight
int nStartingHeight
Definition: net.h:773
CSubNet
Definition: netaddress.h:465
CConnman::ListenSocket::AddSocketPermissionFlags
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:457
V1TransportDeserializer::hasher
CHash256 hasher
Definition: net.h:843
CNode::IsAddrFetchConn
bool IsAddrFetchConn() const
Definition: net.h:1030
AVALANCHE_STATISTICS_REFRESH_PERIOD
static constexpr std::chrono::minutes AVALANCHE_STATISTICS_REFRESH_PERIOD
Refresh period for the avalanche statistics computation.
Definition: net.h:108
CConnman::m_peer_connect_timeout
int64_t m_peer_connect_timeout
Definition: net.h:540
CNode::cs_vProcessMsg
RecursiveMutex cs_vProcessMsg
Definition: net.h:947
CConnman::CONNECTIONS_IN
@ CONNECTIONS_IN
Definition: net.h:225
CNode::nRemoteHostNonce
uint64_t nRemoteHostNonce
Definition: net.h:965
CNode::cs_hSocket
Mutex cs_hSocket
Definition: net.h:944
CNode::AddKnownTx
void AddKnownTx(const TxId &txid)
Definition: net.h:1342
CConnman::threadMessageHandler
std::thread threadMessageHandler
Definition: net.h:650
CConnman::ConnmanTestMsg
friend struct ConnmanTestMsg
Definition: net.h:667
uint256
256-bit opaque blob.
Definition: uint256.h:127
CNodeStats::m_conn_type_string
std::string m_conn_type_string
Definition: net.h:793
TxId
A TxId is the identifier of a transaction.
Definition: txid.h:14
CNode::cs_SubVer
RecursiveMutex cs_SubVer
cleanSubVer is a sanitized string of the user agent byte array we read from the wire.
Definition: net.h:972
MAX_FEELER_CONNECTIONS
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:79
CNode::m_addr_known
std::unique_ptr< CRollingBloomFilter > m_addr_known
Definition: net.h:1081
Amount
Definition: amount.h:19
CConnman::config
const Config * config
Definition: net.h:525
CNetMessage::m_recv
CDataStream m_recv
received message data
Definition: net.h:804
CConnman::GetMaxOutboundTimeLeftInCycle
uint64_t GetMaxOutboundTimeLeftInCycle()
response the time in second left in the current max outbound cycle in case of no limit,...
Definition: net.cpp:3168
cs_mapLocalHost
RecursiveMutex cs_mapLocalHost
Definition: net.cpp:134
CConnman::Options::nReceiveFloodSize
unsigned int nReceiveFloodSize
Definition: net.h:242
CNode::IsBlockOnlyConn
bool IsBlockOnlyConn() const
Definition: net.h:1024
CConnman::SetMaxOutboundTimeframe
void SetMaxOutboundTimeframe(uint64_t timeframe)
set the timeframe for the max outbound target.
Definition: net.cpp:3183
CConnman::nSeed0
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:635
CNode::AvalancheState::getAvailabilityScore
double getAvailabilityScore() const
Definition: net.cpp:3272
NodeEvictionCandidate::nLastProofTime
int64_t nLastProofTime
Definition: net.h:1412
ConnectionType::FEELER
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
CNodeStats::addrBind
CAddress addrBind
Definition: net.h:789
CConnman::~CConnman
~CConnman()
Definition: net.cpp:2960
CConnman::Options
Definition: net.h:230
CNode::GUARDED_BY
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Definition: net.h:941
CConnman::GetReceiveFloodSize
unsigned int GetReceiveFloodSize() const
Definition: net.cpp:3246
CNode::PushAddress
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
Definition: net.h:1320
CNode::grantOutbound
CSemaphoreGrant grantOutbound
Definition: net.h:996
CNode::GUARDED_BY
std::string cleanSubVer GUARDED_BY(cs_SubVer)
Definition: net.h:973
IsReachable
bool IsReachable(enum Network net)
Definition: net.cpp:297
CNode::nStartingHeight
std::atomic< int > nStartingHeight
Definition: net.h:1077
NodeEvictionCandidate::m_is_local
bool m_is_local
Definition: net.h:1419
TransportDeserializer::Read
virtual int Read(const Config &config, const char *data, uint32_t bytes)=0
CConnman::Options::nMaxConnections
int nMaxConnections
Definition: net.h:232
BlockHash
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
CNodeStats::addrLocal
std::string addrLocal
Definition: net.h:785
CDataStream::SetVersion
void SetVersion(int n)
Definition: streams.h:386
NODE_NONE
@ NODE_NONE
Definition: protocol.h:317
CSerializedNetMsg::CSerializedNetMsg
CSerializedNetMsg()=default
BanMan
Definition: banman.h:58
CConnman::Options::nSendBufferMaxSize
unsigned int nSendBufferMaxSize
Definition: net.h:241
CConnman::ListenSocket::m_permissions
NetPermissionFlags m_permissions
Definition: net.h:464
NodeEvictionCandidate::nTimeConnected
int64_t nTimeConnected
Definition: net.h:1409
CNode::nKeyedNetGroup
const uint64_t nKeyedNetGroup
Definition: net.h:999
CConnman::nLastNodeId
std::atomic< NodeId > nLastNodeId
Definition: net.h:560
CConnman::Options::nBestHeight
int nBestHeight
Definition: net.h:237
CNode::nLastTXTime
std::atomic< int64_t > nLastTXTime
UNIX epoch time of the last transaction received from this peer that we had not yet seen (e....
Definition: net.h:1211
CConnman::RemoveAddedNode
bool RemoveAddedNode(const std::string &node)
Definition: net.cpp:3057
CConnman::GetNodeCount
size_t GetNodeCount(NumConnections num)
Definition: net.cpp:3069
fListen
bool fListen
Definition: net.cpp:132
V1TransportDeserializer::hdrbuf
CDataStream hdrbuf
Definition: net.h:849
CNode::IsManualConn
bool IsManualConn() const
Definition: net.h:1022
CConnman::Options::uiInterface
CClientUIInterface * uiInterface
Definition: net.h:238
AddedNodeInfo::resolvedAddress
CService resolvedAddress
Definition: net.h:121
fDiscover
bool fDiscover
Definition: net.cpp:131
CConnman::GUARDED_BY
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent)
Definition: net.h:531
CConnman::GetCurrentBlockRelayOnlyConns
std::vector< CAddress > GetCurrentBlockRelayOnlyConns() const
Return vector of current BLOCK_RELAY peers.
Definition: net.cpp:2299
V1TransportDeserializer::readHeader
int readHeader(const Config &config, const char *pch, uint32_t nBytes)
Definition: net.cpp:700
CConnman::nSeed1
const uint64_t nSeed1
Definition: net.h:635
CConnman
Definition: net.h:221
CAddrMan
Stochastical (IP) address manager.
Definition: addrman.h:190
CAddrMan::m_asmap
std::vector< bool > m_asmap
Definition: addrman.h:341
V1TransportDeserializer::Reset
void Reset()
Definition: net.h:861
CNode::ProofRelay::GUARDED_BY
std::set< avalanche::ProofId > setInventoryProofToSend GUARDED_BY(cs_proof_inventory)
CNode::id
const NodeId id
Definition: net.h:1244
nodeid.h
CPubKey
An encapsulated public key.
Definition: pubkey.h:31
CConnman::Options::nMaxFeeler
int nMaxFeeler
Definition: net.h:236
CConnman::StopNodes
void StopNodes()
Definition: net.cpp:2904
CConnman::CONNECTIONS_OUT
@ CONNECTIONS_OUT
Definition: net.h:226
CConnman::m_try_another_outbound_peer
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.
Definition: net.h:656
CNode::cs_sendProcessing
RecursiveMutex cs_sendProcessing
Definition: net.h:951
CConnman::addrman
CAddrMan addrman
Definition: net.h:552
NetEventsInterface::~NetEventsInterface
~NetEventsInterface()=default
Protected destructor so that instances can only be deleted by derived classes.
V1TransportDeserializer::GetMessageHash
const uint256 & GetMessageHash() const
Definition: net.cpp:750
LocalServiceInfo::nScore
int nScore
Definition: net.h:740
GetLocal
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:148
CAddress
A CService with information about it as peer.
Definition: protocol.h:421
MAX_BLOCK_RELAY_ONLY_CONNECTIONS
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:77
CMessageHeader
Message header.
Definition: protocol.h:37
CConnman::SetNetworkActive
void SetNetworkActive(bool active)
Definition: net.cpp:2630
CNode::nLocalHostNonce
const uint64_t nLocalHostNonce
Definition: net.h:1245
CConnman::NodeFullyConnected
static bool NodeFullyConnected(const CNode *pnode)
Definition: net.cpp:3331
CNode::nRemoteExtraEntropy
uint64_t nRemoteExtraEntropy
Definition: net.h:967
DEFAULT_WHITELISTRELAY
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: net.h:51
AVALANCHE_STATISTICS_TIME_CONSTANT
static constexpr std::chrono::minutes AVALANCHE_STATISTICS_TIME_CONSTANT
Time constant for the avalanche statistics computation.
Definition: net.h:110
LocalServiceInfo
Definition: net.h:739
CNode::cs_addrName
RecursiveMutex cs_addrName
Definition: net.h:1272
V1TransportDeserializer::Read
int Read(const Config &config, const char *pch, uint32_t nBytes) override
Definition: net.h:893
NetPermissions::AddFlag
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
Definition: net_permissions.h:55
CConnman::GetNodeStats
void GetNodeStats(std::vector< CNodeStats > &vstats)
Definition: net.cpp:3087
CNetMessage::m_message_size
uint32_t m_message_size
size of the payload
Definition: net.h:811
CConnman::Options::m_msgproc
NetEventsInterface * m_msgproc
Definition: net.h:239
CNode::m_inbound_onion
const bool m_inbound_onion
Whether this peer connected via our Tor onion service.
Definition: net.h:1280
CNetMessage::CNetMessage
CNetMessage(CDataStream &&recv_in)
Definition: net.h:816
MAX_ADDNODE_CONNECTIONS
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:75
CDataStream::clear
void clear()
Definition: streams.h:288
CConnman::cs_vNodes
RecursiveMutex cs_vNodes
Definition: net.h:559
LOCK
#define LOCK(cs)
Definition: sync.h:241
V1TransportDeserializer::SetVersion
void SetVersion(int nVersionIn) override
Definition: net.h:889
CNode::m_prefer_evict
bool m_prefer_evict
Definition: net.h:975
CNodeStats::nServices
ServiceFlags nServices
Definition: net.h:759
ConnectionType::ADDR_FETCH
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
CNetMessage::SetVersion
void SetVersion(int nVersionIn)
Definition: net.h:818
CConnman::ForEachNode
void ForEachNode(const NodeFn &func)
Definition: net.h:321
CNode::CloseSocketDisconnect
void CloseSocketDisconnect()
Definition: net.cpp:514
CNodeStats::nVersion
int nVersion
Definition: net.h:769
CNode::ConnectionTypeAsString
std::string ConnectionTypeAsString() const
Definition: net.cpp:532
AdvertiseLocal
void AdvertiseLocal(CNode *pnode)
Definition: net.cpp:222
V1TransportDeserializer
Definition: net.h:841
TransportSerializer
The TransportSerializer prepares messages for the network transport.
Definition: net.h:909
CConnman::SetServices
void SetServices(const CService &addr, ServiceFlags nServices)
Definition: net.cpp:2965
CNode::TxRelay::PT_GUARDED_BY
std::unique_ptr< CBloomFilter > pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter)
Definition: net.h:1101
CNetMessage
Transport protocol agnostic message container.
Definition: net.h:801
LOCAL_IF
@ LOCAL_IF
Definition: net.h:702
NodeEvictionCandidate::prefer_evict
bool prefer_evict
Definition: net.h:1418
CNode::AvalancheState::cs_statistics
Mutex cs_statistics
Protect the sequence of operations required for updating the statistics.
Definition: net.h:1156
CNode::cs_addrLocal
RecursiveMutex cs_addrLocal
Definition: net.h:1277
CConnman::SocketHandler
void SocketHandler()
Definition: net.cpp:1617
CNode::GetAddrLocal
CService GetAddrLocal() const
Definition: net.cpp:563
V1TransportSerializer::prepareForTransport
void prepareForTransport(const Config &config, CSerializedNetMsg &msg, std::vector< uint8_t > &header) override
Definition: net.cpp:803
CConnman::DisconnectNodes
void DisconnectNodes()
Definition: net.cpp:1320
CDataStream::resize
void resize(size_type n, value_type c=0)
Definition: streams.h:282
mapMsgCmdSize
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:750
CMessageHeader::MessageMagic
std::array< uint8_t, MESSAGE_START_SIZE > MessageMagic
Definition: protocol.h:49
NET_MESSAGE_COMMAND_OTHER
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:118
CNode::GetLocalNonce
uint64_t GetLocalNonce() const
Definition: net.h:1285
CNodeStats
POD that contains various stats about a node.
Definition: net.h:757
CNodeStats::cleanSubVer
std::string cleanSubVer
Definition: net.h:770
CNode::nLocalExtraEntropy
const uint64_t nLocalExtraEntropy
Definition: net.h:1246
CNodeStats::nLastTXTime
int64_t nLastTXTime
Definition: net.h:763
FastRandomContext::randrange
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
Definition: random.h:204
CNode::nLastBlockTime
std::atomic< int64_t > nLastBlockTime
UNIX epoch time of the last block received from this peer that we had not yet seen (e....
Definition: net.h:1203
hash.h
CConnman::Options::m_specified_outgoing
std::vector< std::string > m_specified_outgoing
Definition: net.h:252
CConnman::Stop
void Stop()
Definition: net.h:302
DEFAULT_PEER_CONNECT_TIMEOUT
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:101
CNode::HasPermission
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:976
CConnman::AddNode
bool AddNode(const std::string &node)
Definition: net.cpp:3045
CNode::IsInboundConn
bool IsInboundConn() const
Definition: net.h:1034
CNode::operator=
CNode & operator=(const CNode &)=delete
CNode::vRecvMsg
std::list< CNetMessage > vRecvMsg
Definition: net.h:1270
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
CNode::RelayAddrsWithConn
bool RelayAddrsWithConn() const
Definition: net.h:1039
CConnman::ListenSocket::ListenSocket
ListenSocket(SOCKET socket_, NetPermissionFlags permissions_)
Definition: net.h:460
NetEventsInterface::ProcessMessages
virtual bool ProcessMessages(const Config &config, CNode *pnode, std::atomic< bool > &interrupt)=0
CConnman::GetExtraOutboundCount
int GetExtraOutboundCount()
Definition: net.cpp:2051
addrman.h
CSerializedNetMsg::data
std::vector< uint8_t > data
Definition: net.h:137
CConnman::threadOpenAddedConnections
std::thread threadOpenAddedConnections
Definition: net.h:648
NodeId
int64_t NodeId
Definition: nodeid.h:10
CConnman::GetNetworkActive
bool GetNetworkActive() const
Definition: net.h:308
CConnman::GetUseAddrmanOutgoing
bool GetUseAddrmanOutgoing() const
Definition: net.h:309
FEELER_INTERVAL
static const int FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes or 120 seconds.
Definition: net.h:61
CConnman::CachedAddrResponse::m_cache_entry_expiration
std::chrono::microseconds m_cache_entry_expiration
Definition: net.h:571
CNode::SetAddrLocal
void SetAddrLocal(const CService &addrLocalIn)
May not be called more than once.
Definition: net.cpp:568
CHash256
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
Definition: hash.h:22
NodeEvictionCandidate::nMinPingUsecTime
int64_t nMinPingUsecTime
Definition: net.h:1410
CConnman::Options::m_max_outbound_full_relay
int m_max_outbound_full_relay
Definition: net.h:233
ConnectionType::BLOCK_RELAY
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
RemoveLocal
void RemoveLocal(const CService &addr)
Definition: net.cpp:283
LOCAL_NONE
@ LOCAL_NONE
Definition: net.h:700
CConnman::GetTryNewOutboundPeer
bool GetTryNewOutboundPeer()
Definition: net.cpp:2035
CNode::m_legacyWhitelisted
bool m_legacyWhitelisted
Definition: net.h:981
CNetAddr::IsAddrV1Compatible
bool IsAddrV1Compatible() const
Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
Definition: netaddress.cpp:489
DEFAULT_WHITELISTFORCERELAY
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: net.h:53
CNode::MaybeSetAddrName
void MaybeSetAddrName(const std::string &addrNameIn)
Sets the addrName only if it was not previously set.
Definition: net.cpp:556
CConnman::ThreadOpenConnections
void ThreadOpenConnections(std::vector< std::string > connect)
Definition: net.cpp:2066
CConnman::semOutbound
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:604
CNode::nVersion
std::atomic< int > nVersion
Definition: net.h:963
V1TransportDeserializer::nHdrPos
uint32_t nHdrPos
Definition: net.h:854
CNode::ProofRelay::nextInvSend
std::chrono::microseconds nextInvSend
Definition: net.h:1135
CNode::cs_inventory
Mutex cs_inventory
Definition: net.h:1091
DEFAULT_UPNP
static const bool DEFAULT_UPNP
-upnp default
Definition: net.h:86
CConnman::semAddnode
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:605
CNodeStats::nRecvBytes
uint64_t nRecvBytes
Definition: net.h:776
CNode::AvalancheState::AvalancheState
AvalancheState()
Definition: net.h:1161
CConnman::flagInterruptMsgProc
std::atomic< bool > flagInterruptMsgProc
Definition: net.h:642
DEFAULT_BLOCKSONLY
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:99
CConnman::m_msgproc
NetEventsInterface * m_msgproc
Definition: net.h:621
CConnman::threadDNSAddressSeed
std::thread threadDNSAddressSeed
Definition: net.h:646
CConnman::GetTotalBytesSent
uint64_t GetTotalBytesSent()
Definition: net.cpp:3229
CConnman::Init
void Init(const Options &connOptions)
Definition: net.h:257
CConnman::GenerateSelectSet
bool GenerateSelectSet(std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Definition: net.cpp:1429
LOCAL_BIND
@ LOCAL_BIND
Definition: net.h:704
CConnman::vNodesDisconnected
std::list< CNode * > vNodesDisconnected
Definition: net.h:558
V1TransportDeserializer::V1TransportDeserializer
V1TransportDeserializer(const CMessageHeader::MessageMagic &pchMessageStartIn, int nTypeIn, int nVersionIn)
Definition: net.h:873
CNode::fClient
bool fClient
Definition: net.h:983
CNode::nPingNonceSent
std::atomic< uint64_t > nPingNonceSent
Definition: net.h:1223
StopMapPort
void StopMapPort()
Definition: net.cpp:1866
CNode::IsFullOutboundConn
bool IsFullOutboundConn() const
Definition: net.h:1018
CNode::nSendSize
size_t nSendSize
Definition: net.h:938
CConnman::threadSocketHandler
std::thread threadSocketHandler
Definition: net.h:647
CConnman::CheckIncomingNonce
bool CheckIncomingNonce(uint64_t nonce)
Definition: net.cpp:362
CConnman::m_max_outbound_block_relay
int m_max_outbound_block_relay
Definition: net.h:613
CConnman::Options::m_asmap
std::vector< bool > m_asmap
Definition: net.h:254
CNode::PushProofInventory
void PushProofInventory(const avalanche::ProofId &proofid)
Definition: net.h:1366
CConnman::CONNECTIONS_NONE
@ CONNECTIONS_NONE
Definition: net.h:224
CNode::m_greatest_common_version
std::atomic< int > m_greatest_common_version
Definition: net.h:1248
CNode::TxRelay::GUARDED_BY
bool fSendMempool GUARDED_BY(cs_tx_inventory)
Definition: net.h:1112
amount.h
CNode::TxRelay::GUARDED_BY
bool fRelayTxes GUARDED_BY(cs_filter)
Definition: net.h:1100
CThreadInterrupt
A helper class for interruptible sleeps.
Definition: threadinterrupt.h:19
ConnectionType
ConnectionType
Different types of connections to a peer.
Definition: net.h:154
TransportDeserializer::Complete
virtual bool Complete() const =0
CNode::GUARDED_BY
std::chrono::microseconds m_next_addr_send GUARDED_BY(cs_sendProcessing)
Definition: net.h:1083
IsLocal
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:317
CNode::fPauseSend
std::atomic_bool fPauseSend
Definition: net.h:1001
CNodeStats::fInbound
bool fInbound
Definition: net.h:771
CRollingBloomFilter
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:119
MAX_SUBVERSION_LENGTH
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
Definition: net.h:68
CNode::AvalancheState::availabilityScore
std::atomic< double > availabilityScore
The last computed score.
Definition: net.h:1150
CConnman::m_use_addrman_outgoing
bool m_use_addrman_outgoing
Definition: net.h:618
CConnman::AddWhitelistPermissionFlags
void AddWhitelistPermissionFlags(NetPermissionFlags &flags, const CNetAddr &addr) const
Definition: net.cpp:523
CConnman::clientInterface
CClientUIInterface * clientInterface
Definition: net.h:620
CConnman::Options::vWhiteBinds
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:248
CConnman::fNetworkActive
std::atomic< bool > fNetworkActive
Definition: net.h:550
CConnman::interruptNet
CThreadInterrupt interruptNet
Definition: net.h:644
CConnman::GetBestHeight
int GetBestHeight() const
Definition: net.cpp:3242
CConnman::GetDeterministicRandomizer
CSipHasher GetDeterministicRandomizer(uint64_t id) const
Get a unique deterministic randomizer.
Definition: net.cpp:3404
CConnman::AddNewAddresses
bool AddNewAddresses(const std::vector< CAddress > &vAddr, const CAddress &addrFrom, int64_t nTimePenalty=0)
Definition: net.cpp:2973
CConnman::nMaxAddnode
int nMaxAddnode
Definition: net.h:615
CConnman::InitBinds
bool InitBinds(const std::vector< CService > &binds, const std::vector< NetWhitebindPermissions > &whiteBinds, const std::vector< CService > &onion_binds)
Definition: net.cpp:2677
CNodeStats::m_ping_wait_usec
int64_t m_ping_wait_usec
Definition: net.h:781
GUARDED_BY
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(cs_mapLocalHost)
CConnman::nMaxConnections
int nMaxConnections
Definition: net.h:606
FastRandomContext
Fast randomness source.
Definition: random.h:129
CConnman::PushMessage
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:3335
CNode::~CNode
~CNode()
Definition: net.cpp:3327
CConnman::BindListenPort
bool BindListenPort(const CService &bindAddr, bilingual_str &strError, NetPermissionFlags permissions)
Definition: net.cpp:2500
CNodeStats::nLastProofTime
int64_t nLastProofTime
Definition: net.h:764
CNetMessage::m_raw_message_size
uint32_t m_raw_message_size
used wire size of the message (including header/checksum)
Definition: net.h:813
CNode::vAddrToSend
std::vector< CAddress > vAddrToSend
Definition: net.h:1080
TIMEOUT_INTERVAL
static const int TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:59
CConnman::Options::m_banman
BanMan * m_banman
Definition: net.h:240
GetLocalAddress
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:195
CSerializedNetMsg::operator=
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
CNodeStats::minFeeFilter
Amount minFeeFilter
Definition: net.h:783
CNode::m_proof_relay
std::unique_ptr< ProofRelay > m_proof_relay
Definition: net.h:1139
INIT_PROTO_VERSION
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
Definition: version.h:14
CNode::fPauseRecv
std::atomic_bool fPauseRecv
Definition: net.h:1000
CConnman::RecordBytesSent
void RecordBytesSent(uint64_t bytes)
Definition: net.cpp:3138
TransportDeserializer::SetVersion
virtual void SetVersion(int version)=0
net_permissions.h
CNode::TxRelay::nNextInvSend
std::chrono::microseconds nNextInvSend
Definition: net.h:1116
DEFAULT_FORCEDNSSEED
static const bool DEFAULT_FORCEDNSSEED
Definition: net.h:103
DEFAULT_LISTEN
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:81
SOCKET
unsigned int SOCKET
Definition: compat.h:44
CNodeStats::m_manual_connection
bool m_manual_connection
Definition: net.h:772
IsPeerAddrLocalGood
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:215
CConnman::MarkAddressGood
void MarkAddressGood(const CAddress &addr)
Definition: net.cpp:2969
NodeEvictionCandidate::nLastBlockTime
int64_t nLastBlockTime
Definition: net.h:1411
NodeEvictionCandidate::nLastTXTime
int64_t nLastTXTime
Definition: net.h:1413
CConnman::DeleteNode
void DeleteNode(CNode *pnode)
Definition: net.cpp:2950
CNodeStats::mapRecvBytesPerMsgCmd
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:777
CNode::addrBind
const CAddress addrBind
Definition: net.h:962
CConnman::ForEachNode
void ForEachNode(const NodeFn &func) const
Definition: net.h:330
NodeEvictionCandidate::fRelevantServices
bool fRelevantServices
Definition: net.h:1414