Bitcoin ABC 0.31.8
P2P Digital Currency
Classes | Typedefs | Enumerations | Functions | Variables
net.h File Reference
#include <avalanche/proofid.h>
#include <avalanche/proofradixtreeadapter.h>
#include <chainparams.h>
#include <common/bloom.h>
#include <compat.h>
#include <consensus/amount.h>
#include <crypto/siphash.h>
#include <hash.h>
#include <i2p.h>
#include <kernel/cs_main.h>
#include <logging.h>
#include <net_permissions.h>
#include <netaddress.h>
#include <netbase.h>
#include <node/connection_types.h>
#include <node/eviction.h>
#include <nodeid.h>
#include <protocol.h>
#include <pubkey.h>
#include <radix.h>
#include <random.h>
#include <span.h>
#include <streams.h>
#include <sync.h>
#include <threadinterrupt.h>
#include <uint256.h>
#include <util/check.h>
#include <util/sock.h>
#include <util/time.h>
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <thread>
#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  AddedNodeInfo
 
struct  CSerializedNetMsg
 
struct  LocalServiceInfo
 
struct  CNodeStats
 POD that contains various stats about a node. More...
 
class  CNetMessage
 Transport protocol agnostic message container. More...
 
class  TransportDeserializer
 The TransportDeserializer takes care of holding and deserializing the network receive buffer. More...
 
class  V1TransportDeserializer
 
class  TransportSerializer
 The TransportSerializer prepares messages for the network transport. More...
 
class  V1TransportSerializer
 
struct  CNodeOptions
 
class  CNode
 Information about a peer. More...
 
class  NetEventsInterface
 Interface for message handling. More...
 
class  CConnman
 
struct  CConnman::Options
 
struct  CConnman::ListenSocket
 
struct  CConnman::CachedAddrResponse
 Cache responses to addr requests to minimize privacy leak. 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 std::map< std::string, uint64_t > mapMsgTypeSize
 

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 ()
 
bool IsPeerAddrLocalGood (CNode *pnode)
 
std::optional< CServiceGetLocalAddrForPeer (CNode &node)
 Returns a local address that we should advertise to this peer. More...
 
void SetReachable (enum Network net, bool reachable)
 Mark a network as reachable or unreachable (no automatic connects to it) More...
 
bool IsReachable (enum Network net)
 
bool IsReachable (const CNetAddr &addr)
 
bool AddLocal (const CService &addr, int nScore=LOCAL_NONE)
 
bool AddLocal (const CNetAddr &addr, int nScore=LOCAL_NONE)
 
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...
 
bool GetLocal (CService &addr, const CNetAddr *paddrPeer=nullptr)
 
CService GetLocalAddress (const CNetAddr &addrPeer)
 
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY (g_maplocalhost_mutex)
 
std::string getSubVersionEB (uint64_t MaxBlockSize)
 This function convert MaxBlockSize from byte to MB with a decimal precision one digit rounded down E.g. More...
 
std::string userAgent (const Config &config)
 
void CaptureMessageToFile (const CAddress &addr, const std::string &msg_type, Span< const uint8_t > data, bool is_incoming)
 Dump binary message to file, with timestamp. More...
 

Variables

static constexpr std::chrono::minutes TIMEOUT_INTERVAL {20}
 Time after which to disconnect, after waiting for a ping response (or inactivity). More...
 
static constexpr auto FEELER_INTERVAL = 2min
 Run the feeler connection loop once every 2 minutes. More...
 
static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min
 Run the extra block-relay-only connection loop once every 5 minutes. More...
 
static const unsigned int MAX_SUBVERSION_LENGTH = 256
 Maximum length of the user agent string in version message. More...
 
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 16
 Maximum number of automatic outgoing nodes over which we'll relay everything (blocks, tx, addrs, etc) More...
 
static const int MAX_ADDNODE_CONNECTIONS = 8
 Maximum number of addnode outgoing nodes. More...
 
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2
 Maximum number of block-relay-only outgoing connections. More...
 
static const int DEFAULT_MAX_AVALANCHE_OUTBOUND_CONNECTIONS = 300
 Maximum number of avalanche enabled outgoing connections by default. More...
 
static const int MAX_FEELER_CONNECTIONS = 1
 Maximum number of feeler connections. More...
 
