Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Macros | Functions | Variables
net.cpp File Reference
#include "net.h"
#include "addrman.h"
#include "chainparams.h"
#include "core.h"
#include "ui_interface.h"
#include <fcntl.h>
#include <boost/filesystem.hpp>
+ Include dependency graph for net.cpp:

Go to the source code of this file.

Classes

class  CNetCleanup
 

Macros

#define DUMP_ADDRESSES_INTERVAL   900
 
#define X(name)   stats.name = name
 

Functions

bool OpenNetworkConnection (const CAddress &addrConnect, CSemaphoreGrant *grantOutbound=NULL, const char *strDest=NULL, bool fOneShot=false)
 
CNodeSignalsGetNodeSignals ()
 
void AddOneShot (string strDest)
 
unsigned short GetListenPort ()
 
bool GetLocal (CService &addr, const CNetAddr *paddrPeer)
 
CAddress GetLocalAddress (const CNetAddr *paddrPeer)
 
bool RecvLine (SOCKET hSocket, string &strLine)
 
static void AdvertizeLocal ()
 
void SetReachable (enum Network net, bool fFlag)
 
bool AddLocal (const CService &addr, int nScore)
 
bool AddLocal (const CNetAddr &addr, int nScore)
 
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 (const CNetAddr &addr)
 check whether a given address is in a network we can probably connect to More...
 
bool GetMyExternalIP2 (const CService &addrConnect, const char *pszGet, const char *pszKeyword, CNetAddr &ipRet)
 
bool GetMyExternalIP (CNetAddr &ipRet)
 
void ThreadGetMyExternalIP ()
 
void AddressCurrentlyConnected (const CService &addr)
 
CNodeFindNode (const CNetAddr &ip)
 
CNodeFindNode (std::string addrName)
 
CNodeFindNode (const CService &addr)
 
CNodeConnectNode (CAddress addrConnect, const char *pszDest)
 
void SocketSendData (CNode *pnode)
 
void ThreadSocketHandler ()
 
void MapPort (bool)
 
void ThreadDNSAddressSeed ()
 
void DumpAddresses ()
 
static void ProcessOneShot ()
 
void ThreadOpenConnections ()
 
void ThreadOpenAddedConnections ()
 
static int64_t NodeSyncScore (const CNode *pnode)
 
static void StartSync (const vector< CNode * > &vNodes)
 
void ThreadMessageHandler ()
 
bool BindListenPort (const CService &addrBind, string &strError)
 
static void Discover (boost::thread_group &threadGroup)
 
void StartNode (boost::thread_group &threadGroup)
 
bool StopNode ()
 
void RelayTransaction (const CTransaction &tx, const uint256 &hash)
 
void RelayTransaction (const CTransaction &tx, const uint256 &hash, const CDataStream &ss)
 

Variables

static const int MAX_OUTBOUND_CONNECTIONS = 8
 
bool fDiscover = true
 
uint64_t nLocalServices = NODE_NETWORK
 
CCriticalSection cs_mapLocalHost
 
map< CNetAddr, LocalServiceInfomapLocalHost
 
static bool vfReachable [NET_MAX] = {}
 
static bool vfLimited [NET_MAX] = {}
 
static CNodepnodeLocalHost = NULL
 
static CNodepnodeSync = NULL
 
uint64_t nLocalHostNonce = 0
 
static std::vector< SOCKETvhListenSocket
 
CAddrMan addrman
 
int nMaxConnections = 125
 
vector< CNode * > vNodes
 
CCriticalSection cs_vNodes
 
map< CInv, CDataStreammapRelay
 
deque< pair< int64_t, CInv > > vRelayExpiration
 
CCriticalSection cs_mapRelay
 
limitedmap< CInv, int64_t > mapAlreadyAskedFor (MAX_INV_SZ)
 
static deque< string > vOneShots
 
CCriticalSection cs_vOneShots
 
set< CNetAddrsetservAddNodeAddresses
 
CCriticalSection cs_setservAddNodeAddresses
 
vector< std::string > vAddedNodes
 
CCriticalSection cs_vAddedNodes
 
NodeId nLastNodeId = 0
 
CCriticalSection cs_nLastNodeId
 
static CSemaphoresemOutbound = NULL
 
static CNodeSignals g_signals
 
static list< CNode * > vNodesDisconnected
 
