Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

net.h File Reference
#include <addrdb.h>
#include <addrman.h>
#include <bloom.h>
#include <compat.h>
#include <fs.h>
#include <hash.h>
#include <limitedmap.h>
#include <netaddress.h>
#include <policy/feerate.h>
#include <protocol.h>
#include <random.h>
#include <saltedhasher.h>
#include <streams.h>
#include <sync.h>
#include <uint256.h>
#include <util.h>
#include <threadinterrupt.h>
#include <consensus/params.h>
#include <atomic>
#include <deque>
#include <stdint.h>
#include <thread>
#include <memory>
#include <condition_variable>
#include <unordered_set>
#include <queue>
#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::CFullyConnectedOnly
 
struct  CConnman::CAllNodes
 
struct  CConnman::ListenSocket
 
struct  CombinerAll
 
class  NetEventsInterface
 Interface for message handling. More...
 
struct  LocalServiceInfo
 
class  CNodeStats
 
class  CNetMessage
 
class  CNode
 Information about a peer. More...
 
class  CExplicitNetCleanup
 

Macros

#define USE_WAKEUP_PIPE
 
#define DEFAULT_SOCKETEVENTS   "select"
 

Typedefs

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

Enumerations

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

Functions

void Discover (boost::thread_group &threadGroup)
 
void MapPort (bool fUseUPnP)
 
unsigned short GetListenPort ()
 
bool BindListenPort (const CService &bindAddr, std::string &strError, bool fWhitelisted=false)
 
bool IsPeerAddrLocalGood (CNode *pnode)
 
void AdvertiseLocal (CNode *pnode)
 
void SetLimited (enum Network net, bool fLimited=true)
 Make a particular network entirely off-limits (no automatic connects to it) More...
 
bool IsLimited (enum Network net)
 
bool IsLimited (const CNetAddr &addr)
 
bool AddLocal (const CService &addr, int nScore=LOCAL_NONE)
 
bool AddLocal (const CNetAddr &addr, int nScore=LOCAL_NONE)
 
bool 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)
 
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...
 
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...
 

Variables

static const int PING_INTERVAL = 2 * 60
 Time between pings automatically sent out for latency probing and keepalive (in seconds). 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 WARNING_INTERVAL = 10 * 60
 Minimum time between warnings printed to log. 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_INV_SZ = 50000
 The maximum number of entries in an 'inv' protocol message. 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_PROTOCOL_MESSAGE_LENGTH = 3 * 1024 * 1024
 Maximum length of incoming protocol messages (no message over 3 MiB is currently acceptable). More...
 
static const unsigned int MAX_SUBVERSION_LENGTH = 256
 Maximum length of strSubVer in version message. More...
 
static const int MAX_OUTBOUND_CONNECTIONS = 8
 Maximum number of automatic outgoing nodes. More...
 
static const int MAX_ADDNODE_CONNECTIONS = 8
 Maximum number of addnode outgoing nodes. More...
 
static const int INBOUND_EVICTION_PROTECTION_TIME = 1
 Eviction protection time for incoming 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 = 125
 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 bool DEFAULT_FORCEDNSSEED = false
 
static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
 
static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
 
static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24
 
std::unique_ptr< CConnmang_connman
 
bool fDiscover
 
bool fListen
 
bool fRelayTxes
 
std::string strSubVersion
 Subversion as sent to the P2P network in version messages. More...
 
CCriticalSection cs_mapLocalHost
 

Macro Definition Documentation

◆ DEFAULT_SOCKETEVENTS

#define DEFAULT_SOCKETEVENTS   "select"

Definition at line 106 of file net.h.

Referenced by AppInitMain(), and HelpMessage().

◆ USE_WAKEUP_PIPE

#define USE_WAKEUP_PIPE

Definition at line 43 of file net.h.

Typedef Documentation

◆ mapMsgCmdSize

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

Definition at line 715 of file net.h.

◆ NodeId

typedef int64_t NodeId

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

Function Documentation

