Bitcoin Core  22.99.0
P2P Digital Currency
net.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2021 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 <chainparams.h>
10 #include <common/bloom.h>
11 #include <compat.h>
12 #include <consensus/amount.h>
13 #include <crypto/siphash.h>
14 #include <hash.h>
15 #include <i2p.h>
16 #include <net_permissions.h>
17 #include <netaddress.h>
18 #include <netbase.h>
19 #include <policy/feerate.h>
20 #include <protocol.h>
21 #include <random.h>
22 #include <span.h>
23 #include <streams.h>
24 #include <sync.h>
25 #include <threadinterrupt.h>
26 #include <uint256.h>
27 #include <util/check.h>
28 #include <util/sock.h>
29 
30 #include <atomic>
31 #include <condition_variable>
32 #include <cstdint>
33 #include <deque>
34 #include <map>
35 #include <memory>
36 #include <optional>
37 #include <thread>
38 #include <vector>
39 
40 class AddrMan;
41 class BanMan;
42 class CNode;
43 class CScheduler;
44 struct bilingual_str;
45 
47 static const bool DEFAULT_WHITELISTRELAY = true;
49 static const bool DEFAULT_WHITELISTFORCERELAY = false;
50 
52 static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
54 static constexpr auto FEELER_INTERVAL = 2min;
56 static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min;
58 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
60 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
64 static const int MAX_ADDNODE_CONNECTIONS = 8;
66 static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2;
68 static const int MAX_FEELER_CONNECTIONS = 1;
70 static const bool DEFAULT_LISTEN = true;
72 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
74 static const std::string DEFAULT_MAX_UPLOAD_TARGET{"0M"};
76 static const bool DEFAULT_BLOCKSONLY = false;
78 static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
80 static const int NUM_FDS_MESSAGE_CAPTURE = 1;
81 
82 static constexpr bool DEFAULT_FORCEDNSSEED{false};
83 static constexpr bool DEFAULT_DNSSEED{true};
84 static constexpr bool DEFAULT_FIXEDSEEDS{true};
85 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
86 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
87 
88 typedef int64_t NodeId;
89 
91 {
92  std::string strAddedNode;
94  bool fConnected;
95  bool fInbound;
96 };
97 
98 class CNodeStats;
99 class CClientUIInterface;
100 
102 {
103  CSerializedNetMsg() = default;
106  // No copying, only moves.
107  CSerializedNetMsg(const CSerializedNetMsg& msg) = delete;
109 
110  std::vector<unsigned char> data;
111  std::string m_type;
112 };
113 
121 enum class ConnectionType {
127  INBOUND,
128 
136 
137 
144  MANUAL,
145 
161  FEELER,
162 
172  BLOCK_RELAY,
173 
180  ADDR_FETCH,
181 };
182 
184 std::string ConnectionTypeAsString(ConnectionType conn_type);
185 void Discover();
186 uint16_t GetListenPort();
187 
188 enum
189 {
190  LOCAL_NONE, // unknown
191  LOCAL_IF, // address a local interface listens on
192  LOCAL_BIND, // address explicit bound to
193  LOCAL_MAPPED, // address reported by UPnP or NAT-PMP
194  LOCAL_MANUAL, // address explicitly specified (-externalip=)
195 
197 };
198 
199 bool IsPeerAddrLocalGood(CNode *pnode);
201 std::optional<CAddress> GetLocalAddrForPeer(CNode *pnode);
202 
207 void SetReachable(enum Network net, bool reachable);
209 bool IsReachable(enum Network net);
211 bool IsReachable(const CNetAddr& addr);
212 
213 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
214 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
215 void RemoveLocal(const CService& addr);
216 bool SeenLocal(const CService& addr);
217 bool IsLocal(const CService& addr);
218 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
219 CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices);
220 
221 
222 extern bool fDiscover;
223 extern bool fListen;
224 
226 extern std::string strSubVersion;
227 
229  int nScore;
230  uint16_t nPort;
231 };
232 
234 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
235 
236 extern const std::string NET_MESSAGE_COMMAND_OTHER;
237 typedef std::map<std::string, uint64_t> mapMsgCmdSize; //command, total bytes
238 
240 {
241 public:
245  std::chrono::seconds m_last_send;
246  std::chrono::seconds m_last_recv;
247  std::chrono::seconds m_last_tx_time;
248  std::chrono::seconds m_last_block_time;
249  std::chrono::seconds m_connected;
250  int64_t nTimeOffset;
251  std::string m_addr_name;
252  int nVersion;
253  std::string cleanSubVer;
254  bool fInbound;
258  uint64_t nSendBytes;
260  uint64_t nRecvBytes;
263  std::chrono::microseconds m_last_ping_time;
264  std::chrono::microseconds m_min_ping_time;
266  // Our address, as reported by the peer
267  std::string addrLocal;
268  // Address of this peer
270  // Bind address of our side of the connection
272  // Network the peer connected through
274  uint32_t m_mapped_as;
276 };
277 
278 
283 class CNetMessage {
284 public:
286  std::chrono::microseconds m_time{0};
287  uint32_t m_message_size{0};
288  uint32_t m_raw_message_size{0};
289  std::string m_type;
290 
291  CNetMessage(CDataStream&& recv_in) : m_recv(std::move(recv_in)) {}
292 
293  void SetVersion(int nVersionIn)
294  {
295  m_recv.SetVersion(nVersionIn);
296  }
297 };
298 
304 public:
305  // returns true if the current deserialization is complete
306  virtual bool Complete() const = 0;
307  // set the serialization context version
308  virtual void SetVersion(int version) = 0;
310  virtual int Read(Span<const uint8_t>& msg_bytes) = 0;
311  // decomposes a message from the context
312  virtual CNetMessage GetMessage(std::chrono::microseconds time, bool& reject_message) = 0;
314 };
315 
317 {
318 private:
320  const NodeId m_node_id; // Only for logging
321  mutable CHash256 hasher;
323  bool in_data; // parsing header (false) or data (true)
324  CDataStream hdrbuf; // partially received header
325  CMessageHeader hdr; // complete header
326  CDataStream vRecv; // received message data
327  unsigned int nHdrPos;
328  unsigned int nDataPos;
329 
330  const uint256& GetMessageHash() const;
331  int readHeader(Span<const uint8_t> msg_bytes);
332  int readData(Span<const uint8_t> msg_bytes);
333 
334  void Reset() {
335  vRecv.clear();
336  hdrbuf.clear();
337  hdrbuf.resize(24);
338  in_data = false;
339  nHdrPos = 0;
340  nDataPos = 0;
341  data_hash.SetNull();
342  hasher.Reset();
343  }
344 
345 public:
346  V1TransportDeserializer(const CChainParams& chain_params, const NodeId node_id, int nTypeIn, int nVersionIn)
347  : m_chain_params(chain_params),
348  m_node_id(node_id),
349  hdrbuf(nTypeIn, nVersionIn),
350  vRecv(nTypeIn, nVersionIn)
351  {
352  Reset();
353  }
354 
355  bool Complete() const override
356  {
357  if (!in_data)
358  return false;
359  return (hdr.nMessageSize == nDataPos);
360  }
361  void SetVersion(int nVersionIn) override
362  {
363  hdrbuf.SetVersion(nVersionIn);
364  vRecv.SetVersion(nVersionIn);
365  }
366  int Read(Span<const uint8_t>& msg_bytes) override
367  {
368  int ret = in_data ? readData(msg_bytes) : readHeader(msg_bytes);
369  if (ret < 0) {
370  Reset();
371  } else {
372  msg_bytes = msg_bytes.subspan(ret);
373  }
374  return ret;
375  }
376  CNetMessage GetMessage(std::chrono::microseconds time, bool& reject_message) override;
377 };
378 
382 public:
383  // prepare message for transport (header construction, error-correction computation, payload encryption, etc.)
384  virtual void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) = 0;
385  virtual ~TransportSerializer() {}
386 };
387 
389 public:
390  void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) override;
391 };
392 
394 class CNode
395 {
396  friend class CConnman;
397  friend struct ConnmanTestMsg;
398 
399 public:
400  std::unique_ptr<TransportDeserializer> m_deserializer;
401  std::unique_ptr<TransportSerializer> m_serializer;
402 
404  std::atomic<ServiceFlags> nServices{NODE_NONE};
405 
414  std::shared_ptr<Sock> m_sock GUARDED_BY(m_sock_mutex);
415 
417  size_t nSendSize GUARDED_BY(cs_vSend){0};
419  size_t nSendOffset GUARDED_BY(cs_vSend){0};
420  uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
421  std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
425 
427  std::list<CNetMessage> vProcessMsg GUARDED_BY(cs_vProcessMsg);
428  size_t nProcessQueueSize{0};
429 
431 
432  uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
433 
434  std::atomic<std::chrono::seconds> m_last_send{0s};
435  std::atomic<std::chrono::seconds> m_last_recv{0s};
437  const std::chrono::seconds m_connected;
438  std::atomic<int64_t> nTimeOffset{0};
439  // Address of this peer
440  const CAddress addr;
441  // Bind address of our side of the connection
443  const std::string m_addr_name;
445  const bool m_inbound_onion;
446  std::atomic<int> nVersion{0};
452  std::string cleanSubVer GUARDED_BY(m_subver_mutex){};
453  bool m_prefer_evict{false}; // This peer is preferred for eviction.
454  bool HasPermission(NetPermissionFlags permission) const {
455  return NetPermissions::HasFlag(m_permissionFlags, permission);
456  }
457  bool fClient{false}; // set by version message
458  bool m_limited_node{false}; //after BIP159, set by version message
460  std::atomic_bool fSuccessfullyConnected{false};
461  // Setting fDisconnect to true will cause the node to be disconnected the
462  // next time DisconnectNodes() runs
463  std::atomic_bool fDisconnect{false};
465  std::atomic<int> nRefCount{0};
466 
467  const uint64_t nKeyedNetGroup;
468  std::atomic_bool fPauseRecv{false};
469  std::atomic_bool fPauseSend{false};
470 
472  switch (m_conn_type) {
475  return true;
480  return false;
481  } // no default case, so the compiler can warn about missing cases
482 
483  assert(false);
484  }
485 
486  bool IsFullOutboundConn() const {
488  }
489 
490  bool IsManualConn() const {
492  }
493 
494  bool IsBlockOnlyConn() const {
496  }
497 
498  bool IsFeelerConn() const {
500  }
501 
502  bool IsAddrFetchConn() const {
504  }
505 
506  bool IsInboundConn() const {
508  }
509 
510  bool ExpectServicesFromConn() const {
511  switch (m_conn_type) {
515  return false;
519  return true;
520  } // no default case, so the compiler can warn about missing cases
521 
522  assert(false);
523  }
524 
536 
537  // We selected peer as (compact blocks) high-bandwidth peer (BIP152)
538  std::atomic<bool> m_bip152_highbandwidth_to{false};
539  // Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
540  std::atomic<bool> m_bip152_highbandwidth_from{false};
541 
542  struct TxRelay {
544  // We use fRelayTxes for two purposes -
545  // a) it allows us to not relay tx invs before receiving the peer's version message
546  // b) the peer may tell us in its version message that we should not relay tx invs
547  // unless it loads a bloom filter.
548  bool fRelayTxes GUARDED_BY(cs_filter){false};
549  std::unique_ptr<CBloomFilter> pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter){nullptr};
550 
552  CRollingBloomFilter filterInventoryKnown GUARDED_BY(cs_tx_inventory){50000, 0.000001};
553  // Set of transaction ids we still have to announce.
554  // They are sorted by the mempool before relay, so the order is not important.
555  std::set<uint256> setInventoryTxToSend;
556  // Used for BIP35 mempool sending
557  bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
558  // Last time a "MEMPOOL" request was serviced.
559  std::atomic<std::chrono::seconds> m_last_mempool_req{0s};
560  std::chrono::microseconds nNextInvSend{0};
561 
563  std::atomic<CAmount> minFeeFilter{0};
565  std::chrono::microseconds m_next_send_feefilter{0};
566  };
567 
568  // m_tx_relay == nullptr if we're not relaying transactions with this peer
569  std::unique_ptr<TxRelay> m_tx_relay;
570 
576  std::atomic<std::chrono::seconds> m_last_block_time{0s};
577 
582  std::atomic<std::chrono::seconds> m_last_tx_time{0s};
583 
585  std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
586 
589  std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()};
590 
591  CNode(NodeId id, ServiceFlags nLocalServicesIn, std::shared_ptr<Sock> sock, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion);
592  CNode(const CNode&) = delete;
593  CNode& operator=(const CNode&) = delete;
594 
595  NodeId GetId() const {
596  return id;
597  }
598 
599  uint64_t GetLocalNonce() const {
600  return nLocalHostNonce;
601  }
602 
603  int GetRefCount() const
604  {
605  assert(nRefCount >= 0);
606  return nRefCount;
607  }
608 
618  bool ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete);
619 
620  void SetCommonVersion(int greatest_common_version)
621  {
623  m_greatest_common_version = greatest_common_version;
624  }
625  int GetCommonVersion() const
626  {
628  }
629 
632  void SetAddrLocal(const CService& addrLocalIn) LOCKS_EXCLUDED(m_addr_local_mutex);
633 
635  {
636  nRefCount++;
637  return this;
638  }
639 
640  void Release()
641  {
642  nRefCount--;
643  }
644 
645  void AddKnownTx(const uint256& hash)
646  {
647  if (m_tx_relay != nullptr) {
648  LOCK(m_tx_relay->cs_tx_inventory);
649  m_tx_relay->filterInventoryKnown.insert(hash);
650  }
651  }
652 
653  void PushTxInventory(const uint256& hash)
654  {
655  if (m_tx_relay == nullptr) return;
656  LOCK(m_tx_relay->cs_tx_inventory);
657  if (!m_tx_relay->filterInventoryKnown.contains(hash)) {
658  m_tx_relay->setInventoryTxToSend.insert(hash);
659  }
660  }
661 
662  void CloseSocketDisconnect();
663 
664  void CopyStats(CNodeStats& stats);
665 
667  {
668  return nLocalServices;
669  }
670 
672 
674  void PongReceived(std::chrono::microseconds ping_time) {
675  m_last_ping_time = ping_time;
676  m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
677  }
678 
679 private:
680  const NodeId id;
681  const uint64_t nLocalHostNonce;
684 
701 
702  std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
703 
704  // Our address, as reported by the peer
707 
708  mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
709  mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
710 };
711 
716 {
717 public:
719  virtual void InitializeNode(CNode* pnode) = 0;
720 
722  virtual void FinalizeNode(const CNode& node) = 0;
723 
731  virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) = 0;
732 
739  virtual bool SendMessages(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_sendProcessing) = 0;
740 
741 
742 protected:
747  ~NetEventsInterface() = default;
748 };
749 
750 class CConnman
751 {
752 public:
753 
754  struct Options
755  {
760  int nMaxAddnode = 0;
761  int nMaxFeeler = 0;
764  BanMan* m_banman = nullptr;
765  unsigned int nSendBufferMaxSize = 0;
766  unsigned int nReceiveFloodSize = 0;
767  uint64_t nMaxOutboundLimit = 0;
769  std::vector<std::string> vSeedNodes;
770  std::vector<NetWhitelistPermissions> vWhitelistedRange;
771  std::vector<NetWhitebindPermissions> vWhiteBinds;
772  std::vector<CService> vBinds;
773  std::vector<CService> onion_binds;
778  std::vector<std::string> m_specified_outgoing;
779  std::vector<std::string> m_added_nodes;
781  };
782 
783  void Init(const Options& connOptions) {
784  nLocalServices = connOptions.nLocalServices;
785  nMaxConnections = connOptions.nMaxConnections;
786  m_max_outbound_full_relay = std::min(connOptions.m_max_outbound_full_relay, connOptions.nMaxConnections);
789  nMaxAddnode = connOptions.nMaxAddnode;
790  nMaxFeeler = connOptions.nMaxFeeler;
792  m_client_interface = connOptions.uiInterface;
793  m_banman = connOptions.m_banman;
794  m_msgproc = connOptions.m_msgproc;
796  nReceiveFloodSize = connOptions.nReceiveFloodSize;
797  m_peer_connect_timeout = std::chrono::seconds{connOptions.m_peer_connect_timeout};
798  {
800  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
801  }
802  vWhitelistedRange = connOptions.vWhitelistedRange;
803  {
805  m_added_nodes = connOptions.m_added_nodes;
806  }
807  m_onion_binds = connOptions.onion_binds;
808  }
809 
810  CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, bool network_active = true);
811  ~CConnman();
812  bool Start(CScheduler& scheduler, const Options& options);
813 
814  void StopThreads();
815  void StopNodes();
816  void Stop()
817  {
818  StopThreads();
819  StopNodes();
820  };
821 
822  void Interrupt();
823  bool GetNetworkActive() const { return fNetworkActive; };
825  void SetNetworkActive(bool active);
826  void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant* grantOutbound, const char* strDest, ConnectionType conn_type);
827  bool CheckIncomingNonce(uint64_t nonce);
828 
829  bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
830 
831  void PushMessage(CNode* pnode, CSerializedNetMsg&& msg);
832 
833  using NodeFn = std::function<void(CNode*)>;
834  void ForEachNode(const NodeFn& func)
835  {
837  for (auto&& node : m_nodes) {
839  func(node);
840  }
841  };
842 
843  void ForEachNode(const NodeFn& func) const
844  {
846  for (auto&& node : m_nodes) {
848  func(node);
849  }
850  };
851 
852  // Addrman functions
860  std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network) const;
867  std::vector<CAddress> GetAddresses(CNode& requestor, size_t max_addresses, size_t max_pct);
868 
869  // This allows temporarily exceeding m_max_outbound_full_relay, with the goal of finding
870  // a peer that is better than all our current peers.
871  void SetTryNewOutboundPeer(bool flag);
872  bool GetTryNewOutboundPeer() const;
873 
875  LogPrint(BCLog::NET, "net: enabling extra block-relay-only peers\n");
877  }
878 
879  // Return the number of outbound peers we have in excess of our target (eg,
880  // if we previously called SetTryNewOutboundPeer(true), and have since set
881  // to false, we may have extra peers that we wish to disconnect). This may
882  // return a value less than (num_outbound_connections - num_outbound_slots)
883  // in cases where some outbound connections are not yet fully connected, or
884  // not yet fully disconnected.
885  int GetExtraFullOutboundCount() const;
886  // Count the number of block-relay-only peers we have over our limit.
887  int GetExtraBlockRelayCount() const;
888 
889  bool AddNode(const std::string& node);
890  bool RemoveAddedNode(const std::string& node);
891  std::vector<AddedNodeInfo> GetAddedNodeInfo() const;
892 
905  bool AddConnection(const std::string& address, ConnectionType conn_type);
906 
907  size_t GetNodeCount(ConnectionDirection) const;
908  void GetNodeStats(std::vector<CNodeStats>& vstats) const;
909  bool DisconnectNode(const std::string& node);
910  bool DisconnectNode(const CSubNet& subnet);
911  bool DisconnectNode(const CNetAddr& addr);
912  bool DisconnectNode(NodeId id);
913 
921 
922  uint64_t GetMaxOutboundTarget() const;
923  std::chrono::seconds GetMaxOutboundTimeframe() const;
924 
928  bool OutboundTargetReached(bool historicalBlockServingLimit) const;
929 
932  uint64_t GetOutboundTargetBytesLeft() const;
933 
936  std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const;
937 
938  uint64_t GetTotalBytesRecv() const;
939  uint64_t GetTotalBytesSent() const;
940 
942  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
943 
944  unsigned int GetReceiveFloodSize() const;
945 
946  void WakeMessageHandler();
947 
949  bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const;
950 
951 private:
952  struct ListenSocket {
953  public:
954  std::shared_ptr<Sock> sock;
956  ListenSocket(std::shared_ptr<Sock> sock_, NetPermissionFlags permissions_)
957  : sock{sock_}, m_permissions{permissions_}
958  {
959  }
960 
961  private:
963  };
964 
965  bool BindListenPort(const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
966  bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
967  bool InitBinds(const Options& options);
968 
970  void AddAddrFetch(const std::string& strDest);
971  void ProcessAddrFetch();
972  void ThreadOpenConnections(std::vector<std::string> connect);
973  void ThreadMessageHandler();
975  void AcceptConnection(const ListenSocket& hListenSocket);
976 
985  void CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
986  NetPermissionFlags permissionFlags,
987  const CAddress& addr_bind,
988  const CAddress& addr);
989 
990  void DisconnectNodes();
993  bool InactivityCheck(const CNode& node) const;
994 
1003  bool GenerateSelectSet(const std::vector<CNode*>& nodes,
1004  std::set<SOCKET>& recv_set,
1005  std::set<SOCKET>& send_set,
1006  std::set<SOCKET>& error_set);
1007 
1016  void SocketEvents(const std::vector<CNode*>& nodes,
1017  std::set<SOCKET>& recv_set,
1018  std::set<SOCKET>& send_set,
1019  std::set<SOCKET>& error_set);
1020 
1024  void SocketHandler();
1025 
1034  void SocketHandlerConnected(const std::vector<CNode*>& nodes,
1035  const std::set<SOCKET>& recv_set,
1036  const std::set<SOCKET>& send_set,
1037  const std::set<SOCKET>& error_set);
1038 
1043  void SocketHandlerListening(const std::set<SOCKET>& recv_set);
1044 
1045  void ThreadSocketHandler();
1046  void ThreadDNSAddressSeed();
1047 
1048  uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
1049 
1050  CNode* FindNode(const CNetAddr& ip);
1051  CNode* FindNode(const CSubNet& subNet);
1052  CNode* FindNode(const std::string& addrName);
1053  CNode* FindNode(const CService& addr);
1054 
1059  bool AlreadyConnectedToAddress(const CAddress& addr);
1060 
1061  bool AttemptToEvictConnection();
1062  CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type);
1064 
1065  void DeleteNode(CNode* pnode);
1066 
1067  NodeId GetNewNodeId();
1068 
1069  size_t SocketSendData(CNode& node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
1070  void DumpAddresses();
1071 
1072  // Network stats
1073  void RecordBytesRecv(uint64_t bytes);
1074  void RecordBytesSent(uint64_t bytes);
1075 
1079  std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;
1080 
1081  // Whether the node should be passed out in ForEach* callbacks
1082  static bool NodeFullyConnected(const CNode* pnode);
1083 
1084  // Network usage totals
1086  std::atomic<uint64_t> nTotalBytesRecv{0};
1087  uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0};
1088 
1089  // outbound limit & stats
1090  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent) {0};
1091  std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent) {0};
1092  uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
1093 
1094  // P2P timeout in seconds
1095  std::chrono::seconds m_peer_connect_timeout;
1096 
1097  // Whitelisted ranges. Any node connecting from these is automatically
1098  // whitelisted (as well as those connecting to whitelisted binds).
1099  std::vector<NetWhitelistPermissions> vWhitelistedRange;
1100 
1101  unsigned int nSendBufferMaxSize{0};
1102  unsigned int nReceiveFloodSize{0};
1103 
1104  std::vector<ListenSocket> vhListenSocket;
1105  std::atomic<bool> fNetworkActive{true};
1108  std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
1110  std::vector<std::string> m_added_nodes GUARDED_BY(m_added_nodes_mutex);
1112  std::vector<CNode*> m_nodes GUARDED_BY(m_nodes_mutex);
1113  std::list<CNode*> m_nodes_disconnected;
1115  std::atomic<NodeId> nLastNodeId{0};
1116  unsigned int nPrevNodeCount{0};
1117 
1125  std::vector<CAddress> m_addrs_response_cache;
1126  std::chrono::microseconds m_cache_entry_expiration{0};
1127  };
1128 
1143  std::map<uint64_t, CachedAddrResponse> m_addr_response_caches;
1144 
1158 
1159  std::unique_ptr<CSemaphore> semOutbound;
1160  std::unique_ptr<CSemaphore> semAddnode;
1162 
1163  // How many full-relay (tx, block, addr) outbound peers we want
1165 
1166  // How many block-relay only outbound peers we want
1167  // We do not relay tx or addr messages with these peers
1169 
1178 
1183  std::vector<CAddress> m_anchors;
1184 
1186  const uint64_t nSeed0, nSeed1;
1187 
1189  bool fMsgProcWake GUARDED_BY(mutexMsgProc);
1190 
1191  std::condition_variable condMsgProc;
1193  std::atomic<bool> flagInterruptMsgProc{false};
1194 
1202 
1207  std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
1208 
1210  std::thread threadSocketHandler;
1215 
1220 
1225  std::atomic_bool m_start_extra_block_relay_peers{false};
1226 
1231  std::vector<CService> m_onion_binds;
1232 
1238  {
1239  public:
1240  explicit NodesSnapshot(const CConnman& connman, bool shuffle)
1241  {
1242  {
1243  LOCK(connman.m_nodes_mutex);
1244  m_nodes_copy = connman.m_nodes;
1245  for (auto& node : m_nodes_copy) {
1246  node->AddRef();
1247  }
1248  }
1249  if (shuffle) {
1251  }
1252  }
1253 
1255  {
1256  for (auto& node : m_nodes_copy) {
1257  node->Release();
1258  }
1259  }
1260 
1261  const std::vector<CNode*>& Nodes() const
1262  {
1263  return m_nodes_copy;
1264  }
1265 
1266  private:
1267  std::vector<CNode*> m_nodes_copy;
1268  };
1269 
1270  friend struct CConnmanTest;
1271  friend struct ConnmanTestMsg;
1272 };
1273 
1275 void CaptureMessage(const CAddress& addr, const std::string& msg_type, const Span<const unsigned char>& data, bool is_incoming);
1276 
1278 {
1280  std::chrono::seconds m_connected;
1281  std::chrono::microseconds m_min_ping_time;
1282  std::chrono::seconds m_last_block_time;
1283  std::chrono::seconds m_last_tx_time;
1287  uint64_t nKeyedNetGroup;
1291 };
1292 
1300 [[nodiscard]] std::optional<NodeId> SelectNodeToEvict(std::vector<NodeEvictionCandidate>&& vEvictionCandidates);
1301 
1323 void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& vEvictionCandidates);
1324 
1325 #endif // BITCOIN_NET_H
NodeEvictionCandidate::m_network
Network m_network
Definition: net.h:1290
V1TransportSerializer
Definition: net.h:388
CConnman::SetTryNewOutboundPeer
void SetTryNewOutboundPeer(bool flag)
Definition: net.cpp:1837
NodeId
int64_t NodeId
Definition: net.h:88
CConnman::DisconnectNode
bool DisconnectNode(const std::string &node)
Definition: net.cpp:2853
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:528
threadinterrupt.h
CNodeStats::m_last_ping_time
std::chrono::microseconds m_last_ping_time
Definition: net.h:263
CNode::IsOutboundOrBlockRelayConn
bool IsOutboundOrBlockRelayConn() const
Definition: net.h:471
CConnman::m_max_outbound
int m_max_outbound
Definition: net.h:1172
CConnman::m_anchors
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
Definition: net.h:1183
feerate.h
CConnman::ConnectNode
CNode * ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type)
Definition: net.cpp:404
CScheduler
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:33
CConnman::Options::vSeedNodes
std::vector< std::string > vSeedNodes
Definition: net.h:769
CConnman::vhListenSocket
std::vector< ListenSocket > vhListenSocket
Definition: net.h:1104
V1TransportDeserializer::Complete
bool Complete() const override
Definition: net.h:355
CNodeStats::fInbound
bool fInbound
Definition: net.h:254
CNode::GUARDED_BY
size_t nSendSize GUARDED_BY(cs_vSend)
Total size of all vSendMsg entries.
Definition: net.h:417
CConnman::NodesSnapshot::~NodesSnapshot
~NodesSnapshot()
Definition: net.h:1254
CNodeStats::m_last_tx_time
std::chrono::seconds m_last_tx_time
Definition: net.h:247
CConnman::ThreadMessageHandler
void ThreadMessageHandler()
Definition: net.cpp:2282
CNode::IsFeelerConn
bool IsFeelerConn() const
Definition: net.h:498
CNode::GetRefCount
int GetRefCount() const
Definition: net.h:603
assert
assert(!tx.IsCoinBase())
TransportDeserializer
The TransportDeserializer takes care of holding and deserializing the network receive buffer.
Definition: net.h:303
NetEventsInterface
Interface for message handling.
Definition: net.h:715
CConnman::Options::nMaxAddnode
int nMaxAddnode
Definition: net.h:760
NodeEvictionCandidate::m_min_ping_time
std::chrono::microseconds m_min_ping_time
Definition: net.h:1281
check.h
CNodeStats::m_network
Network m_network
Definition: net.h:273
CConnman::nSendBufferMaxSize
unsigned int nSendBufferMaxSize
Definition: net.h:1101
NetPermissionFlags::None
@ None
CNode::m_last_tx_time
std::atomic< std::chrono::seconds > m_last_tx_time
UNIX epoch time of the last transaction received from this peer that we had not yet seen (e....
Definition: net.h:582
CConnman::AttemptToEvictConnection
bool AttemptToEvictConnection()
Try to find a connection to evict when the node is full.
Definition: net.cpp:1067
CNode::cs_vSend
Mutex cs_vSend
Definition: net.h:422
CNodeStats::addrLocal
std::string addrLocal
Definition: net.h:267
TIMEOUT_INTERVAL
static constexpr std::chrono::minutes TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:52
CConnman::Interrupt
void Interrupt()
Definition: net.cpp:2663
CClientUIInterface
Signals for UI communication.
Definition: ui_interface.h:24
CNode::GetId
NodeId GetId() const
Definition: net.h:595
CConnman::condMsgProc
std::condition_variable condMsgProc
Definition: net.h:1191
CConnman::nReceiveFloodSize
unsigned int nReceiveFloodSize
Definition: net.h:1102
CNode::GUARDED_BY
size_t nSendOffset GUARDED_BY(cs_vSend)
Offset inside the first vSendMsg already sent.
Definition: net.h:419
NodeEvictionCandidate::fBloomFilter
bool fBloomFilter
Definition: net.h:1286
CNodeStats::nodeid
NodeId nodeid
Definition: net.h:242
CNode::GUARDED_BY
std::string cleanSubVer GUARDED_BY(m_subver_mutex)
cleanSubVer is a sanitized string of the user agent byte array we read from the wire.
Definition: net.h:452
CMessageHeader::nMessageSize
uint32_t nMessageSize
Definition: protocol.h:56
CNode::PongReceived
void PongReceived(std::chrono::microseconds ping_time)
A ping-pong round trip has completed successfully.
Definition: net.h:674
flags
int flags
Definition: bitcoin-tx.cpp:529
NodeEvictionCandidate::m_last_block_time
std::chrono::seconds m_last_block_time
Definition: net.h:1282
CConnman::ThreadDNSAddressSeed
void ThreadDNSAddressSeed()
Definition: net.cpp:1694
CNodeStats::nVersion
int nVersion
Definition: net.h:252
streams.h
CHash256::Reset
CHash256 & Reset()
Definition: hash.h:42
CConnman::Options::vBinds
std::vector< CService > vBinds
Definition: net.h:772
CSerializedNetMsg::data
std::vector< unsigned char > data
Definition: net.h:110
TransportDeserializer::GetMessage
virtual CNetMessage GetMessage(std::chrono::microseconds time, bool &reject_message)=0
CNode::nRefCount
std::atomic< int > nRefCount
Definition: net.h:465
CConnman::StartExtraBlockRelayPeers
void StartExtraBlockRelayPeers()
Definition: net.h:874
CConnman::RecordBytesRecv
void RecordBytesRecv(uint64_t bytes)
Definition: net.cpp:2896
CNode::Release
void Release()
Definition: net.h:640
CConnman::GetMaxOutboundTimeframe
std::chrono::seconds GetMaxOutboundTimeframe() const
Definition: net.cpp:2923
CConnman::WakeMessageHandler
void WakeMessageHandler()
Definition: net.cpp:1685
CNode::m_bip152_highbandwidth_from
std::atomic< bool > m_bip152_highbandwidth_from
Definition: net.h:540
CConnman::ListenSocket::ListenSocket
ListenSocket(std::shared_ptr< Sock > sock_, NetPermissionFlags permissions_)
Definition: net.h:956
CConnman::Bind
bool Bind(const CService &addr, unsigned int flags, NetPermissionFlags permissions)
Definition: net.cpp:2505
CConnman::Options::m_i2p_accept_incoming
bool m_i2p_accept_incoming
Definition: net.h:780
CNode::nProcessQueueSize
size_t nProcessQueueSize
Definition: net.h:428
sync.h
NodeEvictionCandidate::m_last_tx_time
std::chrono::seconds m_last_tx_time
Definition: net.h:1283
CConnman::m_max_outbound_full_relay
int m_max_outbound_full_relay
Definition: net.h:1164
CConnman::m_nodes_disconnected
std::list< CNode * > m_nodes_disconnected
Definition: net.h:1113
Discover
void Discover()
Definition: net.cpp:2423
CNodeStats::m_last_send
std::chrono::seconds m_last_send
Definition: net.h:245
CConnman::Options::nMaxOutboundLimit
uint64_t nMaxOutboundLimit
Definition: net.h:767
CNodeStats::m_last_recv
std::chrono::seconds m_last_recv
Definition: net.h:246
CNode::nLocalServices
const ServiceFlags nLocalServices
Services offered to this peer.
Definition: net.h:700
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:1231
CNodeStats::mapRecvBytesPerMsgCmd
mapMsgCmdSize mapRecvBytesPerMsgCmd
Definition: net.h:261
CNode::m_limited_node
bool m_limited_node
Definition: net.h:458
bilingual_str
Bilingual messages:
Definition: translation.h:16
CNetAddr
Network address.
Definition: netaddress.h:118
CConnman::OutboundTargetReached
bool OutboundTargetReached(bool historicalBlockServingLimit) const
check if the outbound target is reached if param historicalBlockServingLimit is set true,...
Definition: net.cpp:2942
CConnman::ProcessAddrFetch
void ProcessAddrFetch()
Definition: net.cpp:1815
uint256.h
NodeEvictionCandidate::fRelayTxes
bool fRelayTxes
Definition: net.h:1285
DEFAULT_MAX_PEER_CONNECTIONS
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:72
AddLocal
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:252
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:394
CConnman::Options::bind_on_any
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
Definition: net.h:776
DEFAULT_MAXRECEIVEBUFFER
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:85
ProtectEvictionCandidatesByRatio
void ProtectEvictionCandidatesByRatio(std::vector< NodeEvictionCandidate > &vEvictionCandidates)
Protect desirable or disadvantaged inbound peers from eviction by ratio.
Definition: net.cpp:926
AddrMan
Stochastic address manager.
Definition: addrman.h:79
CConnman::Options::nLocalServices
ServiceFlags nLocalServices
Definition: net.h:756
CNode::m_last_block_time
std::atomic< std::chrono::seconds > m_last_block_time
UNIX epoch time of the last block received from this peer that we had not yet seen (e....
Definition: net.h:576
CConnman::CreateNodeFromAcceptedSocket
void CreateNodeFromAcceptedSocket(std::unique_ptr< Sock > &&sock, NetPermissionFlags permissionFlags, const CAddress &addr_bind, const CAddress &addr)
Create a CNode object from a socket that has just been accepted and add the node to the m_nodes membe...
Definition: net.cpp:1139
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:69
base_blob::SetNull
void SetNull()
Definition: uint256.h:41
CConnman::AddConnection
bool AddConnection(const std::string &address, ConnectionType conn_type)
Attempts to open a connection.
Definition: net.cpp:1238
CNode::m_serializer
std::unique_ptr< TransportSerializer > m_serializer
Definition: net.h:401
CConnman::AcceptConnection
void AcceptConnection(const ListenSocket &hListenSocket)
Definition: net.cpp:1111
CNode::CNode
CNode(NodeId id, ServiceFlags nLocalServicesIn, std::shared_ptr< Sock > sock, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn, ConnectionType conn_type_in, bool inbound_onion)
Definition: net.cpp:2989
CConnman::Options::m_added_nodes
std::vector< std::string > m_added_nodes
Definition: net.h:779
CConnman::GetLocalServices
ServiceFlags GetLocalServices() const
Used to convey which local services we are offering peers during node connection.
Definition: net.cpp:2982
NetPermissions::HasFlag
static bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
Definition: net_permissions.h:53
AnnotatedMixin< std::mutex >
CConnman::cs_totalBytesSent
RecursiveMutex cs_totalBytesSent
Definition: net.h:1085
CSerializedNetMsg::m_type
std::string m_type
Definition: net.h:111
CNodeStats::mapSendBytesPerMsgCmd
mapMsgCmdSize mapSendBytesPerMsgCmd
Definition: net.h:259
CNode::PushTxInventory
void PushTxInventory(const uint256 &hash)
Definition: net.h:653
ServiceFlags
ServiceFlags
nServices flags
Definition: protocol.h:271
CConnman::CachedAddrResponse::m_addrs_response_cache
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:1125
CNode::ExpectServicesFromConn
bool ExpectServicesFromConn() const
Definition: net.h:510
V1TransportDeserializer::vRecv
CDataStream vRecv
Definition: net.h:326
CNode::m_permissionFlags
NetPermissionFlags m_permissionFlags
Definition: net.h:403
CNode::nTimeOffset
std::atomic< int64_t > nTimeOffset
Definition: net.h:438
CNode::nServices
std::atomic< ServiceFlags > nServices
Definition: net.h:404
CNode::m_connected
const std::chrono::seconds m_connected
Unix epoch time at peer connection.
Definition: net.h:437
CConnman::SocketEvents
void SocketEvents(const std::vector< CNode * > &nodes, std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Check which sockets are ready for IO.
Definition: net.cpp:1469
chainparams.h
CNode::TxRelay::cs_filter
RecursiveMutex cs_filter
Definition: net.h:543
CConnman::Start
bool Start(CScheduler &scheduler, const Options &options)
Definition: net.cpp:2549
CConnman::CalculateKeyedNetGroup
uint64_t CalculateKeyedNetGroup(const CAddress &ad) const
Definition: net.cpp:3085
CNodeStats::addrBind
CAddress addrBind
Definition: net.h:271
V1TransportDeserializer::readData
int readData(Span< const uint8_t > msg_bytes)
Definition: net.cpp:728
Network
Network
A network type.
Definition: netaddress.h:45
CNodeStats::addr
CAddress addr
Definition: net.h:269
CConnman::GetTryNewOutboundPeer
bool GetTryNewOutboundPeer() const
Definition: net.cpp:1832
CConnman::StopThreads
void StopThreads()
Definition: net.cpp:2687
DEFAULT_FORCEDNSSEED
static constexpr bool DEFAULT_FORCEDNSSEED
Definition: net.h:82
CConnman::NotifyNumConnectionsChanged
void NotifyNumConnectionsChanged()
Definition: net.cpp:1324
LOCAL_MAX
@ LOCAL_MAX
Definition: net.h:196
CNode::fDisconnect
std::atomic_bool fDisconnect
Definition: net.h:463
V1TransportDeserializer::data_hash
uint256 data_hash
Definition: net.h:322
CSipHasher
SipHash-2-4.
Definition: siphash.h:13
CConnman::GetMaxOutboundTimeLeftInCycle
std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const
returns the time left in the current max outbound cycle in case of no limit, it will always return 0
Definition: net.cpp:2928
CNode::GetAddrLocal
CService GetAddrLocal() const LOCKS_EXCLUDED(m_addr_local_mutex)
Definition: net.cpp:563
NetPermissionFlags
NetPermissionFlags
Definition: net_permissions.h:18
CConnman::nPrevNodeCount
unsigned int nPrevNodeCount
Definition: net.h:1116
AddedNodeInfo::fConnected
bool fConnected
Definition: net.h:94
ConnectionType::MANUAL
@ MANUAL
We open manual connections to addresses that users explicitly requested via the addnode RPC or the -a...
CNodeStats::m_min_ping_time
std::chrono::microseconds m_min_ping_time
Definition: net.h:264
CConnman::AddAddrFetch
void AddAddrFetch(const std::string &strDest)
Definition: net.cpp:121
CConnman::InactivityCheck
bool InactivityCheck(const CNode &node) const
Return true if the peer is inactive and should be disconnected.
Definition: net.cpp:1344
CNode::TxRelay::cs_tx_inventory
RecursiveMutex cs_tx_inventory
Definition: net.h:549
CConnman::GUARDED_BY
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1090
CConnman::m_client_interface
CClientUIInterface * m_client_interface
Definition: net.h:1174
CNode::addr
const CAddress addr
Definition: net.h:440
CConnman::GetNodeStats
void GetNodeStats(std::vector< CNodeStats > &vstats) const
Definition: net.cpp:2841
CConnman::OpenNetworkConnection
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *strDest, ConnectionType conn_type)
Definition: net.cpp:2247
ConnmanTestMsg
Definition: net.h:19
CNetMessage::m_type
std::string m_type
Definition: net.h:289
CNodeStats::m_last_block_time
std::chrono::seconds m_last_block_time
Definition: net.h:248
NodeEvictionCandidate::nKeyedNetGroup
uint64_t nKeyedNetGroup
Definition: net.h:1287
CNode::SetCommonVersion
void SetCommonVersion(int greatest_common_version)
Definition: net.h:620
CNode::GetLocalServices
ServiceFlags GetLocalServices() const
Definition: net.h:666
CNodeStats::m_starting_height
int m_starting_height
Definition: net.h:257
bloom.h
Span
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:96
Assume
#define Assume(val)
Assume is the identity function.
Definition: check.h:72
CConnman::FindNode
CNode * FindNode(const CNetAddr &ip)
Definition: net.cpp:329
NetEventsInterface::InitializeNode
virtual void InitializeNode(CNode *pnode)=0
Initialize a peer (setup state, queue any initial messages)
ConnectionType::INBOUND
@ INBOUND
Inbound connections are those initiated by a peer.
V1TransportDeserializer::hdr
CMessageHeader hdr
Definition: net.h:325
CConnman::GenerateSelectSet
bool GenerateSelectSet(const std::vector< CNode * > &nodes, std::set< SOCKET > &recv_set, std::set< SOCKET > &send_set, std::set< SOCKET > &error_set)
Generate a collection of sockets to check for IO readiness.
Definition: net.cpp:1377
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:1143
siphash.h
CSemaphoreGrant
RAII-style semaphore lock.
Definition: sync.h:309
protocol.h
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:62
CConnman::CConnman
CConnman(uint64_t seed0, uint64_t seed1, AddrMan &addrman, bool network_active=true)
Definition: net.cpp:2489
random.h
CConnman::nMaxFeeler
int nMaxFeeler
Definition: net.h:1171
CNode::m_deserializer
std::unique_ptr< TransportDeserializer > m_deserializer
Definition: net.h:400
LOCAL_MAPPED
@ LOCAL_MAPPED
Definition: net.h:193
CConnman::mutexMsgProc
Mutex mutexMsgProc
Definition: net.h:1192
CNodeStats::m_mapped_as
uint32_t m_mapped_as
Definition: net.h:274
SeenLocal
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:312
TransportSerializer::~TransportSerializer
virtual ~TransportSerializer()
Definition: net.h:385
CConnman::nLocalServices
ServiceFlags nLocalServices
Services this instance offers.
Definition: net.h:1157
CConnman::ThreadSocketHandler
void ThreadSocketHandler()
Definition: net.cpp:1674
CConnman::ThreadOpenAddedConnections
void ThreadOpenAddedConnections()
Definition: net.cpp:2218
CNode::AddKnownTx
void AddKnownTx(const uint256 &hash)
Definition: net.h:645
V1TransportDeserializer::in_data
bool in_data
Definition: net.h:323
CConnman::m_addr_fetches_mutex
Mutex m_addr_fetches_mutex
Definition: net.h:1109
DEFAULT_MAXSENDBUFFER
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:86
NodeEvictionCandidate
Definition: net.h:1277
LOCAL_MANUAL
@ LOCAL_MANUAL
Definition: net.h:194
CNode::ConnectedThroughNetwork
Network ConnectedThroughNetwork() const
Get network the peer connected through.
Definition: net.cpp:580
CNode::TxRelay::m_last_mempool_req
std::atomic< std::chrono::seconds > m_last_mempool_req
Definition: net.h:559
CNodeStats::m_permissionFlags
NetPermissionFlags m_permissionFlags
Definition: net.h:262
CNodeStats::m_addr_name
std::string m_addr_name
Definition: net.h:251
CNode::cs_vRecv
Mutex cs_vRecv
Definition: net.h:424
CConnman::DumpAddresses
void DumpAddresses()
Definition: net.cpp:1805
CNode::TxRelay
Definition: net.h:542
CConnman::vWhitelistedRange
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:1099
ip
static CService ip(uint32_t i)
Definition: denialofservice_tests.cpp:30
CConnman::addrman
AddrMan & addrman
Definition: net.h:1107
CConnman::m_start_extra_block_relay_peers
std::atomic_bool m_start_extra_block_relay_peers
flag for initiating extra block-relay-only peer connections.
Definition: net.h:1225
CConnman::Options::vWhitelistedRange
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:770
AddedNodeInfo::strAddedNode
std::string strAddedNode
Definition: net.h:92
CNode::GetCommonVersion
int GetCommonVersion() const
Definition: net.h:625
NodeEvictionCandidate::id
NodeId id
Definition: net.h:1279
CNode::AddRef
CNode * AddRef()
Definition: net.h:634
CConnman::NodesSnapshot
RAII helper to atomically create a copy of m_nodes and add a reference to each of the nodes.
Definition: net.h:1237
CConnman::SocketSendData
size_t SocketSendData(CNode &node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend)
Definition: net.cpp:803
CNode::m_last_recv
std::atomic< std::chrono::seconds > m_last_recv
Definition: net.h:435
CConnman::m_banman
BanMan * m_banman
Pointer to this node's banman.
Definition: net.h:1177
compat.h
CConnman::AlreadyConnectedToAddress
bool AlreadyConnectedToAddress(const CAddress &addr)
Determine whether we're already connected to a given address, in order to avoid initiating duplicate ...
Definition: net.cpp:373
NetEventsInterface::SendMessages
virtual bool SendMessages(CNode *pnode) EXCLUSIVE_LOCKS_REQUIRED(pnode -> cs_sendProcessing)=0
Send queued protocol messages to a given node.
CNode::TxRelay::m_next_send_feefilter
std::chrono::microseconds m_next_send_feefilter
Definition: net.h:565
CNodeStats::fRelayTxes
bool fRelayTxes
Definition: net.h:244
CConnman::threadOpenConnections
std::thread threadOpenConnections
Definition: net.h:1212
CNode::m_tx_relay
std::unique_ptr< TxRelay > m_tx_relay
Definition: net.h:569
MAX_PROTOCOL_MESSAGE_LENGTH
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:58
span.h
CConnman::ShouldRunInactivityChecks
bool ShouldRunInactivityChecks(const CNode &node, std::chrono::seconds now) const
Return true if we should disconnect the peer for failing an inactivity check.
Definition: net.cpp:1339
netaddress.h
CNode::m_sock_mutex
Mutex m_sock_mutex
Definition: net.h:423
CNode::m_conn_type
const ConnectionType m_conn_type
Definition: net.h:682
SelectNodeToEvict
std::optional< NodeId > SelectNodeToEvict(std::vector< NodeEvictionCandidate > &&vEvictionCandidates)
Select an inbound peer to evict after filtering out (protecting) peers having distinct,...
Definition: net.cpp:999
CConnman::ForNode
bool ForNode(NodeId id, std::function< bool(CNode *pnode)> func)
Definition: net.cpp:3067
CNode::TxRelay::lastSentFeeFilter
CAmount lastSentFeeFilter
Definition: net.h:564
SetReachable
void SetReachable(enum Network net, bool reachable)
Mark a network as reachable or unreachable (no automatic connects to it)
Definition: net.cpp:292
CNetMessage::m_time
std::chrono::microseconds m_time
time of message receipt
Definition: net.h:286
AddedNodeInfo::fInbound
bool fInbound
Definition: net.h:95
CSerializedNetMsg
Definition: net.h:101
CNode::GUARDED_BY
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:432
CNode::fSuccessfullyConnected
std::atomic_bool fSuccessfullyConnected
fSuccessfullyConnected is set to true on receiving VERACK from the peer.
Definition: net.h:460
CConnman::Options::onion_binds
std::vector< CService > onion_binds
Definition: net.h:773
CConnman::CachedAddrResponse
Cache responses to addr requests to minimize privacy leak.
Definition: net.h:1124
CConnman::GetNewNodeId
NodeId GetNewNodeId()
Definition: net.cpp:2499
GetListenPort
uint16_t GetListenPort()
Definition: net.cpp:127
CConnman::fAddressesInitialized
bool fAddressesInitialized
Definition: net.h:1106
CConnman::ListenSocket
Definition: net.h:952
V1TransportDeserializer::V1TransportDeserializer
V1TransportDeserializer(const CChainParams &chain_params, const NodeId node_id, int nTypeIn, int nVersionIn)
Definition: net.h:346
AddedNodeInfo
Definition: net.h:90
CConnman::Options::m_peer_connect_timeout
int64_t m_peer_connect_timeout
Definition: net.h:768
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
CNode::TxRelay::setInventoryTxToSend
std::set< uint256 > setInventoryTxToSend
Definition: net.h:552
CNodeStats::minFeeFilter
CAmount minFeeFilter
Definition: net.h:265
CNode::m_bip152_highbandwidth_to
std::atomic< bool > m_bip152_highbandwidth_to
Definition: net.h:538
TransportDeserializer::~TransportDeserializer
virtual ~TransportDeserializer()
Definition: net.h:313
CConnman::Options::m_use_addrman_outgoing
bool m_use_addrman_outgoing
Definition: net.h:777
GUARDED_BY
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(g_maplocalhost_mutex)
CConnman::GetTotalBytesRecv
uint64_t GetTotalBytesRecv() const
Definition: net.cpp:2971
TransportDeserializer::Read
virtual int Read(Span< const uint8_t > &msg_bytes)=0
read and deserialize data, advances msg_bytes data pointer
CConnman::SocketHandlerConnected
void SocketHandlerConnected(const std::vector< CNode * > &nodes, const std::set< SOCKET > &recv_set, const std::set< SOCKET > &send_set, const std::set< SOCKET > &error_set)
Do the read/write for connected sockets that are ready for IO.
Definition: net.cpp:1570
DEFAULT_FIXEDSEEDS
static constexpr bool DEFAULT_FIXEDSEEDS
Definition: net.h:84
CConnman::Options::m_max_outbound_block_relay
int m_max_outbound_block_relay
Definition: net.h:759
Shuffle
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
Definition: random.h:243
CSubNet
Definition: netaddress.h:475
CConnman::ListenSocket::AddSocketPermissionFlags
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:955
V1TransportDeserializer::hasher
CHash256 hasher
Definition: net.h:321
CNode::IsAddrFetchConn
bool IsAddrFetchConn() const
Definition: net.h:502
CConnman::InitBinds
bool InitBinds(const Options &options)
Definition: net.cpp:2527
CConnman::SocketHandlerListening
void SocketHandlerListening(const std::set< SOCKET > &recv_set)
Accept incoming connections, one from each read-ready listening socket.
Definition: net.cpp:1662
CNode::cs_vProcessMsg
RecursiveMutex cs_vProcessMsg
Definition: net.h:426
CNodeStats::cleanSubVer
std::string cleanSubVer
Definition: net.h:253
g_maplocalhost_mutex
Mutex g_maplocalhost_mutex
Definition: net.cpp:116
CNode::m_addr_local_mutex
Mutex m_addr_local_mutex
Definition: net.h:706
CConnman::threadMessageHandler
std::thread threadMessageHandler
Definition: net.h:1213
TransportSerializer::prepareForTransport
virtual void prepareForTransport(CSerializedNetMsg &msg, std::vector< unsigned char > &header)=0
uint256
256-bit opaque blob.
Definition: uint256.h:126
MAX_FEELER_CONNECTIONS
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:68
CNetMessage::m_recv
CDataStream m_recv
received message data
Definition: net.h:285
LogPrint
#define LogPrint(category,...)
Definition: logging.h:192
CConnman::Options::nReceiveFloodSize
unsigned int nReceiveFloodSize
Definition: net.h:766
CNode::IsBlockOnlyConn
bool IsBlockOnlyConn() const
Definition: net.h:494
CConnman::nSeed0
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:1186
ConnectionType::FEELER
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
CNodeStats::m_conn_type
ConnectionType m_conn_type
Definition: net.h:275
CConnman::~CConnman
~CConnman()
Definition: net.cpp:2744
CConnman::m_peer_connect_timeout
std::chrono::seconds m_peer_connect_timeout
Definition: net.h:1095
CConnman::Options
Definition: net.h:754
CNode::GUARDED_BY
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Definition: net.h:420
CConnman::GetReceiveFloodSize
unsigned int GetReceiveFloodSize() const
Definition: net.cpp:2987
CNode::grantOutbound
CSemaphoreGrant grantOutbound
Definition: net.h:464
CConnman::GetMaxOutboundTarget
uint64_t GetMaxOutboundTarget() const
Definition: net.cpp:2917
IsReachable
bool IsReachable(enum Network net)
Definition: net.cpp:300
CNode::TxRelay::minFeeFilter
std::atomic< CAmount > minFeeFilter
Minimum fee rate with which to filter inv's to this node.
Definition: net.h:563
NodeEvictionCandidate::m_is_local
bool m_is_local
Definition: net.h:1289
NetEventsInterface::ProcessMessages
virtual bool ProcessMessages(CNode *pnode, std::atomic< bool > &interrupt)=0
Process protocol messages received from a given node.
CConnman::Options::nMaxConnections
int nMaxConnections
Definition: net.h:757
CDataStream::SetVersion
void SetVersion(int n)
Definition: streams.h:276
NODE_NONE
@ NODE_NONE
Definition: protocol.h:274
CSerializedNetMsg::CSerializedNetMsg
CSerializedNetMsg()=default
BanMan
Definition: banman.h:58
CDataStream::resize
void resize(size_type n, value_type c=value_type{})
Definition: streams.h:238
CNodeStats::nTimeOffset
int64_t nTimeOffset
Definition: net.h:250
CConnman::Options::nSendBufferMaxSize
unsigned int nSendBufferMaxSize
Definition: net.h:765
CConnman::ListenSocket::m_permissions
NetPermissionFlags m_permissions
Definition: net.h:962
CNode::nKeyedNetGroup
const uint64_t nKeyedNetGroup
Definition: net.h:467
CConnman::nLastNodeId
std::atomic< NodeId > nLastNodeId
Definition: net.h:1115
CConnman::RemoveAddedNode
bool RemoveAddedNode(const std::string &node)
Definition: net.cpp:2813
fListen
bool fListen
Definition: net.cpp:115
CConnman::m_nodes_mutex
RecursiveMutex m_nodes_mutex
Definition: net.h:1114
V1TransportDeserializer::hdrbuf
CDataStream hdrbuf
Definition: net.h:324
CNode::IsManualConn
bool IsManualConn() const
Definition: net.h:490
CConnman::Options::uiInterface
CClientUIInterface * uiInterface
Definition: net.h:762
CNode::SetAddrLocal
void SetAddrLocal(const CService &addrLocalIn) LOCKS_EXCLUDED(m_addr_local_mutex)
May not be called more than once.
Definition: net.cpp:570
AddedNodeInfo::resolvedAddress
CService resolvedAddress
Definition: net.h:93
CConnman::GetExtraFullOutboundCount
int GetExtraFullOutboundCount() const
Definition: net.cpp:1849
fDiscover
bool fDiscover
Definition: net.cpp:114
CConnman::GUARDED_BY
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1087
CConnman::GetCurrentBlockRelayOnlyConns
std::vector< CAddress > GetCurrentBlockRelayOnlyConns() const
Return vector of current BLOCK_RELAY peers.
Definition: net.cpp:2151
CConnman::nSeed1
const uint64_t nSeed1
Definition: net.h:1186
CConnman
Definition: net.h:750
CConnman::threadI2PAcceptIncoming
std::thread threadI2PAcceptIncoming
Definition: net.h:1214
V1TransportDeserializer::Reset
void Reset()
Definition: net.h:334
CNode::id
const NodeId id
Definition: net.h:680
CConnman::Options::nMaxFeeler
int nMaxFeeler
Definition: net.h:761
CConnman::StopNodes
void StopNodes()
Definition: net.cpp:2704
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 This t...
Definition: net.h:1219
CNode::cs_sendProcessing
RecursiveMutex cs_sendProcessing
Definition: net.h:430
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:745
LocalServiceInfo::nScore
int nScore
Definition: net.h:229
GetLocal
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=nullptr)
Definition: net.cpp:133
CNodeStats::nSendBytes
uint64_t nSendBytes
Definition: net.h:258
CAddress
A CService with information about it as peer.
Definition: protocol.h:358
MAX_BLOCK_RELAY_ONLY_CONNECTIONS
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:66
LOCKS_EXCLUDED
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
CMessageHeader
Message header.
Definition: protocol.h:30
CNodeStats::m_bip152_highbandwidth_to
bool m_bip152_highbandwidth_to
Definition: net.h:255
CConnman::SetNetworkActive
void SetNetworkActive(bool active)
Definition: net.cpp:2474
CNode::nLocalHostNonce
const uint64_t nLocalHostNonce
Definition: net.h:681
CConnman::NodeFullyConnected
static bool NodeFullyConnected(const CNode *pnode)
Definition: net.cpp:3021
DEFAULT_WHITELISTRELAY
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: net.h:47
LocalServiceInfo
Definition: net.h:228
ConnectionTypeAsString
std::string ConnectionTypeAsString(ConnectionType conn_type)
Convert ConnectionType enum to a string value.
Definition: net.cpp:543
NetPermissions::AddFlag
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
Definition: net_permissions.h:58
CConnman::m_added_nodes_mutex
Mutex m_added_nodes_mutex
Definition: net.h:1111
CNetMessage::m_message_size
uint32_t m_message_size
size of the payload
Definition: net.h:287
CConnman::Options::m_msgproc
NetEventsInterface * m_msgproc
Definition: net.h:763
CNode::m_inbound_onion
const bool m_inbound_onion
Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
Definition: net.h:445
CNetMessage::CNetMessage
CNetMessage(CDataStream &&recv_in)
Definition: net.h:291
MAX_ADDNODE_CONNECTIONS
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:64
CDataStream::clear
void clear()
Definition: streams.h:242
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
CNode::m_last_send
std::atomic< std::chrono::seconds > m_last_send
Definition: net.h:434
LOCK
#define LOCK(cs)
Definition: sync.h:226
V1TransportDeserializer::SetVersion
void SetVersion(int nVersionIn) override
Definition: net.h:361
CNode::m_prefer_evict
bool m_prefer_evict
Definition: net.h:453
ConnectionType::ADDR_FETCH
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
CConnman::GetExtraBlockRelayCount
int GetExtraBlockRelayCount() const
Definition: net.cpp:1863
CNetMessage::SetVersion
void SetVersion(int nVersionIn)
Definition: net.h:293
i2p.h
NetEventsInterface::FinalizeNode
virtual void FinalizeNode(const CNode &node)=0
Handle removal of a peer (clear state)
std
Definition: setup_common.h:33
CConnman::ForEachNode
void ForEachNode(const NodeFn &func)
Definition: net.h:834
CNode::m_subver_mutex
Mutex m_subver_mutex
Definition: net.h:447
CNode::CloseSocketDisconnect
void CloseSocketDisconnect()
Definition: net.cpp:527
CNode::ConnectionTypeAsString
std::string ConnectionTypeAsString() const
Definition: net.h:671
V1TransportDeserializer
Definition: net.h:316
TransportSerializer
The TransportSerializer prepares messages for the network transport.
Definition: net.h:381
CNode::TxRelay::PT_GUARDED_BY
std::unique_ptr< CBloomFilter > pfilter PT_GUARDED_BY(cs_filter) GUARDED_BY(cs_filter)
Definition: net.h:549
CNetMessage
Transport protocol agnostic message container.
Definition: net.h:283
LOCAL_IF
@ LOCAL_IF
Definition: net.h:191
NodeEvictionCandidate::prefer_evict
bool prefer_evict
Definition: net.h:1288
DEFAULT_MAX_UPLOAD_TARGET
static const std::string DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:74
CConnman::SocketHandler
void SocketHandler()
Check connected and listening sockets for IO readiness and process them accordingly.
Definition: net.cpp:1547
CNode::m_last_ping_time
std::atomic< std::chrono::microseconds > m_last_ping_time
Last measured round-trip time.
Definition: net.h:585
CConnman::DisconnectNodes
void DisconnectNodes()
Definition: net.cpp:1274
CNodeStats::m_connected
std::chrono::seconds m_connected
Definition: net.h:249
mapMsgCmdSize
std::map< std::string, uint64_t > mapMsgCmdSize
Definition: net.h:237
FEELER_INTERVAL
static constexpr auto FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes.
Definition: net.h:54
CConnman::GetAddedNodeInfo
std::vector< AddedNodeInfo > GetAddedNodeInfo() const
Definition: net.cpp:2164
NET_MESSAGE_COMMAND_OTHER
const std::string NET_MESSAGE_COMMAND_OTHER
Definition: net.cpp:106
CNode::CopyStats
void CopyStats(CNodeStats &stats)
Definition: net.cpp:587
CNode::GetLocalNonce
uint64_t GetLocalNonce() const
Definition: net.h:599
CNode::m_addr_name
const std::string m_addr_name
Definition: net.h:443
CConnman::nTotalBytesRecv
std::atomic< uint64_t > nTotalBytesRecv
Definition: net.h:1086
LocalServiceInfo::nPort
uint16_t nPort
Definition: net.h:230
hash.h
CConnman::Options::m_specified_outgoing
std::vector< std::string > m_specified_outgoing
Definition: net.h:778
CConnman::Stop
void Stop()
Definition: net.h:816
DEFAULT_PEER_CONNECT_TIMEOUT
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:78
CNode::HasPermission
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:454
node
Definition: init.h:22
NUM_FDS_MESSAGE_CAPTURE
static const int NUM_FDS_MESSAGE_CAPTURE
Number of file descriptors required for message capture.
Definition: net.h:80
CConnman::AddNode
bool AddNode(const std::string &node)
Definition: net.cpp:2802
CNode::IsInboundConn
bool IsInboundConn() const
Definition: net.h:506
CNode::operator=
CNode & operator=(const CNode &)=delete
CNode::vRecvMsg
std::list< CNetMessage > vRecvMsg
Definition: net.h:702
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:184
V1TransportDeserializer::Read
int Read(Span< const uint8_t > &msg_bytes) override
read and deserialize data, advances msg_bytes data pointer
Definition: net.h:366
V1TransportSerializer::prepareForTransport
void prepareForTransport(CSerializedNetMsg &msg, std::vector< unsigned char > &header) override
Definition: net.cpp:790
CNode::GUARDED_BY
std::shared_ptr< Sock > m_sock GUARDED_BY(m_sock_mutex)
Socket used for communication with the node.
CConnman::threadOpenAddedConnections
std::thread threadOpenAddedConnections
Definition: net.h:1211
CConnman::GetNetworkActive
bool GetNetworkActive() const
Definition: net.h:823
CConnman::GetUseAddrmanOutgoing
bool GetUseAddrmanOutgoing() const
Definition: net.h:824
CConnman::CachedAddrResponse::m_cache_entry_expiration
std::chrono::microseconds m_cache_entry_expiration
Definition: net.h:1126
CHash256
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
Definition: hash.h:24
V1TransportDeserializer::m_node_id
const NodeId m_node_id
Definition: net.h:320
CConnman::NodeFn
std::function< void(CNode *)> NodeFn
Definition: net.h:833
CNode::m_min_ping_time
std::atomic< std::chrono::microseconds > m_min_ping_time
Lowest measured round-trip time.
Definition: net.h:589
CConnman::Options::m_max_outbound_full_relay
int m_max_outbound_full_relay
Definition: net.h:758
ConnectionType::BLOCK_RELAY
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
netbase.h
CConnman::GUARDED_BY
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent)
Definition: net.h:1091
RemoveLocal
void RemoveLocal(const CService &addr)
Definition: net.cpp:285
LOCAL_NONE
@ LOCAL_NONE
Definition: net.h:190
CNode::ReceiveMsgBytes
bool ReceiveMsgBytes(Span< const uint8_t > msg_bytes, bool &complete)
Receive bytes from the buffer and deserialize them into messages.
Definition: net.cpp:643
CConnman::CConnmanTest
friend struct CConnmanTest
Definition: net.h:1270
CNodeStats::nRecvBytes
uint64_t nRecvBytes
Definition: net.h:260
CConnman::ThreadI2PAcceptIncoming
void ThreadI2PAcceptIncoming()
Definition: net.cpp:2323
ConnectionDirection
ConnectionDirection
Definition: netbase.h:32
DEFAULT_WHITELISTFORCERELAY
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: net.h:49
CConnman::ThreadOpenConnections
void ThreadOpenConnections(std::vector< std::string > connect)
Definition: net.cpp:1877
CConnman::semOutbound
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:1159
CNode::nVersion
std::atomic< int > nVersion
Definition: net.h:446
BCLog::NET
@ NET
Definition: logging.h:39
CConnman::semAddnode
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:1160
CConnman::GetTotalBytesSent
uint64_t GetTotalBytesSent() const
Definition: net.cpp:2976
CConnman::flagInterruptMsgProc
std::atomic< bool > flagInterruptMsgProc
Definition: net.h:1193
DEFAULT_BLOCKSONLY
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:76
CConnman::m_msgproc
NetEventsInterface * m_msgproc
Definition: net.h:1175
CConnman::threadDNSAddressSeed
std::thread threadDNSAddressSeed
Definition: net.h:1209
CConnman::Init
void Init(const Options &connOptions)
Definition: net.h:783
DEFAULT_DNSSEED
static constexpr bool DEFAULT_DNSSEED
Definition: net.h:83
LOCAL_BIND
@ LOCAL_BIND
Definition: net.h:192
CConnman::NodesSnapshot::Nodes
const std::vector< CNode * > & Nodes() const
Definition: net.h:1261
V1TransportDeserializer::m_chain_params
const CChainParams & m_chain_params
Definition: net.h:319
CNode::fClient
bool fClient
Definition: net.h:457
CConnman::ListenSocket::sock
std::shared_ptr< Sock > sock
Definition: net.h:954
CConnman::m_i2p_sam_session
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session
I2P SAM session.
Definition: net.h:1207
CNode::IsFullOutboundConn
bool IsFullOutboundConn() const
Definition: net.h:486
CConnman::threadSocketHandler
std::thread threadSocketHandler
Definition: net.h:1210
CConnman::CheckIncomingNonce
bool CheckIncomingNonce(uint64_t nonce)
Definition: net.cpp:378
CConnman::m_max_outbound_block_relay
int m_max_outbound_block_relay
Definition: net.h:1168
CNode::m_greatest_common_version
std::atomic< int > m_greatest_common_version
Definition: net.h:683
CNode::TxRelay::GUARDED_BY
bool fSendMempool GUARDED_BY(cs_tx_inventory)
Definition: net.h:557
CConnman::NodesSnapshot::m_nodes_copy
std::vector< CNode * > m_nodes_copy
Definition: net.h:1267
amount.h
CThreadInterrupt
Definition: threadinterrupt.h:19
CNode::TxRelay::GUARDED_BY
bool fRelayTxes GUARDED_BY(cs_filter)
Definition: net.h:548
ConnectionType
ConnectionType
Different types of connections to a peer.
Definition: net.h:121
TransportDeserializer::Complete
virtual bool Complete() const =0
IsLocal
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:323
CNode::fPauseSend
std::atomic_bool fPauseSend
Definition: net.h:469
CRollingBloomFilter
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:108
CNodeStats::nServices
ServiceFlags nServices
Definition: net.h:243
CNodeStats
Definition: net.h:239
nonce
unsigned int nonce
Definition: miner_tests.cpp:57
V1TransportDeserializer::readHeader
int readHeader(Span< const uint8_t > msg_bytes)
Definition: net.cpp:688
sock.h
strSubVersion
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:119
GetLocalAddrForPeer
std::optional< CAddress > GetLocalAddrForPeer(CNode *pnode)
Returns a local address that we should advertise to this peer.
Definition: net.cpp:210
CaptureMessage
void CaptureMessage(const CAddress &addr, const std::string &msg_type, const Span< const unsigned char > &data, bool is_incoming)
Dump binary message to file, with timestamp.
Definition: net.cpp:3092
MAX_SUBVERSION_LENGTH
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
Definition: net.h:60
NodeEvictionCandidate::m_connected
std::chrono::seconds m_connected
Definition: net.h:1280
CConnman::m_use_addrman_outgoing
bool m_use_addrman_outgoing
Definition: net.h:1173
CConnman::AddWhitelistPermissionFlags
void AddWhitelistPermissionFlags(NetPermissionFlags &flags, const CNetAddr &addr) const
Definition: net.cpp:537
CConnman::NodesSnapshot::NodesSnapshot
NodesSnapshot(const CConnman &connman, bool shuffle)
Definition: net.h:1240
CConnman::Options::vWhiteBinds
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:771
CConnman::fNetworkActive
std::atomic< bool > fNetworkActive
Definition: net.h:1105
CConnman::interruptNet
CThreadInterrupt interruptNet
This is signaled when network activity should cease.
Definition: net.h:1201
CNodeStats::m_bip152_highbandwidth_from
bool m_bip152_highbandwidth_from
Definition: net.h:256
CConnman::GetDeterministicRandomizer
CSipHasher GetDeterministicRandomizer(uint64_t id) const
Get a unique deterministic randomizer.
Definition: net.cpp:3080
CConnman::GetNodeCount
size_t GetNodeCount(ConnectionDirection) const
Definition: net.cpp:2825
CConnman::nMaxAddnode
int nMaxAddnode
Definition: net.h:1170
CConnman::nMaxConnections
int nMaxConnections
Definition: net.h:1161
FastRandomContext
Fast randomness source.
Definition: random.h:131
CConnman::GetAddresses
std::vector< CAddress > GetAddresses(size_t max_addresses, size_t max_pct, std::optional< Network > network) const
Return all or many randomly selected addresses, optionally by network.
Definition: net.cpp:2750
CConnman::PushMessage
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg)
Definition: net.cpp:3026
CConnman::BindListenPort
bool BindListenPort(const CService &bindAddr, bilingual_str &strError, NetPermissionFlags permissions)
Definition: net.cpp:2362
CNetMessage::m_raw_message_size
uint32_t m_raw_message_size
used wire size of the message (including header/checksum)
Definition: net.h:288
V1TransportDeserializer::nDataPos
unsigned int nDataPos
Definition: net.h:328
CConnman::Options::m_banman
BanMan * m_banman
Definition: net.h:764
GetLocalAddress
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
Definition: net.cpp:183
EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL
Run the extra block-relay-only connection loop once every 5 minutes.
Definition: net.h:56
CSerializedNetMsg::operator=
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
Span::subspan
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
Definition: span.h:194
V1TransportDeserializer::nHdrPos
unsigned int nHdrPos
Definition: net.h:327
INIT_PROTO_VERSION
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
Definition: version.h:15
CNode::fPauseRecv
std::atomic_bool fPauseRecv
Definition: net.h:468
CConnman::RecordBytesSent
void RecordBytesSent(uint64_t bytes)
Definition: net.cpp:2901
TransportDeserializer::SetVersion
virtual void SetVersion(int version)=0
net_permissions.h
CNode::TxRelay::nNextInvSend
std::chrono::microseconds nNextInvSend
Definition: net.h:560
CConnman::GetOutboundTargetBytesLeft
uint64_t GetOutboundTargetBytesLeft() const
response the bytes left in the current max outbound cycle in case of no limit, it will always respons...
Definition: net.cpp:2962
DEFAULT_LISTEN
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:70
V1TransportDeserializer::GetMessage
CNetMessage GetMessage(std::chrono::microseconds time, bool &reject_message) override
Definition: net.cpp:753
IsPeerAddrLocalGood
bool IsPeerAddrLocalGood(CNode *pnode)
Definition: net.cpp:203
CConnman::DeleteNode
void DeleteNode(CNode *pnode)
Definition: net.cpp:2737
CNode::addrBind
const CAddress addrBind
Definition: net.h:442
CConnman::ForEachNode
void ForEachNode(const NodeFn &func) const
Definition: net.h:843
NodeEvictionCandidate::fRelevantServices
bool fRelevantServices
Definition: net.h:1284