Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

net.cpp File Reference
#include <net.h>
#include <netmessagemaker.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 <utilstrencodings.h>
#include <validation.h>
#include <masternode/masternode-meta.h>
#include <masternode/masternode-sync.h>
#include <privatesend/privatesend.h>
#include <evo/deterministicmns.h>
#include <memory>
#include <fcntl.h>
#include <unordered_map>
#include <math.h>
+ Include dependency graph for net.cpp:

Go to the source code of this file.

Classes

struct  NodeEvictionCandidate
 
class  CNetCleanup
 

Macros

#define DUMP_ADDRESSES_INTERVAL   900
 
#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) }
 Used to pass flags to the Bind() function. More...
 

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)
 
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)
 
bool RemoveLocal (const CService &addr)
 
void SetLimited (enum Network net, bool fLimited)
 Make a particular network entirely off-limits (no automatic connects to it) More...
 
bool IsLimited (enum Network net)
 
bool IsLimited (const CNetAddr &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 IsReachable (enum Network net)
 check whether a given network is one we can probably connect to More...
 
bool IsReachable (const CNetAddr &addr)
 check whether a given address is in a network we can probably connect to More...
 
static CAddress GetBindAddress (SOCKET sock)
 Get the bind address for a socket as CAddress. More...
 
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 MapPort (bool)
 
void Discover (boost::thread_group &threadGroup)
 
int64_t PoissonNextSend (int64_t now, int average_interval_seconds)
 Return a timestamp in the future (in microseconds) for exponentially distributed events. More...
 

Variables

static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50
 
static 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 fRelayTxes = true
 
CCriticalSection cs_mapLocalHost
 
std::string strSubVersion
 Subversion as sent to the P2P network in version messages. More...
 
class CNetCleanup instance_of_cnetcleanup
 

Macro Definition Documentation

◆ DUMP_ADDRESSES_INTERVAL

#define DUMP_ADDRESSES_INTERVAL   900

Definition at line 58 of file net.cpp.

Referenced by CConnman::Start().

◆ FEELER_SLEEP_WINDOW

#define FEELER_SLEEP_WINDOW   1

Definition at line 61 of file net.cpp.

Referenced by CConnman::ThreadOpenConnections().

◆ MSG_DONTWAIT

#define MSG_DONTWAIT   0

Definition at line 69 of file net.cpp.

Referenced by CConnman::SocketRecvData(), and CConnman::SocketSendData().

◆ MSG_NOSIGNAL

#define MSG_NOSIGNAL   0

Definition at line 64 of file net.cpp.

Referenced by CConnman::SocketSendData().

◆ X

#define X (   name)    stats.name = name

Definition at line 756 of file net.cpp.

Referenced by CNode::copyStats(), and memusage::DynamicUsage().

Enumeration Type Documentation

◆ BindFlags

enum BindFlags

Used to pass flags to the Bind() function.

Enumerator
BF_NONE 
BF_EXPLICIT 
BF_REPORT_ERROR 
BF_WHITELIST 

Definition at line 84 of file net.cpp.

Function Documentation

◆ AddLocal() [1/2]

◆ AddLocal() [2/2]

bool AddLocal ( const CNetAddr addr,
int  nScore 
)

Definition at line 262 of file net.cpp.

References AddLocal(), and GetListenPort().

◆ AdvertiseLocal()

◆ CompareNetGroupKeyed()

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

Definition at line 1034 of file net.cpp.

References NodeEvictionCandidate::nKeyedNetGroup.

Referenced by CConnman::AttemptToEvictConnection().

◆ CompareNodeBlockTime()

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

◆ CompareNodeTXTime()

◆ convertSeed6()

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

Convert the pnSeed6 array into usable address objects.

Definition at line 157 of file net.cpp.

References GetDesirableServiceFlags(), GetRand(), GetTime(), memcpy(), NODE_NONE, and CAddress::nTime.

Referenced by CConnman::ThreadOpenConnections().

◆ Discover()

void Discover ( boost::thread_group &  threadGroup)

Definition at line 2835 of file net.cpp.

References AddLocal(), fDiscover, LOCAL_IF, LogPrintf, LookupHost(), SOCKET_ERROR, and CNetAddr::ToString().

Referenced by AppInitMain().

◆ 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.

Definition at line 1058 of file net.cpp.

Referenced by CConnman::AttemptToEvictConnection().

◆ GetBindAddress()

static CAddress GetBindAddress ( SOCKET  sock)
static

Get the bind address for a socket as CAddress.

Definition at line 397 of file net.cpp.

References INVALID_SOCKET, LogPrint, BCLog::NET, and CService::SetSockAddr().

Referenced by CConnman::AcceptConnection(), and CConnman::ConnectNode().

◆ GetListenPort()

◆ GetLocal()

bool GetLocal ( CService addr,
const CNetAddr paddrPeer 
)

Definition at line 132 of file net.cpp.

References cs_mapLocalHost, fListen, and LOCK.

Referenced by CActiveMasternodeManager::GetLocalAddress(), and GetLocalAddress().

◆ GetLocalAddress()

CAddress GetLocalAddress ( const CNetAddr paddrPeer,
ServiceFlags  nLocalServices 
)

Definition at line 180 of file net.cpp.

References GetAdjustedTime(), GetListenPort(), GetLocal(), and CAddress::nTime.

Referenced by AdvertiseLocal(), and ProcessMessage().

◆ GetnScore()

int GetnScore ( const CService addr)

Definition at line 192 of file net.cpp.

References cs_mapLocalHost, LOCAL_NONE, and LOCK.

Referenced by AdvertiseLocal().

◆ GUARDED_BY()

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

◆ IsLimited() [1/2]

bool IsLimited ( enum Network  net)

◆ IsLimited() [2/2]

bool IsLimited ( const CNetAddr addr)

Definition at line 290 of file net.cpp.

References CNetAddr::GetNetwork(), and IsLimited().

◆ IsLocal()

bool IsLocal ( const CService addr)

check whether a given address is potentially local

Definition at line 309 of file net.cpp.

References cs_mapLocalHost, and LOCK.

Referenced by CConnman::ConnectNode(), CConnman::OpenNetworkConnection(), and CConnman::ThreadOpenConnections().

◆ IsPeerAddrLocalGood()

bool IsPeerAddrLocalGood ( CNode pnode)

◆ IsReachable() [1/2]

bool IsReachable ( enum Network  net)

check whether a given network is one we can probably connect to

Definition at line 316 of file net.cpp.

References cs_mapLocalHost, and LOCK.

Referenced by GetNetworksInfo(), IsReachable(), CActiveMasternodeManager::IsValidNetAddr(), and ProcessMessage().

◆ IsReachable() [2/2]

bool IsReachable ( const CNetAddr addr)

check whether a given address is in a network we can probably connect to

Definition at line 323 of file net.cpp.

References CNetAddr::GetNetwork(), and IsReachable().

◆ MapPort()

void MapPort ( bool  )

Definition at line 2065 of file net.cpp.

Referenced by AppInitMain(), PrepareShutdown(), and OptionsModel::setData().

◆ PoissonNextSend()

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

References GetRand().

Referenced by PoissonNextSend(), CConnman::PoissonNextSendInbound(), PeerLogicValidation::SendMessages(), and CConnman::ThreadOpenConnections().

◆ RemoveLocal()

bool RemoveLocal ( const CService addr)

◆ ReverseCompareNodeMinPingTime()

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

Definition at line 1024 of file net.cpp.

References NodeEvictionCandidate::nMinPingUsecTime.

Referenced by CConnman::AttemptToEvictConnection().

◆ ReverseCompareNodeTimeConnected()

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

Definition at line 1029 of file net.cpp.

References NodeEvictionCandidate::nTimeConnected.

Referenced by CConnman::AttemptToEvictConnection().

◆ SeenLocal()

bool SeenLocal ( const CService addr)

vote for a local address

Definition at line 296 of file net.cpp.

References cs_mapLocalHost, and LOCK.

Referenced by ProcessMessage().

◆ SetLimited()

void SetLimited ( enum Network  net,
bool  fLimited 
)

Make a particular network entirely off-limits (no automatic connects to it)

Definition at line 276 of file net.cpp.

References cs_mapLocalHost, LOCK, NET_INTERNAL, and NET_UNROUTABLE.

Referenced by AppInitMain(), and TorController::auth_cb().

Variable Documentation

◆ cs_mapLocalHost

◆ fDiscover

bool fDiscover = true

◆ fListen

◆ fRelayTxes

bool fRelayTxes = true

Definition at line 114 of file net.cpp.

Referenced by AppInitMain(), getnetworkinfo(), and ProcessMessage().

◆ instance_of_cnetcleanup

class CNetCleanup instance_of_cnetcleanup

◆ NET_MESSAGE_COMMAND_OTHER

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

Definition at line 102 of file net.cpp.

Referenced by CNode::CNode(), and CNode::ReceiveMsgBytes().

◆ RANDOMIZER_ID_LOCALHOSTNONCE

const uint64_t RANDOMIZER_ID_LOCALHOSTNONCE = 0xd93e69e2bbfa5735ULL
static

Definition at line 108 of file net.cpp.

Referenced by CConnman::AcceptConnection(), and CConnman::ConnectNode().

◆ RANDOMIZER_ID_NETGROUP

const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL
static

Definition at line 107 of file net.cpp.

Referenced by CConnman::CalculateKeyedNetGroup().

◆ SELECT_TIMEOUT_MILLISECONDS

const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50
static

Definition at line 94 of file net.cpp.

Referenced by CConnman::SocketEventsSelect().

◆ strSubVersion

std::string strSubVersion

Subversion as sent to the P2P network in version messages.

Definition at line 118 of file net.cpp.

Referenced by AppInitMain(), ClientModel::formatSubVersion(), and getnetworkinfo().

Released under the MIT license