36#include <condition_variable>
46#include <unordered_set>
130 std::vector<unsigned char>
data;
234 std::chrono::microseconds m_time{0};
235 uint32_t m_message_size{0};
236 uint32_t m_raw_message_size{0};
271 virtual
bool ReceivedMessageComplete() const = 0;
279 virtual
bool ReceivedBytes(
Span<const uint8_t>& msg_bytes) = 0;
288 virtual
CNetMessage GetReceivedMessage(
std::chrono::microseconds time,
bool& reject_message) = 0;
308 Span<const uint8_t> ,
348 virtual
BytesToSend GetBytesToSend(
bool have_next_message) const noexcept = 0;
356 virtual
void MarkBytesSent(
size_t bytes_sent) noexcept = 0;
359 virtual
size_t GetSendMemoryUsage() const noexcept = 0;
364 virtual
bool ShouldReconnectV1() const noexcept = 0;
401 if (!in_data)
return false;
402 return hdr.nMessageSize == nDataPos;
408 std::vector<uint8_t> m_header_to_send
GUARDED_BY(m_send_mutex);
422 return WITH_LOCK(m_recv_mutex,
return CompleteInternal());
425 Info
GetInfo() const noexcept override;
431 int ret = in_data ? readData(msg_bytes) : readHeader(msg_bytes);
435 msg_bytes = msg_bytes.subspan(
ret);
446 bool ShouldReconnectV1() const noexcept
override {
return false; }
455 static constexpr std::array<std::byte, 0> VERSION_CONTENTS = {};
459 static constexpr size_t V1_PREFIX_LEN = 16;
594 std::vector<uint8_t> m_recv_decode_buffer
GUARDED_BY(m_recv_mutex);
606 std::vector<uint8_t> m_send_garbage
GUARDED_BY(m_send_mutex);
612 bool m_sent_v1_header_worth
GUARDED_BY(m_send_mutex) {
false};
634 static constexpr uint32_t MAX_GARBAGE_LEN = 4095;
665 std::unique_ptr<i2p::sam::Session> i2p_sam_session =
nullptr;
666 bool prefer_evict =
false;
668 bool use_v2transport =
false;
703 std::atomic<std::chrono::seconds> m_last_send{0
s};
704 std::atomic<std::chrono::seconds> m_last_recv{0
s};
716 std::atomic<int> nVersion{0};
723 const bool m_prefer_evict{
false};
728 std::atomic_bool fSuccessfullyConnected{
false};
731 std::atomic_bool fDisconnect{
false};
733 std::atomic<int> nRefCount{0};
736 std::atomic_bool fPauseRecv{
false};
737 std::atomic_bool fPauseSend{
false};
742 void MarkReceivedMsgsForProcessing()
754 void AccountForSentBytes(const
std::
string& msg_type,
size_t sent_bytes)
757 mapSendBytesPerMsgType[msg_type] += sent_bytes;
761 switch (m_conn_type) {
785 switch (m_conn_type) {
816 switch (m_conn_type) {
840 Network ConnectedThroughNetwork()
const;
843 [[nodiscard]]
bool IsConnectedThroughPrivacyNet()
const;
846 std::atomic<bool> m_bip152_highbandwidth_to{
false};
848 std::atomic<bool> m_bip152_highbandwidth_from{
false};
851 std::atomic_bool m_has_all_wanted_services{
false};
855 std::atomic_bool m_relays_txs{
false};
859 std::atomic_bool m_bloom_filter_loaded{
false};
866 std::atomic<std::chrono::seconds> m_last_block_time{0
s};
872 std::atomic<std::chrono::seconds> m_last_tx_time{0
s};
875 std::atomic<std::chrono::microseconds> m_last_ping_time{0us};
879 std::atomic<std::chrono::microseconds> m_min_ping_time{std::chrono::microseconds::max()};
882 std::shared_ptr<Sock> sock,
884 uint64_t nKeyedNetGroupIn,
885 uint64_t nLocalHostNonceIn,
887 const std::string& addrNameIn,
899 return nLocalHostNonce;
922 m_greatest_common_version = greatest_common_version;
926 return m_greatest_common_version;
952 m_last_ping_time = ping_time;
953 m_min_ping_time = std::min(m_min_ping_time.load(), ping_time);
965 std::list<CNetMessage> m_msg_process_queue
GUARDED_BY(m_msg_process_queue_mutex);
966 size_t m_msg_process_queue_size
GUARDED_BY(m_msg_process_queue_mutex){0};
985 std::unique_ptr<i2p::sam::Session> m_i2p_sam_session
GUARDED_BY(m_sock_mutex);
1042 int m_max_automatic_connections = 0;
1046 unsigned int nSendBufferMaxSize = 0;
1047 unsigned int nReceiveFloodSize = 0;
1048 uint64_t nMaxOutboundLimit = 0;
1059 bool m_use_addrman_outgoing =
true;
1071 m_local_services = connOptions.m_local_services;
1072 m_max_automatic_connections = connOptions.m_max_automatic_connections;
1075 m_max_automatic_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + m_max_feeler;
1076 m_max_inbound = std::max(0, m_max_automatic_connections - m_max_automatic_outbound);
1077 m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
1078 m_client_interface = connOptions.uiInterface;
1079 m_banman = connOptions.m_banman;
1080 m_msgproc = connOptions.m_msgproc;
1081 nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
1082 nReceiveFloodSize = connOptions.nReceiveFloodSize;
1083 m_peer_connect_timeout = std::chrono::seconds{connOptions.m_peer_connect_timeout};
1085 LOCK(m_total_bytes_sent_mutex);
1086 nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
1088 vWhitelistedRangeIncoming = connOptions.vWhitelistedRangeIncoming;
1089 vWhitelistedRangeOutgoing = connOptions.vWhitelistedRangeOutgoing;
1091 LOCK(m_added_nodes_mutex);
1095 for (
const std::string& added_node : connOptions.m_added_nodes) {
1096 m_added_node_params.push_back({added_node, use_v2transport});
1099 m_onion_binds = connOptions.onion_binds;
1100 whitelist_forcerelay = connOptions.whitelist_forcerelay;
1101 whitelist_relay = connOptions.whitelist_relay;
1105 const CChainParams& params,
bool network_active =
true);
1120 bool GetNetworkActive()
const {
return fNetworkActive; };
1122 void SetNetworkActive(
bool active);
1124 bool CheckIncomingNonce(uint64_t
nonce);
1125 void ASMapHealthCheck();
1137 LOCK(m_nodes_mutex);
1138 for (
auto&&
node : m_nodes) {
1139 if (NodeFullyConnected(
node))
1146 LOCK(m_nodes_mutex);
1147 for (
auto&&
node : m_nodes) {
1148 if (NodeFullyConnected(
node))
1162 std::vector<CAddress> GetAddresses(
size_t max_addresses,
size_t max_pct, std::optional<Network> network,
const bool filtered =
true)
const;
1169 std::vector<CAddress> GetAddresses(
CNode& requestor,
size_t max_addresses,
size_t max_pct);
1173 void SetTryNewOutboundPeer(
bool flag);
1174 bool GetTryNewOutboundPeer()
const;
1176 void StartExtraBlockRelayPeers();
1179 int GetFullOutboundConnCount()
const;
1186 int GetExtraFullOutboundCount()
const;
1188 int GetExtraBlockRelayCount()
const;
1193 std::vector<AddedNodeInfo> GetAddedNodeInfo(
bool include_connected)
const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex);
1211 std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses()
const;
1212 uint32_t GetMappedAS(
const CNetAddr& addr)
const;
1213 void GetNodeStats(std::vector<CNodeStats>& vstats)
const;
1214 bool DisconnectNode(
const std::string&
node);
1215 bool DisconnectNode(
const CSubNet& subnet);
1216 bool DisconnectNode(
const CNetAddr& addr);
1217 bool DisconnectNode(
NodeId id);
1233 std::chrono::seconds GetMaxOutboundTimeframe() const;
1238 bool OutboundTargetReached(
bool historicalBlockServingLimit) const
EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex);
1246 uint64_t GetTotalBytesRecv() const;
1250 CSipHasher GetDeterministicRandomizer(uint64_t
id) const;
1255 bool ShouldRunInactivityChecks(const
CNode&
node,
std::chrono::seconds now) const;
1265 : sock{sock_}, m_permissions{permissions_}
1279 bool InitBinds(const
Options& options);
1281 void ThreadOpenAddedConnections()
EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_unused_i2p_sessions_mutex, !m_reconnections_mutex);
1284 void ThreadOpenConnections(
std::vector<
std::
string> connect,
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);
1286 void ThreadI2PAcceptIncoming();
1287 void AcceptConnection(const
ListenSocket& hListenSocket);
1297 void CreateNodeFromAcceptedSocket(
std::unique_ptr<
Sock>&& sock,
1303 void NotifyNumConnectionsChanged();
1305 bool InactivityCheck(const
CNode&
node) const;
1312 Sock::EventsPerSock GenerateWaitSockets(
Span<
CNode* const> nodes);
1324 void SocketHandlerConnected(const
std::vector<
CNode*>& nodes,
1325 const
Sock::EventsPerSock& events_per_sock)
1332 void SocketHandlerListening(const
Sock::EventsPerSock& events_per_sock);
1334 void ThreadSocketHandler()
EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex, !mutexMsgProc, !m_nodes_mutex, !m_reconnections_mutex);
1337 uint64_t CalculateKeyedNetGroup(const
CAddress& ad) const;
1340 CNode* FindNode(const
std::
string& addrName);
1347 bool AlreadyConnectedToAddress(const
CAddress& addr);
1349 bool AttemptToEvictConnection();
1353 void DeleteNode(
CNode* pnode);
1360 void DumpAddresses();
1363 void RecordBytesRecv(uint64_t bytes);
1370 std::unordered_set<
Network> GetReachableEmptyNetworks() const;
1375 std::vector<
CAddress> GetCurrentBlockRelayOnlyConns() const;
1387 bool MaybePickPreferredNetwork(
std::optional<
Network>& network);
1390 static
bool NodeFullyConnected(const
CNode* pnode);
1392 uint16_t GetDefaultPort(
Network net) const;
1393 uint16_t GetDefaultPort(const
std::
string& addr) const;
1397 std::atomic<uint64_t> nTotalBytesRecv{0};
1398 uint64_t nTotalBytesSent
GUARDED_BY(m_total_bytes_sent_mutex) {0};
1401 uint64_t nMaxOutboundTotalBytesSentInCycle
GUARDED_BY(m_total_bytes_sent_mutex) {0};
1402 std::chrono::seconds nMaxOutboundCycleStartTime
GUARDED_BY(m_total_bytes_sent_mutex) {0};
1414 unsigned int nSendBufferMaxSize{0};
1415 unsigned int nReceiveFloodSize{0};
1418 std::atomic<bool> fNetworkActive{
true};
1419 bool fAddressesInitialized{
false};
1422 std::deque<std::string> m_addr_fetches
GUARDED_BY(m_addr_fetches_mutex);
1426 std::vector<AddedNodeParams> m_added_node_params
GUARDED_BY(m_added_nodes_mutex);
1432 std::atomic<NodeId> nLastNodeId{0};
1433 unsigned int nPrevNodeCount{0};
1436 std::array<unsigned int, Network::NET_MAX> m_network_conn_counts
GUARDED_BY(m_nodes_mutex) = {};
1446 std::chrono::microseconds m_cache_entry_expiration{0};
1525 std::atomic<bool> flagInterruptMsgProc{
false};
1558 std::atomic_bool m_start_extra_block_relay_peers{
false};
1590 std::queue<std::unique_ptr<i2p::sam::Session>> m_unused_i2p_sessions
GUARDED_BY(m_unused_i2p_sessions_mutex);
1610 std::list<ReconnectionInfo> m_reconnections
GUARDED_BY(m_reconnections_mutex);
1619 static constexpr
size_t MAX_UNUSED_I2P_SESSIONS_SIZE{10};
1632 m_nodes_copy = connman.m_nodes;
1633 for (
auto&
node : m_nodes_copy) {
1644 for (
auto&
node : m_nodes_copy) {
1649 const std::vector<CNode*>&
Nodes()
const
1651 return m_nodes_copy;
1664extern std::function<void(
const CAddress& addr,
1665 const std::string& msg_type,
#define Assume(val)
Assume is the identity function.
Stochastic address manager.
The BIP324 packet cipher, encapsulating its key derivation, stream cipher, and AEAD.
A CService with information about it as peer.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Signals for UI communication.
RAII helper to atomically create a copy of m_nodes and add a reference to each of the nodes.
const std::vector< CNode * > & Nodes() const
NodesSnapshot(const CConnman &connman, bool shuffle)
std::vector< CNode * > m_nodes_copy
bool whitelist_relay
flag for adding 'relay' permission to whitelisted inbound and manual peers with default permissions.
std::condition_variable condMsgProc
std::thread threadMessageHandler
void RemoveLocalServices(ServiceFlags services)
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
CClientUIInterface * m_client_interface
void ForEachNode(const NodeFn &func) const
std::vector< AddedNodeParams > m_added_node_params GUARDED_BY(m_added_nodes_mutex)
const bool use_v2transport(GetLocalServices() &NODE_P2P_V2)
int m_max_outbound_block_relay
std::array< unsigned int, Network::NET_MAX > m_network_conn_counts GUARDED_BY(m_nodes_mutex)
std::thread threadI2PAcceptIncoming
std::list< ReconnectionInfo > m_reconnections GUARDED_BY(m_reconnections_mutex)
List of reconnections we have to make.
int m_max_automatic_outbound
uint64_t nMaxOutboundLimit GUARDED_BY(m_total_bytes_sent_mutex)
CThreadInterrupt interruptNet
This is signaled when network activity should cease.
std::unique_ptr< CSemaphore > semAddnode
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...
BanMan * m_banman
Pointer to this node's banman.
uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(m_total_bytes_sent_mutex)
std::thread threadDNSAddressSeed
const NetGroupManager & m_netgroupman
std::vector< CAddress > m_anchors
Addresses that were saved during the previous clean shutdown.
bool whitelist_forcerelay
flag for adding 'forcerelay' permission to whitelisted inbound and manual peers with default permissi...
std::chrono::seconds m_peer_connect_timeout
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...
std::vector< ListenSocket > vhListenSocket
std::unique_ptr< CSemaphore > semOutbound
std::thread threadOpenConnections
std::atomic< ServiceFlags > m_local_services
Services this node offers.
Mutex m_addr_fetches_mutex
Mutex m_reconnections_mutex
Mutex protecting m_reconnections.
const uint64_t nSeed0
SipHasher seeds for deterministic randomness.
RecursiveMutex m_nodes_mutex
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...
const CChainParams & m_params
std::deque< std::string > m_addr_fetches GUARDED_BY(m_addr_fetches_mutex)
void AddLocalServices(ServiceFlags services)
Updates the local services that this node advertises to other peers during connection handshake.
std::thread threadOpenAddedConnections
Mutex m_added_nodes_mutex
int m_max_outbound_full_relay
Mutex m_unused_i2p_sessions_mutex
Mutex protecting m_i2p_sam_sessions.
std::vector< CNode * > m_nodes GUARDED_BY(m_nodes_mutex)
std::chrono::seconds nMaxOutboundCycleStartTime GUARDED_BY(m_total_bytes_sent_mutex)
uint64_t nTotalBytesSent GUARDED_BY(m_total_bytes_sent_mutex)
bool GetUseAddrmanOutgoing() const
std::list< CNode * > m_nodes_disconnected
std::unique_ptr< i2p::sam::Session > m_i2p_sam_session
I2P SAM session.
bool m_use_addrman_outgoing
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
std::map< uint64_t, CachedAddrResponse > m_addr_response_caches
Addr responses stored in different caches per (network, local socket) prevent cross-network node iden...
std::function< void(CNode *)> NodeFn
NetEventsInterface * m_msgproc
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...
RecursiveMutex & GetNodesMutex() const LOCK_RETURNED(m_nodes_mutex)
std::thread threadSocketHandler
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
An encapsulated private key.
Transport protocol agnostic message container.
CNetMessage(CNetMessage &&)=default
CNetMessage(DataStream &&recv_in)
DataStream m_recv
received message data
CNetMessage & operator=(const CNetMessage &)=delete
CNetMessage(const CNetMessage &)=delete
CNetMessage & operator=(CNetMessage &&)=default
Information about a peer.
bool IsFeelerConn() const
const std::chrono::seconds m_connected
Unix epoch time at peer connection.
bool ExpectServicesFromConn() const
const std::string m_dest
The pszDest argument provided to ConnectNode().
CService m_addr_local GUARDED_BY(m_addr_local_mutex)
uint64_t nRecvBytes GUARDED_BY(cs_vRecv)
bool IsInboundConn() const
bool HasPermission(NetPermissionFlags permission) const
bool IsOutboundOrBlockRelayConn() const
bool IsManualConn() const
const std::string m_addr_name
CNode & operator=(const CNode &)=delete
void SetCommonVersion(int greatest_common_version)
std::list< CNetMessage > vRecvMsg
void PongReceived(std::chrono::microseconds ping_time)
A ping-pong round trip has completed successfully.
size_t m_msg_process_queue_size GUARDED_BY(m_msg_process_queue_mutex)
bool IsAddrFetchConn() const
uint64_t GetLocalNonce() const
CSemaphoreGrant grantOutbound
mapMsgTypeSize mapSendBytesPerMsgType GUARDED_BY(cs_vSend)
const uint64_t nKeyedNetGroup
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
int GetCommonVersion() const
mapMsgTypeSize mapRecvBytesPerMsgType GUARDED_BY(cs_vRecv)
bool IsFullOutboundConn() const
Mutex m_msg_process_queue_mutex
const ConnectionType m_conn_type
const size_t m_recv_flood_size
const uint64_t nLocalHostNonce
bool IsManualOrFullOutboundConn() const
const std::unique_ptr< Transport > m_transport
Transport serializer/deserializer.
std::shared_ptr< Sock > m_sock GUARDED_BY(m_sock_mutex)
Socket used for communication with the node.
const NetPermissionFlags m_permission_flags
CNode(const CNode &)=delete
size_t m_send_memusage GUARDED_BY(cs_vSend)
Sum of GetMemoryUsage of all vSendMsg entries.
const bool m_inbound_onion
Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
uint64_t nSendBytes GUARDED_BY(cs_vSend)
Total number of bytes sent on the wire to this peer.
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.
std::string cleanSubVer GUARDED_BY(m_subver_mutex)
cleanSubVer is a sanitized string of the user agent byte array we read from the wire.
std::string m_session_id
BIP324 session id string in hex, if any.
std::chrono::microseconds m_last_ping_time
mapMsgTypeSize mapRecvBytesPerMsgType
std::chrono::seconds m_last_recv
ConnectionType m_conn_type
std::chrono::seconds m_last_send
std::chrono::seconds m_last_tx_time
mapMsgTypeSize mapSendBytesPerMsgType
std::chrono::microseconds m_min_ping_time
TransportProtocolType m_transport_type
Transport protocol type.
std::chrono::seconds m_connected
bool m_bip152_highbandwidth_from
bool m_bip152_highbandwidth_to
std::chrono::seconds m_last_block_time
NetPermissionFlags m_permission_flags
Simple class for background tasks that should be run periodically or once "after a while".
RAII-style semaphore lock.
A combination of a network address (CNetAddr) and a (TCP) port.
A helper class for interruptible sleeps.
Double ended buffer combining vector and stream-like interfaces.
Different type to mark Mutex at global scope.
Interface for message handling.
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
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)
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.
A Span is an object that can refer to a contiguous sequence of objects.
The Transport converts one connection's sent messages to wire bytes, and received bytes back.
std::tuple< Span< const uint8_t >, bool, const std::string & > BytesToSend
Return type for GetBytesToSend, consisting of:
virtual ~Transport()=default
virtual Info GetInfo() const noexcept=0
Retrieve information about this transport.
CHash256 hasher GUARDED_BY(m_recv_mutex)
DataStream hdrbuf GUARDED_BY(m_recv_mutex)
bool m_sending_header GUARDED_BY(m_send_mutex)
Whether we're currently sending header bytes or message bytes.
Mutex m_send_mutex
Lock for sending state.
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....
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
unsigned int nHdrPos GUARDED_BY(m_recv_mutex)
DataStream vRecv GUARDED_BY(m_recv_mutex)
bool CompleteInternal() const noexcept EXCLUSIVE_LOCKS_REQUIRED(m_recv_mutex)
CMessageHeader hdr GUARDED_BY(m_recv_mutex)
Mutex m_recv_mutex
Lock for receive state.
bool ReceivedMessageComplete() const override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
Returns true if the current message is complete (so GetReceivedMessage can be called).
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).
const NodeId m_nodeid
NodeId (for debug logging).
BIP324Cipher m_cipher
Cipher state.
SendState
State type that controls the sender side.
V1Transport m_v1_fallback
Encapsulate a V1Transport to fall back to.
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.
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.
uint32_t m_send_pos GUARDED_BY(m_send_mutex)
How many bytes from the send buffer have been sent so far.
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...
std::string ConnectionTypeAsString(ConnectionType conn_type)
Convert ConnectionType enum to a string value.
ConnectionType
Different types of connections to a peer.
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ MANUAL
We open manual connections to addresses that users explicitly requested via the addnode RPC or the -a...
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
@ INBOUND
Inbound connections are those initiated by a peer.
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
TransportProtocolType
Transport layer version.
@ V1
Unencrypted, plaintext protocol.
static CService ip(uint32_t i)
CClientUIInterface uiInterface
std::array< uint8_t, 4 > MessageStartChars
static const unsigned char VERSION[]
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
bool IsLocal(const CService &addr)
check whether a given address is potentially local
void RemoveLocal(const CService &addr)
static const unsigned int MAX_SUBVERSION_LENGTH
Maximum length of the user agent string in version message.
static constexpr std::chrono::minutes TIMEOUT_INTERVAL
Time after which to disconnect, after waiting for a ping response (or inactivity).
static const int MAX_ADDNODE_CONNECTIONS
Maximum number of addnode outgoing nodes.
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
static const size_t DEFAULT_MAXSENDBUFFER
static const int NUM_FDS_MESSAGE_CAPTURE
Number of file descriptors required for message capture.
static constexpr bool DEFAULT_FIXEDSEEDS
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable).
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL
Run the extra block-relay-only connection loop once every 5 minutes.
static const size_t DEFAULT_MAXRECEIVEBUFFER
std::string strSubVersion
Subversion as sent to the P2P network in version messages.
static const std::string DEFAULT_MAX_UPLOAD_TARGET
The default for -maxuploadtarget.
std::optional< CService > GetLocalAddrForPeer(CNode &node)
Returns a local address that we should advertise to this peer.
const std::string NET_MESSAGE_TYPE_OTHER
std::map< std::string, uint64_t > mapMsgTypeSize
static constexpr bool DEFAULT_FORCEDNSSEED
static constexpr bool DEFAULT_DNSSEED
CService GetLocalAddress(const CNode &peer)
GlobalMutex g_maplocalhost_mutex
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
static const bool DEFAULT_LISTEN
-listen default
static constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL
Interval for ASMap Health Check.
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY(g_maplocalhost_mutex)
static constexpr auto FEELER_INTERVAL
Run the feeler connection loop once every 2 minutes.
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT
-peertimeout default
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
std::function< void(const CAddress &addr, const std::string &msg_type, Span< const unsigned char > data, bool is_incoming)> CaptureMessage
Defaults to CaptureMessageToFile(), but can be overridden by unit tests.
static constexpr bool DEFAULT_V2_TRANSPORT
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
void Discover()
Look up IP addresses from all interfaces on the machine and add them to the list of local addresses t...
bool SeenLocal(const CService &addr)
vote for a local address
constexpr bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
constexpr bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
ServiceFlags
nServices flags
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
Cache responses to addr requests to minimize privacy leak.
std::vector< CAddress > m_addrs_response_cache
void AddSocketPermissionFlags(NetPermissionFlags &flags) const
ListenSocket(std::shared_ptr< Sock > sock_, NetPermissionFlags permissions_)
NetPermissionFlags m_permissions
std::shared_ptr< Sock > sock
std::vector< NetWhitebindPermissions > vWhiteBinds
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
std::vector< CService > onion_binds
std::vector< std::string > m_specified_outgoing
std::vector< std::string > m_added_nodes
std::vector< CService > vBinds
bool m_i2p_accept_incoming
std::vector< std::string > vSeedNodes
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
Struct for entries in m_reconnections.
CSerializedNetMsg(const CSerializedNetMsg &msg)=delete
CSerializedNetMsg Copy() const
CSerializedNetMsg & operator=(CSerializedNetMsg &&)=default
CSerializedNetMsg & operator=(const CSerializedNetMsg &)=delete
CSerializedNetMsg()=default
CSerializedNetMsg(CSerializedNetMsg &&)=default
std::vector< unsigned char > data
size_t GetMemoryUsage() const noexcept
Compute total memory usage of this object (own memory + any dynamic memory).
std::optional< uint256 > session_id
TransportProtocolType transport_type
#define AssertLockNotHeld(cs)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)