static const bool DEFAULT_LISTEN = true
 -listen default More...
 
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 4096
 The maximum number of peer connections to maintain. More...
 
static constexpr uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0
 The default for -maxuploadtarget. More...
 
static const bool DEFAULT_BLOCKSONLY = false
 Default for blocks only. More...
 
static const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60
 -peertimeout default More...
 
static const int NUM_FDS_MESSAGE_CAPTURE = 1
 Number of file descriptors required for message capture. More...
 
static const bool DEFAULT_FORCEDNSSEED = false
 
static const bool DEFAULT_DNSSEED = true
 
static const bool DEFAULT_FIXEDSEEDS = true
 
static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
 
static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
 
const std::vector< std::string > CONNECTION_TYPE_DOC
 
bool fDiscover
 
bool fListen
 
GlobalMutex g_maplocalhost_mutex
 
const std::string NET_MESSAGE_TYPE_OTHER
 
std::function< void(const CAddress &addr, const std::string &msg_type, Span< const uint8_t > data, bool is_incoming)> CaptureMessage
 Defaults to CaptureMessageToFile(), but can be overridden by unit tests. More...
 

Typedef Documentation

◆ mapMsgTypeSize

typedef std::map< std::string, uint64_t> mapMsgTypeSize

Definition at line 206 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 155 of file net.h.

Function Documentation

◆ AddLocal() [1/2]

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

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 
)

Definition at line 279 of file net.cpp.

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

◆ CaptureMessageToFile()

void CaptureMessageToFile ( const CAddress addr,
const std::string &  msg_type,
Span< const uint8_t >  data,
bool  is_incoming 
)

Dump binary message to file, with timestamp.

Definition at line 3156 of file net.cpp.

Here is the call 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 and only the first address from each interface is used.

Definition at line 2297 of file net.cpp.

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

◆ GetListenPort()

uint16_t GetListenPort ( )

Definition at line 138 of file net.cpp.

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

◆ GetLocal()

bool GetLocal ( CService addr,
const CNetAddr paddrPeer = nullptr 
)

Definition at line 174 of file net.cpp.

Here is the caller graph for this function:

◆ GetLocalAddress()

CService GetLocalAddress ( const CNetAddr addrPeer)

Definition at line 222 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 244 of file net.cpp.

Here is the call graph for this function:

◆ getSubVersionEB()

std::string getSubVersionEB ( uint64_t  MaxBlockSize)

This function convert MaxBlockSize from byte to MB with a decimal precision one digit rounded down E.g.

1660000 -> 1.6 2010000 -> 2.0 1000000 -> 1.0 230000 -> 0.2 50000 -> 0.0

NB behavior for EB<1MB not standardized yet still the function applies the same algo used for EB greater or equal to 1MB

Definition at line 3122 of file net.cpp.

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 347 of file net.cpp.

Here is the caller graph for this function:

◆ IsPeerAddrLocalGood()

bool IsPeerAddrLocalGood ( CNode pnode)

Definition at line 238 of file net.cpp.

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

◆ IsReachable() [1/2]

bool IsReachable ( const CNetAddr addr)
Returns
true if the address is in a reachable network, false otherwise

Definition at line 331 of file net.cpp.

Here is the call graph for this function:

◆ IsReachable() [2/2]

bool IsReachable ( enum Network  net)
Returns
true if the network is reachable, false otherwise

Definition at line 326 of file net.cpp.

Here is the caller graph for this function:

◆ RemoveLocal()

void RemoveLocal ( const CService addr)

Definition at line 312 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 336 of file net.cpp.

◆ SetReachable()

void SetReachable ( enum Network  net,
bool  reachable 
)

Mark a network as reachable or unreachable (no automatic connects to it)

Note
Networks are reachable by default

Definition at line 318 of file net.cpp.

Here is the caller graph for this function:

◆ userAgent()

std::string userAgent ( const Config config)

Definition at line 3136 of file net.cpp.

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

Variable Documentation

◆ CaptureMessage

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

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

Definition at line 3188 of file net.cpp.

◆ CONNECTION_TYPE_DOC

