Dash Core  0.12.2.1
P2P Digital Currency
net.h File Reference
#include "addrdb.h"
#include "addrman.h"
#include "bloom.h"
#include "compat.h"
#include "limitedmap.h"
#include "netaddress.h"
#include "protocol.h"
#include "random.h"
#include "streams.h"
#include "sync.h"
#include "uint256.h"
#include "util.h"
#include "threadinterrupt.h"
#include <atomic>
#include <deque>
#include <stdint.h>
#include <thread>
#include <memory>
#include <condition_variable>
#include <arpa/inet.h>
#include <boost/filesystem/path.hpp>
#include <boost/foreach.hpp>
#include <boost/signals2/signal.hpp>

Go to the source code of this file.

Classes

struct  AddedNodeInfo
 
class  CConnman
 
struct  CConnman::Options
 
struct  CConnman::CFullyConnectedOnly
 
struct  CConnman::CAllNodes
 
struct  CConnman::ListenSocket
 
struct  CombinerAll
 
struct  CNodeSignals
 
struct  LocalServiceInfo
 
class  CNodeStats
 
class  CNetMessage
 
class  CNode
 
class  CExplicitNetCleanup
 

Typedefs

typedef int 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)
 
CNodeSignalsGetNodeSignals ()
 
bool IsPeerAddrLocalGood (CNode *pnode)
 
void AdvertiseLocal (CNode *pnode)
 
void SetLimited (enum Network net, bool fLimited=true)
 
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)
 
bool IsLocal (const CService &addr)
 
bool GetLocal (CService &addr, const CNetAddr *paddrPeer=NULL)
 
bool IsReachable (enum Network net)
 
bool IsReachable (const CNetAddr &addr)
 
CAddress GetLocalAddress (const CNetAddr *paddrPeer, ServiceFlags nLocalServices)
 
int64_t PoissonNextSend (int64_t nNow, int average_interval_seconds)
 

Variables

static const int PING_INTERVAL = 2 * 60
 
static const int TIMEOUT_INTERVAL = 20 * 60
 
static const int WARNING_INTERVAL = 10 * 60
 
static const int FEELER_INTERVAL = 120
 
static const unsigned int MAX_INV_SZ = 50000
 
static const unsigned int MAX_ADDR_TO_SEND = 1000
 
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 3 * 1024 * 1024
 
static const unsigned int MAX_SUBVERSION_LENGTH = 256
 
static const int MAX_OUTBOUND_CONNECTIONS = 8
 
static const int MAX_OUTBOUND_MASTERNODE_CONNECTIONS = 20
 
static const bool DEFAULT_LISTEN = true
 
static const bool DEFAULT_UPNP = false
 
static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ
 
static const size_t SETASKFOR_MAX_SZ = 2 * MAX_INV_SZ
 
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125
 
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0
 
static const bool DEFAULT_BLOCKSONLY = false
 
static const bool DEFAULT_FORCEDNSSEED = false
 
static const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
 
static const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
 
static const ServiceFlags REQUIRED_SERVICES = NODE_NETWORK
 
static const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24
 
std::unique_ptr< CConnmang_connman
 
bool fDiscover
 
bool fListen
 
bool fRelayTxes
 
std::map< CInv, CDataStreammapRelay
 
std::deque< std::pair< int64_t, CInv > > vRelayExpiration
 
CCriticalSection cs_mapRelay
 
limitedmap< uint256, int64_t > mapAlreadyAskedFor
 
std::string strSubVersion
 
CCriticalSection cs_mapLocalHost
 
std::map< CNetAddr, LocalServiceInfomapLocalHost
 

Typedef Documentation

◆ mapMsgCmdSize

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

Definition at line 589 of file net.h.

◆ NodeId

typedef int NodeId

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

Function Documentation

◆ AddLocal() [1/2]

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

◆ AddLocal() [2/2]

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

Definition at line 231 of file net.cpp.