class CNetCleanup instance_of_cnetcleanup
 

Macro Definition Documentation

#define DUMP_ADDRESSES_INTERVAL   900

Definition at line 33 of file net.cpp.

Referenced by StartNode().

#define X (   name)    stats.name = name

Definition at line 575 of file net.cpp.

Referenced by CNode::copyStats().

Function Documentation

bool AddLocal ( const CService addr,
int  nScore 
)

Definition at line 216 of file net.cpp.

References AdvertizeLocal(), fDiscover, CNetAddr::GetNetwork(), CService::GetPort(), IsLimited(), CNetAddr::IsRoutable(), LOCAL_MANUAL, LOCK, LogPrintf, LocalServiceInfo::nPort, LocalServiceInfo::nScore, SetReachable(), and CService::ToString().

Referenced by AddLocal(), AppInit2(), BindListenPort(), Discover(), and ThreadGetMyExternalIP().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AddLocal ( const CNetAddr addr,
int  nScore 
)

Definition at line 245 of file net.cpp.

References AddLocal(), and GetListenPort().

+ Here is the call graph for this function:

void AddOneShot ( string  strDest)

Definition at line 88 of file net.cpp.

References LOCK.

Referenced by AppInit2(), ProcessOneShot(), and ThreadDNSAddressSeed().

+ Here is the caller graph for this function:

void AddressCurrentlyConnected ( const CService addr)

Definition at line 400 of file net.cpp.

References CAddrMan::Connected().

Referenced by ProcessMessage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void AdvertizeLocal ( )
static

Definition at line 190 of file net.cpp.

References CNode::addr, CNode::addrLocal, CNode::fSuccessfullyConnected, GetLocalAddress(), CNetAddr::IsRoutable(), LOCK, and CNode::PushAddress().

Referenced by AddLocal(), and SeenLocal().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool BindListenPort ( const CService addrBind,
string &  strError 
)

Definition at line 1561 of file net.cpp.

References _(), AddLocal(), fDiscover, CService::GetSockAddr(), INVALID_SOCKET, CNetAddr::IsIPv6(), CNetAddr::IsRoutable(), LOCAL_BIND, LogPrintf, NetworkErrorString(), SOCKET_ERROR, strprintf, CService::ToString(), WSAEADDRINUSE, and WSAGetLastError.

Referenced by Bind().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CNode* ConnectNode ( CAddress  addrConnect,
const char *  pszDest 
)

debug print

Definition at line 440 of file net.cpp.

References CNode::AddRef(), CAddrMan::Attempt(), ConnectSocket(), ConnectSocketByName(), FindNode(), GetAdjustedTime(), GetTime(), IsLocal(), LOCK, LogPrint(), LogPrintf, NetworkErrorString(), CAddress::nTime, CNode::nTimeConnected, Params(), SOCKET_ERROR, CService::ToString(), and WSAGetLastError.

Referenced by addnode(), and OpenNetworkConnection().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void Discover ( boost::thread_group &  threadGroup)
static

Definition at line 1654 of file net.cpp.

References AddLocal(), fDiscover, IsLimited(), LOCAL_IF, LogPrintf, LookupHost(), NET_IPV4, SOCKET_ERROR, ThreadGetMyExternalIP(), CNetAddr::ToString(), and TraceThread().

Referenced by StartNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DumpAddresses ( )

Definition at line 1219 of file net.cpp.

References GetTimeMillis(), LogPrint(), CAddrMan::size(), and CAddrDB::Write().

Referenced by StartNode(), and StopNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CNode* FindNode ( const CNetAddr ip)

Definition at line 413 of file net.cpp.

References CNode::addr, and LOCK.

Referenced by ConnectNode(), and OpenNetworkConnection().

+ Here is the caller graph for this function:

CNode* FindNode ( std::string  addrName)

Definition at line 422 of file net.cpp.

References CNode::addrName, and LOCK.

CNode* FindNode ( const CService addr)

Definition at line 431 of file net.cpp.

References CNode::addr, and LOCK.

unsigned short GetListenPort ( )

Definition at line 94 of file net.cpp.

References GetArg(), and Params().

Referenced by AddLocal(), and AppInit2().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool GetLocal ( CService addr,
const CNetAddr paddrPeer 
)

Definition at line 100 of file net.cpp.

References fNoListen, and LOCK.

