Bitcoin Core  26.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-2022 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 <bip324.h>
10 #include <chainparams.h>
11 #include <common/bloom.h>
12 #include <compat/compat.h>
13 #include <consensus/amount.h>
14 #include <crypto/siphash.h>
15 #include <hash.h>
16 #include <i2p.h>
18 #include <net_permissions.h>
19 #include <netaddress.h>
20 #include <netbase.h>
21 #include <netgroup.h>
22 #include <node/connection_types.h>
23 #include <node/protocol_version.h>
24 #include <policy/feerate.h>
25 #include <protocol.h>
26 #include <random.h>
27 #include <span.h>
28 #include <streams.h>
29 #include <sync.h>
30 #include <uint256.h>
31 #include <util/check.h>
32 #include <util/sock.h>
33 #include <util/threadinterrupt.h>
34 
35 #include <atomic>
36 #include <condition_variable>
37 #include <cstdint>
38 #include <deque>
39 #include <functional>
40 #include <list>
41 #include <map>
42 #include <memory>
43 #include <optional>
44 #include <queue>
45 #include <thread>
46 #include <unordered_set>
47 #include <vector>
48 
49 class AddrMan;
50 class BanMan;
51 class CChainParams;
52 class CNode;
53 class CScheduler;
54 struct bilingual_str;
55 
57 static const bool DEFAULT_WHITELISTRELAY = true;
59 static const bool DEFAULT_WHITELISTFORCERELAY = false;
60 
62 static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
64 static constexpr auto FEELER_INTERVAL = 2min;
66 static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min;
68 static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
70 static const unsigned int MAX_SUBVERSION_LENGTH = 256;
74 static const int MAX_ADDNODE_CONNECTIONS = 8;
76 static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2;
78 static const int MAX_FEELER_CONNECTIONS = 1;
80 static const bool DEFAULT_LISTEN = true;
82 static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
84 static const std::string DEFAULT_MAX_UPLOAD_TARGET{"0M"};
86 static const bool DEFAULT_BLOCKSONLY = false;
88 static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
90 static const int NUM_FDS_MESSAGE_CAPTURE = 1;
92 static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL{24};
93 
94 static constexpr bool DEFAULT_FORCEDNSSEED{false};
95 static constexpr bool DEFAULT_DNSSEED{true};
96 static constexpr bool DEFAULT_FIXEDSEEDS{true};
97 static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
98 static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
99 
100 static constexpr bool DEFAULT_V2_TRANSPORT{true};
101 
102 typedef int64_t NodeId;
103 
105  std::string m_added_node;
107 };
108 
113  bool fInbound;
114 };
115 
116 class CNodeStats;
117 class CClientUIInterface;
118 
120  CSerializedNetMsg() = default;
123  // No implicit copying, only moves.
126 
128  {
129  CSerializedNetMsg copy;
130  copy.data = data;
131  copy.m_type = m_type;
132  return copy;
133  }
134 
135  std::vector<unsigned char> data;
136  std::string m_type;
137 
139  size_t GetMemoryUsage() const noexcept;
140 };
141 
148 void Discover();
149 
150 uint16_t GetListenPort();
151 
152 enum
153 {
154  LOCAL_NONE, // unknown
155  LOCAL_IF, // address a local interface listens on
156  LOCAL_BIND, // address explicit bound to
157  LOCAL_MAPPED, // address reported by UPnP or NAT-PMP
158  LOCAL_MANUAL, // address explicitly specified (-externalip=)
159 
160  LOCAL_MAX
161 };
162 
164 std::optional<CService> GetLocalAddrForPeer(CNode& node);
165 
166 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
167 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
168 void RemoveLocal(const CService& addr);
169 bool SeenLocal(const CService& addr);
170 bool IsLocal(const CService& addr);
171 CService GetLocalAddress(const CNode& peer);
172 
173 extern bool fDiscover;
174 extern bool fListen;
175 
177 extern std::string strSubVersion;
178 
180  int nScore;
181  uint16_t nPort;
182 };
183 
185 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
186 
187 extern const std::string NET_MESSAGE_TYPE_OTHER;
188 using mapMsgTypeSize = std::map</* message type */ std::string, /* total bytes */ uint64_t>;
189 
191 {
192 public:
194  std::chrono::seconds m_last_send;
195  std::chrono::seconds m_last_recv;
196  std::chrono::seconds m_last_tx_time;
197  std::chrono::seconds m_last_block_time;
198  std::chrono::seconds m_connected;
199  int64_t nTimeOffset;
200  std::string m_addr_name;
201  int nVersion;
202  std::string cleanSubVer;
203  bool fInbound;
204  // We requested high bandwidth connection to peer
206  // Peer requested high bandwidth connection
209  uint64_t nSendBytes;
211  uint64_t nRecvBytes;
214  std::chrono::microseconds m_last_ping_time;
215  std::chrono::microseconds m_min_ping_time;
216  // Our address, as reported by the peer
217  std::string addrLocal;
218  // Address of this peer
220  // Bind address of our side of the connection
222  // Network the peer connected through
224  uint32_t m_mapped_as;
229  std::string m_session_id;
230 };
231 
232 
238 {
239 public:
241  std::chrono::microseconds m_time{0};
242  uint32_t m_message_size{0};
243  uint32_t m_raw_message_size{0};
244  std::string m_type;
245 
246  explicit CNetMessage(DataStream&& recv_in) : m_recv(std::move(recv_in)) {}
247  // Only one CNetMessage object will exist for the same message on either
248  // the receive or processing queue. For performance reasons we therefore
249  // delete the copy constructor and assignment operator to avoid the
250  // possibility of copying CNetMessage objects.
251  CNetMessage(CNetMessage&&) = default;
252  CNetMessage(const CNetMessage&) = delete;
254  CNetMessage& operator=(const CNetMessage&) = delete;
255 };
256 
258 class Transport {
259 public:
260  virtual ~Transport() {}
261 
262  struct Info
263  {
265  std::optional<uint256> session_id;
266  };
267 
269  virtual Info GetInfo() const noexcept = 0;
270 
271  // 1. Receiver side functions, for decoding bytes received on the wire into transport protocol
272  // agnostic CNetMessage (message type & payload) objects.
273 
275  virtual bool ReceivedMessageComplete() const = 0;
276 
283  virtual bool ReceivedBytes(Span<const uint8_t>& msg_bytes) = 0;
284 
292  virtual CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) = 0;
293 
294  // 2. Sending side functions, for converting messages into bytes to be sent over the wire.
295 
302  virtual bool SetMessageToSend(CSerializedNetMsg& msg) noexcept = 0;
303 
311  using BytesToSend = std::tuple<
312  Span<const uint8_t> /*to_send*/,
313  bool /*more*/,
314  const std::string& /*m_type*/
315  >;
316 
352  virtual BytesToSend GetBytesToSend(bool have_next_message) const noexcept = 0;
353 
360  virtual void MarkBytesSent(size_t bytes_sent) noexcept = 0;
361 
363  virtual size_t GetSendMemoryUsage() const noexcept = 0;
364 
365  // 3. Miscellaneous functions.
366 
368  virtual bool ShouldReconnectV1() const noexcept = 0;
369 };
370 
371 class V1Transport final : public Transport
372 {
373 private:
375  const NodeId m_node_id; // Only for logging
376  mutable Mutex m_recv_mutex;
377  mutable CHash256 hasher GUARDED_BY(m_recv_mutex);
378  mutable uint256 data_hash GUARDED_BY(m_recv_mutex);
379  bool in_data GUARDED_BY(m_recv_mutex); // parsing header (false) or data (true)
380  DataStream hdrbuf GUARDED_BY(m_recv_mutex){}; // partially received header
381  CMessageHeader hdr GUARDED_BY(m_recv_mutex); // complete header
382  DataStream vRecv GUARDED_BY(m_recv_mutex){}; // received message data
383  unsigned int nHdrPos GUARDED_BY(m_recv_mutex);
384  unsigned int nDataPos GUARDED_BY(m_recv_mutex);
385 
386  const uint256& GetMessageHash() const EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
387  int readHeader(Span<const uint8_t> msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
388  int readData(Span<const uint8_t> msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
389 
390  void Reset() EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex) {
391  AssertLockHeld(m_recv_mutex);
392  vRecv.clear();
393  hdrbuf.clear();
394  hdrbuf.resize(24);
395  in_data = false;
396  nHdrPos = 0;
397  nDataPos = 0;
398  data_hash.SetNull();
399  hasher.Reset();
400  }
401 
402  bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
403  {
404  AssertLockHeld(m_recv_mutex);
405  if (!in_data) return false;
406  return hdr.nMessageSize == nDataPos;
407  }
408 
412  std::vector<uint8_t> m_header_to_send GUARDED_BY(m_send_mutex);
414  CSerializedNetMsg m_message_to_send GUARDED_BY(m_send_mutex);
416  bool m_sending_header GUARDED_BY(m_send_mutex) {false};
418  size_t m_bytes_sent GUARDED_BY(m_send_mutex) {0};
419 
420 public:
421  explicit V1Transport(const NodeId node_id) noexcept;
422 
423  bool ReceivedMessageComplete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
424  {
425  AssertLockNotHeld(m_recv_mutex);
426  return WITH_LOCK(m_recv_mutex, return CompleteInternal());
427  }
428 
429  Info GetInfo() const noexcept override;
430 
431  bool ReceivedBytes(Span<const uint8_t>& msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
432  {
433  AssertLockNotHeld(m_recv_mutex);
434  LOCK(m_recv_mutex);
435  int ret = in_data ? readData(msg_bytes) : readHeader(msg_bytes);
436  if (ret < 0) {
437  Reset();
438  } else {
439  msg_bytes = msg_bytes.subspan(ret);
440  }
441  return ret >= 0;
442  }
443 
444  CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
445 
446  bool SetMessageToSend(CSerializedNetMsg& msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
447  BytesToSend GetBytesToSend(bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
448  void MarkBytesSent(size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
449  size_t GetSendMemoryUsage() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
450  bool ShouldReconnectV1() const noexcept override { return false; }
451 };
452 
453 class V2Transport final : public Transport
454 {
455 private:
459  static constexpr std::array<std::byte, 0> VERSION_CONTENTS = {};
460 
463  static constexpr size_t V1_PREFIX_LEN = 16;
464 
465  // The sender side and receiver side of V2Transport are state machines that are transitioned
466  // through, based on what has been received. The receive state corresponds to the contents of,
467  // and bytes received to, the receive buffer. The send state controls what can be appended to
468  // the send buffer and what can be sent from it.
469 
484  enum class RecvState : uint8_t {
490  KEY_MAYBE_V1,
491 
497  KEY,
498 
505  GARB_GARBTERM,
506 
515  VERSION,
516 
522  APP,
523 
528  APP_READY,
529 
533  V1,
534  };
535 
549  enum class SendState : uint8_t {
556  MAYBE_V1,
557 
563  AWAITING_KEY,
564 
571  READY,
572 
576  V1,
577  };
578 
582  const bool m_initiating;
587 
589  mutable Mutex m_recv_mutex ACQUIRED_BEFORE(m_send_mutex);
592  uint32_t m_recv_len GUARDED_BY(m_recv_mutex) {0};
594  std::vector<uint8_t> m_recv_buffer GUARDED_BY(m_recv_mutex);
596  std::vector<uint8_t> m_recv_aad GUARDED_BY(m_recv_mutex);
598  std::vector<uint8_t> m_recv_decode_buffer GUARDED_BY(m_recv_mutex);
600  RecvState m_recv_state GUARDED_BY(m_recv_mutex);
601 
604  mutable Mutex m_send_mutex ACQUIRED_AFTER(m_recv_mutex);
606  std::vector<uint8_t> m_send_buffer GUARDED_BY(m_send_mutex);
608  uint32_t m_send_pos GUARDED_BY(m_send_mutex) {0};
610  std::vector<uint8_t> m_send_garbage GUARDED_BY(m_send_mutex);
612  std::string m_send_type GUARDED_BY(m_send_mutex);
614  SendState m_send_state GUARDED_BY(m_send_mutex);
616  bool m_sent_v1_header_worth GUARDED_BY(m_send_mutex) {false};
617 
619  void SetReceiveState(RecvState recv_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
621  void SetSendState(SendState send_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex);
623  static std::optional<std::string> GetMessageType(Span<const uint8_t>& contents) noexcept;
625  size_t GetMaxBytesToProcess() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
627  void StartSendingHandshake() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex);
629  void ProcessReceivedMaybeV1Bytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex, !m_send_mutex);
631  bool ProcessReceivedKeyBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex, !m_send_mutex);
633  bool ProcessReceivedGarbageBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
635  bool ProcessReceivedPacketBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
636 
637 public:
638  static constexpr uint32_t MAX_GARBAGE_LEN = 4095;
639 
645  V2Transport(NodeId nodeid, bool initiating) noexcept;
646 
648  V2Transport(NodeId nodeid, bool initiating, const CKey& key, Span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept;
649 
650  // Receive side functions.
651  bool ReceivedMessageComplete() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
652  bool ReceivedBytes(Span<const uint8_t>& msg_bytes) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex, !m_send_mutex);
653  CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
654 
655  // Send side functions.
656  bool SetMessageToSend(CSerializedNetMsg& msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
657  BytesToSend GetBytesToSend(bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
658  void MarkBytesSent(size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
659  size_t GetSendMemoryUsage() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
660 
661  // Miscellaneous functions.
662  bool ShouldReconnectV1() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex, !m_send_mutex);
663  Info GetInfo() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
664 };
665 
667 {
669  std::unique_ptr<i2p::sam::Session> i2p_sam_session = nullptr;
670  bool prefer_evict = false;
671  size_t recv_flood_size{DEFAULT_MAXRECEIVEBUFFER * 1000};
672  bool use_v2transport = false;
673 };
674 
676 class CNode
677 {
678 public:
681  const std::unique_ptr<Transport> m_transport;
682 
684 
693  std::shared_ptr<Sock> m_sock GUARDED_BY(m_sock_mutex);
694 
696  size_t m_send_memusage GUARDED_BY(cs_vSend){0};
698  uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
700  std::deque<CSerializedNetMsg> vSendMsg GUARDED_BY(cs_vSend);
704 
705  uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
706 
707  std::atomic<std::chrono::seconds> m_last_send{0s};
708  std::atomic<std::chrono::seconds> m_last_recv{0s};
710  const std::chrono::seconds m_connected;
711  std::atomic<int64_t> nTimeOffset{0};
712  // Address of this peer
713  const CAddress addr;
714  // Bind address of our side of the connection
716  const std::string m_addr_name;
718  const std::string m_dest;
720  const bool m_inbound_onion;
721  std::atomic<int> nVersion{0};
727  std::string cleanSubVer GUARDED_BY(m_subver_mutex){};
728  const bool m_prefer_evict{false}; // This peer is preferred for eviction.
729  bool HasPermission(NetPermissionFlags permission) const {
730  return NetPermissions::HasFlag(m_permission_flags, permission);
731  }
733  std::atomic_bool fSuccessfullyConnected{false};
734  // Setting fDisconnect to true will cause the node to be disconnected the
735  // next time DisconnectNodes() runs
736  std::atomic_bool fDisconnect{false};
738  std::atomic<int> nRefCount{0};
739 
740  const uint64_t nKeyedNetGroup;
741  std::atomic_bool fPauseRecv{false};
742  std::atomic_bool fPauseSend{false};
743 
745 
747  void MarkReceivedMsgsForProcessing()
748  EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex);
749 
755  std::optional<std::pair<CNetMessage, bool>> PollMessage()
756  EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex);
757 
759  void AccountForSentBytes(const std::string& msg_type, size_t sent_bytes)
760  EXCLUSIVE_LOCKS_REQUIRED(cs_vSend)
761  {
762  mapSendBytesPerMsgType[msg_type] += sent_bytes;
763  }
764 
766  switch (m_conn_type) {
769  return true;
774  return false;
775  } // no default case, so the compiler can warn about missing cases
776 
777  assert(false);
778  }
779 
780  bool IsFullOutboundConn() const {
781  return m_conn_type == ConnectionType::OUTBOUND_FULL_RELAY;
782  }
783 
784  bool IsManualConn() const {
785  return m_conn_type == ConnectionType::MANUAL;
786  }
787 
789  {
790  switch (m_conn_type) {
795  return false;
798  return true;
799  } // no default case, so the compiler can warn about missing cases
800 
801  assert(false);
802  }
803 
804  bool IsBlockOnlyConn() const {
805  return m_conn_type == ConnectionType::BLOCK_RELAY;
806  }
807 
808  bool IsFeelerConn() const {
809  return m_conn_type == ConnectionType::FEELER;
810  }
811 
812  bool IsAddrFetchConn() const {
813  return m_conn_type == ConnectionType::ADDR_FETCH;
814  }
815 
816  bool IsInboundConn() const {
817  return m_conn_type == ConnectionType::INBOUND;
818  }
819 
820  bool ExpectServicesFromConn() const {
821  switch (m_conn_type) {
825  return false;
829  return true;
830  } // no default case, so the compiler can warn about missing cases
831 
832  assert(false);
833  }
834 
845  Network ConnectedThroughNetwork() const;
846 
848  [[nodiscard]] bool IsConnectedThroughPrivacyNet() const;
849 
850  // We selected peer as (compact blocks) high-bandwidth peer (BIP152)
851  std::atomic<bool> m_bip152_highbandwidth_to{false};
852  // Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
853  std::atomic<bool> m_bip152_highbandwidth_from{false};
854 
856  std::atomic_bool m_has_all_wanted_services{false};
857 
860  std::atomic_bool m_relays_txs{false};
861 
864  std::atomic_bool m_bloom_filter_loaded{false};
865 
871  std::atomic<std::chrono::seconds> m_last_block_time{0s};
872 
877  std::atomic<std::chrono::seconds> m_last_tx_time{0s};
878 
880  std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
881 
884  std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()};
885 
886  CNode(NodeId id,
887  std::shared_ptr<Sock> sock,
888  const CAddress& addrIn,
889  uint64_t nKeyedNetGroupIn,
890  uint64_t nLocalHostNonceIn,
891  const CAddress& addrBindIn,
892  const std::string& addrNameIn,
893  ConnectionType conn_type_in,
894  bool inbound_onion,
895  CNodeOptions&& node_opts = {});
896  CNode(const CNode&) = delete;
897  CNode& operator=(const CNode&) = delete;
898 
899  NodeId GetId() const {
900  return id;
901  }
902 
903  uint64_t GetLocalNonce() const {
904  return nLocalHostNonce;
905  }
906 
907  int GetRefCount() const
908  {
909  assert(nRefCount >= 0);
910  return nRefCount;
911  }
912 
922  bool ReceiveMsgBytes(Span<const uint8_t> msg_bytes, bool& complete) EXCLUSIVE_LOCKS_REQUIRED(!cs_vRecv);
923 
924  void SetCommonVersion(int greatest_common_version)
925  {
926  Assume(m_greatest_common_version == INIT_PROTO_VERSION);
927  m_greatest_common_version = greatest_common_version;
928  }
929  int GetCommonVersion() const
930  {
931  return m_greatest_common_version;
932  }
933 
934  CService GetAddrLocal() const EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
936  void SetAddrLocal(const CService& addrLocalIn) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
937 
938  CNode* AddRef()
939  {
940  nRefCount++;
941  return this;
942  }
943 
944  void Release()
945  {
946  nRefCount--;
947  }
948 
949  void CloseSocketDisconnect() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex);
950 
951  void CopyStats(CNodeStats& stats) EXCLUSIVE_LOCKS_REQUIRED(!m_subver_mutex, !m_addr_local_mutex, !cs_vSend, !cs_vRecv);
952 
954 
956  void PongReceived(std::chrono::microseconds ping_time) {
957  m_last_ping_time = ping_time;
958  m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
959  }
960 
961 private:
962  const NodeId id;
963  const uint64_t nLocalHostNonce;
964  std::atomic<int> m_greatest_common_version{INIT_PROTO_VERSION};
965 
966  const size_t m_recv_flood_size;
967  std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
968 
970  std::list<CNetMessage> m_msg_process_queue GUARDED_BY(m_msg_process_queue_mutex);
971  size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex){0};
972 
973  // Our address, as reported by the peer
974  CService addrLocal GUARDED_BY(m_addr_local_mutex);
976 
977  mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend);
978  mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv);
979 
990  std::unique_ptr<i2p::sam::Session> m_i2p_sam_session GUARDED_BY(m_sock_mutex);
991 };
992 
997 {
998 public:
1001 
1003  virtual void InitializeNode(CNode& node, ServiceFlags our_services) = 0;
1004 
1006  virtual void FinalizeNode(const CNode& node) = 0;
1007 
1012  virtual bool HasAllDesirableServiceFlags(ServiceFlags services) const = 0;
1013 
1021  virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
1022 
1029  virtual bool SendMessages(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
1030 
1031 
1032 protected:
1037  ~NetEventsInterface() = default;
1038 };
1039 
1041 {
1042 public:
1043 
1044  struct Options
1045  {
1046  ServiceFlags nLocalServices = NODE_NONE;
1047  int m_max_automatic_connections = 0;
1049  NetEventsInterface* m_msgproc = nullptr;
1050  BanMan* m_banman = nullptr;
1051  unsigned int nSendBufferMaxSize = 0;
1052  unsigned int nReceiveFloodSize = 0;
1053  uint64_t nMaxOutboundLimit = 0;
1054  int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
1055  std::vector<std::string> vSeedNodes;
1056  std::vector<NetWhitelistPermissions> vWhitelistedRange;
1057  std::vector<NetWhitebindPermissions> vWhiteBinds;
1058  std::vector<CService> vBinds;
1059  std::vector<CService> onion_binds;
1063  bool m_use_addrman_outgoing = true;
1064  std::vector<std::string> m_specified_outgoing;
1065  std::vector<std::string> m_added_nodes;
1067  };
1068 
1069  void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_total_bytes_sent_mutex)
1070  {
1071  AssertLockNotHeld(m_total_bytes_sent_mutex);
1072 
1073  nLocalServices = connOptions.nLocalServices;
1074  m_max_automatic_connections = connOptions.m_max_automatic_connections;
1075  m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, m_max_automatic_connections);
1076  m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, m_max_automatic_connections - m_max_outbound_full_relay);
1077  m_max_automatic_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + m_max_feeler;
1078  m_max_inbound = std::max(0, m_max_automatic_connections - m_max_automatic_outbound);
1079  m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
1080  m_client_interface = connOptions.uiInterface;
1081  m_banman = connOptions.m_banman;
1082  m_msgproc = connOptions.m_msgproc;
1083  nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
1084  nReceiveFloodSize = connOptions.nReceiveFloodSize;
1085  m_peer_connect_timeout = std::chrono::seconds{connOptions.m_peer_connect_timeout};
1086  {
1087  LOCK(m_total_bytes_sent_mutex);
1088  nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
1089  }
1090  vWhitelistedRange = connOptions.vWhitelistedRange;
1091  {
1092  LOCK(m_added_nodes_mutex);
1093  // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
1094  // peer doesn't support it or immediately disconnects us for another reason.
1095  const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
1096  for (const std::string& added_node : connOptions.m_added_nodes) {
1097  m_added_node_params.push_back({added_node, use_v2transport});
1098  }
1099  }
1100  m_onion_binds = connOptions.onion_binds;
1101  }
1102 
1103  CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, const NetGroupManager& netgroupman,
1104  const CChainParams& params, bool network_active = true);
1105 
1106  ~CConnman();
1107 
1108  bool Start(CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !m_added_nodes_mutex, !m_addr_fetches_mutex, !mutexMsgProc);
1109 
1110  void StopThreads();
1111  void StopNodes();
1112  void Stop()
1113  {
1114  StopThreads();
1115  StopNodes();
1116  };
1117 
1118  void Interrupt() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1119  bool GetNetworkActive() const { return fNetworkActive; };
1120  bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
1121  void SetNetworkActive(bool active);
1122  void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant&& grant_outbound, const char* strDest, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1123  bool CheckIncomingNonce(uint64_t nonce);
1124  void ASMapHealthCheck();
1125 
1126  // alias for thread safety annotations only, not defined
1127  RecursiveMutex& GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex);
1128 
1129  bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
1130 
1131  void PushMessage(CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1132 
1133  using NodeFn = std::function<void(CNode*)>;
1134  void ForEachNode(const NodeFn& func)
1135  {
1136  LOCK(m_nodes_mutex);
1137  for (auto&& node : m_nodes) {
1138  if (NodeFullyConnected(node))
1139  func(node);
1140  }
1141  };
1142 
1143  void ForEachNode(const NodeFn& func) const
1144  {
1145  LOCK(m_nodes_mutex);
1146  for (auto&& node : m_nodes) {
1147  if (NodeFullyConnected(node))
1148  func(node);
1149  }
1150  };
1151 
1152  // Addrman functions
1161  std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
1168  std::vector<CAddress> GetAddresses(CNode& requestor, size_t max_addresses, size_t max_pct);
1169 
1170  // This allows temporarily exceeding m_max_outbound_full_relay, with the goal of finding
1171  // a peer that is better than all our current peers.
1172  void SetTryNewOutboundPeer(bool flag);
1173  bool GetTryNewOutboundPeer() const;
1174 
1175  void StartExtraBlockRelayPeers();
1176 
1177  // Return the number of outbound peers we have in excess of our target (eg,
1178  // if we previously called SetTryNewOutboundPeer(true), and have since set
1179  // to false, we may have extra peers that we wish to disconnect). This may
1180  // return a value less than (num_outbound_connections - num_outbound_slots)
1181  // in cases where some outbound connections are not yet fully connected, or
1182  // not yet fully disconnected.
1183  int GetExtraFullOutboundCount() const;
1184  // Count the number of block-relay-only peers we have over our limit.
1185  int GetExtraBlockRelayCount() const;
1186 
1187  bool AddNode(const AddedNodeParams& add) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1188  bool RemoveAddedNode(const std::string& node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1189  bool AddedNodesContain(const CAddress& addr) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1190  std::vector<AddedNodeInfo> GetAddedNodeInfo(bool include_connected) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1191 
1205  bool AddConnection(const std::string& address, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1206 
1207  size_t GetNodeCount(ConnectionDirection) const;
1208  uint32_t GetMappedAS(const CNetAddr& addr) const;
1209  void GetNodeStats(std::vector<CNodeStats>& vstats) const;
1210  bool DisconnectNode(const std::string& node);
1211  bool DisconnectNode(const CSubNet& subnet);
1212  bool DisconnectNode(const CNetAddr& addr);
1213  bool DisconnectNode(NodeId id);
1214 
1221  ServiceFlags GetLocalServices() const;
1222 
1223  uint64_t GetMaxOutboundTarget() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1224  std::chrono::seconds GetMaxOutboundTimeframe() const;
1225 
1229  bool OutboundTargetReached(bool historicalBlockServingLimit) const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1230 
1233  uint64_t GetOutboundTargetBytesLeft() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1234 
1235  std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1236 
1237  uint64_t GetTotalBytesRecv() const;
1238  uint64_t GetTotalBytesSent() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1239 
1241  CSipHasher GetDeterministicRandomizer(uint64_t id) const;
1242 
1243  void WakeMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1244 
1246  bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const;
1247 
1248  bool MultipleManualOrFullOutboundConns(Network net) const EXCLUSIVE_LOCKS_REQUIRED(m_nodes_mutex);
1249 
1250 private:
1251  struct ListenSocket {
1252  public:
1253  std::shared_ptr<Sock> sock;
1255  ListenSocket(std::shared_ptr<Sock> sock_, NetPermissionFlags permissions_)
1256  : sock{sock_}, m_permissions{permissions_}
1257  {
1258  }
1259 
1260  private:
1262  };
1263 
1266  std::chrono::seconds GetMaxOutboundTimeLeftInCycle_() const EXCLUSIVE_LOCKS_REQUIRED(m_total_bytes_sent_mutex);
1267 
1268  bool BindListenPort(const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
1269  bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
1270  bool InitBinds(const Options& options);
1271 
1272  void ThreadOpenAddedConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_unused_i2p_sessions_mutex, !m_reconnections_mutex);
1273  void AddAddrFetch(const std::string& strDest) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex);
1274  void ProcessAddrFetch() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_unused_i2p_sessions_mutex);
1275  void ThreadOpenConnections(std::vector<std::string> connect) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_added_nodes_mutex, !m_nodes_mutex, !m_unused_i2p_sessions_mutex, !m_reconnections_mutex);
1276  void ThreadMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1277  void ThreadI2PAcceptIncoming();
1278  void AcceptConnection(const ListenSocket& hListenSocket);
1279 
1288  void CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
1289  NetPermissionFlags permission_flags,
1290  const CAddress& addr_bind,
1291  const CAddress& addr);
1292 
1293  void DisconnectNodes() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_nodes_mutex);
1294  void NotifyNumConnectionsChanged();
1296  bool InactivityCheck(const CNode& node) const;
1297 
1303  Sock::EventsPerSock GenerateWaitSockets(Span<CNode* const> nodes);
1304 
1308  void SocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1309 
1315  void SocketHandlerConnected(const std::vector<CNode*>& nodes,
1316  const Sock::EventsPerSock& events_per_sock)
1317  EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1318 
1323  void SocketHandlerListening(const Sock::EventsPerSock& events_per_sock);
1324 
1325  void ThreadSocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc, !m_nodes_mutex, !m_reconnections_mutex);
1326  void ThreadDNSAddressSeed() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_nodes_mutex);
1327 
1328  uint64_t CalculateKeyedNetGroup(const CAddress& ad) const;
1329 
1330  CNode* FindNode(const CNetAddr& ip);
1331  CNode* FindNode(const std::string& addrName);
1332  CNode* FindNode(const CService& addr);
1333 
1338  bool AlreadyConnectedToAddress(const CAddress& addr);
1339 
1340  bool AttemptToEvictConnection();
1341  CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1342  void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const;
1343 
1344  void DeleteNode(CNode* pnode);
1345 
1346  NodeId GetNewNodeId();
1347 
1349  std::pair<size_t, bool> SocketSendData(CNode& node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
1350 
1351  void DumpAddresses();
1352 
1353  // Network stats
1354  void RecordBytesRecv(uint64_t bytes);
1355  void RecordBytesSent(uint64_t bytes) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1356 
1361  std::unordered_set<Network> GetReachableEmptyNetworks() const;
1362 
1366  std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;
1367 
1378  bool MaybePickPreferredNetwork(std::optional<Network>& network);
1379 
1380  // Whether the node should be passed out in ForEach* callbacks
1381  static bool NodeFullyConnected(const CNode* pnode);
1382 
1383  uint16_t GetDefaultPort(Network net) const;
1384  uint16_t GetDefaultPort(const std::string& addr) const;
1385 
1386  // Network usage totals
1387  mutable Mutex m_total_bytes_sent_mutex;
1388  std::atomic<uint64_t> nTotalBytesRecv{0};
1389  uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex) {0};
1390 
1391  // outbound limit & stats
1392  uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex) {0};
1393  std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex) {0};
1394  uint64_t nMaxOutboundLimit GUARDED_BY(m_total_bytes_sent_mutex);
1395 
1396  // P2P timeout in seconds
1397  std::chrono::seconds m_peer_connect_timeout;
1398 
1399  // Whitelisted ranges. Any node connecting from these is automatically
1400  // whitelisted (as well as those connecting to whitelisted binds).
1401  std::vector<NetWhitelistPermissions> vWhitelistedRange;
1402 
1403  unsigned int nSendBufferMaxSize{0};
1404  unsigned int nReceiveFloodSize{0};
1405 
1406  std::vector<ListenSocket> vhListenSocket;
1407  std::atomic<bool> fNetworkActive{true};
1408  bool fAddressesInitialized{false};
1411  std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
1413 
1414  // connection string and whether to use v2 p2p
1415  std::vector<AddedNodeParams> m_added_node_params GUARDED_BY(m_added_nodes_mutex);
1416 
1418  std::vector<CNode*> m_nodes GUARDED_BY(m_nodes_mutex);
1419  std::list<CNode*> m_nodes_disconnected;
1421  std::atomic<NodeId> nLastNodeId{0};
1422  unsigned int nPrevNodeCount{0};
1423 
1424  // Stores number of full-tx connections (outbound and manual) per network
1425  std::array<unsigned int, Network::NET_MAX> m_network_conn_counts GUARDED_BY(m_nodes_mutex) = {};
1426 
1434  std::vector<CAddress> m_addrs_response_cache;
1435  std::chrono::microseconds m_cache_entry_expiration{0};
1436  };
1437 
1452  std::map<uint64_t, CachedAddrResponse> m_addr_response_caches;
1453 
1465 
1466  std::unique_ptr<CSemaphore> semOutbound;
1467  std::unique_ptr<CSemaphore> semAddnode;
1468 
1475 
1476  /*
1477  * Maximum number of peers by connection type. Might vary from defaults
1478  * based on -maxconnections init value.
1479  */
1480 
1481  // How many full-relay (tx, block, addr) outbound peers we want
1483 
1484  // How many block-relay only outbound peers we want
1485  // We do not relay tx or addr messages with these peers
1487 
1488  int m_max_addnode{MAX_ADDNODE_CONNECTIONS};
1489  int m_max_feeler{MAX_FEELER_CONNECTIONS};
1492 
1498 
1503  std::vector<CAddress> m_anchors;
1504 
1506  const uint64_t nSeed0, nSeed1;
1507 
1509  bool fMsgProcWake GUARDED_BY(mutexMsgProc);
1510 
1511  std::condition_variable condMsgProc;
1513  std::atomic<bool> flagInterruptMsgProc{false};
1514 
1522 
1528  std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
1529 
1531  std::thread threadSocketHandler;
1536 
1541 
1546  std::atomic_bool m_start_extra_block_relay_peers{false};
1547 
1552  std::vector<CService> m_onion_binds;
1553 
1558 
1566  std::queue<std::unique_ptr<i2p::sam::Session>> m_unused_i2p_sessions GUARDED_BY(m_unused_i2p_sessions_mutex);
1567 
1572 
1575  {
1578  std::string destination;
1581  };
1582 
1586  std::list<ReconnectionInfo> m_reconnections GUARDED_BY(m_reconnections_mutex);
1587 
1589  void PerformReconnections() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_unused_i2p_sessions_mutex);
1590 
1595  static constexpr size_t MAX_UNUSED_I2P_SESSIONS_SIZE{10};
1596 
1602  {
1603  public:
1604  explicit NodesSnapshot(const CConnman& connman, bool shuffle)
1605  {
1606  {
1607  LOCK(connman.m_nodes_mutex);
1608  m_nodes_copy = connman.m_nodes;
1609  for (auto& node : m_nodes_copy) {
1610  node->AddRef();
1611  }
1612  }
1613  if (shuffle) {
1614  Shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});
1615  }
1616  }
1617 
1619  {
1620  for (auto& node : m_nodes_copy) {
1621  node->Release();
1622  }
1623  }
1624 
1625  const std::vector<CNode*>& Nodes() const
1626  {
1627  return m_nodes_copy;
1628  }
1629 
1630  private:
1631  std::vector<CNode*> m_nodes_copy;
1632  };
1633 
1635 
1636  friend struct ConnmanTestMsg;
1637 };
1638 
1640 extern std::function<void(const CAddress& addr,
1641  const std::string& msg_type,
1643  bool is_incoming)>
1645 
1646 #endif // BITCOIN_NET_H
int ret
int flags
Definition: bitcoin-tx.cpp:530
Interrupt(node)
#define Assume(val)
Assume is the identity function.
Definition: check.h:89
Stochastic address manager.
Definition: addrman.h:88
The BIP324 packet cipher, encapsulating its key derivation, stream cipher, and AEAD.
Definition: bip324.h:20
Definition: banman.h:59
A CService with information about it as peer.
Definition: protocol.h:332
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:81
Signals for UI communication.
Definition: interface_ui.h:25
RAII helper to atomically create a copy of m_nodes and add a reference to each of the nodes.
Definition: net.h:1602
NodesSnapshot(const CConnman &connman, bool shuffle)
Definition: net.h:1604
const std::vector< CNode * > & Nodes() const
Definition: net.h:1625
std::vector< CNode * > m_nodes_copy
Definition: net.h:1631
Definition: net.h:1041
std::condition_variable condMsgProc
Definition: net.h:1511
std::thread threadMessageHandler
Definition: net.h:1534
CClientUIInterface * m_client_interface
Definition: net.h:1494
std::vector< AddedNodeParams > m_added_node_params GUARDED_BY(m_added_nodes_mutex)
void ForEachNode(const NodeFn &func) const
Definition: net.h:1143
RecursiveMutex & GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex)
std::list< ReconnectionInfo > m_reconnections GUARDED_BY(m_reconnections_mutex)
List of reconnections we have to make.
ServiceFlags nLocalServices
Services this node offers.
Definition: net.h:1464
int m_max_inbound
Definition: net.h:1491
const bool use_v2transport(GetLocalServices() &NODE_P2P_V2)
void Stop()
Definition: net.h:1112
int m_max_outbound_block_relay
Definition: net.h:1486
std::thread threadI2PAcceptIncoming
Definition: net.h:1535
int m_max_automatic_outbound
Definition: net.h:1490
std::vector< CNode * > m_nodes GUARDED_BY(m_nodes_mutex)
uint64_t nMaxOutboundLimit GUARDED_BY(m_total_bytes_sent_mutex)
CThreadInterrupt interruptNet
This is signaled when network activity should cease.
Definition: net.h:1521
std::unique_ptr< CSemaphore > semAddnode
Definition: net.h:1467
bool fMsgProcWake GUARDED_BY(mutexMsgProc)
flag for waking the message processor.
int m_max_automatic_connections
Maximum number of automatic connections permitted, excluding manual connections but including inbound...
Definition: net.h:1474
BanMan * m_banman
Pointer to this node's banman.
Definition: net.h:1497
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1392
std::thread threadDNSAddressSeed
Definition: net.h:1530
const NetGroupManager & m_netgroupman
Definition: net.h:1410
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
Definition: net.h:1503
std::chrono::seconds m_peer_connect_timeout
Definition: net.h:1397
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:1540
std::vector< ListenSocket > vhListenSocket
Definition: net.h:1406
std::unique_ptr< CSemaphore > semOutbound
Definition: net.h:1466
std::array< unsigned int, Network::NET_MAX > m_network_conn_counts GUARDED_BY(m_nodes_mutex)
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:1401
std::thread threadOpenConnections
Definition: net.h:1533
Mutex m_addr_fetches_mutex
Definition: net.h:1412
Mutex m_reconnections_mutex
Mutex protecting m_reconnections.
Definition: net.h:1571
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:1506
RecursiveMutex m_nodes_mutex
Definition: net.h:1420
std::queue< std::unique_ptr< i2p::sam::Session > > m_unused_i2p_sessions GUARDED_BY(m_unused_i2p_sessions_mutex)
A pool of created I2P SAM transient sessions that should be used instead of creating new ones in orde...
std::deque< std::string > m_addr_fetches GUARDED_BY(m_addr_fetches_mutex)
const CChainParams & m_params
Definition: net.h:1634
AddrMan & addrman
Definition: net.h:1409
Mutex mutexMsgProc
Definition: net.h:1512
std::thread threadOpenAddedConnections
Definition: net.h:1532
Mutex m_added_nodes_mutex
Definition: net.h:1417
int m_max_outbound_full_relay
Definition: net.h:1482
Mutex m_unused_i2p_sessions_mutex
Mutex protecting m_i2p_sam_sessions.
Definition: net.h:1557
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1393
uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1389
bool GetUseAddrmanOutgoing() const
Definition: net.h:1120
std::list< CNode * > m_nodes_disconnected
Definition: net.h:1419
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session
I2P SAM session.
Definition: net.h:1528
bool m_use_addrman_outgoing
Definition: net.h:1493
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:1452
std::function< void(CNode *)> NodeFn
Definition: net.h:1133
NetEventsInterface * m_msgproc
Definition: net.h:1495
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:1552
std::thread threadSocketHandler
Definition: net.h:1531
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
Definition: hash.h:24
An encapsulated private key.
Definition: key.h:33
Message header.
Definition: protocol.h:29
Network address.
Definition: netaddress.h:112
Transport protocol agnostic message container.
Definition: net.h:238
CNetMessage & operator=(CNetMessage &&)=default
CNetMessage(CNetMessage &&)=default
CNetMessage & operator=(const CNetMessage &)=delete
CNetMessage(DataStream &&recv_in)
Definition: net.h:246
std::string m_type
Definition: net.h:244
DataStream m_recv
received message data
Definition: net.h:240
CNetMessage(const CNetMessage &)=delete
Information about a peer.
Definition: net.h:677
const CAddress addrBind
Definition: net.h:715
bool IsFeelerConn() const
Definition: net.h:808
const std::chrono::seconds m_connected
Unix epoch time at peer connection.
Definition: net.h:710
bool ExpectServicesFromConn() const
Definition: net.h:820
const std::string m_dest
The pszDest argument provided to ConnectNode().
Definition: net.h:718
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:705
bool IsInboundConn() const
Definition: net.h:816
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:729
bool IsOutboundOrBlockRelayConn() const
Definition: net.h:765
NodeId GetId() const
Definition: net.h:899
bool IsManualConn() const
Definition: net.h:784
const std::string m_addr_name
Definition: net.h:716
void SetCommonVersion(int greatest_common_version)
Definition: net.h:924
std::list< CNetMessage > vRecvMsg
Definition: net.h:967
std::deque< CSerializedNetMsg > vSendMsg GUARDED_BY(cs_vSend)
Messages still to be fed to m_transport->SetMessageToSend.
std::list< CNetMessage > m_msg_process_queue GUARDED_BY(m_msg_process_queue_mutex)
void PongReceived(std::chrono::microseconds ping_time)
A ping-pong round trip has completed successfully.
Definition: net.h:956
size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex)
Definition: net.h:971
bool IsAddrFetchConn() const
Definition: net.h:812
uint64_t GetLocalNonce() const
Definition: net.h:903
const CAddress addr
Definition: net.h:713
CSemaphoreGrant grantOutbound
Definition: net.h:737
mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend)
const uint64_t nKeyedNetGroup
Definition: net.h:740
bool IsBlockOnlyConn() const
Definition: net.h:804
int GetCommonVersion() const
Definition: net.h:929
mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv)
bool IsFullOutboundConn() const
Definition: net.h:780
std::shared_ptr< Sock > m_sock GUARDED_BY(m_sock_mutex)
Socket used for communication with the node.
Mutex m_subver_mutex
Definition: net.h:722
Mutex cs_vSend
Definition: net.h:701
int GetRefCount() const
Definition: net.h:907
Mutex m_msg_process_queue_mutex
Definition: net.h:969
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session GUARDED_BY(m_sock_mutex)
If an I2P session is created per connection (for outbound transient I2P connections) then it is store...
CService addrLocal GUARDED_BY(m_addr_local_mutex)
const ConnectionType m_conn_type
Definition: net.h:744
const size_t m_recv_flood_size
Definition: net.h:966
const uint64_t nLocalHostNonce
Definition: net.h:963
bool IsManualOrFullOutboundConn() const
Definition: net.h:788
const std::unique_ptr< Transport > m_transport
Transport serializer/deserializer.
Definition: net.h:681
const NetPermissionFlags m_permission_flags
Definition: net.h:683
Mutex m_addr_local_mutex
Definition: net.h:975
CNode(const CNode &)=delete
size_t m_send_memusage GUARDED_BY(cs_vSend)
Sum of GetMemoryUsage of all vSendMsg entries.
Definition: net.h:696
const bool m_inbound_onion
Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
Definition: net.h:720
const NodeId id
Definition: net.h:962
Mutex cs_vRecv
Definition: net.h:703
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Total number of bytes sent on the wire to this peer.
Definition: net.h:698
Mutex m_sock_mutex
Definition: net.h:702
void Release()
Definition: net.h:944
CNode & operator=(const CNode &)=delete
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:727
std::string m_session_id
BIP324 session id string in hex, if any.
Definition: net.h:229
std::string addrLocal
Definition: net.h:217
CAddress addrBind
Definition: net.h:221
uint64_t nRecvBytes
Definition: net.h:211
std::chrono::microseconds m_last_ping_time
Definition: net.h:214
uint32_t m_mapped_as
Definition: net.h:224
mapMsgTypeSize mapRecvBytesPerMsgType
Definition: net.h:212
bool fInbound
Definition: net.h:203
uint64_t nSendBytes
Definition: net.h:209
std::chrono::seconds m_last_recv
Definition: net.h:195
ConnectionType m_conn_type
Definition: net.h:225
std::chrono::seconds m_last_send
Definition: net.h:194
std::chrono::seconds m_last_tx_time
Definition: net.h:196
CAddress addr
Definition: net.h:219
mapMsgTypeSize mapSendBytesPerMsgType
Definition: net.h:210
std::chrono::microseconds m_min_ping_time
Definition: net.h:215
int64_t nTimeOffset
Definition: net.h:199
TransportProtocolType m_transport_type
Transport protocol type.
Definition: net.h:227
std::chrono::seconds m_connected
Definition: net.h:198
bool m_bip152_highbandwidth_from
Definition: net.h:207
bool m_bip152_highbandwidth_to
Definition: net.h:205
std::string m_addr_name
Definition: net.h:200
int nVersion
Definition: net.h:201
std::chrono::seconds m_last_block_time
Definition: net.h:197
Network m_network
Definition: net.h:223
NodeId nodeid
Definition: net.h:193
std::string cleanSubVer
Definition: net.h:202
int m_starting_height
Definition: net.h:208
NetPermissionFlags m_permission_flags
Definition: net.h:213
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:39
RAII-style semaphore lock.
Definition: sync.h:353
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:531
SipHash-2-4.
Definition: siphash.h:15
A helper class for interruptible sleeps.
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
Fast randomness source.
Definition: random.h:144
Different type to mark Mutex at global scope.
Definition: sync.h:140
Interface for message handling.
Definition: net.h:997
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition: net.h:1000
virtual bool SendMessages(CNode *pnode) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex)=0
Send queued protocol messages to a given node.
virtual void FinalizeNode(const CNode &node)=0
Handle removal of a peer (clear state)
virtual bool HasAllDesirableServiceFlags(ServiceFlags services) const =0
Callback to determine whether the given set of service flags are sufficient for a peer to be "relevan...
virtual bool ProcessMessages(CNode *pnode, std::atomic< bool > &interrupt) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex)=0
Process protocol messages received from a given node.
~NetEventsInterface()=default
Protected destructor so that instances can only be deleted by derived classes.
virtual void InitializeNode(CNode &node, ServiceFlags our_services)=0
Initialize a peer (setup state, queue any initial messages)
Netgroup manager.
Definition: netgroup.h:16
static void AddFlag(NetPermissionFlags &flags, NetPermissionFlags f)
static bool HasFlag(NetPermissionFlags flags, NetPermissionFlags f)
RAII helper class that manages a socket and closes it automatically when it goes out of scope.
Definition: sock.h:27
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:98
The Transport converts one connection's sent messages to wire bytes, and received bytes back.
Definition: net.h:258
virtual ~Transport()
Definition: net.h:260
std::tuple< Span< const uint8_t >, bool, const std::string & > BytesToSend
Return type for GetBytesToSend, consisting of:
Definition: net.h:315
virtual Info GetInfo() const noexcept=0
Retrieve information about this transport.
CHash256 hasher GUARDED_BY(m_recv_mutex)
DataStream hdrbuf GUARDED_BY(m_recv_mutex)
Definition: net.h:380
bool m_sending_header GUARDED_BY(m_send_mutex)
Whether we're currently sending header bytes or message bytes.
Definition: net.h:416
const NodeId m_node_id
Definition: net.h:375
Mutex m_send_mutex
Lock for sending state.
Definition: net.h:410
CSerializedNetMsg m_message_to_send GUARDED_BY(m_send_mutex)
The data of the message currently being sent.
size_t m_bytes_sent GUARDED_BY(m_send_mutex)
How many bytes have been sent so far (from m_header_to_send, or from m_message_to_send....
Definition: net.h:418
unsigned int nDataPos GUARDED_BY(m_recv_mutex)
bool in_data GUARDED_BY(m_recv_mutex)
uint256 data_hash GUARDED_BY(m_recv_mutex)
const MessageStartChars m_magic_bytes
Definition: net.h:374
unsigned int nHdrPos GUARDED_BY(m_recv_mutex)
DataStream vRecv GUARDED_BY(m_recv_mutex)
Definition: net.h:382
bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
Definition: net.h:402
CMessageHeader hdr GUARDED_BY(m_recv_mutex)
std::vector< uint8_t > m_header_to_send GUARDED_BY(m_send_mutex)
The header of the message currently being sent.
Mutex m_recv_mutex
Lock for receive state.
Definition: net.h:376
bool ReceivedMessageComplete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
Returns true if the current message is complete (so GetReceivedMessage can be called).
Definition: net.h:423
bool m_sent_v1_header_worth GUARDED_BY(m_send_mutex)
Whether we've sent at least 24 bytes (which would trigger disconnect for V1 peers).
Definition: net.h:616
const NodeId m_nodeid
NodeId (for debug logging).
Definition: net.h:584
BIP324Cipher m_cipher
Cipher state.
Definition: net.h:580
std::vector< uint8_t > m_recv_aad GUARDED_BY(m_recv_mutex)
AAD expected in next received packet (currently used only for garbage).
SendState
State type that controls the sender side.
Definition: net.h:549
V1Transport m_v1_fallback
Encapsulate a V1Transport to fall back to.
Definition: net.h:586
Mutex m_send_mutex ACQUIRED_AFTER(m_recv_mutex)
Lock for sending-side fields.
SendState m_send_state GUARDED_BY(m_send_mutex)
Current sender state.
std::vector< uint8_t > m_send_garbage GUARDED_BY(m_send_mutex)
The garbage sent, or to be sent (MAYBE_V1 and AWAITING_KEY state only).
std::string m_send_type GUARDED_BY(m_send_mutex)
Type of the message being sent.
const bool m_initiating
Whether we are the initiator side.
Definition: net.h:582
std::vector< uint8_t > m_send_buffer GUARDED_BY(m_send_mutex)
The send buffer; meaning is determined by m_send_state.
std::vector< uint8_t > m_recv_buffer GUARDED_BY(m_recv_mutex)
Receive buffer; meaning is determined by m_recv_state.
uint32_t m_recv_len GUARDED_BY(m_recv_mutex)
In {VERSION, APP}, the decrypted packet length, if m_recv_buffer.size() >= BIP324Cipher::LENGTH_LEN.
Definition: net.h:592
uint32_t m_send_pos GUARDED_BY(m_send_mutex)
How many bytes from the send buffer have been sent so far.
Definition: net.h:608
RecvState m_recv_state GUARDED_BY(m_recv_mutex)
Current receiver state.
Mutex m_recv_mutex ACQUIRED_BEFORE(m_send_mutex)
Lock for receiver-side fields.
std::vector< uint8_t > m_recv_decode_buffer GUARDED_BY(m_recv_mutex)
Buffer to put decrypted contents in, for converting to CNetMessage.
RecvState
State type that defines the current contents of the receive buffer and/or how the next received bytes...
Definition: net.h:484
256-bit opaque blob.
Definition: uint256.h:106
std::string ConnectionTypeAsString(ConnectionType conn_type)
Convert ConnectionType enum to a string value.
ConnectionType
Different types of connections to a peer.
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ MANUAL
We open manual connections to addresses that users explicitly requested via the addnode RPC or the -a...
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
@ INBOUND
Inbound connections are those initiated by a peer.
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
TransportProtocolType
Transport layer version.
@ V1
Unencrypted, plaintext protocol.
static CService ip(uint32_t i)
CClientUIInterface uiInterface
#define VERSION
std::array< uint8_t, 4 > MessageStartChars
unsigned int nonce
Definition: miner_tests.cpp:71
Definition: init.h:25
const std::string KEY
Definition: walletdb.cpp:49
uint16_t GetListenPort()
Definition: net.cpp:135
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:82
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:326
void RemoveLocal(const CService &addr)
Definition: net.cpp:307
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
Definition: net.h:70
static constexpr std::chrono::minutes TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:62
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:74
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:274
std::optional< CService > GetLocalAddrForPeer(CNode &node)
Returns a local address that we should advertise to this peer.
Definition: net.cpp:238
bool fDiscover
Definition: net.cpp:115
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:98
static const int NUM_FDS_MESSAGE_CAPTURE
Number of file descriptors required for message capture.
Definition: net.h:90
static constexpr bool DEFAULT_FIXEDSEEDS
Definition: net.h:96
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:86
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: net.h:59
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:68
bool fListen
Definition: net.cpp:116
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: net.h:57
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(g_maplocalhost_mutex)
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL
Run the extra block-relay-only connection loop once every 5 minutes.
Definition: net.h:66
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:97
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:119
static const std::string DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:84
const std::string NET_MESSAGE_TYPE_OTHER
Definition: net.cpp:107
std::map< std::string, uint64_t > mapMsgTypeSize
Definition: net.h:188
static constexpr bool DEFAULT_FORCEDNSSEED
Definition: net.h:94
static constexpr bool DEFAULT_DNSSEED
Definition: net.h:95
int64_t NodeId
Definition: net.h:102
CService GetLocalAddress(const CNode &peer)
Definition: net.cpp:218
GlobalMutex g_maplocalhost_mutex
Definition: net.cpp:117
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:78
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:80
static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL
Interval for ASMap Health Check.
Definition: net.h:92
static constexpr auto FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes.
Definition: net.h:64
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:88
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition: net.h:72
std::function< void(const CAddress &addr, const std::string &msg_type, Span< const unsigned char > data, bool is_incoming)> CaptureMessage
Defaults to CaptureMessageToFile(), but can be overridden by unit tests.
Definition: net.cpp:3899
@ LOCAL_NONE
Definition: net.h:154
@ LOCAL_MAPPED
Definition: net.h:157
@ LOCAL_MANUAL
Definition: net.h:158
@ LOCAL_MAX
Definition: net.h:160
@ LOCAL_BIND
Definition: net.h:156
@ LOCAL_IF
Definition: net.h:155
static constexpr bool DEFAULT_V2_TRANSPORT
Definition: net.h:100
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:76
void Discover()
Look up IP addresses from all interfaces on the machine and add them to the list of local addresses t...
Definition: net.cpp:3051
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:315
NetPermissionFlags
Network
A network type.
Definition: netaddress.h:32
ConnectionDirection
Definition: netbase.h:30
ServiceFlags
nServices flags
Definition: protocol.h:274
@ NODE_NONE
Definition: protocol.h:277
@ NODE_P2P_V2
Definition: protocol.h:295
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
Definition: random.h:264
bool fInbound
Definition: net.h:113
CService resolvedAddress
Definition: net.h:111
AddedNodeParams m_params
Definition: net.h:110
bool fConnected
Definition: net.h:112
std::string m_added_node
Definition: net.h:105
bool m_use_v2transport
Definition: net.h:106
Cache responses to addr requests to minimize privacy leak.
Definition: net.h:1433
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:1434
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:1254
ListenSocket(std::shared_ptr< Sock > sock_, NetPermissionFlags permissions_)
Definition: net.h:1255
NetPermissionFlags m_permissions
Definition: net.h:1261
std::shared_ptr< Sock > sock
Definition: net.h:1253
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:1057
std::vector< NetWhitelistPermissions > vWhitelistedRange
Definition: net.h:1056
std::vector< CService > onion_binds
Definition: net.h:1059
std::vector< std::string > m_specified_outgoing
Definition: net.h:1064
std::vector< std::string > m_added_nodes
Definition: net.h:1065
std::vector< CService > vBinds
Definition: net.h:1058
bool m_i2p_accept_incoming
Definition: net.h:1066
std::vector< std::string > vSeedNodes
Definition: net.h:1055
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
Definition: net.h:1062
Struct for entries in m_reconnections.
Definition: net.h:1575
CSemaphoreGrant grant
Definition: net.h:1577
ConnectionType conn_type
Definition: net.h:1579
std::string destination
Definition: net.h:1578
CSerializedNetMsg(const CSerializedNetMsg &msg)=delete
CSerializedNetMsg Copy() const
Definition: net.h:127
std::string m_type
Definition: net.h:136
CSerializedNetMsg & operator=(const CSerializedNetMsg &)=delete
CSerializedNetMsg()=default
CSerializedNetMsg(CSerializedNetMsg &&)=default
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
std::vector< unsigned char > data
Definition: net.h:135
size_t GetMemoryUsage() const noexcept
Compute total memory usage of this object (own memory + any dynamic memory).
Definition: net.cpp:121
uint16_t nPort
Definition: net.h:181
int nScore
Definition: net.h:180
std::optional< uint256 > session_id
Definition: net.h:265
TransportProtocolType transport_type
Definition: net.h:264
Bilingual messages:
Definition: translation.h:18
#define AssertLockNotHeld(cs)
Definition: sync.h:147
#define LOCK(cs)
Definition: sync.h:257
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:301
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
#define LOCK_RETURNED(x)
Definition: threadsafety.h:47
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
Definition: txmempool.cpp:806
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())