◆ AdvertiseLocal()

void AdvertiseLocal ( CNode pnode)

Definition at line 183 of file net.cpp.

Referenced by SendMessages().

◆ BindListenPort()

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

◆ Discover()

void Discover ( boost::thread_group &  threadGroup)

Definition at line 2062 of file net.cpp.

Referenced by AppInit2().

◆ GetListenPort()

unsigned short GetListenPort ( )

◆ GetLocal()

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

Definition at line 106 of file net.cpp.

Referenced by GetLocalAddress(), and CActiveMasternode::ManageStateInitial().

◆ GetLocalAddress()

CAddress GetLocalAddress ( const CNetAddr paddrPeer,
ServiceFlags  nLocalServices 
)

Definition at line 155 of file net.cpp.

Referenced by AdvertiseLocal(), and ProcessMessage().

◆ GetNodeSignals()

◆ IsLimited() [1/2]

bool IsLimited ( enum Network  net)

◆ IsLimited() [2/2]

bool IsLimited ( const CNetAddr addr)

Definition at line 259 of file net.cpp.

◆ IsLocal()

bool IsLocal ( const CService addr)

check whether a given address is potentially local

Definition at line 278 of file net.cpp.

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

◆ IsPeerAddrLocalGood()

bool IsPeerAddrLocalGood ( CNode pnode)

Definition at line 176 of file net.cpp.

Referenced by AdvertiseLocal(), and ProcessMessage().

◆ IsReachable() [1/2]

bool IsReachable ( enum Network  net)

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

Definition at line 285 of file net.cpp.

Referenced by GetNetworksInfo(), IsReachable(), CMasternode::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 292 of file net.cpp.

◆ MapPort()

void MapPort ( bool  fUseUPnP)

Definition at line 1511 of file net.cpp.

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

◆ PoissonNextSend()

int64_t PoissonNextSend ( int64_t  nNow,
int  average_interval_seconds 
)

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

Definition at line 2892 of file net.cpp.

Referenced by SendMessages(), and CConnman::ThreadOpenConnections().

◆ RemoveLocal()

bool RemoveLocal ( const CService addr)

Definition at line 236 of file net.cpp.

Referenced by TorController::disconnected_cb(), and TorController::~TorController().

◆ SeenLocal()

bool SeenLocal ( const CService addr)

vote for a local address

Definition at line 265 of file net.cpp.

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

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

Variable Documentation

◆ cs_mapLocalHost

◆ cs_mapRelay

CCriticalSection cs_mapRelay

Definition at line 87 of file net.cpp.

Referenced by ProcessGetData(), and CConnman::RelayTransaction().

◆ DEFAULT_BLOCKSONLY

const bool DEFAULT_BLOCKSONLY = false
static

Default for blocks only

Definition at line 83 of file net.h.

Referenced by AppInit2(), HelpMessage(), and InitParameterInteraction().

◆ DEFAULT_FORCEDNSSEED

const bool DEFAULT_FORCEDNSSEED = false
static

Definition at line 85 of file net.h.

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

◆ DEFAULT_LISTEN

const bool DEFAULT_LISTEN = true
static

-listen default

Definition at line 67 of file net.h.

Referenced by AppInit2(), 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.

Definition at line 79 of file net.h.

Referenced by AppInit2(), and HelpMessage().

◆ DEFAULT_MAX_UPLOAD_TARGET

const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0
static

The default for -maxuploadtarget. 0 = Unlimited

Definition at line 81 of file net.h.

Referenced by AppInit2(), and HelpMessage().

◆ DEFAULT_MAXRECEIVEBUFFER

const size_t DEFAULT_MAXRECEIVEBUFFER = 5 * 1000
static

Definition at line 86 of file net.h.

Referenced by AppInit2(), and HelpMessage().

◆ DEFAULT_MAXSENDBUFFER