◆ AddLocal() [1/2]

◆ AddLocal() [2/2]

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

Definition at line 262 of file net.cpp.

References AddLocal(), and GetListenPort().

◆ AdvertiseLocal()

◆ BindListenPort()

bool BindListenPort ( const CService bindAddr,
std::string &  strError,
bool  fWhitelisted = false 
)

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

◆ GetListenPort()

◆ GetLocal()

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

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().

◆ 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  fUseUPnP)

Definition at line 2065 of file net.cpp.

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

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

References GetRand().

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

◆ 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 1109 of file net.h.

References PoissonNextSend().

◆ RemoveLocal()

bool RemoveLocal ( const CService addr)

◆ 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 = true 
)

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

◆ DEFAULT_BLOCKSONLY

const bool DEFAULT_BLOCKSONLY = false
static

Default for blocks only.

Definition at line 92 of file net.h.

Referenced by AppInitMain(), HelpMessage(), InitParameterInteraction(), and WalletInit::ParameterInteraction().

◆ DEFAULT_FORCEDNSSEED

const bool DEFAULT_FORCEDNSSEED = false
static

Definition at line 94 of file net.h.

Referenced by HelpMessage(), and CConnman::ThreadDNSAddressSeed().

◆ DEFAULT_LISTEN

const bool DEFAULT_LISTEN = true
static

-listen default

Definition at line 76 of file net.h.

Referenced by AppInitMain(), AppInitParameterInteraction(), OptionsModel::Init(), and InitParameterInteraction().

◆ DEFAULT_MAX_PEER_CONNECTIONS

const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125
static

The maximum number of peer connections to maintain.

Masternodes are forced to accept at least this many connections

Definition at line 86 of file net.h.

Referenced by AppInitParameterInteraction(), and HelpMessage().

◆ DEFAULT_MAX_UPLOAD_TARGET

const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0
static

The default for -maxuploadtarget.

0 = Unlimited

Definition at line 88 of file net.h.

Referenced by AppInitMain(), and HelpMessage().

◆ DEFAULT_MAXRECEIVEBUFFER

const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
static

Definition at line 95 of file net.h.

Referenced by AppInitMain(), and HelpMessage().

◆ DEFAULT_MAXSENDBUFFER

const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
static

Definition at line 96 of file net.h.

Referenced by AppInitMain(), and HelpMessage().

◆ DEFAULT_MISBEHAVING_BANTIME

const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24
static

Definition at line 99 of file net.h.

Referenced by CConnman::Ban(), and HelpMessage().

◆ DEFAULT_UPNP

const bool DEFAULT_UPNP = false
static

-upnp default

Definition at line 81 of file net.h.

Referenced by AppInitMain(), and OptionsModel::Init().

◆ fDiscover

bool fDiscover

◆ FEELER_INTERVAL

const int FEELER_INTERVAL = 120
static

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

Definition at line 60 of file net.h.

Referenced by CConnman::ThreadOpenConnections().

◆ fListen

◆ fRelayTxes

bool fRelayTxes

Definition at line 114 of file net.cpp.

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

◆ g_connman

std::unique_ptr<CConnman> g_connman

Definition at line 97 of file init.cpp.

