Bitcoin
Classes | Macros | Enumerations | Functions | Variables
net.cpp File Reference
#include <net.h>
#include <banman.h>
#include <chainparams.h>
#include <clientversion.h>
#include <consensus/consensus.h>
#include <crypto/common.h>
#include <crypto/sha256.h>
#include <primitives/transaction.h>
#include <netbase.h>
#include <scheduler.h>
#include <ui_interface.h>
#include <util/strencodings.h>
#include <fcntl.h>
#include <unordered_map>
#include <math.h>

Classes

struct  NodeEvictionCandidate
 
class  CNetCleanup
 

Macros

#define FEELER_SLEEP_WINDOW   1
 
#define MSG_NOSIGNAL   0
 
#define MSG_DONTWAIT   0
 
#define X(name)   stats.name = name
 

Enumerations

enum  BindFlags { BF_NONE = 0, BF_EXPLICIT = (1U << 0), BF_REPORT_ERROR = (1U << 1), BF_WHITELIST = (1U << 2) }
 

Functions

std::map< CNetAddr, LocalServiceInfo > mapLocalHost GUARDED_BY (cs_mapLocalHost)
 
unsigned short GetListenPort ()
 
bool GetLocal (CService &addr, const CNetAddr *paddrPeer)
 
static std::vector< CAddressconvertSeed6 (const std::vector< SeedSpec6 > &vSeedsIn)
 Convert the pnSeed6 array into usable address objects. More...
 
CAddress GetLocalAddress (const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
 
static int GetnScore (const CService &addr)
 
bool IsPeerAddrLocalGood (CNode *pnode)
 
void AdvertiseLocal (CNode *pnode)
 
bool AddLocal (const CService &addr, int nScore)
 
bool AddLocal (const CNetAddr &addr, int nScore)
 
void RemoveLocal (const CService &addr)
 
void SetReachable (enum Network net, bool reachable)
 
bool IsReachable (enum Network net)
 
bool IsReachable (const CNetAddr &addr)
 
bool SeenLocal (const CService &addr)
 
bool IsLocal (const CService &addr)
 
static CAddress GetBindAddress (SOCKET sock)
 
static bool ReverseCompareNodeMinPingTime (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool ReverseCompareNodeTimeConnected (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool CompareNetGroupKeyed (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool CompareNodeBlockTime (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
static bool CompareNodeTXTime (const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
 
template<typename T , typename Comparator >
static void EraseLastKElements (std::vector< T > &elements, Comparator comparator, size_t k)
 Sort an array by the specified comparator, then erase the last K elements. More...
 
void StartMapPort ()
 
void InterruptMapPort ()
 
void StopMapPort ()
 
void Discover ()
 
int64_t PoissonNextSend (int64_t now, int average_interval_seconds)
 

Variables

static constexpr int DUMP_PEERS_INTERVAL = 15 * 60
 
static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50
 
const std::string NET_MESSAGE_COMMAND_OTHER = "*other*"
 
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL
 
static const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL
 
bool fDiscover = true
 
bool fListen = true
 
bool g_relay_txes = !DEFAULT_BLOCKSONLY
 
CCriticalSection cs_mapLocalHost
 
std::string strSubVersion
 
static CNetCleanup instance_of_cnetcleanup
 

Macro Definition Documentation

◆ FEELER_SLEEP_WINDOW

#define FEELER_SLEEP_WINDOW   1

◆ MSG_DONTWAIT

#define MSG_DONTWAIT   0

◆ MSG_NOSIGNAL

#define MSG_NOSIGNAL   0

◆ X

#define X (   name)    stats.name = name

Enumeration Type Documentation

◆ BindFlags

enum BindFlags

Used to pass flags to the Bind() function

Enumerator
BF_NONE 
BF_EXPLICIT 
BF_REPORT_ERROR 
BF_WHITELIST 

Function Documentation

◆ AddLocal() [1/2]

bool AddLocal ( const CService addr,
int  nScore 
)

◆ AddLocal() [2/2]

bool AddLocal ( const CNetAddr addr,
int  nScore 
)

◆ AdvertiseLocal()

void AdvertiseLocal ( CNode pnode)

◆ CompareNetGroupKeyed()

static bool CompareNetGroupKeyed ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

◆ CompareNodeBlockTime()

static bool CompareNodeBlockTime ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

◆ CompareNodeTXTime()

static bool CompareNodeTXTime ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

◆ convertSeed6()

static std::vector<CAddress> convertSeed6 ( const std::vector< SeedSpec6 > &  vSeedsIn)
static

Convert the pnSeed6 array into usable address objects.

◆ Discover()

void Discover ( )

◆ EraseLastKElements()

template<typename T , typename Comparator >
static void EraseLastKElements ( std::vector< T > &  elements,
Comparator  comparator,
size_t  k 
)
static

Sort an array by the specified comparator, then erase the last K elements.

◆ GetBindAddress()

static CAddress GetBindAddress ( SOCKET  sock)
static

Get the bind address for a socket as CAddress

◆ GetListenPort()

unsigned short GetListenPort ( )

◆ GetLocal()

bool GetLocal ( CService addr,
const CNetAddr paddrPeer 
)

◆ GetLocalAddress()

CAddress GetLocalAddress ( const CNetAddr paddrPeer,
ServiceFlags  nLocalServices 
)

◆ GetnScore()

static int GetnScore ( const CService addr)
static

◆ GUARDED_BY()

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

◆ InterruptMapPort()

void InterruptMapPort ( )

◆ IsLocal()

bool IsLocal ( const CService addr)

check whether a given address is potentially local

◆ IsPeerAddrLocalGood()

bool IsPeerAddrLocalGood ( CNode pnode)

◆ IsReachable() [1/2]

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

◆ IsReachable() [2/2]

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

◆ PoissonNextSend()

int64_t PoissonNextSend ( int64_t  now,
int  average_interval_seconds 
)

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

◆ RemoveLocal()

void RemoveLocal ( const CService addr)

◆ ReverseCompareNodeMinPingTime()

static bool ReverseCompareNodeMinPingTime ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

◆ ReverseCompareNodeTimeConnected()

static bool ReverseCompareNodeTimeConnected ( const NodeEvictionCandidate a,
const NodeEvictionCandidate b 
)
static

◆ SeenLocal()

bool SeenLocal ( const CService addr)

vote for a local address

◆ 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

◆ StartMapPort()

void StartMapPort ( )

◆ StopMapPort()

void StopMapPort ( )

Variable Documentation

◆ cs_mapLocalHost

CCriticalSection cs_mapLocalHost

◆ DUMP_PEERS_INTERVAL

constexpr int DUMP_PEERS_INTERVAL = 15 * 60
static

◆ fDiscover

bool fDiscover = true

◆ fListen

bool fListen = true

◆ g_relay_txes

bool g_relay_txes = !DEFAULT_BLOCKSONLY

◆ instance_of_cnetcleanup

CNetCleanup instance_of_cnetcleanup
static

◆ NET_MESSAGE_COMMAND_OTHER

const std::string NET_MESSAGE_COMMAND_OTHER = "*other*"

◆ RANDOMIZER_ID_LOCALHOSTNONCE

const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL
static

◆ RANDOMIZER_ID_NETGROUP

const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL
static

◆ SELECT_TIMEOUT_MILLISECONDS

const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50
static

◆ strSubVersion

std::string strSubVersion

Subversion as sent to the P2P network in version messages