const size_t DEFAULT_MAXSENDBUFFER = 1 * 1000
static

Definition at line 87 of file net.h.

Referenced by AppInit2(), and HelpMessage().

◆ DEFAULT_MISBEHAVING_BANTIME

const unsigned int DEFAULT_MISBEHAVING_BANTIME = 60 * 60 * 24
static

Definition at line 92 of file net.h.

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

◆ DEFAULT_UPNP

const bool DEFAULT_UPNP = false
static

-upnp default

Definition at line 72 of file net.h.

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

◆ fDiscover

bool fDiscover

Definition at line 76 of file net.cpp.

Referenced by AddLocal(), AppInit2(), CConnman::BindListenPort(), Discover(), and IsPeerAddrLocalGood().

◆ FEELER_INTERVAL

const int FEELER_INTERVAL = 120
static

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

Definition at line 53 of file net.h.

Referenced by CConnman::ThreadOpenConnections().

◆ fListen

bool fListen

◆ fRelayTxes

bool fRelayTxes

Definition at line 78 of file net.cpp.

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

◆ g_connman

◆ mapAlreadyAskedFor

limitedmap<uint256, int64_t> mapAlreadyAskedFor

Referenced by CNode::AskFor(), and ProcessMessage().

◆ MAPASKFOR_MAX_SZ

const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ
static

The maximum number of entries in mapAskFor

Definition at line 75 of file net.h.

Referenced by CNode::AskFor().

◆ mapLocalHost

std::map<CNetAddr, LocalServiceInfo> mapLocalHost

Definition at line 80 of file net.cpp.

Referenced by AddLocal(), GetLocal(), getnetworkinfo(), GetnScore(), IsLocal(), RemoveLocal(), and SeenLocal().

◆ mapRelay

std::map<CInv, CDataStream> mapRelay

Definition at line 85 of file net.cpp.

Referenced by ProcessGetData(), and CConnman::RelayTransaction().

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

Referenced by ProcessMessage(), and CMasternodePayments::RequestLowDataPaymentBlocks().

◆ MAX_OUTBOUND_CONNECTIONS

const int MAX_OUTBOUND_CONNECTIONS = 8
static

Maximum number of outgoing nodes

Definition at line 63 of file net.h.

Referenced by AppInit2().

◆ MAX_OUTBOUND_MASTERNODE_CONNECTIONS

const int MAX_OUTBOUND_MASTERNODE_CONNECTIONS = 20
static

Maximum number if outgoing masternodes

Definition at line 65 of file net.h.

Referenced by CConnman::Start(), and CConnman::Stop().

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

Referenced by AppInit2(), and ProcessMessage().

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

Referenced by SendMessages().

◆ REQUIRED_SERVICES

const ServiceFlags REQUIRED_SERVICES = NODE_NETWORK
static

Definition at line 89 of file net.h.

Referenced by ProcessMessage(), and CConnman::ThreadOpenConnections().

◆ SETASKFOR_MAX_SZ

const size_t SETASKFOR_MAX_SZ = 2 * MAX_INV_SZ
static

The maximum number of entries in setAskFor (larger due to getdata latency)

Definition at line 77 of file net.h.

Referenced by CNode::AskFor(), and CGovernanceManager::RequestGovernanceObjectVotes().

◆ strSubVersion

std::string strSubVersion

Subversion as sent to the P2P network in version messages

Definition at line 83 of file net.cpp.

Referenced by AppInit2(), 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 49 of file net.h.

Referenced by CConnman::ThreadSocketHandler().

◆ vRelayExpiration

std::deque<std::pair<int64_t, CInv> > vRelayExpiration

Definition at line 86 of file net.cpp.

Referenced by CConnman::RelayTransaction().

◆ WARNING_INTERVAL

const int WARNING_INTERVAL = 10 * 60
static

Minimum time between warnings printed to log.

Definition at line 51 of file net.h.

Referenced by CNode::AskFor().