const std::vector<std::string> CONNECTION_TYPE_DOC
Initial value:
{
"outbound-full-relay (default automatic connections)",
"block-relay-only (does not relay transactions or addresses)",
"inbound (initiated by the peer)",
"manual (added via addnode RPC or -addnode/-connect configuration options)",
"addr-fetch (short-lived automatic connection for soliciting addresses)",
"feeler (short-lived automatic connection for testing addresses)"}

Definition at line 137 of file net.h.

◆ DEFAULT_BLOCKSONLY

const bool DEFAULT_BLOCKSONLY = false
static

Default for blocks only.

Definition at line 96 of file net.h.

◆ DEFAULT_DNSSEED

const bool DEFAULT_DNSSEED = true
static

Definition at line 103 of file net.h.

◆ DEFAULT_FIXEDSEEDS

const bool DEFAULT_FIXEDSEEDS = true
static

Definition at line 104 of file net.h.

◆ DEFAULT_FORCEDNSSEED

const bool DEFAULT_FORCEDNSSEED = false
static

Definition at line 102 of file net.h.

◆ DEFAULT_LISTEN

const bool DEFAULT_LISTEN = true
static

-listen default

Definition at line 86 of file net.h.

◆ DEFAULT_MAX_AVALANCHE_OUTBOUND_CONNECTIONS

const int DEFAULT_MAX_AVALANCHE_OUTBOUND_CONNECTIONS = 300
static

Maximum number of avalanche enabled outgoing connections by default.

Can be overridden with the -maxavalancheoutbound option.

Definition at line 82 of file net.h.

◆ DEFAULT_MAX_PEER_CONNECTIONS

const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 4096
static

The maximum number of peer connections to maintain.

This quantity might not be reachable on some systems, especially on platforms that do not provide a working poll() interface.

Definition at line 92 of file net.h.

◆ DEFAULT_MAX_UPLOAD_TARGET

constexpr uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0
staticconstexpr

The default for -maxuploadtarget.

0 = Unlimited

Definition at line 94 of file net.h.

◆ DEFAULT_MAXRECEIVEBUFFER

const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
static

Definition at line 105 of file net.h.

◆ DEFAULT_MAXSENDBUFFER

const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
static

Definition at line 106 of file net.h.

◆ DEFAULT_PEER_CONNECT_TIMEOUT

const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60
static

-peertimeout default

Definition at line 98 of file net.h.

◆ EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL

constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min
staticconstexpr

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

Definition at line 66 of file net.h.

◆ fDiscover

bool fDiscover
extern

Definition at line 126 of file net.cpp.

◆ FEELER_INTERVAL

constexpr auto FEELER_INTERVAL = 2min
staticconstexpr

Run the feeler connection loop once every 2 minutes.

Definition at line 64 of file net.h.

◆ fListen

bool fListen
extern

Definition at line 127 of file net.cpp.

◆ g_maplocalhost_mutex

GlobalMutex g_maplocalhost_mutex
extern

Definition at line 128 of file net.cpp.

◆ MAX_ADDNODE_CONNECTIONS

const int MAX_ADDNODE_CONNECTIONS = 8
static

Maximum number of addnode outgoing nodes.

Definition at line 75 of file net.h.

◆ MAX_BLOCK_RELAY_ONLY_CONNECTIONS

const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2
static

Maximum number of block-relay-only outgoing connections.

Definition at line 77 of file net.h.

◆ MAX_FEELER_CONNECTIONS

const int MAX_FEELER_CONNECTIONS = 1
static

Maximum number of feeler connections.

Definition at line 84 of file net.h.

◆ MAX_OUTBOUND_FULL_RELAY_CONNECTIONS

const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 16
static

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

Definition at line 73 of file net.h.

◆ MAX_SUBVERSION_LENGTH

const unsigned int MAX_SUBVERSION_LENGTH = 256
static

Maximum length of the user agent string in version message.

Definition at line 68 of file net.h.

◆ NET_MESSAGE_TYPE_OTHER

const std::string NET_MESSAGE_TYPE_OTHER
extern

Definition at line 113 of file net.cpp.

◆ NUM_FDS_MESSAGE_CAPTURE

const int NUM_FDS_MESSAGE_CAPTURE = 1
static

Number of file descriptors required for message capture.

Definition at line 100 of file net.h.

◆ TIMEOUT_INTERVAL

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

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

Definition at line 62 of file net.h.