Bitcoin Core 31.99.0
P2P Digital Currency
Classes | Typedefs | Enumerations | Functions | Variables
net.h File Reference
#include <bip324.h>
#include <chainparams.h>
#include <common/bloom.h>
#include <compat/compat.h>
#include <consensus/amount.h>
#include <crypto/siphash.h>
#include <hash.h>
#include <i2p.h>
#include <kernel/messagestartchars.h>
#include <net_permissions.h>
#include <netaddress.h>
#include <netbase.h>
#include <netgroup.h>
#include <node/connection_types.h>
#include <node/protocol_version.h>
#include <policy/feerate.h>
#include <protocol.h>
#include <random.h>
#include <semaphore_grant.h>
#include <span.h>
#include <streams.h>
#include <sync.h>
#include <uint256.h>
#include <util/check.h>
#include <util/sock.h>
#include <util/threadinterrupt.h>
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <queue>
#include <string_view>
#include <thread>
#include <unordered_set>
#include <vector>
Include dependency graph for net.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  AddedNodeParams
 
struct  AddedNodeInfo
 
struct  CSerializedNetMsg
 
struct  LocalServiceInfo
 
class  CNodeStats
 
class  CNetMessage
 Transport protocol agnostic message container. More...
 
class  Transport
 The Transport converts one connection's sent messages to wire bytes, and received bytes back. More...
 
struct  Transport::Info
 
class  V1Transport
 
class  V2Transport
 
struct  CNodeOptions
 
class  CNode
 Information about a peer. More...
 
class  NetEventsInterface
 Interface for message handling. More...
 
class  CConnman
 
struct  CConnman::Options
 
class  CConnman::PrivateBroadcast
 Group of private broadcast related members. More...
 
struct  CConnman::ListenSocket
 
struct  CConnman::CachedAddrResponse
 Cache responses to addr requests to minimize privacy leak. More...
 
struct  CConnman::ReconnectionInfo
 Struct for entries in m_reconnections. More...
 
class  CConnman::NodesSnapshot
 RAII helper to atomically create a copy of m_nodes and add a reference to each of the nodes. More...
 

Typedefs

typedef int64_t NodeId
 
using mapMsgTypeSize = std::map< std::string, uint64_t >
 

Enumerations

enum  {
  LOCAL_NONE , LOCAL_IF , LOCAL_BIND , LOCAL_MAPPED ,
  LOCAL_MANUAL , LOCAL_MAX
}
 

Functions

void Discover ()
 Look up IP addresses from all interfaces on the machine and add them to the list of local addresses to self-advertise. More...
 
uint16_t GetListenPort ()
 
std::optional< CServiceGetLocalAddrForPeer (CNode &node)
 Returns a local address that we should advertise to this peer. More...
 
void ClearLocal ()
 
bool AddLocal (const CService &addr, int nScore=LOCAL_NONE, bool add_even_if_unreachable=false)
 
bool AddLocal (const CNetAddr &addr, int nScore=LOCAL_NONE, bool add_even_if_unreachable=false)
 
void RemoveLocal (const CService &addr)
 
bool SeenLocal (const CService &addr)
 vote for a local address More...
 
bool IsLocal (const CService &addr)
 check whether a given address is potentially local More...
 
CService GetLocalAddress (const CNode &peer)
 
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY (g_maplocalhost_mutex)
 

Variables

constexpr std::chrono::minutes TIMEOUT_INTERVAL {20}
 Time after which to disconnect, after waiting for a ping response (or inactivity). More...
 
constexpr auto FEELER_INTERVAL = 2min
 Run the feeler connection loop once every 2 minutes. More...
 
constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min
 Run the extra block-relay-only connection loop once every 5 minutes. More...
 
constexpr unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000
 Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable). More...
 
constexpr unsigned int MAX_SUBVERSION_LENGTH = 256
 Maximum length of the user agent string in version message. More...
 
constexpr int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 8
 Maximum number of automatic outgoing nodes over which we'll relay everything (blocks, tx, addrs, etc) More...
 
constexpr int MAX_ADDNODE_CONNECTIONS = 8
 Maximum number of addnode outgoing nodes. More...
 
constexpr int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2
 Maximum number of block-relay-only outgoing connections. More...
 
constexpr int MAX_FEELER_CONNECTIONS = 1
 Maximum number of feeler connections. More...
 
constexpr size_t MAX_PRIVATE_BROADCAST_CONNECTIONS {64}
 Maximum number of private broadcast connections. More...
 
constexpr bool DEFAULT_LISTEN = true
 -listen default More...
 
constexpr unsigned int DEFAULT_MAX_PEER_CONNECTIONS {200}
 The maximum number of peer connections to maintain. More...
 
