Bitcoin Core 29.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-present 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>
24#include <policy/feerate.h>
25#include <protocol.h>
26#include <random.h>
27#include <semaphore_grant.h>
28#include <span.h>
29#include <streams.h>
30#include <sync.h>
31#include <uint256.h>
32#include <util/check.h>
33#include <util/sock.h>
35
36#include <atomic>
37#include <condition_variable>
38#include <cstdint>
39#include <deque>
40#include <functional>
41#include <list>
42#include <map>
43#include <memory>
44#include <optional>
45#include <queue>
46#include <thread>
47#include <unordered_set>
48#include <vector>
49
50class AddrMan;
51class BanMan;
52class CChainParams;
53class CNode;
54class CScheduler;
55struct bilingual_str;
56
58static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
60static constexpr auto FEELER_INTERVAL = 2min;
62static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min;
64static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
66static const unsigned int MAX_SUBVERSION_LENGTH = 256;
70static const int MAX_ADDNODE_CONNECTIONS = 8;
74static const int MAX_FEELER_CONNECTIONS = 1;
76static const bool DEFAULT_LISTEN = true;
78static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
80static const std::string DEFAULT_MAX_UPLOAD_TARGET{"0M"};
82static const bool DEFAULT_BLOCKSONLY = false;
84static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
86static const int NUM_FDS_MESSAGE_CAPTURE = 1;
88static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL{24};
89
90static constexpr bool DEFAULT_FORCEDNSSEED{false};
91static constexpr bool DEFAULT_DNSSEED{true};
92static constexpr bool DEFAULT_FIXEDSEEDS{true};
93static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
94static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
95
96static constexpr bool DEFAULT_V2_TRANSPORT{true};
97
98typedef int64_t NodeId;
99
101 std::string m_added_node;
103};
104
110};
111
112class CNodeStats;
114
116 CSerializedNetMsg() = default;
119 // No implicit copying, only moves.
122
124 {
126 copy.data = data;
127 copy.m_type = m_type;
128 return copy;
129 }
130
131 std::vector<unsigned char> data;
132 std::string m_type;
133
135 size_t GetMemoryUsage() const noexcept;
136};
137
143void Discover();
144
145uint16_t GetListenPort();
146
147enum
148{
149 LOCAL_NONE, // unknown
150 LOCAL_IF, // address a local interface listens on
151 LOCAL_BIND, // address explicit bound to
152 LOCAL_MAPPED, // address reported by PCP
153 LOCAL_MANUAL, // address explicitly specified (-externalip=)
154
157
159std::optional<CService> GetLocalAddrForPeer(CNode& node);
160
161bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
162bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
163void RemoveLocal(const CService& addr);
164bool SeenLocal(const CService& addr);
165bool IsLocal(const CService& addr);
166CService GetLocalAddress(const CNode& peer);
167
168extern bool fDiscover;
169extern bool fListen;
170
172extern std::string strSubVersion;
173
176 uint16_t nPort;
177};
178
180extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
181
182extern const std::string NET_MESSAGE_TYPE_OTHER;
183using mapMsgTypeSize = std::map</* message type */ std::string, /* total bytes */ uint64_t>;
184
186{
187public:
189 std::chrono::seconds m_last_send;
190 std::chrono::seconds m_last_recv;
191 std::chrono::seconds m_last_tx_time;
192 std::chrono::seconds m_last_block_time;
193 std::chrono::seconds m_connected;
194 std::string m_addr_name;
196 std::string cleanSubVer;
198 // We requested high bandwidth connection to peer
200 // Peer requested high bandwidth connection
203 uint64_t nSendBytes;
205 uint64_t nRecvBytes;
208 std::chrono::microseconds m_last_ping_time;
209 std::chrono::microseconds m_min_ping_time;
210 // Our address, as reported by the peer
211 std::string addrLocal;
212 // Address of this peer
214 // Bind address of our side of the connection
216 // Network the peer connected through
218 uint32_t m_mapped_as;
223 std::string m_session_id;
224};
225
226
232{
233public:
235 std::chrono::microseconds m_time{0};
236 uint32_t m_message_size{0};
237 uint32_t m_raw_message_size{0};
238 std::string m_type;
239
240 explicit CNetMessage(DataStream&& recv_in) : m_recv(std::move(recv_in)) {}
241 // Only one CNetMessage object will exist for the same message on either
242 // the receive or processing queue. For performance reasons we therefore
243 // delete the copy constructor and assignment operator to avoid the
244 // possibility of copying CNetMessage objects.
246 CNetMessage(const CNetMessage&) = delete;
249
251 size_t GetMemoryUsage() const noexcept;
252};
253
256public:
257 virtual ~Transport() = default;
258
259 struct Info
260 {
262 std::optional<uint256> session_id;
263 };
264
266 virtual Info GetInfo() const noexcept = 0;
267
268 // 1. Receiver side functions, for decoding bytes received on the wire into transport protocol
269 // agnostic CNetMessage (message type & payload) objects.
270
272 virtual bool ReceivedMessageComplete() const = 0;
273
280 virtual bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) = 0;
281
289 virtual CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) = 0;
290
291 // 2. Sending side functions, for converting messages into bytes to be sent over the wire.
292
299 virtual bool SetMessageToSend(CSerializedNetMsg& msg) noexcept = 0;
300
308 using BytesToSend = std::tuple<
309 std::span<const uint8_t> /*to_send*/,
310 bool /*more*/,
311 const std::string& /*m_type*/
312 >;
313
349 virtual BytesToSend GetBytesToSend(bool have_next_message) const noexcept = 0;
350
357 virtual void MarkBytesSent(size_t bytes_sent) noexcept = 0;
358
360 virtual size_t GetSendMemoryUsage() const noexcept = 0;
361
362 // 3. Miscellaneous functions.
363
365 virtual bool ShouldReconnectV1() const noexcept = 0;
366};
367
368class V1Transport final : public Transport
369{
370private:
372 const NodeId m_node_id; // Only for logging
374 mutable CHash256 hasher GUARDED_BY(m_recv_mutex);
375 mutable uint256 data_hash GUARDED_BY(m_recv_mutex);
376 bool in_data GUARDED_BY(m_recv_mutex); // parsing header (false) or data (true)
377 DataStream hdrbuf GUARDED_BY(m_recv_mutex){}; // partially received header
378 CMessageHeader hdr GUARDED_BY(m_recv_mutex); // complete header
379 DataStream vRecv GUARDED_BY(m_recv_mutex){}; // received message data
380 unsigned int nHdrPos GUARDED_BY(m_recv_mutex);
381 unsigned int nDataPos GUARDED_BY(m_recv_mutex);
382
383 const uint256& GetMessageHash() const EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
384 int readHeader(std::span<const uint8_t> msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
385 int readData(std::span<const uint8_t> msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
386
387 void Reset() EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex) {
388 AssertLockHeld(m_recv_mutex);
389 vRecv.clear();
390 hdrbuf.clear();
391 hdrbuf.resize(24);
392 in_data = false;
393 nHdrPos = 0;
394 nDataPos = 0;
395 data_hash.SetNull();
396 hasher.Reset();
397 }
398
399 bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
400 {
401 AssertLockHeld(m_recv_mutex);
402 if (!in_data) return false;
403 return hdr.nMessageSize == nDataPos;
404 }
405
409 std::vector<uint8_t> m_header_to_send GUARDED_BY(m_send_mutex);
411 CSerializedNetMsg m_message_to_send GUARDED_BY(m_send_mutex);
413 bool m_sending_header GUARDED_BY(m_send_mutex) {false};
415 size_t m_bytes_sent GUARDED_BY(m_send_mutex) {0};
416
417public:
418 explicit V1Transport(const NodeId node_id) noexcept;
419
420 bool ReceivedMessageComplete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
421 {
422 AssertLockNotHeld(m_recv_mutex);
423 return WITH_LOCK(m_recv_mutex, return CompleteInternal());
424 }
425
426 Info GetInfo() const noexcept override;
427
428 bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
429 {
430 AssertLockNotHeld(m_recv_mutex);
431 LOCK(m_recv_mutex);
432 int ret = in_data ? readData(msg_bytes) : readHeader(msg_bytes);
433 if (ret < 0) {
434 Reset();
435 } else {
436 msg_bytes = msg_bytes.subspan(ret);
437 }
438 return ret >= 0;
439 }
440
441 CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
442
443 bool SetMessageToSend(CSerializedNetMsg& msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
444 BytesToSend GetBytesToSend(bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
445 void MarkBytesSent(size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
446 size_t GetSendMemoryUsage() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
447 bool ShouldReconnectV1() const noexcept override { return false; }
448};
449
450class V2Transport final : public Transport
451{
452private:
456 static constexpr std::array<std::byte, 0> VERSION_CONTENTS = {};
457
460 static constexpr size_t V1_PREFIX_LEN = 16;
461
462 // The sender side and receiver side of V2Transport are state machines that are transitioned
463 // through, based on what has been received. The receive state corresponds to the contents of,
464 // and bytes received to, the receive buffer. The send state controls what can be appended to
465 // the send buffer and what can be sent from it.
466
481 enum class RecvState : uint8_t {
487 KEY_MAYBE_V1,
488
494 KEY,
495
502 GARB_GARBTERM,
503
512 VERSION,
513
519 APP,
520
525 APP_READY,
526
530 V1,
531 };
532
546 enum class SendState : uint8_t {
553 MAYBE_V1,
554
560 AWAITING_KEY,
561
568 READY,
569
573 V1,
574 };
575
579 const bool m_initiating;
584
586 mutable Mutex m_recv_mutex ACQUIRED_BEFORE(m_send_mutex);
589 uint32_t m_recv_len GUARDED_BY(m_recv_mutex) {0};
591 std::vector<uint8_t> m_recv_buffer GUARDED_BY(m_recv_mutex);
593 std::vector<uint8_t> m_recv_aad GUARDED_BY(m_recv_mutex);
595 std::vector<uint8_t> m_recv_decode_buffer GUARDED_BY(m_recv_mutex);
597 RecvState m_recv_state GUARDED_BY(m_recv_mutex);
598
601 mutable Mutex m_send_mutex ACQUIRED_AFTER(m_recv_mutex);
603 std::vector<uint8_t> m_send_buffer GUARDED_BY(m_send_mutex);
605 uint32_t m_send_pos GUARDED_BY(m_send_mutex) {0};
607 std::vector<uint8_t> m_send_garbage GUARDED_BY(m_send_mutex);
609 std::string m_send_type GUARDED_BY(m_send_mutex);
611 SendState m_send_state GUARDED_BY(m_send_mutex);
613 bool m_sent_v1_header_worth GUARDED_BY(m_send_mutex) {false};
614
616 void SetReceiveState(RecvState recv_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
618 void SetSendState(SendState send_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex);
620 static std::optional<std::string> GetMessageType(std::span<const uint8_t>& contents) noexcept;
622 size_t GetMaxBytesToProcess() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
624 void StartSendingHandshake() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex);
626 void ProcessReceivedMaybeV1Bytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex, !m_send_mutex);
628 bool ProcessReceivedKeyBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex, !m_send_mutex);
630 bool ProcessReceivedGarbageBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
632 bool ProcessReceivedPacketBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
633
634public:
635 static constexpr uint32_t MAX_GARBAGE_LEN = 4095;
636
642 V2Transport(NodeId nodeid, bool initiating) noexcept;
643
645 V2Transport(NodeId nodeid, bool initiating, const CKey& key, std::span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept;
646
647 // Receive side functions.
648 bool ReceivedMessageComplete() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
649 bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex, !m_send_mutex);
650 CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
651
652 // Send side functions.
653 bool SetMessageToSend(CSerializedNetMsg& msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
654 BytesToSend GetBytesToSend(bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
655 void MarkBytesSent(size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
656 size_t GetSendMemoryUsage() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
657
658 // Miscellaneous functions.
659 bool ShouldReconnectV1() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex, !m_send_mutex);
660 Info GetInfo() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
661};
662
664{
666 std::unique_ptr<i2p::sam::Session> i2p_sam_session = nullptr;
667 bool prefer_evict = false;
668 size_t recv_flood_size{DEFAULT_MAXRECEIVEBUFFER * 1000};
669 bool use_v2transport = false;
670};
671
673class CNode
674{
675public:
678 const std::unique_ptr<Transport> m_transport;
679
681
690 std::shared_ptr<Sock> m_sock GUARDED_BY(m_sock_mutex);
691
693 size_t m_send_memusage GUARDED_BY(cs_vSend){0};
695 uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
697 std::deque<CSerializedNetMsg> vSendMsg GUARDED_BY(cs_vSend);
701
702 uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
703
704 std::atomic<std::chrono::seconds> m_last_send{0s};
705 std::atomic<std::chrono::seconds> m_last_recv{0s};
707 const std::chrono::seconds m_connected;
708 // Address of this peer
710 // Bind address of our side of the connection
712 const std::string m_addr_name;
714 const std::string m_dest;
716 const bool m_inbound_onion;
717 std::atomic<int> nVersion{0};
723 std::string cleanSubVer GUARDED_BY(m_subver_mutex){};
724 const bool m_prefer_evict{false}; // This peer is preferred for eviction.
725 bool HasPermission(NetPermissionFlags permission) const {
726 return NetPermissions::HasFlag(m_permission_flags, permission);
727 }
729 std::atomic_bool fSuccessfullyConnected{false};
730 // Setting fDisconnect to true will cause the node to be disconnected the
731 // next time DisconnectNodes() runs
732 std::atomic_bool fDisconnect{false};
734 std::atomic<int> nRefCount{0};
735
736 const uint64_t nKeyedNetGroup;
737 std::atomic_bool fPauseRecv{false};
738 std::atomic_bool fPauseSend{false};
739
741
743 void MarkReceivedMsgsForProcessing()
744 EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex);
745
751 std::optional<std::pair<CNetMessage, bool>> PollMessage()
752 EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex);
753
755 void AccountForSentBytes(const std::string& msg_type, size_t sent_bytes)
757 {
758 mapSendBytesPerMsgType[msg_type] += sent_bytes;
759 }
760
762 switch (m_conn_type) {
765 return true;
770 return false;
771 } // no default case, so the compiler can warn about missing cases
772
773 assert(false);
774 }
775
776 bool IsFullOutboundConn() const {
777 return m_conn_type == ConnectionType::OUTBOUND_FULL_RELAY;
778 }
779
780 bool IsManualConn() const {
781 return m_conn_type == ConnectionType::MANUAL;
782 }
783
785 {
786 switch (m_conn_type) {
791 return false;
794 return true;
795 } // no default case, so the compiler can warn about missing cases
796
797 assert(false);
798 }
799
800 bool IsBlockOnlyConn() const {
801 return m_conn_type == ConnectionType::BLOCK_RELAY;
802 }
803
804 bool IsFeelerConn() const {
805 return m_conn_type == ConnectionType::FEELER;
806 }
807
808 bool IsAddrFetchConn() const {
809 return m_conn_type == ConnectionType::ADDR_FETCH;
810 }
811
812 bool IsInboundConn() const {
813 return m_conn_type == ConnectionType::INBOUND;
814 }
815
817 switch (m_conn_type) {
821 return false;
825 return true;
826 } // no default case, so the compiler can warn about missing cases
827
828 assert(false);
829 }
830
841 Network ConnectedThroughNetwork() const;
842
844 [[nodiscard]] bool IsConnectedThroughPrivacyNet() const;
845
846 // We selected peer as (compact blocks) high-bandwidth peer (BIP152)
847 std::atomic<bool> m_bip152_highbandwidth_to{false};
848 // Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
849 std::atomic<bool> m_bip152_highbandwidth_from{false};
850
852 std::atomic_bool m_has_all_wanted_services{false};
853
856 std::atomic_bool m_relays_txs{false};
857
860 std::atomic_bool m_bloom_filter_loaded{false};
861
867 std::atomic<std::chrono::seconds> m_last_block_time{0s};
868
873 std::atomic<std::chrono::seconds> m_last_tx_time{0s};
874
876 std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
877
880 std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()};
881
882 CNode(NodeId id,
883 std::shared_ptr<Sock> sock,
884 const CAddress& addrIn,
885 uint64_t nKeyedNetGroupIn,
886 uint64_t nLocalHostNonceIn,
887 const CService& addrBindIn,
888 const std::string& addrNameIn,
889 ConnectionType conn_type_in,
890 bool inbound_onion,
891 CNodeOptions&& node_opts = {});
892 CNode(const CNode&) = delete;
893 CNode& operator=(const CNode&) = delete;
894
895 NodeId GetId() const {
896 return id;
897 }
898
899 uint64_t GetLocalNonce() const {
900 return nLocalHostNonce;
901 }
902
903 int GetRefCount() const
904 {
905 assert(nRefCount >= 0);
906 return nRefCount;
907 }
908
918 bool ReceiveMsgBytes(std::span<const uint8_t> msg_bytes, bool& complete) EXCLUSIVE_LOCKS_REQUIRED(!cs_vRecv);
919
920 void SetCommonVersion(int greatest_common_version)
921 {
922 Assume(m_greatest_common_version == INIT_PROTO_VERSION);
923 m_greatest_common_version = greatest_common_version;
924 }
926 {
927 return m_greatest_common_version;
928 }
929
930 CService GetAddrLocal() const EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
932 void SetAddrLocal(const CService& addrLocalIn) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
933
934 CNode* AddRef()
935 {
936 nRefCount++;
937 return this;
938 }
939
940 void Release()
941 {
942 nRefCount--;
943 }
944
945 void CloseSocketDisconnect() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex);
946
947 void CopyStats(CNodeStats& stats) EXCLUSIVE_LOCKS_REQUIRED(!m_subver_mutex, !m_addr_local_mutex, !cs_vSend, !cs_vRecv);
948
950
957 std::string LogIP(bool log_ip) const;
958
965 std::string DisconnectMsg(bool log_ip) const;
966
968 void PongReceived(std::chrono::microseconds ping_time) {
969 m_last_ping_time = ping_time;
970 m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
971 }
972
973private:
974 const NodeId id;
975 const uint64_t nLocalHostNonce;
976 std::atomic<int> m_greatest_common_version{INIT_PROTO_VERSION};
977
978 const size_t m_recv_flood_size;
979 std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
980
982 std::list<CNetMessage> m_msg_process_queue GUARDED_BY(m_msg_process_queue_mutex);
983 size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex){0};
984
985 // Our address, as reported by the peer
986 CService m_addr_local GUARDED_BY(m_addr_local_mutex);
988
989 mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend);
990 mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv);
991
1002 std::unique_ptr<i2p::sam::Session> m_i2p_sam_session GUARDED_BY(m_sock_mutex);
1003};
1004
1009{
1010public:
1013
1015 virtual void InitializeNode(const CNode& node, ServiceFlags our_services) = 0;
1016
1018 virtual void FinalizeNode(const CNode& node) = 0;
1019
1024 virtual bool HasAllDesirableServiceFlags(ServiceFlags services) const = 0;
1025
1033 virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
1034
1041 virtual bool SendMessages(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
1042
1043
1044protected:
1050};
1051
1053{
1054public:
1055
1056 struct Options
1057 {
1058 ServiceFlags m_local_services = NODE_NONE;
1059 int m_max_automatic_connections = 0;
1061 NetEventsInterface* m_msgproc = nullptr;
1062 BanMan* m_banman = nullptr;
1063 unsigned int nSendBufferMaxSize = 0;
1064 unsigned int nReceiveFloodSize = 0;
1065 uint64_t nMaxOutboundLimit = 0;
1066 int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
1067 std::vector<std::string> vSeedNodes;
1068 std::vector<NetWhitelistPermissions> vWhitelistedRangeIncoming;
1069 std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
1070 std::vector<NetWhitebindPermissions> vWhiteBinds;
1071 std::vector<CService> vBinds;
1072 std::vector<CService> onion_binds;
1076 bool m_use_addrman_outgoing = true;
1077 std::vector<std::string> m_specified_outgoing;
1078 std::vector<std::string> m_added_nodes;
1080 bool whitelist_forcerelay = DEFAULT_WHITELISTFORCERELAY;
1081 bool whitelist_relay = DEFAULT_WHITELISTRELAY;
1082 };
1083
1084 void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_total_bytes_sent_mutex)
1085 {
1086 AssertLockNotHeld(m_total_bytes_sent_mutex);
1087
1088 m_local_services = connOptions.m_local_services;
1089 m_max_automatic_connections = connOptions.m_max_automatic_connections;
1090 m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, m_max_automatic_connections);
1091 m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, m_max_automatic_connections - m_max_outbound_full_relay);
1092 m_max_automatic_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + m_max_feeler;
1093 m_max_inbound = std::max(0, m_max_automatic_connections - m_max_automatic_outbound);
1094 m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
1095 m_client_interface = connOptions.uiInterface;
1096 m_banman = connOptions.m_banman;
1097 m_msgproc = connOptions.m_msgproc;
1098 nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
1099 nReceiveFloodSize = connOptions.nReceiveFloodSize;
1100 m_peer_connect_timeout = std::chrono::seconds{connOptions.m_peer_connect_timeout};
1101 {
1102 LOCK(m_total_bytes_sent_mutex);
1103 nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
1104 }
1105 vWhitelistedRangeIncoming = connOptions.vWhitelistedRangeIncoming;
1106 vWhitelistedRangeOutgoing = connOptions.vWhitelistedRangeOutgoing;
1107 {
1108 LOCK(m_added_nodes_mutex);
1109 // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
1110 // peer doesn't support it or immediately disconnects us for another reason.
1111 const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
1112 for (const std::string& added_node : connOptions.m_added_nodes) {
1113 m_added_node_params.push_back({added_node, use_v2transport});
1114 }
1115 }
1116 m_onion_binds = connOptions.onion_binds;
1117 whitelist_forcerelay = connOptions.whitelist_forcerelay;
1118 whitelist_relay = connOptions.whitelist_relay;
1119 }
1120
1121 CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, const NetGroupManager& netgroupman,
1122 const CChainParams& params, bool network_active = true);
1123
1124 ~CConnman();
1125
1126 bool Start(CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !m_added_nodes_mutex, !m_addr_fetches_mutex, !mutexMsgProc);
1127
1128 void StopThreads();
1129 void StopNodes();
1130 void Stop()
1131 {
1132 StopThreads();
1133 StopNodes();
1134 };
1135
1136 void Interrupt() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1137 bool GetNetworkActive() const { return fNetworkActive; };
1138 bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
1139 void SetNetworkActive(bool active);
1140 void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CountingSemaphoreGrant<>&& grant_outbound, const char* strDest, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1141 bool CheckIncomingNonce(uint64_t nonce);
1142 void ASMapHealthCheck();
1143
1144 // alias for thread safety annotations only, not defined
1146
1147 bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
1148
1149 void PushMessage(CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1150
1151 using NodeFn = std::function<void(CNode*)>;
1152 void ForEachNode(const NodeFn& func)
1153 {
1154 LOCK(m_nodes_mutex);
1155 for (auto&& node : m_nodes) {
1156 if (NodeFullyConnected(node))
1157 func(node);
1158 }
1159 };
1160
1161 void ForEachNode(const NodeFn& func) const
1162 {
1163 LOCK(m_nodes_mutex);
1164 for (auto&& node : m_nodes) {
1165 if (NodeFullyConnected(node))
1166 func(node);
1167 }
1168 };
1169
1170 // Addrman functions
1179 std::vector<CAddress> GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
1186 std::vector<CAddress> GetAddresses(CNode& requestor, size_t max_addresses, size_t max_pct);
1187
1188 // This allows temporarily exceeding m_max_outbound_full_relay, with the goal of finding
1189 // a peer that is better than all our current peers.
1190 void SetTryNewOutboundPeer(bool flag);
1191 bool GetTryNewOutboundPeer() const;
1192
1193 void StartExtraBlockRelayPeers();
1194
1195 // Count the number of full-relay peer we have.
1196 int GetFullOutboundConnCount() const;
1197 // Return the number of outbound peers we have in excess of our target (eg,
1198 // if we previously called SetTryNewOutboundPeer(true), and have since set
1199 // to false, we may have extra peers that we wish to disconnect). This may
1200 // return a value less than (num_outbound_connections - num_outbound_slots)
1201 // in cases where some outbound connections are not yet fully connected, or
1202 // not yet fully disconnected.
1203 int GetExtraFullOutboundCount() const;
1204 // Count the number of block-relay-only peers we have over our limit.
1205 int GetExtraBlockRelayCount() const;
1206
1207 bool AddNode(const AddedNodeParams& add) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1208 bool RemoveAddedNode(const std::string& node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1209 bool AddedNodesContain(const CAddress& addr) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1210 std::vector<AddedNodeInfo> GetAddedNodeInfo(bool include_connected) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1211
1225 bool AddConnection(const std::string& address, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1226
1227 size_t GetNodeCount(ConnectionDirection) const;
1228 std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
1229 uint32_t GetMappedAS(const CNetAddr& addr) const;
1230 void GetNodeStats(std::vector<CNodeStats>& vstats) const;
1231 bool DisconnectNode(const std::string& node);
1232 bool DisconnectNode(const CSubNet& subnet);
1233 bool DisconnectNode(const CNetAddr& addr);
1234 bool DisconnectNode(NodeId id);
1235
1242 ServiceFlags GetLocalServices() const;
1243
1246 void AddLocalServices(ServiceFlags services) { m_local_services = ServiceFlags(m_local_services | services); };
1247 void RemoveLocalServices(ServiceFlags services) { m_local_services = ServiceFlags(m_local_services & ~services); }
1248
1249 uint64_t GetMaxOutboundTarget() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1250 std::chrono::seconds GetMaxOutboundTimeframe() const;
1251
1255 bool OutboundTargetReached(bool historicalBlockServingLimit) const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1256
1259 uint64_t GetOutboundTargetBytesLeft() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1260
1261 std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1262
1263 uint64_t GetTotalBytesRecv() const;
1264 uint64_t GetTotalBytesSent() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1265
1267 CSipHasher GetDeterministicRandomizer(uint64_t id) const;
1268
1269 void WakeMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1270
1272 bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const;
1273
1274 bool MultipleManualOrFullOutboundConns(Network net) const EXCLUSIVE_LOCKS_REQUIRED(m_nodes_mutex);
1275
1276private:
1278 public:
1279 std::shared_ptr<Sock> sock;
1281 ListenSocket(std::shared_ptr<Sock> sock_, NetPermissionFlags permissions_)
1282 : sock{sock_}, m_permissions{permissions_}
1283 {
1284 }
1285
1286 private:
1288 };
1289
1292 std::chrono::seconds GetMaxOutboundTimeLeftInCycle_() const EXCLUSIVE_LOCKS_REQUIRED(m_total_bytes_sent_mutex);
1293
1294 bool BindListenPort(const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
1295 bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
1296 bool InitBinds(const Options& options);
1297
1298 void ThreadOpenAddedConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_unused_i2p_sessions_mutex, !m_reconnections_mutex);
1299 void AddAddrFetch(const std::string& strDest) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex);
1300 void ProcessAddrFetch() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_unused_i2p_sessions_mutex);
1301 void ThreadOpenConnections(std::vector<std::string> connect, std::span<const std::string> seed_nodes) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_added_nodes_mutex, !m_nodes_mutex, !m_unused_i2p_sessions_mutex, !m_reconnections_mutex);
1302 void ThreadMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1303 void ThreadI2PAcceptIncoming();
1304 void AcceptConnection(const ListenSocket& hListenSocket);
1305
1314 void CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
1315 NetPermissionFlags permission_flags,
1316 const CService& addr_bind,
1317 const CService& addr);
1318
1319 void DisconnectNodes() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_nodes_mutex);
1320 void NotifyNumConnectionsChanged();
1322 bool InactivityCheck(const CNode& node) const;
1323
1329 Sock::EventsPerSock GenerateWaitSockets(std::span<CNode* const> nodes);
1330
1334 void SocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1335
1341 void SocketHandlerConnected(const std::vector<CNode*>& nodes,
1342 const Sock::EventsPerSock& events_per_sock)
1343 EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1344
1349 void SocketHandlerListening(const Sock::EventsPerSock& events_per_sock);
1350
1351 void ThreadSocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc, !m_nodes_mutex, !m_reconnections_mutex);
1352 void ThreadDNSAddressSeed() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_nodes_mutex);
1353
1354 uint64_t CalculateKeyedNetGroup(const CNetAddr& ad) const;
1355
1356 CNode* FindNode(const CNetAddr& ip);
1357 CNode* FindNode(const std::string& addrName);
1358 CNode* FindNode(const CService& addr);
1359
1364 bool AlreadyConnectedToAddress(const CAddress& addr);
1365
1366 bool AttemptToEvictConnection();
1367 CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1368 void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr, const std::vector<NetWhitelistPermissions>& ranges) const;
1369
1370 void DeleteNode(CNode* pnode);
1371
1372 NodeId GetNewNodeId();
1373
1375 std::pair<size_t, bool> SocketSendData(CNode& node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
1376
1377 void DumpAddresses();
1378
1379 // Network stats
1380 void RecordBytesRecv(uint64_t bytes);
1381 void RecordBytesSent(uint64_t bytes) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1382
1387 std::unordered_set<Network> GetReachableEmptyNetworks() const;
1388
1392 std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;
1393
1404 bool MaybePickPreferredNetwork(std::optional<Network>& network);
1405
1406 // Whether the node should be passed out in ForEach* callbacks
1407 static bool NodeFullyConnected(const CNode* pnode);
1408
1409 uint16_t GetDefaultPort(Network net) const;
1410 uint16_t GetDefaultPort(const std::string& addr) const;
1411
1412 // Network usage totals
1413 mutable Mutex m_total_bytes_sent_mutex;
1414 std::atomic<uint64_t> nTotalBytesRecv{0};
1415 uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex) {0};
1416
1417 // outbound limit & stats
1418 uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex) {0};
1419 std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex) {0};
1420 uint64_t nMaxOutboundLimit GUARDED_BY(m_total_bytes_sent_mutex);
1421
1422 // P2P timeout in seconds
1423 std::chrono::seconds m_peer_connect_timeout;
1424
1425 // Whitelisted ranges. Any node connecting from these is automatically
1426 // whitelisted (as well as those connecting to whitelisted binds).
1427 std::vector<NetWhitelistPermissions> vWhitelistedRangeIncoming;
1428 // Whitelisted ranges for outgoing connections.
1429 std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
1430
1431 unsigned int nSendBufferMaxSize{0};
1432 unsigned int nReceiveFloodSize{0};
1433
1434 std::vector<ListenSocket> vhListenSocket;
1435 std::atomic<bool> fNetworkActive{true};
1436 bool fAddressesInitialized{false};
1439 std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
1441
1442 // connection string and whether to use v2 p2p
1443 std::vector<AddedNodeParams> m_added_node_params GUARDED_BY(m_added_nodes_mutex);
1444
1446 std::vector<CNode*> m_nodes GUARDED_BY(m_nodes_mutex);
1447 std::list<CNode*> m_nodes_disconnected;
1449 std::atomic<NodeId> nLastNodeId{0};
1450 unsigned int nPrevNodeCount{0};
1451
1452 // Stores number of full-tx connections (outbound and manual) per network
1453 std::array<unsigned int, Network::NET_MAX> m_network_conn_counts GUARDED_BY(m_nodes_mutex) = {};
1454
1462 std::vector<CAddress> m_addrs_response_cache;
1463 std::chrono::microseconds m_cache_entry_expiration{0};
1464 };
1465
1480 std::map<uint64_t, CachedAddrResponse> m_addr_response_caches;
1481
1493 std::atomic<ServiceFlags> m_local_services;
1494
1495 std::unique_ptr<std::counting_semaphore<>> semOutbound;
1496 std::unique_ptr<std::counting_semaphore<>> semAddnode;
1497
1504
1505 /*
1506 * Maximum number of peers by connection type. Might vary from defaults
1507 * based on -maxconnections init value.
1508 */
1509
1510 // How many full-relay (tx, block, addr) outbound peers we want
1512
1513 // How many block-relay only outbound peers we want
1514 // We do not relay tx or addr messages with these peers
1516
1517 int m_max_addnode{MAX_ADDNODE_CONNECTIONS};
1518 int m_max_feeler{MAX_FEELER_CONNECTIONS};
1521
1527
1532 std::vector<CAddress> m_anchors;
1533
1535 const uint64_t nSeed0, nSeed1;
1536
1538 bool fMsgProcWake GUARDED_BY(mutexMsgProc);
1539
1540 std::condition_variable condMsgProc;
1542 std::atomic<bool> flagInterruptMsgProc{false};
1543
1551
1557 std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
1558
1565
1570
1575 std::atomic_bool m_start_extra_block_relay_peers{false};
1576
1581 std::vector<CService> m_onion_binds;
1582
1588
1594
1599
1607 std::queue<std::unique_ptr<i2p::sam::Session>> m_unused_i2p_sessions GUARDED_BY(m_unused_i2p_sessions_mutex);
1608
1613
1616 {
1619 std::string destination;
1622 };
1623
1627 std::list<ReconnectionInfo> m_reconnections GUARDED_BY(m_reconnections_mutex);
1628
1630 void PerformReconnections() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_unused_i2p_sessions_mutex);
1631
1636 static constexpr size_t MAX_UNUSED_I2P_SESSIONS_SIZE{10};
1637
1643 {
1644 public:
1645 explicit NodesSnapshot(const CConnman& connman, bool shuffle)
1646 {
1647 {
1648 LOCK(connman.m_nodes_mutex);
1649 m_nodes_copy = connman.m_nodes;
1650 for (auto& node : m_nodes_copy) {
1651 node->AddRef();
1652 }
1653 }
1654 if (shuffle) {
1655 std::shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});
1656 }
1657 }
1658
1660 {
1661 for (auto& node : m_nodes_copy) {
1662 node->Release();
1663 }
1664 }
1665
1666 const std::vector<CNode*>& Nodes() const
1667 {
1668 return m_nodes_copy;
1669 }
1670
1671 private:
1672 std::vector<CNode*> m_nodes_copy;
1673 };
1674
1676
1677 friend struct ConnmanTestMsg;
1678};
1679
1681extern std::function<void(const CAddress& addr,
1682 const std::string& msg_type,
1683 std::span<const unsigned char> data,
1684 bool is_incoming)>
1686
1687#endif // BITCOIN_NET_H
int ret
int flags
Definition: bitcoin-tx.cpp:529
Interrupt(node)
#define Assume(val)
Assume is the identity function.
Definition: check.h:118
Stochastic address manager.
Definition: addrman.h:89
The BIP324 packet cipher, encapsulating its key derivation, stream cipher, and AEAD.
Definition: bip324.h:20
Definition: banman.h:64
A CService with information about it as peer.
Definition: protocol.h:367
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:69
Signals for UI communication.
Definition: interface_ui.h:26
RAII helper to atomically create a copy of m_nodes and add a reference to each of the nodes.
Definition: net.h:1643
const std::vector< CNode * > & Nodes() const
Definition: net.h:1666
NodesSnapshot(const CConnman &connman, bool shuffle)
Definition: net.h:1645
std::vector< CNode * > m_nodes_copy
Definition: net.h:1672
Definition: net.h:1053
bool whitelist_relay
flag for adding 'relay' permission to whitelisted inbound and manual peers with default permissions.
Definition: net.h:1593
std::condition_variable condMsgProc
Definition: net.h:1540
std::thread threadMessageHandler
Definition: net.h:1563
void RemoveLocalServices(ServiceFlags services)
Definition: net.h:1247
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
Definition: net.h:1427
CClientUIInterface * m_client_interface
Definition: net.h:1523
void ForEachNode(const NodeFn &func) const
Definition: net.h:1161
std::vector< AddedNodeParams > m_added_node_params GUARDED_BY(m_added_nodes_mutex)
int m_max_inbound
Definition: net.h:1520
const bool use_v2transport(GetLocalServices() &NODE_P2P_V2)
void Stop()
Definition: net.h:1130
int m_max_outbound_block_relay
Definition: net.h:1515
std::array< unsigned int, Network::NET_MAX > m_network_conn_counts GUARDED_BY(m_nodes_mutex)
std::thread threadI2PAcceptIncoming
Definition: net.h:1564
std::list< ReconnectionInfo > m_reconnections GUARDED_BY(m_reconnections_mutex)
List of reconnections we have to make.
int m_max_automatic_outbound
Definition: net.h:1519
uint64_t nMaxOutboundLimit GUARDED_BY(m_total_bytes_sent_mutex)
CThreadInterrupt interruptNet
This is signaled when network activity should cease.
Definition: net.h:1550
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:1503
BanMan * m_banman
Pointer to this node's banman.
Definition: net.h:1526
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1418
std::thread threadDNSAddressSeed
Definition: net.h:1559
const NetGroupManager & m_netgroupman
Definition: net.h:1438
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
Definition: net.h:1532
bool whitelist_forcerelay
flag for adding 'forcerelay' permission to whitelisted inbound and manual peers with default permissi...
Definition: net.h:1587
std::chrono::seconds m_peer_connect_timeout
Definition: net.h:1423
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:1569
std::vector< ListenSocket > vhListenSocket
Definition: net.h:1434
std::thread threadOpenConnections
Definition: net.h:1562
std::atomic< ServiceFlags > m_local_services
Services this node offers.
Definition: net.h:1493
Mutex m_addr_fetches_mutex
Definition: net.h:1440
Mutex m_reconnections_mutex
Mutex protecting m_reconnections.
Definition: net.h:1612
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:1535
RecursiveMutex m_nodes_mutex
Definition: net.h:1448
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::unique_ptr< std::counting_semaphore<> > semOutbound
Definition: net.h:1495
const CChainParams & m_params
Definition: net.h:1675
std::deque< std::string > m_addr_fetches GUARDED_BY(m_addr_fetches_mutex)
void AddLocalServices(ServiceFlags services)
Updates the local services that this node advertises to other peers during connection handshake.
Definition: net.h:1246
AddrMan & addrman
Definition: net.h:1437
Mutex mutexMsgProc
Definition: net.h:1541
std::thread threadOpenAddedConnections
Definition: net.h:1561
Mutex m_added_nodes_mutex
Definition: net.h:1445
int m_max_outbound_full_relay
Definition: net.h:1511
Mutex m_unused_i2p_sessions_mutex
Mutex protecting m_i2p_sam_sessions.
Definition: net.h:1598
std::vector< CNode * > m_nodes GUARDED_BY(m_nodes_mutex)
std::unique_ptr< std::counting_semaphore<> > semAddnode
Definition: net.h:1496
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1419
uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1415
bool GetUseAddrmanOutgoing() const
Definition: net.h:1138
std::list< CNode * > m_nodes_disconnected
Definition: net.h:1447
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session
I2P SAM session.
Definition: net.h:1557
bool m_use_addrman_outgoing
Definition: net.h:1522
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
Definition: net.h:1429
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:1480
std::function< void(CNode *)> NodeFn
Definition: net.h:1151
NetEventsInterface * m_msgproc
Definition: net.h:1524
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:1581
RecursiveMutex & GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex)
std::thread threadSocketHandler
Definition: net.h:1560
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
Definition: hash.h:24
An encapsulated private key.
Definition: key.h:35
Message header.
Definition: protocol.h:29
Network address.
Definition: netaddress.h:112
Transport protocol agnostic message container.
Definition: net.h:232
CNetMessage(CNetMessage &&)=default
CNetMessage(DataStream &&recv_in)
Definition: net.h:240
std::string m_type
Definition: net.h:238
DataStream m_recv
received message data
Definition: net.h:234
CNetMessage & operator=(const CNetMessage &)=delete
CNetMessage(const CNetMessage &)=delete
CNetMessage & operator=(CNetMessage &&)=default
Information about a peer.
Definition: net.h:674
bool IsFeelerConn() const
Definition: net.h:804
const std::chrono::seconds m_connected
Unix epoch time at peer connection.
Definition: net.h:707
bool ExpectServicesFromConn() const
Definition: net.h:816
const std::string m_dest
The pszDest argument provided to ConnectNode().
Definition: net.h:714
CService m_addr_local GUARDED_BY(m_addr_local_mutex)
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:702
bool IsInboundConn() const
Definition: net.h:812
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:725
CountingSemaphoreGrant grantOutbound
Definition: net.h:733
bool IsOutboundOrBlockRelayConn() const
Definition: net.h:761
NodeId GetId() const
Definition: net.h:895
bool IsManualConn() const
Definition: net.h:780
const std::string m_addr_name
Definition: net.h:712
CNode & operator=(const CNode &)=delete
const CService addrBind
Definition: net.h:711
void SetCommonVersion(int greatest_common_version)
Definition: net.h:920
std::list< CNetMessage > vRecvMsg
Definition: net.h:979
void PongReceived(std::chrono::microseconds ping_time)
A ping-pong round trip has completed successfully.
Definition: net.h:968
size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex)
Definition: net.h:983
bool IsAddrFetchConn() const
Definition: net.h:808
uint64_t GetLocalNonce() const
Definition: net.h:899
const CAddress addr
Definition: net.h:709
mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend)
const uint64_t nKeyedNetGroup
Definition: net.h:736
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...
bool IsBlockOnlyConn() const
Definition: net.h:800
int GetCommonVersion() const
Definition: net.h:925
mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv)
bool IsFullOutboundConn() const
Definition: net.h:776
Mutex m_subver_mutex
Definition: net.h:718
Mutex cs_vSend
Definition: net.h:698
int GetRefCount() const
Definition: net.h:903
Mutex m_msg_process_queue_mutex
Definition: net.h:981
const ConnectionType m_conn_type
Definition: net.h:740
const size_t m_recv_flood_size
Definition: net.h:978
const uint64_t nLocalHostNonce
Definition: net.h:975
bool IsManualOrFullOutboundConn() const
Definition: net.h:784
const std::unique_ptr< Transport > m_transport
Transport serializer/deserializer.
Definition: net.h:678
std::shared_ptr< Sock > m_sock GUARDED_BY(m_sock_mutex)
Socket used for communication with the node.
const NetPermissionFlags m_permission_flags
Definition: net.h:680
Mutex m_addr_local_mutex
Definition: net.h:987
CNode(const CNode &)=delete
size_t m_send_memusage GUARDED_BY(cs_vSend)
Sum of GetMemoryUsage of all vSendMsg entries.
Definition: net.h:693
const bool m_inbound_onion
Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
Definition: net.h:716
const NodeId id
Definition: net.h:974
Mutex cs_vRecv
Definition: net.h:700
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Total number of bytes sent on the wire to this peer.
Definition: net.h:695
Mutex m_sock_mutex
Definition: net.h:699
std::list< CNetMessage > m_msg_process_queue GUARDED_BY(m_msg_process_queue_mutex)
std::deque< CSerializedNetMsg > vSendMsg GUARDED_BY(cs_vSend)
Messages still to be fed to m_transport->SetMessageToSend.
void Release()
Definition: net.h:940
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:723
std::string m_session_id
BIP324 session id string in hex, if any.
Definition: net.h:223
std::string addrLocal
Definition: net.h:211
uint64_t nRecvBytes
Definition: net.h:205
std::chrono::microseconds m_last_ping_time
Definition: net.h:208
uint32_t m_mapped_as
Definition: net.h:218
mapMsgTypeSize mapRecvBytesPerMsgType
Definition: net.h:206
bool fInbound
Definition: net.h:197
uint64_t nSendBytes
Definition: net.h:203
std::chrono::seconds m_last_recv
Definition: net.h:190
ConnectionType m_conn_type
Definition: net.h:219
std::chrono::seconds m_last_send
Definition: net.h:189
std::chrono::seconds m_last_tx_time
Definition: net.h:191
CAddress addr
Definition: net.h:213
mapMsgTypeSize mapSendBytesPerMsgType
Definition: net.h:204
std::chrono::microseconds m_min_ping_time
Definition: net.h:209
CService addrBind
Definition: net.h:215
TransportProtocolType m_transport_type
Transport protocol type.
Definition: net.h:221
std::chrono::seconds m_connected
Definition: net.h:193
bool m_bip152_highbandwidth_from
Definition: net.h:201
bool m_bip152_highbandwidth_to
Definition: net.h:199
std::string m_addr_name
Definition: net.h:194
int nVersion
Definition: net.h:195
std::chrono::seconds m_last_block_time
Definition: net.h:192
Network m_network
Definition: net.h:217
NodeId nodeid
Definition: net.h:188
std::string cleanSubVer
Definition: net.h:196
int m_starting_height
Definition: net.h:202
NetPermissionFlags m_permission_flags
Definition: net.h:207
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:40
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.
RAII-style semaphore lock.
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:148
Fast randomness source.
Definition: random.h:377
Different type to mark Mutex at global scope.
Definition: sync.h:140
Definition: init.h:13
Interface for message handling.
Definition: net.h:1009
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition: net.h:1012
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(const CNode &node, ServiceFlags our_services)=0
Initialize a peer (setup state)
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
The Transport converts one connection's sent messages to wire bytes, and received bytes back.
Definition: net.h:255
virtual ~Transport()=default
virtual Info GetInfo() const noexcept=0
Retrieve information about this transport.
std::tuple< std::span< const uint8_t >, bool, const std::string & > BytesToSend
Return type for GetBytesToSend, consisting of:
Definition: net.h:312
CHash256 hasher GUARDED_BY(m_recv_mutex)
DataStream hdrbuf GUARDED_BY(m_recv_mutex)
Definition: net.h:377
bool m_sending_header GUARDED_BY(m_send_mutex)
Whether we're currently sending header bytes or message bytes.
Definition: net.h:413
const NodeId m_node_id
Definition: net.h:372
Mutex m_send_mutex
Lock for sending state.
Definition: net.h:407
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:415
unsigned int nDataPos GUARDED_BY(m_recv_mutex)
bool in_data GUARDED_BY(m_recv_mutex)
uint256 data_hash 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.
const MessageStartChars m_magic_bytes
Definition: net.h:371
unsigned int nHdrPos GUARDED_BY(m_recv_mutex)
DataStream vRecv GUARDED_BY(m_recv_mutex)
Definition: net.h:379
bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
Definition: net.h:399
CMessageHeader hdr GUARDED_BY(m_recv_mutex)
Mutex m_recv_mutex
Lock for receive state.
Definition: net.h:373
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:420
std::vector< uint8_t > m_send_buffer GUARDED_BY(m_send_mutex)
The send buffer; meaning is determined by m_send_state.
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:613
const NodeId m_nodeid
NodeId (for debug logging).
Definition: net.h:581
BIP324Cipher m_cipher
Cipher state.
Definition: net.h:577
SendState
State type that controls the sender side.
Definition: net.h:546
V1Transport m_v1_fallback
Encapsulate a V1Transport to fall back to.
Definition: net.h:583
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::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:579
std::vector< uint8_t > m_recv_buffer GUARDED_BY(m_recv_mutex)
Receive buffer; meaning is determined by m_recv_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).
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:589
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:605
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_aad GUARDED_BY(m_recv_mutex)
AAD expected in next received packet (currently used only for garbage).
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:481
256-bit opaque blob.
Definition: uint256.h:196
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
std::array< uint8_t, 4 > MessageStartChars
unsigned int nonce
Definition: miner_tests.cpp:74
Definition: messages.h:20
static const unsigned char VERSION[]
Definition: netaddress.cpp:187
const std::string KEY
Definition: walletdb.cpp:44
uint16_t GetListenPort()
Definition: net.cpp:137
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:78
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:322
void RemoveLocal(const CService &addr)
Definition: net.cpp:303
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
Definition: net.h:66
static constexpr std::chrono::minutes TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:58
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:70
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:270
bool fDiscover
Definition: net.cpp:115
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:94
static const int NUM_FDS_MESSAGE_CAPTURE
Number of file descriptors required for message capture.
Definition: net.h:86
static constexpr bool DEFAULT_FIXEDSEEDS
Definition: net.h:92
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:82
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:64
bool fListen
Definition: net.cpp:116
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL
Run the extra block-relay-only connection loop once every 5 minutes.
Definition: net.h:62
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:93
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:80
std::optional< CService > GetLocalAddrForPeer(CNode &node)
Returns a local address that we should advertise to this peer.
Definition: net.cpp:239
const std::string NET_MESSAGE_TYPE_OTHER
Definition: net.cpp:107
std::map< std::string, uint64_t > mapMsgTypeSize
Definition: net.h:183
static constexpr bool DEFAULT_FORCEDNSSEED
Definition: net.h:90
static constexpr bool DEFAULT_DNSSEED
Definition: net.h:91
int64_t NodeId
Definition: net.h:98
CService GetLocalAddress(const CNode &peer)
Definition: net.cpp:219
GlobalMutex g_maplocalhost_mutex
Definition: net.cpp:117
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:74
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:76
static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL
Interval for ASMap Health Check.
Definition: net.h:88
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(g_maplocalhost_mutex)
static constexpr auto FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes.
Definition: net.h:60
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:84
std::function< void(const CAddress &addr, const std::string &msg_type, std::span< const unsigned char > data, bool is_incoming)> CaptureMessage
Defaults to CaptureMessageToFile(), but can be overridden by unit tests.
Definition: net.cpp:4014
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition: net.h:68
@ LOCAL_NONE
Definition: net.h:149
@ LOCAL_MAPPED
Definition: net.h:152
@ LOCAL_MANUAL
Definition: net.h:153
@ LOCAL_MAX
Definition: net.h:155
@ LOCAL_BIND
Definition: net.h:151
@ LOCAL_IF
Definition: net.h:150
static constexpr bool DEFAULT_V2_TRANSPORT
Definition: net.h:96
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:72
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:3179
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:311
constexpr bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
constexpr bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
NetPermissionFlags
Network
A network type.
Definition: netaddress.h:32
ConnectionDirection
Definition: netbase.h:33
ServiceFlags
nServices flags
Definition: protocol.h:309
@ NODE_NONE
Definition: protocol.h:312
@ NODE_P2P_V2
Definition: protocol.h:330
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
bool fInbound
Definition: net.h:109
CService resolvedAddress
Definition: net.h:107
AddedNodeParams m_params
Definition: net.h:106
bool fConnected
Definition: net.h:108
std::string m_added_node
Definition: net.h:101
bool m_use_v2transport
Definition: net.h:102
Cache responses to addr requests to minimize privacy leak.
Definition: net.h:1461
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:1462
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:1280
ListenSocket(std::shared_ptr< Sock > sock_, NetPermissionFlags permissions_)
Definition: net.h:1281
NetPermissionFlags m_permissions
Definition: net.h:1287
std::shared_ptr< Sock > sock
Definition: net.h:1279
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:1070
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
Definition: net.h:1068
std::vector< CService > onion_binds
Definition: net.h:1072
std::vector< std::string > m_specified_outgoing
Definition: net.h:1077
std::vector< std::string > m_added_nodes
Definition: net.h:1078
std::vector< CService > vBinds
Definition: net.h:1071
bool m_i2p_accept_incoming
Definition: net.h:1079
std::vector< std::string > vSeedNodes
Definition: net.h:1067
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
Definition: net.h:1075
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
Definition: net.h:1069
Struct for entries in m_reconnections.
Definition: net.h:1616
ConnectionType conn_type
Definition: net.h:1620
std::string destination
Definition: net.h:1619
CountingSemaphoreGrant grant
Definition: net.h:1618
CSerializedNetMsg(const CSerializedNetMsg &msg)=delete
CSerializedNetMsg Copy() const
Definition: net.h:123
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
std::string m_type
Definition: net.h:132
CSerializedNetMsg & operator=(const CSerializedNetMsg &)=delete
CSerializedNetMsg()=default
CSerializedNetMsg(CSerializedNetMsg &&)=default
std::vector< unsigned char > data
Definition: net.h:131
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:176
int nScore
Definition: net.h:175
std::optional< uint256 > session_id
Definition: net.h:262
TransportProtocolType transport_type
Definition: net.h:261
Bilingual messages:
Definition: translation.h:24
#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:302
#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:847
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())