Referenced by llmq::CQuorumBlockProcessor::AddMinableCommitment(), addnode(), llmq::CLLMQUtils::AddQuorumProbeConnections(), AppInitMain(), llmq::CInstantSendManager::AskNodesForLockedTx(), RPCConsole::banSelectedNode(), PeerLogicValidation::BlockConnected(), llmq::CSigSharesManager::Cleanup(), clearbanned(), llmq::CSigSharesManager::CollectSigSharesToAnnounce(), CTransactionBuilder::Commit(), disconnectnode(), RPCConsole::disconnectSelectedNode(), llmq::CLLMQUtils::EnsureQuorumConnections(), llmq::CQuorumManager::EnsureQuorumConnections(), getaddednodeinfo(), getblocktemplate(), getconnectioncount(), CActiveMasternodeManager::GetLocalAddress(), getnettotals(), ClientModel::getNetworkActive(), getnetworkinfo(), ClientModel::getNumConnections(), getpeerinfo(), ClientModel::getTotalBytesRecv(), ClientModel::getTotalBytesSent(), gobject_submit(), gobject_vote_conf(), Interrupt(), listbanned(), masternode_connect(), mnsync(), CMNAuth::NotifyMasternodeListChanged(), ping(), PrepareShutdown(), llmq::CInstantSendManager::ProcessInstantSendLock(), llmq::CChainLocksHandler::ProcessNewChainLock(), llmq::CSigningManager::ProcessPendingReconstructedRecoveredSigs(), llmq::CInstantSendManager::ProcessTx(), quorum_dkgstatus(), BanTablePriv::refreshBanlist(), PeerTablePriv::refreshPeers(), llmq::CDKGSession::RelayInvToParticipants(), resendwallettransactions(), WalletModel::sendCoins(), sendmany(), llmq::CSigSharesManager::SendMessages(), SendMoney(), sendrawtransaction(), setban(), ClientModel::setNetworkActive(), setnetworkactive(), llmq::CSigSharesManager::Sign(), spork(), WalletInit::Start(), RPCConsole::unbanSelectedNode(), llmq::CDKGSession::VerifyConnectionAndMinProtoVersions(), voteraw(), VoteWithMasternodes(), and llmq::CSigSharesManager::WorkThreadMain().

◆ INBOUND_EVICTION_PROTECTION_TIME

const int INBOUND_EVICTION_PROTECTION_TIME = 1
static

Eviction protection time for incoming connections.

Definition at line 74 of file net.h.

Referenced by CConnman::AttemptToEvictConnection().

◆ MAX_ADDNODE_CONNECTIONS

const int MAX_ADDNODE_CONNECTIONS = 8
static

Maximum number of addnode outgoing nodes.

Definition at line 72 of file net.h.

Referenced by AppInitMain(), and AppInitParameterInteraction().

◆ 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 64 of file net.h.

Referenced by CNode::PushAddress().

◆ MAX_INV_SZ

const unsigned int MAX_INV_SZ = 50000
static

The maximum number of entries in an 'inv' protocol message.

Definition at line 62 of file net.h.

Referenced by ProcessMessage(), CGovernanceManager::RequestGovernanceObjectVotes(), and PeerLogicValidation::SendMessages().

◆ MAX_OUTBOUND_CONNECTIONS

const int MAX_OUTBOUND_CONNECTIONS = 8
static

Maximum number of automatic outgoing nodes.

Definition at line 70 of file net.h.

Referenced by AppInitMain().

◆ MAX_PROTOCOL_MESSAGE_LENGTH

const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 3 * 1024 * 1024
static

Maximum length of incoming protocol messages (no message over 3 MiB is currently acceptable).

Definition at line 66 of file net.h.

Referenced by CNode::ReceiveMsgBytes().

◆ MAX_SUBVERSION_LENGTH

const unsigned int MAX_SUBVERSION_LENGTH = 256
static

Maximum length of strSubVer in version message.

Definition at line 68 of file net.h.

Referenced by AppInitMain(), and ProcessMessage().

◆ MAX_UPLOAD_TIMEFRAME

const uint64_t MAX_UPLOAD_TIMEFRAME = 60 * 60 * 24
static

The default timeframe for -maxuploadtarget.

1 day.

Definition at line 90 of file net.h.

Referenced by AppInitMain().

◆ PING_INTERVAL

const int PING_INTERVAL = 2 * 60
static

Time between pings automatically sent out for latency probing and keepalive (in seconds).

Definition at line 54 of file net.h.

Referenced by PeerLogicValidation::SendMessages().

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

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

Referenced by CConnman::InactivityCheck().

◆ WARNING_INTERVAL

const int WARNING_INTERVAL = 10 * 60
static

Minimum time between warnings printed to log.

Definition at line 58 of file net.h.

Released under the MIT license