constexpr int DEFAULT_FULL_RELAY_INBOUND_PCT {50}
 Default percentage of inbound connection slots that tx-relaying peers can use. More...
 
const std::string DEFAULT_MAX_UPLOAD_TARGET {"0M"}
 The default for -maxuploadtarget. More...
 
constexpr bool DEFAULT_BLOCKSONLY = false
 Default for blocks only. More...
 
constexpr int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60
 -peertimeout default More...
 
constexpr bool DEFAULT_PRIVATE_BROADCAST {false}
 Default for -privatebroadcast. More...
 
constexpr int NUM_FDS_MESSAGE_CAPTURE = 1
 Number of file descriptors required for message capture. More...
 
constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL {24}
 Interval for ASMap Health Check. More...
 
constexpr bool DEFAULT_FORCEDNSSEED {false}
 
constexpr bool DEFAULT_DNSSEED {true}
 
constexpr bool DEFAULT_FIXEDSEEDS {true}
 
constexpr size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
 
constexpr size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
 
constexpr bool DEFAULT_V2_TRANSPORT {true}
 
bool fDiscover
 
bool fListen
 
std::string strSubVersion
 Subversion as sent to the P2P network in version messages. More...
 
GlobalMutex g_maplocalhost_mutex
 
const std::string NET_MESSAGE_TYPE_OTHER
 
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. More...
 

Typedef Documentation

◆ mapMsgTypeSize

using mapMsgTypeSize = std::map< std::string, uint64_t>

Definition at line 191 of file net.h.

◆ NodeId

typedef int64_t NodeId

Definition at line 105 of file net.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LOCAL_NONE 
LOCAL_IF 
LOCAL_BIND 
LOCAL_MAPPED 
LOCAL_MANUAL 
LOCAL_MAX 

Definition at line 154 of file net.h.

Function Documentation

◆ AddLocal() [1/2]

bool AddLocal ( const CNetAddr addr,
int  nScore = LOCAL_NONE,
bool  add_even_if_unreachable = false 
)

Definition at line 308 of file net.cpp.

Here is the call graph for this function:

◆ AddLocal() [2/2]

bool AddLocal ( const CService addr,
int  nScore = LOCAL_NONE,
bool  add_even_if_unreachable = false 
)

Definition at line 278 of file net.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearLocal()

void ClearLocal ( )

Definition at line 271 of file net.cpp.

Here is the caller graph for this function:

◆ Discover()

void Discover ( )

Look up IP addresses from all interfaces on the machine and add them to the list of local addresses to self-advertise.

The loopback interface is skipped.

Definition at line 3440 of file net.cpp.

Here is the call graph for this function:

◆ GetListenPort()

uint16_t GetListenPort ( )

Definition at line 139 of file net.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLocalAddress()

CService GetLocalAddress ( const CNode peer)

Definition at line 221 of file net.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLocalAddrForPeer()

std::optional< CService > GetLocalAddrForPeer ( CNode node)

Returns a local address that we should advertise to this peer.

Definition at line 241 of file net.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GUARDED_BY()

std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY ( g_maplocalhost_mutex  )

◆ IsLocal()

bool IsLocal ( const CService addr)

check whether a given address is potentially local

Definition at line 335 of file net.cpp.

Here is the caller graph for this function:

◆ RemoveLocal()

void RemoveLocal ( const CService addr)

Definition at line 313 of file net.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SeenLocal()

bool SeenLocal ( const CService addr)

vote for a local address

Definition at line 324 of file net.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ASMAP_HEALTH_CHECK_INTERVAL

constexpr std::chrono::hours ASMAP_HEALTH_CHECK_INTERVAL {24}
inlineconstexpr

Interval for ASMap Health Check.

Definition at line 95 of file net.h.

◆ CaptureMessage

std::function<void(const CAddress& addr, const std::string& msg_type, std::span<const unsigned char> data, bool is_incoming)> CaptureMessage
extern

Defaults to CaptureMessageToFile(), but can be overridden by unit tests.

Definition at line 4333 of file net.cpp.

◆ DEFAULT_BLOCKSONLY

constexpr bool DEFAULT_BLOCKSONLY = false
inlineconstexpr

Default for blocks only.

Definition at line 87 of file net.h.

◆ DEFAULT_DNSSEED

constexpr bool DEFAULT_DNSSEED {true}
inlineconstexpr

Definition at line 98 of file net.h.

◆ DEFAULT_FIXEDSEEDS

constexpr bool DEFAULT_FIXEDSEEDS {true}
inlineconstexpr

Definition at line 99 of file net.h.

◆ DEFAULT_FORCEDNSSEED

constexpr bool DEFAULT_FORCEDNSSEED {false}
inlineconstexpr

Definition at line 97 of file net.h.

◆ DEFAULT_FULL_RELAY_INBOUND_PCT