Referenced by GetLocalAddress().

+ Here is the caller graph for this function:

CAddress GetLocalAddress ( const CNetAddr paddrPeer)

Definition at line 125 of file net.cpp.

References GetAdjustedTime(), GetLocal(), nLocalServices, CAddress::nServices, and CAddress::nTime.

Referenced by AdvertizeLocal(), ProcessMessage(), CNode::PushVersion(), and SendMessages().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool GetMyExternalIP ( CNetAddr ipRet)

Definition at line 346 of file net.cpp.

References GetMyExternalIP2(), and CNetAddr::IsValid().

Referenced by ThreadGetMyExternalIP().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool GetMyExternalIP2 ( const CService addrConnect,
const char *  pszGet,
const char *  pszKeyword,
CNetAddr ipRet 
)

Definition at line 300 of file net.cpp.

References closesocket, ConnectSocket(), error(), CNetAddr::IsRoutable(), CNetAddr::IsValid(), LogPrintf, MSG_NOSIGNAL, RecvLine(), CNetAddr::SetIP(), and CService::ToString().

Referenced by GetMyExternalIP().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CNodeSignals& GetNodeSignals ( )

Definition at line 86 of file net.cpp.

References g_signals.

Referenced by AppInit2(), CNode::CNode(), Shutdown(), and CNode::~CNode().

+ Here is the caller graph for this function:

bool IsLimited ( enum Network  net)

Definition at line 259 of file net.cpp.

References LOCK, and vfLimited.

Referenced by AddLocal(), AppInit2(), Bind(), Discover(), IsLimited(), and ThreadOpenConnections().

+ Here is the caller graph for this function:

bool IsLimited ( const CNetAddr addr)

Definition at line 265 of file net.cpp.

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

+ Here is the call graph for this function:

bool IsLocal ( const CService addr)

check whether a given address is potentially local

Definition at line 286 of file net.cpp.

References LOCK.

Referenced by ConnectNode(), CNetAddr::GetGroup(), CNetAddr::IsRoutable(), OpenNetworkConnection(), and ThreadOpenConnections().

+ Here is the caller graph for this function:

bool IsReachable ( const CNetAddr addr)

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

Definition at line 293 of file net.cpp.

References CNetAddr::GetNetwork(), LOCK, vfLimited, and vfReachable.

Referenced by ProcessMessage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MapPort ( bool  )

Definition at line 1154 of file net.cpp.

Referenced by OptionsModel::setData(), StartNode(), and StopNode().

+ Here is the caller graph for this function:

static int64_t NodeSyncScore ( const CNode pnode)
static

Definition at line 1452 of file net.cpp.

References CNode::nLastRecv.

Referenced by StartSync().

+ Here is the caller graph for this function:

bool OpenNetworkConnection ( const CAddress addrConnect,
CSemaphoreGrant grantOutbound = NULL,
const char *  strDest = NULL,
bool  fOneShot = false 
)

Definition at line 1421 of file net.cpp.

References ConnectNode(), FindNode(), CNode::fNetworkNode, CNode::fOneShot, CNode::grantOutbound, CNode::IsBanned(), IsLocal(), and CSemaphoreGrant::MoveTo().

Referenced by ProcessOneShot(), ThreadOpenAddedConnections(), and ThreadOpenConnections().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void ProcessOneShot ( )
static

Definition at line 1230 of file net.cpp.

References AddOneShot(), LOCK, and OpenNetworkConnection().

Referenced by ThreadOpenConnections().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool RecvLine ( SOCKET  hSocket,
string &  strLine 
)

Definition at line 138 of file net.cpp.

References LogPrint(), MilliSleep(), NetworkErrorString(), WSAEINPROGRESS, WSAEINTR, WSAEMSGSIZE, WSAEWOULDBLOCK, and WSAGetLastError.

Referenced by GetMyExternalIP2().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelayTransaction ( const CTransaction tx,
const uint256 hash 
)

Definition at line 1807 of file net.cpp.

References PROTOCOL_VERSION, RelayTransaction(), CDataStream::reserve(), and SER_NETWORK.

Referenced by ProcessMessage(), RelayTransaction(), CWalletTx::RelayWalletTransaction(), and sendrawtransaction().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelayTransaction ( const CTransaction tx,
const uint256 hash,
const CDataStream ss 
)

