Bitcoin ABC  0.22.12
P2P Digital Currency
Classes | Typedefs | Enumerations | Functions | Variables
net.h File Reference
#include <addrdb.h>
#include <addrman.h>
#include <amount.h>
#include <avalanche/delegation.h>
#include <bloom.h>
#include <chainparams.h>
#include <compat.h>
#include <crypto/siphash.h>
#include <hash.h>
#include <limitedmap.h>
#include <net_permissions.h>
#include <netaddress.h>
#include <protocol.h>
#include <random.h>
#include <streams.h>
#include <sync.h>
#include <threadinterrupt.h>
#include <uint256.h>
#include <validation.h>
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <deque>
#include <memory>
#include <thread>
#include <arpa/inet.h>
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
 
class  CConnman
 
struct  CConnman::Options
 
struct  CConnman::ListenSocket
 
class  NetEventsInterface
 Interface for message handling. More...
 
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
 
class  CNode
 Information about a peer. More...
 
struct  CNode::TxRelay
 
struct  CNode::AvalancheState
 

Typedefs

typedef int64_t NodeId
 
typedef std::map< std::string, uint64_t > mapMsgCmdSize
 

Enumerations

enum  ConnectionType {
  ConnectionType::INBOUND, ConnectionType::OUTBOUND, ConnectionType::MANUAL, ConnectionType::FEELER,
  ConnectionType::BLOCK_RELAY, ConnectionType::ADDR_FETCH
}
 Different types of connections to a peer. More...
 
enum  {
  LOCAL_NONE, LOCAL_IF, LOCAL_BIND, LOCAL_UPNP,
  LOCAL_MANUAL, LOCAL_MAX
}
 

Functions

void Discover ()
 
void StartMapPort ()
 
void InterruptMapPort ()
 
void StopMapPort ()
 
unsigned short GetListenPort ()
 
bool IsPeerAddrLocalGood (CNode *pnode)
 
void AdvertiseLocal (CNode *pnode)
 
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)
 
CAddress GetLocalAddress (const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
 
std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY (cs_mapLocalHost)
 
int64_t PoissonNextSend (int64_t now, int average_interval_seconds)
 Return a timestamp in the future (in microseconds) for exponentially distributed events. More...
 
std::chrono::microseconds PoissonNextSend (std::chrono::microseconds now, std::chrono::seconds average_interval)
 Wrapper to return mockable type. More...
 
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)
 

Variables

static const bool DEFAULT_WHITELISTRELAY = true
 Default for -whitelistrelay. More...
 
static const bool DEFAULT_WHITELISTFORCERELAY = false
 Default for -whitelistforcerelay. More...
 
static const int TIMEOUT_INTERVAL = 20 * 60
 Time after which to disconnect, after waiting for a ping response (or inactivity). More...
 
static const int FEELER_INTERVAL = 120
 Run the feeler connection loop once every 2 minutes or 120 seconds. More...
 
static const unsigned int MAX_ADDR_TO_SEND = 1000
 The maximum number of new addresses to accumulate before announcing. 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 = 8
 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_BLOCKS_ONLY_CONNECTIONS = 2
 Maximum number of block-relay-only outgoing connections. More...
 
static const bool DEFAULT_LISTEN = true
 -listen default More...
 
static const bool DEFAULT_UPNP = false
 -upnp default More...
 
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 4096
 The maximum number of peer connections to maintain. More...
 
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0
 The default for -maxuploadtarget. More...
 
static const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24
 The default timeframe 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 bool DEFAULT_FORCEDNSSEED = false
 
static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
 
static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
 
static constexpr NodeId NO_NODE = -1
 Special NodeId that represent no node. More...
 
bool fDiscover
 
bool fListen
 
bool g_relay_txes
 
RecursiveMutex cs_mapLocalHost
 
const std::string NET_MESSAGE_COMMAND_OTHER
 

Typedef Documentation

◆ mapMsgCmdSize

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

Definition at line 638 of file net.h.

◆ NodeId

typedef int64_t NodeId

Definition at line 99 of file net.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LOCAL_NONE 
LOCAL_IF 
LOCAL_BIND 
LOCAL_UPNP 
LOCAL_MANUAL 
LOCAL_MAX 

Definition at line 586 of file net.h.

◆ ConnectionType

enum ConnectionType
strong

Different types of connections to a peer.

This enum encapsulates the information we have available at the time of opening or accepting the connection. Aside from INBOUND, all types are initiated by us.

Enumerator
INBOUND 

Peer initiated connections.

OUTBOUND 

Full relay connections (blocks, addrs, txns) made automatically.

Addresses selected from AddrMan.

MANUAL 

Connections to addresses added via addnode or the connect command line argument.

FEELER 

Short lived connections used to test address validity.

BLOCK_RELAY 

Only relay blocks to these automatic outbound connections.

Addresses selected from AddrMan.

ADDR_FETCH 

Short lived connections used to solicit addrs when starting the node without a populated AddrMan.

Definition at line 133 of file net.h.

Function Documentation

◆ AddLocal() [1/2]

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

Definition at line 229 of file net.cpp.

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

◆ AddLocal() [2/2]

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

Definition at line 257 of file net.cpp.

Here is the call graph for this function:

◆ AdvertiseLocal()

void AdvertiseLocal ( CNode pnode)

Definition at line 200 of file net.cpp.

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

◆ Discover()

void Discover ( )

Definition at line 2437 of file net.cpp.

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

◆ GetListenPort()

unsigned short GetListenPort ( )

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

Here is the caller graph for this function:

◆ GetLocalAddress()