constexpr int DEFAULT_FULL_RELAY_INBOUND_PCT {50}
inlineconstexpr

Default percentage of inbound connection slots that tx-relaying peers can use.

Definition at line 83 of file net.h.

◆ DEFAULT_LISTEN

constexpr bool DEFAULT_LISTEN = true
inlineconstexpr

-listen default

Definition at line 79 of file net.h.

◆ DEFAULT_MAX_PEER_CONNECTIONS

constexpr unsigned int DEFAULT_MAX_PEER_CONNECTIONS {200}
inlineconstexpr

The maximum number of peer connections to maintain.

Definition at line 81 of file net.h.

◆ DEFAULT_MAX_UPLOAD_TARGET

const std::string DEFAULT_MAX_UPLOAD_TARGET {"0M"}
inline

The default for -maxuploadtarget.

0 = Unlimited

Definition at line 85 of file net.h.

◆ DEFAULT_MAXRECEIVEBUFFER

constexpr size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
inlineconstexpr

Definition at line 100 of file net.h.

◆ DEFAULT_MAXSENDBUFFER

constexpr size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
inlineconstexpr

Definition at line 101 of file net.h.

◆ DEFAULT_PEER_CONNECT_TIMEOUT

constexpr int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60
inlineconstexpr

-peertimeout default

Definition at line 89 of file net.h.

◆ DEFAULT_PRIVATE_BROADCAST

constexpr bool DEFAULT_PRIVATE_BROADCAST {false}
inlineconstexpr

Default for -privatebroadcast.

Definition at line 91 of file net.h.

◆ DEFAULT_V2_TRANSPORT

constexpr bool DEFAULT_V2_TRANSPORT {true}
inlineconstexpr

Definition at line 103 of file net.h.

◆ EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL

constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min
inlineconstexpr

Run the extra block-relay-only connection loop once every 5 minutes.

Definition at line 63 of file net.h.

◆ fDiscover

bool fDiscover
extern

Definition at line 117 of file net.cpp.

◆ FEELER_INTERVAL

constexpr auto FEELER_INTERVAL = 2min
inlineconstexpr

Run the feeler connection loop once every 2 minutes.

Definition at line 61 of file net.h.

◆ fListen

bool fListen
extern

Definition at line 118 of file net.cpp.

◆ g_maplocalhost_mutex

GlobalMutex g_maplocalhost_mutex
extern

Definition at line 119 of file net.cpp.

◆ MAX_ADDNODE_CONNECTIONS

constexpr int MAX_ADDNODE_CONNECTIONS = 8
inlineconstexpr

Maximum number of addnode outgoing nodes.

Definition at line 71 of file net.h.

◆ MAX_BLOCK_RELAY_ONLY_CONNECTIONS

constexpr int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2
inlineconstexpr

Maximum number of block-relay-only outgoing connections.

Definition at line 73 of file net.h.

◆ MAX_FEELER_CONNECTIONS

constexpr int MAX_FEELER_CONNECTIONS = 1
inlineconstexpr

Maximum number of feeler connections.

Definition at line 75 of file net.h.

◆ MAX_OUTBOUND_FULL_RELAY_CONNECTIONS

constexpr int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 8
inlineconstexpr

Maximum number of automatic outgoing nodes over which we'll relay everything (blocks, tx, addrs, etc)

Definition at line 69 of file net.h.

◆ MAX_PRIVATE_BROADCAST_CONNECTIONS

constexpr size_t MAX_PRIVATE_BROADCAST_CONNECTIONS {64}
inlineconstexpr

Maximum number of private broadcast connections.

Definition at line 77 of file net.h.

◆ MAX_PROTOCOL_MESSAGE_LENGTH

constexpr unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000
inlineconstexpr

Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable).

Definition at line 65 of file net.h.

◆ MAX_SUBVERSION_LENGTH

constexpr unsigned int MAX_SUBVERSION_LENGTH = 256
inlineconstexpr

Maximum length of the user agent string in version message.

Definition at line 67 of file net.h.

◆ NET_MESSAGE_TYPE_OTHER

const std::string NET_MESSAGE_TYPE_OTHER
extern

Definition at line 109 of file net.cpp.

◆ NUM_FDS_MESSAGE_CAPTURE

constexpr int NUM_FDS_MESSAGE_CAPTURE = 1
inlineconstexpr

Number of file descriptors required for message capture.

Definition at line 93 of file net.h.

◆ strSubVersion

std::string strSubVersion
extern

Subversion as sent to the P2P network in version messages.

Definition at line 121 of file net.cpp.

◆ TIMEOUT_INTERVAL

constexpr std::chrono::minutes TIMEOUT_INTERVAL {20}
inlineconstexpr

Time after which to disconnect, after waiting for a ping response (or inactivity).

Definition at line 59 of file net.h.