Definition at line 1815 of file net.cpp.

References CNode::cs_filter, CNode::fRelayTxes, GetTime(), CBloomFilter::IsRelevantAndUpdate(), LOCK, MSG_TX, CNode::pfilter, and CNode::PushInventory().

+ Here is the call graph for this function:

bool SeenLocal ( const CService addr)

vote for a local address

Definition at line 271 of file net.cpp.

References AdvertizeLocal(), and LOCK.

Referenced by ProcessMessage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SetLimited ( enum Network  net,
bool  fLimited 
)

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

Definition at line 251 of file net.cpp.

References LOCK, NET_UNROUTABLE, and vfLimited.

Referenced by AppInit2().

+ Here is the caller graph for this function:

void SetReachable ( enum Network  net,
bool  fFlag 
)

Definition at line 207 of file net.cpp.

References LOCK, NET_IPV4, NET_IPV6, and vfReachable.

Referenced by AddLocal(), and AppInit2().

+ Here is the caller graph for this function:

void SocketSendData ( CNode pnode)

Definition at line 693 of file net.cpp.

References CNode::CloseSocketDisconnect(), Checkpoints::data, GetTime(), CNode::hSocket, LogPrintf, MSG_NOSIGNAL, NetworkErrorString(), CNode::nLastSend, CNode::nSendBytes, CNode::nSendOffset, CNode::nSendSize, CNode::RecordBytesSent(), CNode::vSendMsg, WSAEINPROGRESS, WSAEINTR, WSAEMSGSIZE, WSAEWOULDBLOCK, and WSAGetLastError.

Referenced by CNode::EndMessage(), and ThreadSocketHandler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void StartNode ( boost::thread_group &  threadGroup)

Definition at line 1708 of file net.cpp.

References Discover(), DUMP_ADDRESSES_INTERVAL, DumpAddresses(), GetBoolArg(), INVALID_SOCKET, LogPrintf, LoopForever(), MapPort(), nLocalServices, ThreadDNSAddressSeed(), ThreadMessageHandler(), ThreadOpenAddedConnections(), ThreadOpenConnections(), ThreadSocketHandler(), TraceThread(), and USE_UPNP.

Referenced by AppInit2().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void StartSync ( const vector< CNode * > &  vNodes)
static

Definition at line 1456 of file net.cpp.

References CNode::fClient, CNode::fDisconnect, CNode::fOneShot, CNode::fStartSync, CNode::fSuccessfullyConnected, CNodeSignals::GetHeight, NOBLKS_VERSION_END, NOBLKS_VERSION_START, NodeSyncScore(), CNode::nStartingHeight, and CNode::nVersion.

Referenced by ThreadMessageHandler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool StopNode ( )

Definition at line 1751 of file net.cpp.

References DumpAddresses(), LogPrintf, MapPort(), MAX_OUTBOUND_CONNECTIONS, MilliSleep(), and CSemaphore::post().

Referenced by Shutdown().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreadDNSAddressSeed ( )

Definition at line 1165 of file net.cpp.

References CAddrMan::Add(), AddOneShot(), CChainParams::DNSSeeds(), GetBoolArg(), GetRand(), GetTime(), HaveNameProxy(), CDNSSeedData::host, LOCK, LogPrintf, LookupHost(), MilliSleep(), CDNSSeedData::name, CAddress::nTime, Params(), and CAddrMan::size().

Referenced by StartNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreadGetMyExternalIP ( )

Definition at line 386 of file net.cpp.

References AddLocal(), GetMyExternalIP(), LOCAL_HTTP, LogPrintf, and CNetAddr::ToStringIP().

Referenced by Discover().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreadMessageHandler ( )

Definition at line 1484 of file net.cpp.

References CNode::AddRef(), CNode::CloseSocketDisconnect(), CNode::cs_vRecvMsg, CNode::cs_vSend, CNode::fDisconnect, GetRand(), LOCK, MilliSleep(), CNode::nSendSize, CNodeSignals::ProcessMessages, CNode::Release(), SendBufferSize(), CNodeSignals::SendMessages, SetThreadPriority(), StartSync(), THREAD_PRIORITY_BELOW_NORMAL, TRY_LOCK, vNodes, CNode::vRecvGetData, and CNode::vRecvMsg.

Referenced by StartNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreadOpenAddedConnections ( )