CAddress GetLocalAddress ( const CNetAddr paddrPeer,
ServiceFlags  nLocalServices 
)

Definition at line 173 of file net.cpp.

Here is the call graph for this function:
Here is the caller 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 3150 of file net.cpp.

Here is the caller graph for this function:

◆ GUARDED_BY()

std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY ( cs_mapLocalHost  )
Here is the caller graph for this function:

◆ InterruptMapPort()

void InterruptMapPort ( )

Definition at line 1735 of file net.cpp.

Here is the caller graph for this function:

◆ IsLocal()

bool IsLocal ( const CService addr)

check whether a given address is potentially local

Definition at line 295 of file net.cpp.

Here is the caller graph for this function:

◆ IsPeerAddrLocalGood()

bool IsPeerAddrLocalGood ( CNode pnode)

Definition at line 193 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 ( enum Network  net)
Returns
true if the network is reachable, false otherwise

Definition at line 275 of file net.cpp.

Here is the caller graph for this function:

◆ IsReachable() [2/2]

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

Definition at line 280 of file net.cpp.

Here is the call graph for this function:

◆ PoissonNextSend() [1/2]

int64_t PoissonNextSend ( int64_t  now,
int  average_interval_seconds 
)

Return a timestamp in the future (in microseconds) for exponentially distributed events.

Definition at line 3117 of file net.cpp.

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

◆ PoissonNextSend() [2/2]

std::chrono::microseconds PoissonNextSend ( std::chrono::microseconds  now,
std::chrono::seconds  average_interval 
)
inline

Wrapper to return mockable type.

Definition at line 1161 of file net.h.

Here is the call graph for this function:

◆ RemoveLocal()

void RemoveLocal ( const CService addr)

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

◆ StartMapPort()

void StartMapPort ( )

Definition at line 1732 of file net.cpp.

Here is the caller graph for this function:

◆ StopMapPort()

void StopMapPort ( )

Definition at line 1738 of file net.cpp.

Here is the caller graph for this function:

◆ userAgent()

std::string userAgent ( const Config config)

Definition at line 3164 of file net.cpp.

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

Variable Documentation

◆ cs_mapLocalHost

RecursiveMutex cs_mapLocalHost

Definition at line 112 of file net.cpp.

◆ DEFAULT_BLOCKSONLY

const bool DEFAULT_BLOCKSONLY = false
static

Default for blocks only.

Definition at line 91 of file net.h.

◆ DEFAULT_FORCEDNSSEED

const bool DEFAULT_FORCEDNSSEED = false
static

Definition at line 95 of file net.h.

◆ DEFAULT_LISTEN

const bool DEFAULT_LISTEN = true
static

-listen default

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

◆ DEFAULT_MAX_UPLOAD_TARGET

const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0
static

The default for -maxuploadtarget.

0 = Unlimited

Definition at line 87 of file net.h.

◆ DEFAULT_MAXRECEIVEBUFFER

const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
static

Definition at line 96 of file net.h.

◆ DEFAULT_MAXSENDBUFFER

const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
static

Definition at line 97 of file net.h.

◆ DEFAULT_PEER_CONNECT_TIMEOUT

const int64_t DEFAULT_PEER_CONNECT_TIMEOUT = 60
static

-peertimeout default

Definition at line 93 of file net.h.

◆ DEFAULT_UPNP

const bool DEFAULT_UPNP = false
static

-upnp default

Definition at line 78 of file net.h.

◆ DEFAULT_WHITELISTFORCERELAY

const bool DEFAULT_WHITELISTFORCERELAY = false
static

Default for -whitelistforcerelay.

Definition at line 50 of file net.h.

◆ DEFAULT_WHITELISTRELAY

const bool DEFAULT_WHITELISTRELAY = true
static

Default for -whitelistrelay.

Definition at line 48 of file net.h.

◆ fDiscover

bool fDiscover

Definition at line 109 of file net.cpp.

◆ FEELER_INTERVAL

const int FEELER_INTERVAL = 120
static

Run the feeler connection loop once every 2 minutes or 120 seconds.

Definition at line 58 of file net.h.

◆ fListen

bool fListen

Definition at line 110 of file net.cpp.

◆ g_relay_txes

bool g_relay_txes

Definition at line 111 of file net.cpp.

◆ MAX_ADDNODE_CONNECTIONS

const int MAX_ADDNODE_CONNECTIONS = 8
static

Maximum number of addnode outgoing nodes.

Definition at line 69 of file net.h.

◆ MAX_ADDR_TO_SEND

const unsigned int MAX_ADDR_TO_SEND = 1000
static

The maximum number of new addresses to accumulate before announcing.

Definition at line 60 of file net.h.

◆ MAX_BLOCKS_ONLY_CONNECTIONS

const int MAX_BLOCKS_ONLY_CONNECTIONS = 2
static

Maximum number of block-relay-only outgoing connections.

Definition at line 71 of file net.h.

◆ MAX_OUTBOUND_FULL_RELAY_CONNECTIONS

const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 8
static

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

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

◆ MAX_UPLOAD_TIMEFRAME

const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24
static

The default timeframe for -maxuploadtarget.

1 day.

Definition at line 89 of file net.h.

◆ NET_MESSAGE_COMMAND_OTHER

const std::string NET_MESSAGE_COMMAND_OTHER

Definition at line 98 of file net.cpp.

◆ NO_NODE

constexpr NodeId NO_NODE = -1
static

Special NodeId that represent no node.

Definition at line 104 of file net.h.

◆ TIMEOUT_INTERVAL

const int TIMEOUT_INTERVAL = 20 * 60
static

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

Definition at line 56 of file net.h.