Bitcoin Core 30.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>
34#include <util/threadinterrupt.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
161void ClearLocal();
162bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
163bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
164void RemoveLocal(const CService& addr);
165bool SeenLocal(const CService& addr);
166bool IsLocal(const CService& addr);
167CService GetLocalAddress(const CNode& peer);
168
169extern bool fDiscover;
170extern bool fListen;
171
173extern std::string strSubVersion;
174
177 uint16_t nPort;
178};
179
181extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
182
183extern const std::string NET_MESSAGE_TYPE_OTHER;
184using mapMsgTypeSize = std::map</* message type */ std::string, /* total bytes */ uint64_t>;
185
187{
188public:
190 std::chrono::seconds m_last_send;
191 std::chrono::seconds m_last_recv;
192 std::chrono::seconds m_last_tx_time;
193 std::chrono::seconds m_last_block_time;
194 std::chrono::seconds m_connected;
195 std::string m_addr_name;
197 std::string cleanSubVer;
199 // We requested high bandwidth connection to peer
201 // Peer requested high bandwidth connection
204 uint64_t nSendBytes;
206 uint64_t nRecvBytes;
209 std::chrono::microseconds m_last_ping_time;
210 std::chrono::microseconds m_min_ping_time;
211 // Our address, as reported by the peer
212 std::string addrLocal;
213 // Address of this peer
215 // Bind address of our side of the connection
217 // Network the peer connected through
219 uint32_t m_mapped_as;
224 std::string m_session_id;
225};
226
227
233{
234public:
236 std::chrono::microseconds m_time{0};
237 uint32_t m_message_size{0};
238 uint32_t m_raw_message_size{0};
239 std::string m_type;
240
241 explicit CNetMessage(DataStream&& recv_in) : m_recv(std::move(recv_in)) {}
242 // Only one CNetMessage object will exist for the same message on either
243 // the receive or processing queue. For performance reasons we therefore
244 // delete the copy constructor and assignment operator to avoid the
245 // possibility of copying CNetMessage objects.
247 CNetMessage(const CNetMessage&) = delete;
250
252 size_t GetMemoryUsage() const noexcept;
253};
254
257public:
258 virtual ~Transport() = default;
259
260 struct Info
261 {
263 std::optional<uint256> session_id;
264 };
265
267 virtual Info GetInfo() const noexcept = 0;
268
269 // 1. Receiver side functions, for decoding bytes received on the wire into transport protocol
270 // agnostic CNetMessage (message type & payload) objects.
271
273 virtual bool ReceivedMessageComplete() const = 0;
274
281 virtual bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) = 0;
282
290 virtual CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) = 0;
291
292 // 2. Sending side functions, for converting messages into bytes to be sent over the wire.
293
300 virtual bool SetMessageToSend(CSerializedNetMsg& msg) noexcept = 0;
301
309 using BytesToSend = std::tuple<
310 std::span<const uint8_t> /*to_send*/,
311 bool /*more*/,
312 const std::string& /*m_type*/
313 >;
314
350 virtual BytesToSend GetBytesToSend(bool have_next_message) const noexcept = 0;
351
358 virtual void MarkBytesSent(size_t bytes_sent) noexcept = 0;
359
361 virtual size_t GetSendMemoryUsage() const noexcept = 0;
362
363 // 3. Miscellaneous functions.
364
366 virtual bool ShouldReconnectV1() const noexcept = 0;
367};
368
369class V1Transport final : public Transport
370{
371private:
373 const NodeId m_node_id; // Only for logging
375 mutable CHash256 hasher GUARDED_BY(m_recv_mutex);
376 mutable uint256 data_hash GUARDED_BY(m_recv_mutex);
377 bool in_data GUARDED_BY(m_recv_mutex); // parsing header (false) or data (true)
378 DataStream hdrbuf GUARDED_BY(m_recv_mutex){}; // partially received header
379 CMessageHeader hdr GUARDED_BY(m_recv_mutex); // complete header
380 DataStream vRecv GUARDED_BY(m_recv_mutex){}; // received message data
381 unsigned int nHdrPos GUARDED_BY(m_recv_mutex);
382 unsigned int nDataPos GUARDED_BY(m_recv_mutex);
383
384 const uint256& GetMessageHash() const EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
385 int readHeader(std::span<const uint8_t> msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
386 int readData(std::span<const uint8_t> msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
387
388 void Reset() EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex) {
389 AssertLockHeld(m_recv_mutex);
390 vRecv.clear();
391 hdrbuf.clear();
392 hdrbuf.resize(24);
393 in_data = false;
394 nHdrPos = 0;
395 nDataPos = 0;
396 data_hash.SetNull();
397 hasher.Reset();
398 }
399
400 bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
401 {
402 AssertLockHeld(m_recv_mutex);
403 if (!in_data) return false;
404 return hdr.nMessageSize == nDataPos;
405 }
406
410 std::vector<uint8_t> m_header_to_send GUARDED_BY(m_send_mutex);
412 CSerializedNetMsg m_message_to_send GUARDED_BY(m_send_mutex);
414 bool m_sending_header GUARDED_BY(m_send_mutex) {false};
416 size_t m_bytes_sent GUARDED_BY(m_send_mutex) {0};
417
418public:
419 explicit V1Transport(const NodeId node_id) noexcept;
420
421 bool ReceivedMessageComplete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
422 {
423 AssertLockNotHeld(m_recv_mutex);
424 return WITH_LOCK(m_recv_mutex, return CompleteInternal());
425 }
426
427 Info GetInfo() const noexcept override;
428
429 bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
430 {
431 AssertLockNotHeld(m_recv_mutex);
432 LOCK(m_recv_mutex);
433 int ret = in_data ? readData(msg_bytes) : readHeader(msg_bytes);
434 if (ret < 0) {
435 Reset();
436 } else {
437 msg_bytes = msg_bytes.subspan(ret);
438 }
439 return ret >= 0;
440 }
441
442 CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
443
444 bool SetMessageToSend(CSerializedNetMsg& msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
445 BytesToSend GetBytesToSend(bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
446 void MarkBytesSent(size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
447 size_t GetSendMemoryUsage() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
448 bool ShouldReconnectV1() const noexcept override { return false; }
449};
450
451class V2Transport final : public Transport
452{
453private:
457 static constexpr std::array<std::byte, 0> VERSION_CONTENTS = {};
458
461 static constexpr size_t V1_PREFIX_LEN = 16;
462
463 // The sender side and receiver side of V2Transport are state machines that are transitioned
464 // through, based on what has been received. The receive state corresponds to the contents of,
465 // and bytes received to, the receive buffer. The send state controls what can be appended to
466 // the send buffer and what can be sent from it.
467
482 enum class RecvState : uint8_t {
488 KEY_MAYBE_V1,
489
495 KEY,
496
503 GARB_GARBTERM,
504
513 VERSION,
514
520 APP,
521
526 APP_READY,
527
531 V1,
532 };
533
547 enum class SendState : uint8_t {
554 MAYBE_V1,
555
561 AWAITING_KEY,
562
569 READY,
570
574 V1,
575 };
576
580 const bool m_initiating;
585
587 mutable Mutex m_recv_mutex ACQUIRED_BEFORE(m_send_mutex);
590 uint32_t m_recv_len GUARDED_BY(m_recv_mutex) {0};
592 std::vector<uint8_t> m_recv_buffer GUARDED_BY(m_recv_mutex);
594 std::vector<uint8_t> m_recv_aad GUARDED_BY(m_recv_mutex);
596 std::vector<uint8_t> m_recv_decode_buffer GUARDED_BY(m_recv_mutex);
598 RecvState m_recv_state GUARDED_BY(m_recv_mutex);
599
602 mutable Mutex m_send_mutex ACQUIRED_AFTER(m_recv_mutex);
604 std::vector<uint8_t> m_send_buffer GUARDED_BY(m_send_mutex);
606 uint32_t m_send_pos GUARDED_BY(m_send_mutex) {0};
608 std::vector<uint8_t> m_send_garbage GUARDED_BY(m_send_mutex);
610 std::string m_send_type GUARDED_BY(m_send_mutex);
612 SendState m_send_state GUARDED_BY(m_send_mutex);
614 bool m_sent_v1_header_worth GUARDED_BY(m_send_mutex) {false};
615
617 void SetReceiveState(RecvState recv_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
619 void SetSendState(SendState send_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex);
621 static std::optional<std::string> GetMessageType(std::span<const uint8_t>& contents) noexcept;
623 size_t GetMaxBytesToProcess() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
625 void StartSendingHandshake() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex);
627 void ProcessReceivedMaybeV1Bytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex, !m_send_mutex);
629 bool ProcessReceivedKeyBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex, !m_send_mutex);
631 bool ProcessReceivedGarbageBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
633 bool ProcessReceivedPacketBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
634
635public:
636 static constexpr uint32_t MAX_GARBAGE_LEN = 4095;
637
643 V2Transport(NodeId nodeid, bool initiating) noexcept;
644
646 V2Transport(NodeId nodeid, bool initiating, const CKey& key, std::span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept;
647
648 // Receive side functions.
649 bool ReceivedMessageComplete() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
650 bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex, !m_send_mutex);
651 CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
652
653 // Send side functions.
654 bool SetMessageToSend(CSerializedNetMsg& msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
655 BytesToSend GetBytesToSend(bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
656 void MarkBytesSent(size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
657 size_t GetSendMemoryUsage() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
658
659 // Miscellaneous functions.
660 bool ShouldReconnectV1() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex, !m_send_mutex);
661 Info GetInfo() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
662};
663
665{
667 std::unique_ptr<i2p::sam::Session> i2p_sam_session = nullptr;
668 bool prefer_evict = false;
669 size_t recv_flood_size{DEFAULT_MAXRECEIVEBUFFER * 1000};
670 bool use_v2transport = false;
671};
672
674class CNode
675{
676public:
679 const std::unique_ptr<Transport> m_transport;
680
682
691 std::shared_ptr<Sock> m_sock GUARDED_BY(m_sock_mutex);
692
694 size_t m_send_memusage GUARDED_BY(cs_vSend){0};
696 uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
698 std::deque<CSerializedNetMsg> vSendMsg GUARDED_BY(cs_vSend);
702
703 uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
704
705 std::atomic<std::chrono::seconds> m_last_send{0s};
706 std::atomic<std::chrono::seconds> m_last_recv{0s};
708 const std::chrono::seconds m_connected;
709 // Address of this peer
711 // Bind address of our side of the connection
713 const std::string m_addr_name;
715 const std::string m_dest;
717 const bool m_inbound_onion;
718 std::atomic<int> nVersion{0};
724 std::string cleanSubVer GUARDED_BY(m_subver_mutex){};
725 const bool m_prefer_evict{false}; // This peer is preferred for eviction.
726 bool HasPermission(NetPermissionFlags permission) const {
727 return NetPermissions::HasFlag(m_permission_flags, permission);
728 }
730 std::atomic_bool fSuccessfullyConnected{false};
731 // Setting fDisconnect to true will cause the node to be disconnected the
732 // next time DisconnectNodes() runs
733 std::atomic_bool fDisconnect{false};
735 std::atomic<int> nRefCount{0};
736
737 const uint64_t nKeyedNetGroup;
738 std::atomic_bool fPauseRecv{false};
739 std::atomic_bool fPauseSend{false};
740
743 const uint64_t m_network_key;
744
746
748 void MarkReceivedMsgsForProcessing()
749 EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex);
750
756 std::optional<std::pair<CNetMessage, bool>> PollMessage()
757 EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex);
758
760 void AccountForSentBytes(const std::string& msg_type, size_t sent_bytes)
762 {
763 mapSendBytesPerMsgType[msg_type] += sent_bytes;
764 }
765
767 switch (m_conn_type) {
770 return true;
775 return false;
776 } // no default case, so the compiler can warn about missing cases
777
778 assert(false);
779 }
780
781 bool IsFullOutboundConn() const {
782 return m_conn_type == ConnectionType::OUTBOUND_FULL_RELAY;
783 }
784
785 bool IsManualConn() const {
786 return m_conn_type == ConnectionType::MANUAL;
787 }
788
790 {
791 switch (m_conn_type) {
796 return false;
799 return true;
800 } // no default case, so the compiler can warn about missing cases
801
802 assert(false);
803 }
804
805 bool IsBlockOnlyConn() const {
806 return m_conn_type == ConnectionType::BLOCK_RELAY;
807 }
808
809 bool IsFeelerConn() const {
810 return m_conn_type == ConnectionType::FEELER;
811 }
812
813 bool IsAddrFetchConn() const {
814 return m_conn_type == ConnectionType::ADDR_FETCH;
815 }
816
817 bool IsInboundConn() const {
818 return m_conn_type == ConnectionType::INBOUND;
819 }
820
822 switch (m_conn_type) {
826 return false;
830 return true;
831 } // no default case, so the compiler can warn about missing cases
832
833 assert(false);
834 }
835
846 Network ConnectedThroughNetwork() const;
847
849 [[nodiscard]] bool IsConnectedThroughPrivacyNet() const;
850
851 // We selected peer as (compact blocks) high-bandwidth peer (BIP152)
852 std::atomic<bool> m_bip152_highbandwidth_to{false};
853 // Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
854 std::atomic<bool> m_bip152_highbandwidth_from{false};
855
857 std::atomic_bool m_has_all_wanted_services{false};
858
861 std::atomic_bool m_relays_txs{false};
862
865 std::atomic_bool m_bloom_filter_loaded{false};
866
872 std::atomic<std::chrono::seconds> m_last_block_time{0s};
873
878 std::atomic<std::chrono::seconds> m_last_tx_time{0s};
879
881 std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
882
885 std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()};
886
887 CNode(NodeId id,
888 std::shared_ptr<Sock> sock,
889 const CAddress& addrIn,
890 uint64_t nKeyedNetGroupIn,
891 uint64_t nLocalHostNonceIn,
892 const CService& addrBindIn,
893 const std::string& addrNameIn,
894 ConnectionType conn_type_in,
895 bool inbound_onion,
896 uint64_t network_key,
897 CNodeOptions&& node_opts = {});
898 CNode(const CNode&) = delete;
899 CNode& operator=(const CNode&) = delete;
900
901 NodeId GetId() const {
902 return id;
903 }
904
905 uint64_t GetLocalNonce() const {
906 return nLocalHostNonce;
907 }
908
909 int GetRefCount() const
910 {
911 assert(nRefCount >= 0);
912 return nRefCount;
913 }
914
924 bool ReceiveMsgBytes(std::span<const uint8_t> msg_bytes, bool& complete) EXCLUSIVE_LOCKS_REQUIRED(!cs_vRecv);
925
926 void SetCommonVersion(int greatest_common_version)
927 {
928 Assume(m_greatest_common_version == INIT_PROTO_VERSION);
929 m_greatest_common_version = greatest_common_version;
930 }
932 {
933 return m_greatest_common_version;
934 }
935
936 CService GetAddrLocal() const EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
938 void SetAddrLocal(const CService& addrLocalIn) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
939
940 CNode* AddRef()
941 {
942 nRefCount++;
943 return this;
944 }
945
946 void Release()
947 {
948 nRefCount--;
949 }
950
951 void CloseSocketDisconnect() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex);
952
953 void CopyStats(CNodeStats& stats) EXCLUSIVE_LOCKS_REQUIRED(!m_subver_mutex, !m_addr_local_mutex, !cs_vSend, !cs_vRecv);
954
956
963 std::string LogIP(bool log_ip) const;
964
971 std::string DisconnectMsg(bool log_ip) const;
972
974 void PongReceived(std::chrono::microseconds ping_time) {
975 m_last_ping_time = ping_time;
976 m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
977 }
978
979private:
980 const NodeId id;
981 const uint64_t nLocalHostNonce;
982 std::atomic<int> m_greatest_common_version{INIT_PROTO_VERSION};
983
984 const size_t m_recv_flood_size;
985 std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
986
988 std::list<CNetMessage> m_msg_process_queue GUARDED_BY(m_msg_process_queue_mutex);
989 size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex){0};
990
991 // Our address, as reported by the peer
992 CService m_addr_local GUARDED_BY(m_addr_local_mutex);
994
995 mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend);
996 mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv);
997
1008 std::unique_ptr<i2p::sam::Session> m_i2p_sam_session GUARDED_BY(m_sock_mutex);
1009};
1010
1015{
1016public:
1019
1021 virtual void InitializeNode(const CNode& node, ServiceFlags our_services) = 0;
1022
1024 virtual void FinalizeNode(const CNode& node) = 0;
1025
1030 virtual bool HasAllDesirableServiceFlags(ServiceFlags services) const = 0;
1031
1039 virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
1040
1047 virtual bool SendMessages(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
1048
1049
1050protected:
1056};
1057
1059{
1060public:
1061
1062 struct Options
1063 {
1064 ServiceFlags m_local_services = NODE_NONE;
1065 int m_max_automatic_connections = 0;
1067 NetEventsInterface* m_msgproc = nullptr;
1068 BanMan* m_banman = nullptr;
1069 unsigned int nSendBufferMaxSize = 0;
1070 unsigned int nReceiveFloodSize = 0;
1071 uint64_t nMaxOutboundLimit = 0;
1072 int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
1073 std::vector<std::string> vSeedNodes;
1074 std::vector<NetWhitelistPermissions> vWhitelistedRangeIncoming;
1075 std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
1076 std::vector<NetWhitebindPermissions> vWhiteBinds;
1077 std::vector<CService> vBinds;
1078 std::vector<CService> onion_binds;
1082 bool m_use_addrman_outgoing = true;
1083 std::vector<std::string> m_specified_outgoing;
1084 std::vector<std::string> m_added_nodes;
1086 bool whitelist_forcerelay = DEFAULT_WHITELISTFORCERELAY;
1087 bool whitelist_relay = DEFAULT_WHITELISTRELAY;
1088 };
1089
1090 void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_total_bytes_sent_mutex)
1091 {
1092 AssertLockNotHeld(m_total_bytes_sent_mutex);
1093
1094 m_local_services = connOptions.m_local_services;
1095 m_max_automatic_connections = connOptions.m_max_automatic_connections;
1096 m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, m_max_automatic_connections);
1097 m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, m_max_automatic_connections - m_max_outbound_full_relay);
1098 m_max_automatic_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + m_max_feeler;
1099 m_max_inbound = std::max(0, m_max_automatic_connections - m_max_automatic_outbound);
1100 m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
1101 m_client_interface = connOptions.uiInterface;
1102 m_banman = connOptions.m_banman;
1103 m_msgproc = connOptions.m_msgproc;
1104 nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
1105 nReceiveFloodSize = connOptions.nReceiveFloodSize;
1106 m_peer_connect_timeout = std::chrono::seconds{connOptions.m_peer_connect_timeout};
1107 {
1108 LOCK(m_total_bytes_sent_mutex);
1109 nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
1110 }
1111 vWhitelistedRangeIncoming = connOptions.vWhitelistedRangeIncoming;
1112 vWhitelistedRangeOutgoing = connOptions.vWhitelistedRangeOutgoing;
1113 {
1114 LOCK(m_added_nodes_mutex);
1115 // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
1116 // peer doesn't support it or immediately disconnects us for another reason.
1117 const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
1118 for (const std::string& added_node : connOptions.m_added_nodes) {
1119 m_added_node_params.push_back({added_node, use_v2transport});
1120 }
1121 }
1122 m_onion_binds = connOptions.onion_binds;
1123 whitelist_forcerelay = connOptions.whitelist_forcerelay;
1124 whitelist_relay = connOptions.whitelist_relay;
1125 }
1126
1127 CConnman(uint64_t seed0,
1128 uint64_t seed1,
1129 AddrMan& addrman,
1130 const NetGroupManager& netgroupman,
1131 const CChainParams& params,
1132 bool network_active = true,
1133 std::shared_ptr<CThreadInterrupt> interrupt_net = std::make_shared<CThreadInterrupt>());
1134
1135 ~CConnman();
1136
1137 bool Start(CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !m_added_nodes_mutex, !m_addr_fetches_mutex, !mutexMsgProc);
1138
1139 void StopThreads();
1140 void StopNodes();
1141 void Stop()
1142 {
1143 StopThreads();
1144 StopNodes();
1145 };
1146
1147 void Interrupt() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1148 bool GetNetworkActive() const { return fNetworkActive; };
1149 bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
1150 void SetNetworkActive(bool active);
1151 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);
1152 bool CheckIncomingNonce(uint64_t nonce);
1153 void ASMapHealthCheck();
1154
1155 // alias for thread safety annotations only, not defined
1157
1158 bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
1159
1160 void PushMessage(CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1161
1162 using NodeFn = std::function<void(CNode*)>;
1163 void ForEachNode(const NodeFn& func)
1164 {
1165 LOCK(m_nodes_mutex);
1166 for (auto&& node : m_nodes) {
1167 if (NodeFullyConnected(node))
1168 func(node);
1169 }
1170 };
1171
1172 void ForEachNode(const NodeFn& func) const
1173 {
1174 LOCK(m_nodes_mutex);
1175 for (auto&& node : m_nodes) {
1176 if (NodeFullyConnected(node))
1177 func(node);
1178 }
1179 };
1180
1181 // Addrman functions
1193 std::vector<CAddress> GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
1208 std::vector<CAddress> GetAddresses(CNode& requestor, size_t max_addresses, size_t max_pct);
1209
1210 // This allows temporarily exceeding m_max_outbound_full_relay, with the goal of finding
1211 // a peer that is better than all our current peers.
1212 void SetTryNewOutboundPeer(bool flag);
1213 bool GetTryNewOutboundPeer() const;
1214
1215 void StartExtraBlockRelayPeers();
1216
1217 // Count the number of full-relay peer we have.
1218 int GetFullOutboundConnCount() const;
1219 // Return the number of outbound peers we have in excess of our target (eg,
1220 // if we previously called SetTryNewOutboundPeer(true), and have since set
1221 // to false, we may have extra peers that we wish to disconnect). This may
1222 // return a value less than (num_outbound_connections - num_outbound_slots)
1223 // in cases where some outbound connections are not yet fully connected, or
1224 // not yet fully disconnected.
1225 int GetExtraFullOutboundCount() const;
1226 // Count the number of block-relay-only peers we have over our limit.
1227 int GetExtraBlockRelayCount() const;
1228
1229 bool AddNode(const AddedNodeParams& add) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1230 bool RemoveAddedNode(const std::string& node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1231 bool AddedNodesContain(const CAddress& addr) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1232 std::vector<AddedNodeInfo> GetAddedNodeInfo(bool include_connected) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1233
1247 bool AddConnection(const std::string& address, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1248
1249 size_t GetNodeCount(ConnectionDirection) const;
1250 std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
1251 uint32_t GetMappedAS(const CNetAddr& addr) const;
1252 void GetNodeStats(std::vector<CNodeStats>& vstats) const;
1253 bool DisconnectNode(const std::string& node);
1254 bool DisconnectNode(const CSubNet& subnet);
1255 bool DisconnectNode(const CNetAddr& addr);
1256 bool DisconnectNode(NodeId id);
1257
1264 ServiceFlags GetLocalServices() const;
1265
1268 void AddLocalServices(ServiceFlags services) { m_local_services = ServiceFlags(m_local_services | services); };
1269 void RemoveLocalServices(ServiceFlags services) { m_local_services = ServiceFlags(m_local_services & ~services); }
1270
1271 uint64_t GetMaxOutboundTarget() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1272 std::chrono::seconds GetMaxOutboundTimeframe() const;
1273
1277 bool OutboundTargetReached(bool historicalBlockServingLimit) const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1278
1281 uint64_t GetOutboundTargetBytesLeft() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1282
1283 std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1284
1285 uint64_t GetTotalBytesRecv() const;
1286 uint64_t GetTotalBytesSent() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1287
1289 CSipHasher GetDeterministicRandomizer(uint64_t id) const;
1290
1291 void WakeMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1292
1294 bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const;
1295
1296 bool MultipleManualOrFullOutboundConns(Network net) const EXCLUSIVE_LOCKS_REQUIRED(m_nodes_mutex);
1297
1298private:
1300 public:
1301 std::shared_ptr<Sock> sock;
1303 ListenSocket(std::shared_ptr<Sock> sock_, NetPermissionFlags permissions_)
1304 : sock{sock_}, m_permissions{permissions_}
1305 {
1306 }
1307
1308 private:
1310 };
1311
1314 std::chrono::seconds GetMaxOutboundTimeLeftInCycle_() const EXCLUSIVE_LOCKS_REQUIRED(m_total_bytes_sent_mutex);
1315
1316 bool BindListenPort(const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
1317 bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
1318 bool InitBinds(const Options& options);
1319
1320 void ThreadOpenAddedConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_unused_i2p_sessions_mutex, !m_reconnections_mutex);
1321 void AddAddrFetch(const std::string& strDest) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex);
1322 void ProcessAddrFetch() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_unused_i2p_sessions_mutex);
1323 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);
1324 void ThreadMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1325 void ThreadI2PAcceptIncoming();
1326 void AcceptConnection(const ListenSocket& hListenSocket);
1327
1336 void CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
1337 NetPermissionFlags permission_flags,
1338 const CService& addr_bind,
1339 const CService& addr);
1340
1341 void DisconnectNodes() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_nodes_mutex);
1342 void NotifyNumConnectionsChanged();
1344 bool InactivityCheck(const CNode& node) const;
1345
1351 Sock::EventsPerSock GenerateWaitSockets(std::span<CNode* const> nodes);
1352
1356 void SocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1357
1363 void SocketHandlerConnected(const std::vector<CNode*>& nodes,
1364 const Sock::EventsPerSock& events_per_sock)
1365 EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1366
1371 void SocketHandlerListening(const Sock::EventsPerSock& events_per_sock);
1372
1373 void ThreadSocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc, !m_nodes_mutex, !m_reconnections_mutex);
1374 void ThreadDNSAddressSeed() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_nodes_mutex);
1375
1376 uint64_t CalculateKeyedNetGroup(const CNetAddr& ad) const;
1377
1385 bool AlreadyConnectedToHost(const std::string& host) const;
1386
1394 bool AlreadyConnectedToAddressPort(const CService& addr_port) const;
1395
1399 bool AlreadyConnectedToAddress(const CNetAddr& addr) const;
1400
1401 bool AttemptToEvictConnection();
1402 CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1403 void AddWhitelistPermissionFlags(NetPermissionFlags& flags, std::optional<CNetAddr> addr, const std::vector<NetWhitelistPermissions>& ranges) const;
1404
1405 void DeleteNode(CNode* pnode);
1406
1407 NodeId GetNewNodeId();
1408
1410 std::pair<size_t, bool> SocketSendData(CNode& node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
1411
1412 void DumpAddresses();
1413
1414 // Network stats
1415 void RecordBytesRecv(uint64_t bytes);
1416 void RecordBytesSent(uint64_t bytes) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1417
1422 std::unordered_set<Network> GetReachableEmptyNetworks() const;
1423
1427 std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;
1428
1439 bool MaybePickPreferredNetwork(std::optional<Network>& network);
1440
1441 // Whether the node should be passed out in ForEach* callbacks
1442 static bool NodeFullyConnected(const CNode* pnode);
1443
1444 uint16_t GetDefaultPort(Network net) const;
1445 uint16_t GetDefaultPort(const std::string& addr) const;
1446
1447 // Network usage totals
1448 mutable Mutex m_total_bytes_sent_mutex;
1449 std::atomic<uint64_t> nTotalBytesRecv{0};
1450 uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex) {0};
1451
1452 // outbound limit & stats
1453 uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex) {0};
1454 std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex) {0};
1455 uint64_t nMaxOutboundLimit GUARDED_BY(m_total_bytes_sent_mutex);
1456
1457 // P2P timeout in seconds
1458 std::chrono::seconds m_peer_connect_timeout;
1459
1460 // Whitelisted ranges. Any node connecting from these is automatically
1461 // whitelisted (as well as those connecting to whitelisted binds).
1462 std::vector<NetWhitelistPermissions> vWhitelistedRangeIncoming;
1463 // Whitelisted ranges for outgoing connections.
1464 std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
1465
1466 unsigned int nSendBufferMaxSize{0};
1467 unsigned int nReceiveFloodSize{0};
1468
1469 std::vector<ListenSocket> vhListenSocket;
1470 std::atomic<bool> fNetworkActive{true};
1471 bool fAddressesInitialized{false};
1474 std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
1476
1477 // connection string and whether to use v2 p2p
1478 std::vector<AddedNodeParams> m_added_node_params GUARDED_BY(m_added_nodes_mutex);
1479
1481 std::vector<CNode*> m_nodes GUARDED_BY(m_nodes_mutex);
1482 std::list<CNode*> m_nodes_disconnected;
1484 std::atomic<NodeId> nLastNodeId{0};
1485 unsigned int nPrevNodeCount{0};
1486
1487 // Stores number of full-tx connections (outbound and manual) per network
1488 std::array<unsigned int, Network::NET_MAX> m_network_conn_counts GUARDED_BY(m_nodes_mutex) = {};
1489
1497 std::vector<CAddress> m_addrs_response_cache;
1498 std::chrono::microseconds m_cache_entry_expiration{0};
1499 };
1500
1515 std::map<uint64_t, CachedAddrResponse> m_addr_response_caches;
1516
1528 std::atomic<ServiceFlags> m_local_services;
1529
1530 std::unique_ptr<std::counting_semaphore<>> semOutbound;
1531 std::unique_ptr<std::counting_semaphore<>> semAddnode;
1532
1539
1540 /*
1541 * Maximum number of peers by connection type. Might vary from defaults
1542 * based on -maxconnections init value.
1543 */
1544
1545 // How many full-relay (tx, block, addr) outbound peers we want
1547
1548 // How many block-relay only outbound peers we want
1549 // We do not relay tx or addr messages with these peers
1551
1552 int m_max_addnode{MAX_ADDNODE_CONNECTIONS};
1553 int m_max_feeler{MAX_FEELER_CONNECTIONS};
1556
1562
1567 std::vector<CAddress> m_anchors;
1568
1570 const uint64_t nSeed0, nSeed1;
1571
1573 bool fMsgProcWake GUARDED_BY(mutexMsgProc);
1574
1575 std::condition_variable condMsgProc;
1577 std::atomic<bool> flagInterruptMsgProc{false};
1578
1583 const std::shared_ptr<CThreadInterrupt> m_interrupt_net;
1584
1590 std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
1591
1598
1603
1608 std::atomic_bool m_start_extra_block_relay_peers{false};
1609
1614 std::vector<CService> m_onion_binds;
1615
1621
1627
1632
1640 std::queue<std::unique_ptr<i2p::sam::Session>> m_unused_i2p_sessions GUARDED_BY(m_unused_i2p_sessions_mutex);
1641
1646
1649 {
1652 std::string destination;
1655 };
1656
1660 std::list<ReconnectionInfo> m_reconnections GUARDED_BY(m_reconnections_mutex);
1661
1663 void PerformReconnections() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_unused_i2p_sessions_mutex);
1664
1669 static constexpr size_t MAX_UNUSED_I2P_SESSIONS_SIZE{10};
1670
1676 {
1677 public:
1678 explicit NodesSnapshot(const CConnman& connman, bool shuffle)
1679 {
1680 {
1681 LOCK(connman.m_nodes_mutex);
1682 m_nodes_copy = connman.m_nodes;
1683 for (auto& node : m_nodes_copy) {
1684 node->AddRef();
1685 }
1686 }
1687 if (shuffle) {
1688 std::shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});
1689 }
1690 }
1691
1693 {
1694 for (auto& node : m_nodes_copy) {
1695 node->Release();
1696 }
1697 }
1698
1699 const std::vector<CNode*>& Nodes() const
1700 {
1701 return m_nodes_copy;
1702 }
1703
1704 private:
1705 std::vector<CNode*> m_nodes_copy;
1706 };
1707
1709
1710 friend struct ConnmanTestMsg;
1711};
1712
1714extern std::function<void(const CAddress& addr,
1715 const std::string& msg_type,
1716 std::span<const unsigned char> data,
1717 bool is_incoming)>
1719
1720#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:1676
const std::vector< CNode * > & Nodes() const
Definition: net.h:1699
NodesSnapshot(const CConnman &connman, bool shuffle)
Definition: net.h:1678
std::vector< CNode * > m_nodes_copy
Definition: net.h:1705
Definition: net.h:1059
bool whitelist_relay
flag for adding 'relay' permission to whitelisted inbound and manual peers with default permissions.
Definition: net.h:1626
std::condition_variable condMsgProc
Definition: net.h:1575
std::thread threadMessageHandler
Definition: net.h:1596
void RemoveLocalServices(ServiceFlags services)
Definition: net.h:1269
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
Definition: net.h:1462
CClientUIInterface * m_client_interface
Definition: net.h:1558
void ForEachNode(const NodeFn &func) const
Definition: net.h:1172
std::vector< AddedNodeParams > m_added_node_params GUARDED_BY(m_added_nodes_mutex)
int m_max_inbound
Definition: net.h:1555
const bool use_v2transport(GetLocalServices() &NODE_P2P_V2)
void Stop()
Definition: net.h:1141
int m_max_outbound_block_relay
Definition: net.h:1550
std::array< unsigned int, Network::NET_MAX > m_network_conn_counts GUARDED_BY(m_nodes_mutex)
std::thread threadI2PAcceptIncoming
Definition: net.h:1597
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:1554
uint64_t nMaxOutboundLimit GUARDED_BY(m_total_bytes_sent_mutex)
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:1538
BanMan * m_banman
Pointer to this node's banman.
Definition: net.h:1561
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1453
std::thread threadDNSAddressSeed
Definition: net.h:1592
const NetGroupManager & m_netgroupman
Definition: net.h:1473
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
Definition: net.h:1567
bool whitelist_forcerelay
flag for adding 'forcerelay' permission to whitelisted inbound and manual peers with default permissi...
Definition: net.h:1620
std::chrono::seconds m_peer_connect_timeout
Definition: net.h:1458
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:1602
std::vector< ListenSocket > vhListenSocket
Definition: net.h:1469
std::thread threadOpenConnections
Definition: net.h:1595
std::atomic< ServiceFlags > m_local_services
Services this node offers.
Definition: net.h:1528
Mutex m_addr_fetches_mutex
Definition: net.h:1475
Mutex m_reconnections_mutex
Mutex protecting m_reconnections.
Definition: net.h:1645
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:1570
RecursiveMutex m_nodes_mutex
Definition: net.h:1483
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:1530
const CChainParams & m_params
Definition: net.h:1708
std::deque< std::string > m_addr_fetches GUARDED_BY(m_addr_fetches_mutex)
const std::shared_ptr< CThreadInterrupt > m_interrupt_net
This is signaled when network activity should cease.
Definition: net.h:1583
void AddLocalServices(ServiceFlags services)
Updates the local services that this node advertises to other peers during connection handshake.
Definition: net.h:1268
AddrMan & addrman
Definition: net.h:1472
Mutex mutexMsgProc
Definition: net.h:1576
std::thread threadOpenAddedConnections
Definition: net.h:1594
Mutex m_added_nodes_mutex
Definition: net.h:1480
int m_max_outbound_full_relay
Definition: net.h:1546
Mutex m_unused_i2p_sessions_mutex
Mutex protecting m_i2p_sam_sessions.
Definition: net.h:1631
std::vector< CNode * > m_nodes GUARDED_BY(m_nodes_mutex)
std::unique_ptr< std::counting_semaphore<> > semAddnode
Definition: net.h:1531
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1454
uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1450
bool GetUseAddrmanOutgoing() const
Definition: net.h:1149
std::list< CNode * > m_nodes_disconnected
Definition: net.h:1482
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session
I2P SAM session.
Definition: net.h:1590
bool m_use_addrman_outgoing
Definition: net.h:1557
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
Definition: net.h:1464
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:1515
std::function< void(CNode *)> NodeFn
Definition: net.h:1162
NetEventsInterface * m_msgproc
Definition: net.h:1559
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:1614
RecursiveMutex & GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex)
std::thread threadSocketHandler
Definition: net.h:1593
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:233
CNetMessage(CNetMessage &&)=default
CNetMessage(DataStream &&recv_in)
Definition: net.h:241
std::string m_type
Definition: net.h:239
DataStream m_recv
received message data
Definition: net.h:235
CNetMessage & operator=(const CNetMessage &)=delete
CNetMessage(const CNetMessage &)=delete
CNetMessage & operator=(CNetMessage &&)=default
Information about a peer.
Definition: net.h:675
bool IsFeelerConn() const
Definition: net.h:809
const std::chrono::seconds m_connected
Unix epoch time at peer connection.
Definition: net.h:708
bool ExpectServicesFromConn() const
Definition: net.h:821
const std::string m_dest
The pszDest argument provided to ConnectNode().
Definition: net.h:715
CService m_addr_local GUARDED_BY(m_addr_local_mutex)
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:703
bool IsInboundConn() const
Definition: net.h:817
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:726
CountingSemaphoreGrant grantOutbound
Definition: net.h:734
bool IsOutboundOrBlockRelayConn() const
Definition: net.h:766
NodeId GetId() const
Definition: net.h:901
bool IsManualConn() const
Definition: net.h:785
const std::string m_addr_name
Definition: net.h:713
CNode & operator=(const CNode &)=delete
const CService addrBind
Definition: net.h:712
void SetCommonVersion(int greatest_common_version)
Definition: net.h:926
std::list< CNetMessage > vRecvMsg
Definition: net.h:985
void PongReceived(std::chrono::microseconds ping_time)
A ping-pong round trip has completed successfully.
Definition: net.h:974
size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex)
Definition: net.h:989
bool IsAddrFetchConn() const
Definition: net.h:813
uint64_t GetLocalNonce() const
Definition: net.h:905
const CAddress addr
Definition: net.h:710
mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend)
const uint64_t nKeyedNetGroup
Definition: net.h:737
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:805
int GetCommonVersion() const
Definition: net.h:931
mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv)
bool IsFullOutboundConn() const
Definition: net.h:781
Mutex m_subver_mutex
Definition: net.h:719
Mutex cs_vSend
Definition: net.h:699
const uint64_t m_network_key
Network key used to prevent fingerprinting our node across networks.
Definition: net.h:743
int GetRefCount() const
Definition: net.h:909
Mutex m_msg_process_queue_mutex
Definition: net.h:987
const ConnectionType m_conn_type
Definition: net.h:745
const size_t m_recv_flood_size
Definition: net.h:984
const uint64_t nLocalHostNonce
Definition: net.h:981
bool IsManualOrFullOutboundConn() const
Definition: net.h:789
const std::unique_ptr< Transport > m_transport
Transport serializer/deserializer.
Definition: net.h:679
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:681
Mutex m_addr_local_mutex
Definition: net.h:993
CNode(const CNode &)=delete
size_t m_send_memusage GUARDED_BY(cs_vSend)
Sum of GetMemoryUsage of all vSendMsg entries.
Definition: net.h:694
const bool m_inbound_onion
Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
Definition: net.h:717
const NodeId id
Definition: net.h:980
Mutex cs_vRecv
Definition: net.h:701
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Total number of bytes sent on the wire to this peer.
Definition: net.h:696
Mutex m_sock_mutex
Definition: net.h:700
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:946
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:724
std::string m_session_id
BIP324 session id string in hex, if any.
Definition: net.h:224
std::string addrLocal
Definition: net.h:212
uint64_t nRecvBytes
Definition: net.h:206
std::chrono::microseconds m_last_ping_time
Definition: net.h:209
uint32_t m_mapped_as
Definition: net.h:219
mapMsgTypeSize mapRecvBytesPerMsgType
Definition: net.h:207
bool fInbound
Definition: net.h:198
uint64_t nSendBytes
Definition: net.h:204
std::chrono::seconds m_last_recv
Definition: net.h:191
ConnectionType m_conn_type
Definition: net.h:220
std::chrono::seconds m_last_send
Definition: net.h:190
std::chrono::seconds m_last_tx_time
Definition: net.h:192
CAddress addr
Definition: net.h:214
mapMsgTypeSize mapSendBytesPerMsgType
Definition: net.h:205
std::chrono::microseconds m_min_ping_time
Definition: net.h:210
CService addrBind
Definition: net.h:216
TransportProtocolType m_transport_type
Transport protocol type.
Definition: net.h:222
std::chrono::seconds m_connected
Definition: net.h:194
bool m_bip152_highbandwidth_from
Definition: net.h:202
bool m_bip152_highbandwidth_to
Definition: net.h:200
std::string m_addr_name
Definition: net.h:195
int nVersion
Definition: net.h:196
std::chrono::seconds m_last_block_time
Definition: net.h:193
Network m_network
Definition: net.h:218
NodeId nodeid
Definition: net.h:189
std::string cleanSubVer
Definition: net.h:197
int m_starting_height
Definition: net.h:203
NetPermissionFlags m_permission_flags
Definition: net.h:208
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
RAII-style semaphore lock.
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:130
Fast randomness source.
Definition: random.h:386
Different type to mark Mutex at global scope.
Definition: sync.h:135
Definition: init.h:13
Interface for message handling.
Definition: net.h:1015
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition: net.h:1018
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:256
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:313
CHash256 hasher GUARDED_BY(m_recv_mutex)
DataStream hdrbuf GUARDED_BY(m_recv_mutex)
Definition: net.h:378
bool m_sending_header GUARDED_BY(m_send_mutex)
Whether we're currently sending header bytes or message bytes.
Definition: net.h:414
const NodeId m_node_id
Definition: net.h:373
Mutex m_send_mutex
Lock for sending state.
Definition: net.h:408
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:416
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:372
unsigned int nHdrPos GUARDED_BY(m_recv_mutex)
DataStream vRecv GUARDED_BY(m_recv_mutex)
Definition: net.h:380
bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
Definition: net.h:400
CMessageHeader hdr GUARDED_BY(m_recv_mutex)
Mutex m_recv_mutex
Lock for receive state.
Definition: net.h:374
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:421
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:614
const NodeId m_nodeid
NodeId (for debug logging).
Definition: net.h:582
BIP324Cipher m_cipher
Cipher state.
Definition: net.h:578
SendState
State type that controls the sender side.
Definition: net.h:547
V1Transport m_v1_fallback
Encapsulate a V1Transport to fall back to.
Definition: net.h:584
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:580
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:590
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:606
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:482
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.
CClientUIInterface uiInterface
std::array< uint8_t, 4 > MessageStartChars
unsigned int nonce
Definition: miner_tests.cpp:76
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:328
void RemoveLocal(const CService &addr)
Definition: net.cpp:309
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:276
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
void ClearLocal()
Definition: net.cpp:269
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:184
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:4027
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:3183
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:317
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:1496
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:1497
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:1302
ListenSocket(std::shared_ptr< Sock > sock_, NetPermissionFlags permissions_)
Definition: net.h:1303
NetPermissionFlags m_permissions
Definition: net.h:1309
std::shared_ptr< Sock > sock
Definition: net.h:1301
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:1076
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
Definition: net.h:1074
std::vector< CService > onion_binds
Definition: net.h:1078
std::vector< std::string > m_specified_outgoing
Definition: net.h:1083
std::vector< std::string > m_added_nodes
Definition: net.h:1084
std::vector< CService > vBinds
Definition: net.h:1077
bool m_i2p_accept_incoming
Definition: net.h:1085
std::vector< std::string > vSeedNodes
Definition: net.h:1073
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
Definition: net.h:1081
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
Definition: net.h:1075
Struct for entries in m_reconnections.
Definition: net.h:1649
ConnectionType conn_type
Definition: net.h:1653
std::string destination
Definition: net.h:1652
CountingSemaphoreGrant grant
Definition: net.h:1651
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:177
int nScore
Definition: net.h:176
std::optional< uint256 > session_id
Definition: net.h:263
TransportProtocolType transport_type
Definition: net.h:262
Bilingual messages:
Definition: translation.h:24
#define AssertLockNotHeld(cs)
Definition: sync.h:142
#define LOCK(cs)
Definition: sync.h:259
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:290
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
#define LOCK_RETURNED(x)
Definition: threadsafety.h:49
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())