Definition at line 1348 of file net.cpp.

References CNode::addr, fNameLookup, CChainParams::GetDefaultPort(), HaveNameProxy(), LOCK, Lookup(), mapMultiArgs, MilliSleep(), OpenNetworkConnection(), and Params().

Referenced by StartNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreadOpenConnections ( )

Definition at line 1248 of file net.cpp.

References CAddrMan::Add(), CNode::addr, CNode::fInbound, GetAdjustedTime(), CChainParams::GetDefaultPort(), CNetAddr::GetGroup(), CService::GetPort(), GetTime(), IsLimited(), IsLocal(), CNetAddr::IsValid(), LOCK, LogPrintf, mapArgs, mapMultiArgs, MilliSleep(), CAddress::nLastTry, OpenNetworkConnection(), Params(), ProcessOneShot(), CAddrMan::Select(), and CAddrMan::size().

Referenced by StartNode().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ThreadSocketHandler ( )

Variable Documentation

CAddrMan addrman

Definition at line 60 of file net.cpp.

Referenced by AppInit2(), and ProcessMessage().

CCriticalSection cs_mapLocalHost

Definition at line 52 of file net.cpp.

Referenced by getnetworkinfo().

CCriticalSection cs_mapRelay

Definition at line 67 of file net.cpp.

Referenced by ProcessGetData().

CCriticalSection cs_nLastNodeId

Definition at line 80 of file net.cpp.

CCriticalSection cs_setservAddNodeAddresses

Definition at line 74 of file net.cpp.

CCriticalSection cs_vAddedNodes

Definition at line 77 of file net.cpp.

Referenced by addnode(), and getaddednodeinfo().

CCriticalSection cs_vNodes
CCriticalSection cs_vOneShots

Definition at line 71 of file net.cpp.

bool fDiscover = true

Definition at line 50 of file net.cpp.

Referenced by AddLocal(), AppInit2(), BindListenPort(), and Discover().

CNodeSignals g_signals
static
class CNetCleanup instance_of_cnetcleanup
limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ)

Referenced by ProcessMessage().

map<CNetAddr, LocalServiceInfo> mapLocalHost

Definition at line 53 of file net.cpp.

Referenced by getnetworkinfo().

map<CInv, CDataStream> mapRelay

Definition at line 65 of file net.cpp.

Referenced by ProcessGetData().

const int MAX_OUTBOUND_CONNECTIONS = 8
static

Definition at line 42 of file net.cpp.

Referenced by StopNode().

NodeId nLastNodeId = 0

Definition at line 79 of file net.cpp.

uint64_t nLocalHostNonce = 0

Definition at line 58 of file net.cpp.

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

uint64_t nLocalServices = NODE_NETWORK

Definition at line 51 of file net.cpp.

Referenced by GetLocalAddress(), CNode::PushVersion(), and StartNode().

int nMaxConnections = 125

Definition at line 61 of file net.cpp.

Referenced by AppInit2().

CNode* pnodeLocalHost = NULL
static

Definition at line 56 of file net.cpp.

Referenced by CNetCleanup::~CNetCleanup().

CNode* pnodeSync = NULL
static

Definition at line 57 of file net.cpp.

Referenced by CNode::copyStats().

CSemaphore* semOutbound = NULL
static

Definition at line 82 of file net.cpp.

Referenced by CNetCleanup::~CNetCleanup().

set<CNetAddr> setservAddNodeAddresses

Definition at line 73 of file net.cpp.

vector<std::string> vAddedNodes

Definition at line 76 of file net.cpp.

Referenced by addnode(), and getaddednodeinfo().

bool vfLimited[NET_MAX] = {}
static

Definition at line 55 of file net.cpp.

Referenced by IsLimited(), IsReachable(), and SetLimited().

bool vfReachable[NET_MAX] = {}
static

Definition at line 54 of file net.cpp.

Referenced by IsReachable(), and SetReachable().

std::vector<SOCKET> vhListenSocket
static

Definition at line 59 of file net.cpp.

vector<CNode*> vNodes
list<CNode*> vNodesDisconnected
static

Definition at line 736 of file net.cpp.

Referenced by ThreadSocketHandler().

deque<string> vOneShots
static

Definition at line 70 of file net.cpp.

deque<pair<int64_t, CInv> > vRelayExpiration

Definition at line 66 of file net.cpp.