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 <string_view>
47#include <thread>
48#include <unordered_set>
49#include <vector>
50
51class AddrMan;
52class BanMan;
53class CChainParams;
54class CNode;
55class CScheduler;
56struct bilingual_str;
57
59static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20};
61static constexpr auto FEELER_INTERVAL = 2min;
63static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min;
65static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000;
67static const unsigned int MAX_SUBVERSION_LENGTH = 256;
71static const int MAX_ADDNODE_CONNECTIONS = 8;
75static const int MAX_FEELER_CONNECTIONS = 1;
77static const bool DEFAULT_LISTEN = true;
79static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
81static const std::string DEFAULT_MAX_UPLOAD_TARGET{"0M"};
83static const bool DEFAULT_BLOCKSONLY = false;
85static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60;
87static const int NUM_FDS_MESSAGE_CAPTURE = 1;
89static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL{24};
90
91static constexpr bool DEFAULT_FORCEDNSSEED{false};
92static constexpr bool DEFAULT_DNSSEED{true};
93static constexpr bool DEFAULT_FIXEDSEEDS{true};
94static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000;
95static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000;
96
97static constexpr bool DEFAULT_V2_TRANSPORT{true};
98
99typedef int64_t NodeId;
100
102 std::string m_added_node;
104};
105
111};
112
113class CNodeStats;
115
117 CSerializedNetMsg() = default;
120 // No implicit copying, only moves.
123
125 {
127 copy.data = data;
128 copy.m_type = m_type;
129 return copy;
130 }
131
132 std::vector<unsigned char> data;
133 std::string m_type;
134
136 size_t GetMemoryUsage() const noexcept;
137};
138
144void Discover();
145
146uint16_t GetListenPort();
147
148enum
149{
150 LOCAL_NONE, // unknown
151 LOCAL_IF, // address a local interface listens on
152 LOCAL_BIND, // address explicit bound to
153 LOCAL_MAPPED, // address reported by PCP
154 LOCAL_MANUAL, // address explicitly specified (-externalip=)
155
158
160std::optional<CService> GetLocalAddrForPeer(CNode& node);
161
162void ClearLocal();
163bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
164bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
165void RemoveLocal(const CService& addr);
166bool SeenLocal(const CService& addr);
167bool IsLocal(const CService& addr);
168CService GetLocalAddress(const CNode& peer);
169
170extern bool fDiscover;
171extern bool fListen;
172
174extern std::string strSubVersion;
175
178 uint16_t nPort;
179};
180
182extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(g_maplocalhost_mutex);
183
184extern const std::string NET_MESSAGE_TYPE_OTHER;
185using mapMsgTypeSize = std::map</* message type */ std::string, /* total bytes */ uint64_t>;
186
188{
189public:
191 std::chrono::seconds m_last_send;
192 std::chrono::seconds m_last_recv;
193 std::chrono::seconds m_last_tx_time;
194 std::chrono::seconds m_last_block_time;
195 std::chrono::seconds m_connected;
196 std::string m_addr_name;
198 std::string cleanSubVer;
200 // We requested high bandwidth connection to peer
202 // Peer requested high bandwidth connection
205 uint64_t nSendBytes;
207 uint64_t nRecvBytes;
210 std::chrono::microseconds m_last_ping_time;
211 std::chrono::microseconds m_min_ping_time;
212 // Our address, as reported by the peer
213 std::string addrLocal;
214 // Address of this peer
216 // Bind address of our side of the connection
218 // Network the peer connected through
220 uint32_t m_mapped_as;
225 std::string m_session_id;
226};
227
228
234{
235public:
237 std::chrono::microseconds m_time{0};
238 uint32_t m_message_size{0};
239 uint32_t m_raw_message_size{0};
240 std::string m_type;
241
242 explicit CNetMessage(DataStream&& recv_in) : m_recv(std::move(recv_in)) {}
243 // Only one CNetMessage object will exist for the same message on either
244 // the receive or processing queue. For performance reasons we therefore
245 // delete the copy constructor and assignment operator to avoid the
246 // possibility of copying CNetMessage objects.
248 CNetMessage(const CNetMessage&) = delete;
251
253 size_t GetMemoryUsage() const noexcept;
254};
255
258public:
259 virtual ~Transport() = default;
260
261 struct Info
262 {
264 std::optional<uint256> session_id;
265 };
266
268 virtual Info GetInfo() const noexcept = 0;
269
270 // 1. Receiver side functions, for decoding bytes received on the wire into transport protocol
271 // agnostic CNetMessage (message type & payload) objects.
272
274 virtual bool ReceivedMessageComplete() const = 0;
275
282 virtual bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) = 0;
283
291 virtual CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) = 0;
292
293 // 2. Sending side functions, for converting messages into bytes to be sent over the wire.
294
301 virtual bool SetMessageToSend(CSerializedNetMsg& msg) noexcept = 0;
302
310 using BytesToSend = std::tuple<
311 std::span<const uint8_t> /*to_send*/,
312 bool /*more*/,
313 const std::string& /*m_type*/
314 >;
315
351 virtual BytesToSend GetBytesToSend(bool have_next_message) const noexcept = 0;
352
359 virtual void MarkBytesSent(size_t bytes_sent) noexcept = 0;
360
362 virtual size_t GetSendMemoryUsage() const noexcept = 0;
363
364 // 3. Miscellaneous functions.
365
367 virtual bool ShouldReconnectV1() const noexcept = 0;
368};
369
370class V1Transport final : public Transport
371{
372private:
374 const NodeId m_node_id; // Only for logging
376 mutable CHash256 hasher GUARDED_BY(m_recv_mutex);
377 mutable uint256 data_hash GUARDED_BY(m_recv_mutex);
378 bool in_data GUARDED_BY(m_recv_mutex); // parsing header (false) or data (true)
379 DataStream hdrbuf GUARDED_BY(m_recv_mutex){}; // partially received header
380 CMessageHeader hdr GUARDED_BY(m_recv_mutex); // complete header
381 DataStream vRecv GUARDED_BY(m_recv_mutex){}; // received message data
382 unsigned int nHdrPos GUARDED_BY(m_recv_mutex);
383 unsigned int nDataPos GUARDED_BY(m_recv_mutex);
384
385 const uint256& GetMessageHash() const EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
386 int readHeader(std::span<const uint8_t> msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
387 int readData(std::span<const uint8_t> msg_bytes) EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
388
389 void Reset() EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex) {
390 AssertLockHeld(m_recv_mutex);
391 vRecv.clear();
392 hdrbuf.clear();
393 hdrbuf.resize(24);
394 in_data = false;
395 nHdrPos = 0;
396 nDataPos = 0;
397 data_hash.SetNull();
398 hasher.Reset();
399 }
400
401 bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
402 {
403 AssertLockHeld(m_recv_mutex);
404 if (!in_data) return false;
405 return hdr.nMessageSize == nDataPos;
406 }
407
411 std::vector<uint8_t> m_header_to_send GUARDED_BY(m_send_mutex);
413 CSerializedNetMsg m_message_to_send GUARDED_BY(m_send_mutex);
415 bool m_sending_header GUARDED_BY(m_send_mutex) {false};
417 size_t m_bytes_sent GUARDED_BY(m_send_mutex) {0};
418
419public:
420 explicit V1Transport(const NodeId node_id) noexcept;
421
422 bool ReceivedMessageComplete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
423 {
424 AssertLockNotHeld(m_recv_mutex);
425 return WITH_LOCK(m_recv_mutex, return CompleteInternal());
426 }
427
428 Info GetInfo() const noexcept override;
429
430 bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
431 {
432 AssertLockNotHeld(m_recv_mutex);
433 LOCK(m_recv_mutex);
434 int ret = in_data ? readData(msg_bytes) : readHeader(msg_bytes);
435 if (ret < 0) {
436 Reset();
437 } else {
438 msg_bytes = msg_bytes.subspan(ret);
439 }
440 return ret >= 0;
441 }
442
443 CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
444
445 bool SetMessageToSend(CSerializedNetMsg& msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
446 BytesToSend GetBytesToSend(bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
447 void MarkBytesSent(size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
448 size_t GetSendMemoryUsage() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
449 bool ShouldReconnectV1() const noexcept override { return false; }
450};
451
452class V2Transport final : public Transport
453{
454private:
458 static constexpr std::array<std::byte, 0> VERSION_CONTENTS = {};
459
462 static constexpr size_t V1_PREFIX_LEN = 16;
463
464 // The sender side and receiver side of V2Transport are state machines that are transitioned
465 // through, based on what has been received. The receive state corresponds to the contents of,
466 // and bytes received to, the receive buffer. The send state controls what can be appended to
467 // the send buffer and what can be sent from it.
468
483 enum class RecvState : uint8_t {
489 KEY_MAYBE_V1,
490
496 KEY,
497
504 GARB_GARBTERM,
505
514 VERSION,
515
521 APP,
522
527 APP_READY,
528
532 V1,
533 };
534
548 enum class SendState : uint8_t {
555 MAYBE_V1,
556
562 AWAITING_KEY,
563
570 READY,
571
575 V1,
576 };
577
581 const bool m_initiating;
586
588 mutable Mutex m_recv_mutex ACQUIRED_BEFORE(m_send_mutex);
591 uint32_t m_recv_len GUARDED_BY(m_recv_mutex) {0};
593 std::vector<uint8_t> m_recv_buffer GUARDED_BY(m_recv_mutex);
595 std::vector<uint8_t> m_recv_aad GUARDED_BY(m_recv_mutex);
597 std::vector<uint8_t> m_recv_decode_buffer GUARDED_BY(m_recv_mutex);
599 RecvState m_recv_state GUARDED_BY(m_recv_mutex);
600
603 mutable Mutex m_send_mutex ACQUIRED_AFTER(m_recv_mutex);
605 std::vector<uint8_t> m_send_buffer GUARDED_BY(m_send_mutex);
607 uint32_t m_send_pos GUARDED_BY(m_send_mutex) {0};
609 std::vector<uint8_t> m_send_garbage GUARDED_BY(m_send_mutex);
611 std::string m_send_type GUARDED_BY(m_send_mutex);
613 SendState m_send_state GUARDED_BY(m_send_mutex);
615 bool m_sent_v1_header_worth GUARDED_BY(m_send_mutex) {false};
616
618 void SetReceiveState(RecvState recv_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
620 void SetSendState(SendState send_state) noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex);
622 static std::optional<std::string> GetMessageType(std::span<const uint8_t>& contents) noexcept;
624 size_t GetMaxBytesToProcess() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
626 void StartSendingHandshake() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_send_mutex);
628 void ProcessReceivedMaybeV1Bytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex, !m_send_mutex);
630 bool ProcessReceivedKeyBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex, !m_send_mutex);
632 bool ProcessReceivedGarbageBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
634 bool ProcessReceivedPacketBytes() noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex);
635
636public:
637 static constexpr uint32_t MAX_GARBAGE_LEN = 4095;
638
644 V2Transport(NodeId nodeid, bool initiating) noexcept;
645
647 V2Transport(NodeId nodeid, bool initiating, const CKey& key, std::span<const std::byte> ent32, std::vector<uint8_t> garbage) noexcept;
648
649 // Receive side functions.
650 bool ReceivedMessageComplete() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
651 bool ReceivedBytes(std::span<const uint8_t>& msg_bytes) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex, !m_send_mutex);
652 CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
653
654 // Send side functions.
655 bool SetMessageToSend(CSerializedNetMsg& msg) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
656 BytesToSend GetBytesToSend(bool have_next_message) const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
657 void MarkBytesSent(size_t bytes_sent) noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
658 size_t GetSendMemoryUsage() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex);
659
660 // Miscellaneous functions.
661 bool ShouldReconnectV1() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex, !m_send_mutex);
662 Info GetInfo() const noexcept override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
663};
664
666{
668 std::unique_ptr<i2p::sam::Session> i2p_sam_session = nullptr;
669 bool prefer_evict = false;
670 size_t recv_flood_size{DEFAULT_MAXRECEIVEBUFFER * 1000};
671 bool use_v2transport = false;
672};
673
675class CNode
676{
677public:
680 const std::unique_ptr<Transport> m_transport;
681
683
692 std::shared_ptr<Sock> m_sock GUARDED_BY(m_sock_mutex);
693
695 size_t m_send_memusage GUARDED_BY(cs_vSend){0};
697 uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
699 std::deque<CSerializedNetMsg> vSendMsg GUARDED_BY(cs_vSend);
703
704 uint64_t nRecvBytes GUARDED_BY(cs_vRecv){0};
705
706 std::atomic<std::chrono::seconds> m_last_send{0s};
707 std::atomic<std::chrono::seconds> m_last_recv{0s};
709 const std::chrono::seconds m_connected;
710 // Address of this peer
712 // Bind address of our side of the connection
714 const std::string m_addr_name;
716 const std::string m_dest;
718 const bool m_inbound_onion;
719 std::atomic<int> nVersion{0};
725 std::string cleanSubVer GUARDED_BY(m_subver_mutex){};
726 const bool m_prefer_evict{false}; // This peer is preferred for eviction.
727 bool HasPermission(NetPermissionFlags permission) const {
728 return NetPermissions::HasFlag(m_permission_flags, permission);
729 }
731 std::atomic_bool fSuccessfullyConnected{false};
732 // Setting fDisconnect to true will cause the node to be disconnected the
733 // next time DisconnectNodes() runs
734 std::atomic_bool fDisconnect{false};
736 std::atomic<int> nRefCount{0};
737
738 const uint64_t nKeyedNetGroup;
739 std::atomic_bool fPauseRecv{false};
740 std::atomic_bool fPauseSend{false};
741
744 const uint64_t m_network_key;
745
747
749 void MarkReceivedMsgsForProcessing()
750 EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex);
751
757 std::optional<std::pair<CNetMessage, bool>> PollMessage()
758 EXCLUSIVE_LOCKS_REQUIRED(!m_msg_process_queue_mutex);
759
761 void AccountForSentBytes(const std::string& msg_type, size_t sent_bytes)
763 {
764 mapSendBytesPerMsgType[msg_type] += sent_bytes;
765 }
766
768 switch (m_conn_type) {
771 return true;
776 return false;
777 } // no default case, so the compiler can warn about missing cases
778
779 assert(false);
780 }
781
782 bool IsFullOutboundConn() const {
783 return m_conn_type == ConnectionType::OUTBOUND_FULL_RELAY;
784 }
785
786 bool IsManualConn() const {
787 return m_conn_type == ConnectionType::MANUAL;
788 }
789
791 {
792 switch (m_conn_type) {
797 return false;
800 return true;
801 } // no default case, so the compiler can warn about missing cases
802
803 assert(false);
804 }
805
806 bool IsBlockOnlyConn() const {
807 return m_conn_type == ConnectionType::BLOCK_RELAY;
808 }
809
810 bool IsFeelerConn() const {
811 return m_conn_type == ConnectionType::FEELER;
812 }
813
814 bool IsAddrFetchConn() const {
815 return m_conn_type == ConnectionType::ADDR_FETCH;
816 }
817
818 bool IsInboundConn() const {
819 return m_conn_type == ConnectionType::INBOUND;
820 }
821
823 switch (m_conn_type) {
827 return false;
831 return true;
832 } // no default case, so the compiler can warn about missing cases
833
834 assert(false);
835 }
836
847 Network ConnectedThroughNetwork() const;
848
850 [[nodiscard]] bool IsConnectedThroughPrivacyNet() const;
851
852 // We selected peer as (compact blocks) high-bandwidth peer (BIP152)
853 std::atomic<bool> m_bip152_highbandwidth_to{false};
854 // Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
855 std::atomic<bool> m_bip152_highbandwidth_from{false};
856
858 std::atomic_bool m_has_all_wanted_services{false};
859
862 std::atomic_bool m_relays_txs{false};
863
866 std::atomic_bool m_bloom_filter_loaded{false};
867
873 std::atomic<std::chrono::seconds> m_last_block_time{0s};
874
879 std::atomic<std::chrono::seconds> m_last_tx_time{0s};
880
882 std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
883
886 std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()};
887
888 CNode(NodeId id,
889 std::shared_ptr<Sock> sock,
890 const CAddress& addrIn,
891 uint64_t nKeyedNetGroupIn,
892 uint64_t nLocalHostNonceIn,
893 const CService& addrBindIn,
894 const std::string& addrNameIn,
895 ConnectionType conn_type_in,
896 bool inbound_onion,
897 uint64_t network_key,
898 CNodeOptions&& node_opts = {});
899 CNode(const CNode&) = delete;
900 CNode& operator=(const CNode&) = delete;
901
902 NodeId GetId() const {
903 return id;
904 }
905
906 uint64_t GetLocalNonce() const {
907 return nLocalHostNonce;
908 }
909
910 int GetRefCount() const
911 {
912 assert(nRefCount >= 0);
913 return nRefCount;
914 }
915
925 bool ReceiveMsgBytes(std::span<const uint8_t> msg_bytes, bool& complete) EXCLUSIVE_LOCKS_REQUIRED(!cs_vRecv);
926
927 void SetCommonVersion(int greatest_common_version)
928 {
929 Assume(m_greatest_common_version == INIT_PROTO_VERSION);
930 m_greatest_common_version = greatest_common_version;
931 }
933 {
934 return m_greatest_common_version;
935 }
936
937 CService GetAddrLocal() const EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
939 void SetAddrLocal(const CService& addrLocalIn) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_local_mutex);
940
941 CNode* AddRef()
942 {
943 nRefCount++;
944 return this;
945 }
946
947 void Release()
948 {
949 nRefCount--;
950 }
951
952 void CloseSocketDisconnect() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex);
953
954 void CopyStats(CNodeStats& stats) EXCLUSIVE_LOCKS_REQUIRED(!m_subver_mutex, !m_addr_local_mutex, !cs_vSend, !cs_vRecv);
955
957
964 std::string LogIP(bool log_ip) const;
965
972 std::string DisconnectMsg(bool log_ip) const;
973
975 void PongReceived(std::chrono::microseconds ping_time) {
976 m_last_ping_time = ping_time;
977 m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
978 }
979
980private:
981 const NodeId id;
982 const uint64_t nLocalHostNonce;
983 std::atomic<int> m_greatest_common_version{INIT_PROTO_VERSION};
984
985 const size_t m_recv_flood_size;
986 std::list<CNetMessage> vRecvMsg; // Used only by SocketHandler thread
987
989 std::list<CNetMessage> m_msg_process_queue GUARDED_BY(m_msg_process_queue_mutex);
990 size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex){0};
991
992 // Our address, as reported by the peer
993 CService m_addr_local GUARDED_BY(m_addr_local_mutex);
995
996 mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend);
997 mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv);
998
1009 std::unique_ptr<i2p::sam::Session> m_i2p_sam_session GUARDED_BY(m_sock_mutex);
1010};
1011
1016{
1017public:
1020
1022 virtual void InitializeNode(const CNode& node, ServiceFlags our_services) = 0;
1023
1025 virtual void FinalizeNode(const CNode& node) = 0;
1026
1031 virtual bool HasAllDesirableServiceFlags(ServiceFlags services) const = 0;
1032
1040 virtual bool ProcessMessages(CNode* pnode, std::atomic<bool>& interrupt) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
1041
1048 virtual bool SendMessages(CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0;
1049
1050
1051protected:
1057};
1058
1060{
1061public:
1062
1063 struct Options
1064 {
1065 ServiceFlags m_local_services = NODE_NONE;
1066 int m_max_automatic_connections = 0;
1068 NetEventsInterface* m_msgproc = nullptr;
1069 BanMan* m_banman = nullptr;
1070 unsigned int nSendBufferMaxSize = 0;
1071 unsigned int nReceiveFloodSize = 0;
1072 uint64_t nMaxOutboundLimit = 0;
1073 int64_t m_peer_connect_timeout = DEFAULT_PEER_CONNECT_TIMEOUT;
1074 std::vector<std::string> vSeedNodes;
1075 std::vector<NetWhitelistPermissions> vWhitelistedRangeIncoming;
1076 std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
1077 std::vector<NetWhitebindPermissions> vWhiteBinds;
1078 std::vector<CService> vBinds;
1079 std::vector<CService> onion_binds;
1083 bool m_use_addrman_outgoing = true;
1084 std::vector<std::string> m_specified_outgoing;
1085 std::vector<std::string> m_added_nodes;
1087 bool whitelist_forcerelay = DEFAULT_WHITELISTFORCERELAY;
1088 bool whitelist_relay = DEFAULT_WHITELISTRELAY;
1089 };
1090
1091 void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_total_bytes_sent_mutex)
1092 {
1093 AssertLockNotHeld(m_total_bytes_sent_mutex);
1094
1095 m_local_services = connOptions.m_local_services;
1096 m_max_automatic_connections = connOptions.m_max_automatic_connections;
1097 m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, m_max_automatic_connections);
1098 m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, m_max_automatic_connections - m_max_outbound_full_relay);
1099 m_max_automatic_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + m_max_feeler;
1100 m_max_inbound = std::max(0, m_max_automatic_connections - m_max_automatic_outbound);
1101 m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
1102 m_client_interface = connOptions.uiInterface;
1103 m_banman = connOptions.m_banman;
1104 m_msgproc = connOptions.m_msgproc;
1105 nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
1106 nReceiveFloodSize = connOptions.nReceiveFloodSize;
1107 m_peer_connect_timeout = std::chrono::seconds{connOptions.m_peer_connect_timeout};
1108 {
1109 LOCK(m_total_bytes_sent_mutex);
1110 nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
1111 }
1112 vWhitelistedRangeIncoming = connOptions.vWhitelistedRangeIncoming;
1113 vWhitelistedRangeOutgoing = connOptions.vWhitelistedRangeOutgoing;
1114 {
1115 LOCK(m_added_nodes_mutex);
1116 // Attempt v2 connection if we support v2 - we'll reconnect with v1 if our
1117 // peer doesn't support it or immediately disconnects us for another reason.
1118 const bool use_v2transport(GetLocalServices() & NODE_P2P_V2);
1119 for (const std::string& added_node : connOptions.m_added_nodes) {
1120 m_added_node_params.push_back({added_node, use_v2transport});
1121 }
1122 }
1123 m_onion_binds = connOptions.onion_binds;
1124 whitelist_forcerelay = connOptions.whitelist_forcerelay;
1125 whitelist_relay = connOptions.whitelist_relay;
1126 }
1127
1128 CConnman(uint64_t seed0,
1129 uint64_t seed1,
1130 AddrMan& addrman,
1131 const NetGroupManager& netgroupman,
1132 const CChainParams& params,
1133 bool network_active = true,
1134 std::shared_ptr<CThreadInterrupt> interrupt_net = std::make_shared<CThreadInterrupt>());
1135
1136 ~CConnman();
1137
1138 bool Start(CScheduler& scheduler, const Options& options) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !m_added_nodes_mutex, !m_addr_fetches_mutex, !mutexMsgProc);
1139
1140 void StopThreads();
1141 void StopNodes();
1142 void Stop()
1143 {
1144 StopThreads();
1145 StopNodes();
1146 };
1147
1148 void Interrupt() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1149 bool GetNetworkActive() const { return fNetworkActive; };
1150 bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
1151 void SetNetworkActive(bool active);
1152
1165 bool OpenNetworkConnection(const CAddress& addrConnect,
1166 bool fCountFailure,
1167 CountingSemaphoreGrant<>&& grant_outbound,
1168 const char* pszDest,
1169 ConnectionType conn_type,
1170 bool use_v2transport,
1171 const std::optional<Proxy>& proxy_override = std::nullopt)
1172 EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1173
1174 bool CheckIncomingNonce(uint64_t nonce);
1175 void ASMapHealthCheck();
1176
1177 // alias for thread safety annotations only, not defined
1179
1180 bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
1181
1182 void PushMessage(CNode* pnode, CSerializedNetMsg&& msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1183
1184 using NodeFn = std::function<void(CNode*)>;
1185 void ForEachNode(const NodeFn& func)
1186 {
1187 LOCK(m_nodes_mutex);
1188 for (auto&& node : m_nodes) {
1189 if (NodeFullyConnected(node))
1190 func(node);
1191 }
1192 };
1193
1194 void ForEachNode(const NodeFn& func) const
1195 {
1196 LOCK(m_nodes_mutex);
1197 for (auto&& node : m_nodes) {
1198 if (NodeFullyConnected(node))
1199 func(node);
1200 }
1201 };
1202
1203 // Addrman functions
1215 std::vector<CAddress> GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered = true) const;
1230 std::vector<CAddress> GetAddresses(CNode& requestor, size_t max_addresses, size_t max_pct);
1231
1232 // This allows temporarily exceeding m_max_outbound_full_relay, with the goal of finding
1233 // a peer that is better than all our current peers.
1234 void SetTryNewOutboundPeer(bool flag);
1235 bool GetTryNewOutboundPeer() const;
1236
1237 void StartExtraBlockRelayPeers();
1238
1239 // Count the number of full-relay peer we have.
1240 int GetFullOutboundConnCount() const;
1241 // Return the number of outbound peers we have in excess of our target (eg,
1242 // if we previously called SetTryNewOutboundPeer(true), and have since set
1243 // to false, we may have extra peers that we wish to disconnect). This may
1244 // return a value less than (num_outbound_connections - num_outbound_slots)
1245 // in cases where some outbound connections are not yet fully connected, or
1246 // not yet fully disconnected.
1247 int GetExtraFullOutboundCount() const;
1248 // Count the number of block-relay-only peers we have over our limit.
1249 int GetExtraBlockRelayCount() const;
1250
1251 bool AddNode(const AddedNodeParams& add) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1252 bool RemoveAddedNode(std::string_view node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1253 bool AddedNodesContain(const CAddress& addr) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1254 std::vector<AddedNodeInfo> GetAddedNodeInfo(bool include_connected) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1255
1269 bool AddConnection(const std::string& address, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1270
1271 size_t GetNodeCount(ConnectionDirection) const;
1272 std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
1273 uint32_t GetMappedAS(const CNetAddr& addr) const;
1274 void GetNodeStats(std::vector<CNodeStats>& vstats) const;
1275 bool DisconnectNode(std::string_view node);
1276 bool DisconnectNode(const CSubNet& subnet);
1277 bool DisconnectNode(const CNetAddr& addr);
1278 bool DisconnectNode(NodeId id);
1279
1286 ServiceFlags GetLocalServices() const;
1287
1290 void AddLocalServices(ServiceFlags services) { m_local_services = ServiceFlags(m_local_services | services); };
1291 void RemoveLocalServices(ServiceFlags services) { m_local_services = ServiceFlags(m_local_services & ~services); }
1292
1293 uint64_t GetMaxOutboundTarget() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1294 std::chrono::seconds GetMaxOutboundTimeframe() const;
1295
1299 bool OutboundTargetReached(bool historicalBlockServingLimit) const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1300
1303 uint64_t GetOutboundTargetBytesLeft() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1304
1305 std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1306
1307 uint64_t GetTotalBytesRecv() const;
1308 uint64_t GetTotalBytesSent() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1309
1311 CSipHasher GetDeterministicRandomizer(uint64_t id) const;
1312
1313 void WakeMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1314
1316 bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const;
1317
1318 bool MultipleManualOrFullOutboundConns(Network net) const EXCLUSIVE_LOCKS_REQUIRED(m_nodes_mutex);
1319
1320private:
1322 public:
1323 std::shared_ptr<Sock> sock;
1325 ListenSocket(std::shared_ptr<Sock> sock_, NetPermissionFlags permissions_)
1326 : sock{sock_}, m_permissions{permissions_}
1327 {
1328 }
1329
1330 private:
1332 };
1333
1336 std::chrono::seconds GetMaxOutboundTimeLeftInCycle_() const EXCLUSIVE_LOCKS_REQUIRED(m_total_bytes_sent_mutex);
1337
1338 bool BindListenPort(const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
1339 bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
1340 bool InitBinds(const Options& options);
1341
1342 void ThreadOpenAddedConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_unused_i2p_sessions_mutex, !m_reconnections_mutex);
1343 void AddAddrFetch(const std::string& strDest) EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex);
1344 void ProcessAddrFetch() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_unused_i2p_sessions_mutex);
1345 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);
1346 void ThreadMessageHandler() EXCLUSIVE_LOCKS_REQUIRED(!mutexMsgProc);
1347 void ThreadI2PAcceptIncoming();
1348 void AcceptConnection(const ListenSocket& hListenSocket);
1349
1358 void CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
1359 NetPermissionFlags permission_flags,
1360 const CService& addr_bind,
1361 const CService& addr);
1362
1363 void DisconnectNodes() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_nodes_mutex);
1364 void NotifyNumConnectionsChanged();
1366 bool InactivityCheck(const CNode& node) const;
1367
1373 Sock::EventsPerSock GenerateWaitSockets(std::span<CNode* const> nodes);
1374
1378 void SocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1379
1385 void SocketHandlerConnected(const std::vector<CNode*>& nodes,
1386 const Sock::EventsPerSock& events_per_sock)
1387 EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc);
1388
1393 void SocketHandlerListening(const Sock::EventsPerSock& events_per_sock);
1394
1395 void ThreadSocketHandler() EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc, !m_nodes_mutex, !m_reconnections_mutex);
1396 void ThreadDNSAddressSeed() EXCLUSIVE_LOCKS_REQUIRED(!m_addr_fetches_mutex, !m_nodes_mutex);
1397
1398 uint64_t CalculateKeyedNetGroup(const CNetAddr& ad) const;
1399
1407 bool AlreadyConnectedToHost(std::string_view host) const;
1408
1416 bool AlreadyConnectedToAddressPort(const CService& addr_port) const;
1417
1421 bool AlreadyConnectedToAddress(const CNetAddr& addr) const;
1422
1423 bool AttemptToEvictConnection();
1424
1435 CNode* ConnectNode(CAddress addrConnect,
1436 const char* pszDest,
1437 bool fCountFailure,
1438 ConnectionType conn_type,
1439 bool use_v2transport,
1440 const std::optional<Proxy>& proxy_override)
1441 EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
1442
1443 void AddWhitelistPermissionFlags(NetPermissionFlags& flags, std::optional<CNetAddr> addr, const std::vector<NetWhitelistPermissions>& ranges) const;
1444
1445 void DeleteNode(CNode* pnode);
1446
1447 NodeId GetNewNodeId();
1448
1450 std::pair<size_t, bool> SocketSendData(CNode& node) const EXCLUSIVE_LOCKS_REQUIRED(node.cs_vSend);
1451
1452 void DumpAddresses();
1453
1454 // Network stats
1455 void RecordBytesRecv(uint64_t bytes);
1456 void RecordBytesSent(uint64_t bytes) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1457
1462 std::unordered_set<Network> GetReachableEmptyNetworks() const;
1463
1467 std::vector<CAddress> GetCurrentBlockRelayOnlyConns() const;
1468
1479 bool MaybePickPreferredNetwork(std::optional<Network>& network);
1480
1481 // Whether the node should be passed out in ForEach* callbacks
1482 static bool NodeFullyConnected(const CNode* pnode);
1483
1484 uint16_t GetDefaultPort(Network net) const;
1485 uint16_t GetDefaultPort(const std::string& addr) const;
1486
1487 // Network usage totals
1488 mutable Mutex m_total_bytes_sent_mutex;
1489 std::atomic<uint64_t> nTotalBytesRecv{0};
1490 uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex) {0};
1491
1492 // outbound limit & stats
1493 uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex) {0};
1494 std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex) {0};
1495 uint64_t nMaxOutboundLimit GUARDED_BY(m_total_bytes_sent_mutex);
1496
1497 // P2P timeout in seconds
1498 std::chrono::seconds m_peer_connect_timeout;
1499
1500 // Whitelisted ranges. Any node connecting from these is automatically
1501 // whitelisted (as well as those connecting to whitelisted binds).
1502 std::vector<NetWhitelistPermissions> vWhitelistedRangeIncoming;
1503 // Whitelisted ranges for outgoing connections.
1504 std::vector<NetWhitelistPermissions> vWhitelistedRangeOutgoing;
1505
1506 unsigned int nSendBufferMaxSize{0};
1507 unsigned int nReceiveFloodSize{0};
1508
1509 std::vector<ListenSocket> vhListenSocket;
1510 std::atomic<bool> fNetworkActive{true};
1511 bool fAddressesInitialized{false};
1514 std::deque<std::string> m_addr_fetches GUARDED_BY(m_addr_fetches_mutex);
1516
1517 // connection string and whether to use v2 p2p
1518 std::vector<AddedNodeParams> m_added_node_params GUARDED_BY(m_added_nodes_mutex);
1519
1521 std::vector<CNode*> m_nodes GUARDED_BY(m_nodes_mutex);
1522 std::list<CNode*> m_nodes_disconnected;
1524 std::atomic<NodeId> nLastNodeId{0};
1525 unsigned int nPrevNodeCount{0};
1526
1527 // Stores number of full-tx connections (outbound and manual) per network
1528 std::array<unsigned int, Network::NET_MAX> m_network_conn_counts GUARDED_BY(m_nodes_mutex) = {};
1529
1537 std::vector<CAddress> m_addrs_response_cache;
1538 std::chrono::microseconds m_cache_entry_expiration{0};
1539 };
1540
1555 std::map<uint64_t, CachedAddrResponse> m_addr_response_caches;
1556
1568 std::atomic<ServiceFlags> m_local_services;
1569
1570 std::unique_ptr<std::counting_semaphore<>> semOutbound;
1571 std::unique_ptr<std::counting_semaphore<>> semAddnode;
1572
1579
1580 /*
1581 * Maximum number of peers by connection type. Might vary from defaults
1582 * based on -maxconnections init value.
1583 */
1584
1585 // How many full-relay (tx, block, addr) outbound peers we want
1587
1588 // How many block-relay only outbound peers we want
1589 // We do not relay tx or addr messages with these peers
1591
1592 int m_max_addnode{MAX_ADDNODE_CONNECTIONS};
1593 int m_max_feeler{MAX_FEELER_CONNECTIONS};
1596
1602
1607 std::vector<CAddress> m_anchors;
1608
1610 const uint64_t nSeed0, nSeed1;
1611
1613 bool fMsgProcWake GUARDED_BY(mutexMsgProc);
1614
1615 std::condition_variable condMsgProc;
1617 std::atomic<bool> flagInterruptMsgProc{false};
1618
1623 const std::shared_ptr<CThreadInterrupt> m_interrupt_net;
1624
1630 std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
1631
1638
1643
1648 std::atomic_bool m_start_extra_block_relay_peers{false};
1649
1654 std::vector<CService> m_onion_binds;
1655
1661
1667
1672
1680 std::queue<std::unique_ptr<i2p::sam::Session>> m_unused_i2p_sessions GUARDED_BY(m_unused_i2p_sessions_mutex);
1681
1686
1689 {
1692 std::string destination;
1695 };
1696
1700 std::list<ReconnectionInfo> m_reconnections GUARDED_BY(m_reconnections_mutex);
1701
1703 void PerformReconnections() EXCLUSIVE_LOCKS_REQUIRED(!m_reconnections_mutex, !m_unused_i2p_sessions_mutex);
1704
1709 static constexpr size_t MAX_UNUSED_I2P_SESSIONS_SIZE{10};
1710
1716 {
1717 public:
1718 explicit NodesSnapshot(const CConnman& connman, bool shuffle)
1719 {
1720 {
1721 LOCK(connman.m_nodes_mutex);
1722 m_nodes_copy = connman.m_nodes;
1723 for (auto& node : m_nodes_copy) {
1724 node->AddRef();
1725 }
1726 }
1727 if (shuffle) {
1728 std::shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});
1729 }
1730 }
1731
1733 {
1734 for (auto& node : m_nodes_copy) {
1735 node->Release();
1736 }
1737 }
1738
1739 const std::vector<CNode*>& Nodes() const
1740 {
1741 return m_nodes_copy;
1742 }
1743
1744 private:
1745 std::vector<CNode*> m_nodes_copy;
1746 };
1747
1749
1750 friend struct ConnmanTestMsg;
1751};
1752
1754extern std::function<void(const CAddress& addr,
1755 const std::string& msg_type,
1756 std::span<const unsigned char> data,
1757 bool is_incoming)>
1759
1760#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:127
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:78
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:1716
const std::vector< CNode * > & Nodes() const
Definition: net.h:1739
NodesSnapshot(const CConnman &connman, bool shuffle)
Definition: net.h:1718
std::vector< CNode * > m_nodes_copy
Definition: net.h:1745
Definition: net.h:1060
bool whitelist_relay
flag for adding 'relay' permission to whitelisted inbound and manual peers with default permissions.
Definition: net.h:1666
std::condition_variable condMsgProc
Definition: net.h:1615
std::thread threadMessageHandler
Definition: net.h:1636
void RemoveLocalServices(ServiceFlags services)
Definition: net.h:1291
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
Definition: net.h:1502
CClientUIInterface * m_client_interface
Definition: net.h:1598
void ForEachNode(const NodeFn &func) const
Definition: net.h:1194
std::vector< AddedNodeParams > m_added_node_params GUARDED_BY(m_added_nodes_mutex)
int m_max_inbound
Definition: net.h:1595
const bool use_v2transport(GetLocalServices() &NODE_P2P_V2)
void Stop()
Definition: net.h:1142
int m_max_outbound_block_relay
Definition: net.h:1590
std::array< unsigned int, Network::NET_MAX > m_network_conn_counts GUARDED_BY(m_nodes_mutex)
std::thread threadI2PAcceptIncoming
Definition: net.h:1637
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:1594
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:1578
BanMan * m_banman
Pointer to this node's banman.
Definition: net.h:1601
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1493
std::thread threadDNSAddressSeed
Definition: net.h:1632
const NetGroupManager & m_netgroupman
Definition: net.h:1513
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
Definition: net.h:1607
bool whitelist_forcerelay
flag for adding 'forcerelay' permission to whitelisted inbound and manual peers with default permissi...
Definition: net.h:1660
std::chrono::seconds m_peer_connect_timeout
Definition: net.h:1498
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:1642
std::vector< ListenSocket > vhListenSocket
Definition: net.h:1509
std::thread threadOpenConnections
Definition: net.h:1635
std::atomic< ServiceFlags > m_local_services
Services this node offers.
Definition: net.h:1568
Mutex m_addr_fetches_mutex
Definition: net.h:1515
Mutex m_reconnections_mutex
Mutex protecting m_reconnections.
Definition: net.h:1685
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
Definition: net.h:1610
RecursiveMutex m_nodes_mutex
Definition: net.h:1523
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:1570
const CChainParams & m_params
Definition: net.h:1748
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:1623
void AddLocalServices(ServiceFlags services)
Updates the local services that this node advertises to other peers during connection handshake.
Definition: net.h:1290
AddrMan & addrman
Definition: net.h:1512
Mutex mutexMsgProc
Definition: net.h:1616
std::thread threadOpenAddedConnections
Definition: net.h:1634
Mutex m_added_nodes_mutex
Definition: net.h:1520
int m_max_outbound_full_relay
Definition: net.h:1586
Mutex m_unused_i2p_sessions_mutex
Mutex protecting m_i2p_sam_sessions.
Definition: net.h:1671
std::vector< CNode * > m_nodes GUARDED_BY(m_nodes_mutex)
std::unique_ptr< std::counting_semaphore<> > semAddnode
Definition: net.h:1571
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1494
uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex)
Definition: net.h:1490
bool GetUseAddrmanOutgoing() const
Definition: net.h:1150
std::list< CNode * > m_nodes_disconnected
Definition: net.h:1522
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session
I2P SAM session.
Definition: net.h:1630
bool m_use_addrman_outgoing
Definition: net.h:1597
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
Definition: net.h:1504
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:1555
std::function< void(CNode *)> NodeFn
Definition: net.h:1184
NetEventsInterface * m_msgproc
Definition: net.h:1599
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:1654
RecursiveMutex & GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex)
std::thread threadSocketHandler
Definition: net.h:1633
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
Definition: hash.h:24
An encapsulated private key.
Definition: key.h:36
Message header.
Definition: protocol.h:29
Network address.
Definition: netaddress.h:113
Transport protocol agnostic message container.
Definition: net.h:234
CNetMessage(CNetMessage &&)=default
CNetMessage(DataStream &&recv_in)
Definition: net.h:242
std::string m_type
Definition: net.h:240
DataStream m_recv
received message data
Definition: net.h:236
CNetMessage & operator=(const CNetMessage &)=delete
CNetMessage(const CNetMessage &)=delete
CNetMessage & operator=(CNetMessage &&)=default
Information about a peer.
Definition: net.h:676
bool IsFeelerConn() const
Definition: net.h:810
const std::chrono::seconds m_connected
Unix epoch time at peer connection.
Definition: net.h:709
bool ExpectServicesFromConn() const
Definition: net.h:822
const std::string m_dest
The pszDest argument provided to ConnectNode().
Definition: net.h:716
CService m_addr_local GUARDED_BY(m_addr_local_mutex)
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
Definition: net.h:704
bool IsInboundConn() const
Definition: net.h:818
bool HasPermission(NetPermissionFlags permission) const
Definition: net.h:727
CountingSemaphoreGrant grantOutbound
Definition: net.h:735
bool IsOutboundOrBlockRelayConn() const
Definition: net.h:767
NodeId GetId() const
Definition: net.h:902
bool IsManualConn() const
Definition: net.h:786
const std::string m_addr_name
Definition: net.h:714
CNode & operator=(const CNode &)=delete
const CService addrBind
Definition: net.h:713
void SetCommonVersion(int greatest_common_version)
Definition: net.h:927
std::list< CNetMessage > vRecvMsg
Definition: net.h:986
void PongReceived(std::chrono::microseconds ping_time)
A ping-pong round trip has completed successfully.
Definition: net.h:975
size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex)
Definition: net.h:990
bool IsAddrFetchConn() const
Definition: net.h:814
uint64_t GetLocalNonce() const
Definition: net.h:906
const CAddress addr
Definition: net.h:711
mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend)
const uint64_t nKeyedNetGroup
Definition: net.h:738
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:806
int GetCommonVersion() const
Definition: net.h:932
mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv)
bool IsFullOutboundConn() const
Definition: net.h:782
Mutex m_subver_mutex
Definition: net.h:720
Mutex cs_vSend
Definition: net.h:700
const uint64_t m_network_key
Network key used to prevent fingerprinting our node across networks.
Definition: net.h:744
int GetRefCount() const
Definition: net.h:910
Mutex m_msg_process_queue_mutex
Definition: net.h:988
const ConnectionType m_conn_type
Definition: net.h:746
const size_t m_recv_flood_size
Definition: net.h:985
const uint64_t nLocalHostNonce
Definition: net.h:982
bool IsManualOrFullOutboundConn() const
Definition: net.h:790
const std::unique_ptr< Transport > m_transport
Transport serializer/deserializer.
Definition: net.h:680
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:682
Mutex m_addr_local_mutex
Definition: net.h:994
CNode(const CNode &)=delete
size_t m_send_memusage GUARDED_BY(cs_vSend)
Sum of GetMemoryUsage of all vSendMsg entries.
Definition: net.h:695
const bool m_inbound_onion
Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
Definition: net.h:718
const NodeId id
Definition: net.h:981
Mutex cs_vRecv
Definition: net.h:702
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Total number of bytes sent on the wire to this peer.
Definition: net.h:697
Mutex m_sock_mutex
Definition: net.h:701
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:947
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:725
std::string m_session_id
BIP324 session id string in hex, if any.
Definition: net.h:225
std::string addrLocal
Definition: net.h:213
uint64_t nRecvBytes
Definition: net.h:207
std::chrono::microseconds m_last_ping_time
Definition: net.h:210
uint32_t m_mapped_as
Definition: net.h:220
mapMsgTypeSize mapRecvBytesPerMsgType
Definition: net.h:208
bool fInbound
Definition: net.h:199
uint64_t nSendBytes
Definition: net.h:205
std::chrono::seconds m_last_recv
Definition: net.h:192
ConnectionType m_conn_type
Definition: net.h:221
std::chrono::seconds m_last_send
Definition: net.h:191
std::chrono::seconds m_last_tx_time
Definition: net.h:193
CAddress addr
Definition: net.h:215
mapMsgTypeSize mapSendBytesPerMsgType
Definition: net.h:206
std::chrono::microseconds m_min_ping_time
Definition: net.h:211
CService addrBind
Definition: net.h:217
TransportProtocolType m_transport_type
Transport protocol type.
Definition: net.h:223
std::chrono::seconds m_connected
Definition: net.h:195
bool m_bip152_highbandwidth_from
Definition: net.h:203
bool m_bip152_highbandwidth_to
Definition: net.h:201
std::string m_addr_name
Definition: net.h:196
int nVersion
Definition: net.h:197
std::chrono::seconds m_last_block_time
Definition: net.h:194
Network m_network
Definition: net.h:219
NodeId nodeid
Definition: net.h:190
std::string cleanSubVer
Definition: net.h:198
int m_starting_height
Definition: net.h:204
NetPermissionFlags m_permission_flags
Definition: net.h:209
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:532
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:1016
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition: net.h:1019
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)
Definition: netbase.h:59
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:257
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:314
CHash256 hasher GUARDED_BY(m_recv_mutex)
DataStream hdrbuf GUARDED_BY(m_recv_mutex)
Definition: net.h:379
bool m_sending_header GUARDED_BY(m_send_mutex)
Whether we're currently sending header bytes or message bytes.
Definition: net.h:415
const NodeId m_node_id
Definition: net.h:374
Mutex m_send_mutex
Lock for sending state.
Definition: net.h:409
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:417
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:373
unsigned int nHdrPos GUARDED_BY(m_recv_mutex)
DataStream vRecv GUARDED_BY(m_recv_mutex)
Definition: net.h:381
bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
Definition: net.h:401
CMessageHeader hdr GUARDED_BY(m_recv_mutex)
Mutex m_recv_mutex
Lock for receive state.
Definition: net.h:375
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:422
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:615
const NodeId m_nodeid
NodeId (for debug logging).
Definition: net.h:583
BIP324Cipher m_cipher
Cipher state.
Definition: net.h:579
SendState
State type that controls the sender side.
Definition: net.h:548
V1Transport m_v1_fallback
Encapsulate a V1Transport to fall back to.
Definition: net.h:585
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:581
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:591
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:607
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:483
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:21
static const unsigned char VERSION[]
Definition: netaddress.cpp:188
const std::string KEY
Definition: walletdb.cpp:44
uint16_t GetListenPort()
Definition: net.cpp:138
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:79
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:329
void RemoveLocal(const CService &addr)
Definition: net.cpp:310
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
Definition: net.h:67
static constexpr std::chrono::minutes TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
Definition: net.h:59
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
Definition: net.h:71
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:277
bool fDiscover
Definition: net.cpp:116
static const size_t DEFAULT_MAXSENDBUFFER
Definition: net.h:95
static const int NUM_FDS_MESSAGE_CAPTURE
Number of file descriptors required for message capture.
Definition: net.h:87
static constexpr bool DEFAULT_FIXEDSEEDS
Definition: net.h:93
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:83
void ClearLocal()
Definition: net.cpp:270
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:65
bool fListen
Definition: net.cpp:117
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL
Run the extra block-relay-only connection loop once every 5 minutes.
Definition: net.h:63
static const size_t DEFAULT_MAXRECEIVEBUFFER
Definition: net.h:94
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
Definition: net.cpp:120
static const std::string DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
Definition: net.h:81
std::optional< CService > GetLocalAddrForPeer(CNode &node)
Returns a local address that we should advertise to this peer.
Definition: net.cpp:240
const std::string NET_MESSAGE_TYPE_OTHER
Definition: net.cpp:108
std::map< std::string, uint64_t > mapMsgTypeSize
Definition: net.h:185
static constexpr bool DEFAULT_FORCEDNSSEED
Definition: net.h:91
static constexpr bool DEFAULT_DNSSEED
Definition: net.h:92
int64_t NodeId
Definition: net.h:99
CService GetLocalAddress(const CNode &peer)
Definition: net.cpp:220
GlobalMutex g_maplocalhost_mutex
Definition: net.cpp:118
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:75
static const bool DEFAULT_LISTEN
-listen default
Definition: net.h:77
static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL
Interval for ASMap Health Check.
Definition: net.h:89
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:61
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
Definition: net.h:85
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:4047
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition: net.h:69
@ LOCAL_NONE
Definition: net.h:150
@ LOCAL_MAPPED
Definition: net.h:153
@ LOCAL_MANUAL
Definition: net.h:154
@ LOCAL_MAX
Definition: net.h:156
@ LOCAL_BIND
Definition: net.h:152
@ LOCAL_IF
Definition: net.h:151
static constexpr bool DEFAULT_V2_TRANSPORT
Definition: net.h:97
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:73
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:3203
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:318
constexpr bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
constexpr bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
NetPermissionFlags
Network
A network type.
Definition: netaddress.h:33
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:110
CService resolvedAddress
Definition: net.h:108
AddedNodeParams m_params
Definition: net.h:107
bool fConnected
Definition: net.h:109
std::string m_added_node
Definition: net.h:102
bool m_use_v2transport
Definition: net.h:103
Cache responses to addr requests to minimize privacy leak.
Definition: net.h:1536
std::vector< CAddress > m_addrs_response_cache
Definition: net.h:1537
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
Definition: net.h:1324
ListenSocket(std::shared_ptr< Sock > sock_, NetPermissionFlags permissions_)
Definition: net.h:1325
NetPermissionFlags m_permissions
Definition: net.h:1331
std::shared_ptr< Sock > sock
Definition: net.h:1323
std::vector< NetWhitebindPermissions > vWhiteBinds
Definition: net.h:1077
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
Definition: net.h:1075
std::vector< CService > onion_binds
Definition: net.h:1079
std::vector< std::string > m_specified_outgoing
Definition: net.h:1084
std::vector< std::string > m_added_nodes
Definition: net.h:1085
std::vector< CService > vBinds
Definition: net.h:1078
bool m_i2p_accept_incoming
Definition: net.h:1086
std::vector< std::string > vSeedNodes
Definition: net.h:1074
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
Definition: net.h:1082
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
Definition: net.h:1076
Struct for entries in m_reconnections.
Definition: net.h:1689
ConnectionType conn_type
Definition: net.h:1693
std::string destination
Definition: net.h:1692
CountingSemaphoreGrant grant
Definition: net.h:1691
CSerializedNetMsg(const CSerializedNetMsg &msg)=delete
CSerializedNetMsg Copy() const
Definition: net.h:124
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
std::string m_type
Definition: net.h:133
CSerializedNetMsg & operator=(const CSerializedNetMsg &)=delete
CSerializedNetMsg()=default
CSerializedNetMsg(CSerializedNetMsg &&)=default
std::vector< unsigned char > data
Definition: net.h:132
size_t GetMemoryUsage() const noexcept
Compute total memory usage of this object (own memory + any dynamic memory).
Definition: net.cpp:122
uint16_t nPort
Definition: net.h:178
int nScore
Definition: net.h:177
std::optional< uint256 > session_id
Definition: net.h:264
TransportProtocolType transport_type
Definition: net.h:263
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())