![]() |
Master Core
v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
|
#include "net.h"
#include "addrman.h"
#include "chainparams.h"
#include "core.h"
#include "ui_interface.h"
#include <fcntl.h>
#include <boost/filesystem.hpp>
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) |
CNodeSignals & | GetNodeSignals () |
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) |
CNode * | FindNode (const CNetAddr &ip) |
CNode * | FindNode (std::string addrName) |
CNode * | FindNode (const CService &addr) |
CNode * | ConnectNode (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) |
#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().
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().
Definition at line 245 of file net.cpp.
References AddLocal(), and GetListenPort().
void AddOneShot | ( | string | strDest | ) |
Definition at line 88 of file net.cpp.
References LOCK.
Referenced by AppInit2(), ProcessOneShot(), and ThreadDNSAddressSeed().
void AddressCurrentlyConnected | ( | const CService & | addr | ) |
Definition at line 400 of file net.cpp.
References CAddrMan::Connected().
Referenced by ProcessMessage().
|
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().
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().
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().
|
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().
void DumpAddresses | ( | ) |
Definition at line 1219 of file net.cpp.
References GetTimeMillis(), LogPrint(), CAddrMan::size(), and CAddrDB::Write().
Referenced by StartNode(), and StopNode().
Definition at line 413 of file net.cpp.
References CNode::addr, and LOCK.
Referenced by ConnectNode(), and OpenNetworkConnection().
CNode* FindNode | ( | std::string | addrName | ) |
Definition at line 422 of file net.cpp.
References CNode::addrName, and LOCK.
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().
Definition at line 100 of file net.cpp.
References fNoListen, and LOCK.
Referenced by GetLocalAddress().
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().
bool GetMyExternalIP | ( | CNetAddr & | ipRet | ) |
Definition at line 346 of file net.cpp.
References GetMyExternalIP2(), and CNetAddr::IsValid().
Referenced by ThreadGetMyExternalIP().
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().
CNodeSignals& GetNodeSignals | ( | ) |
Definition at line 86 of file net.cpp.
References g_signals.
Referenced by AppInit2(), CNode::CNode(), Shutdown(), and CNode::~CNode().
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().
bool IsLimited | ( | const CNetAddr & | addr | ) |
Definition at line 265 of file net.cpp.
References CNetAddr::GetNetwork(), and IsLimited().
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().
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().
void MapPort | ( | bool | ) |
Definition at line 1154 of file net.cpp.
Referenced by OptionsModel::setData(), StartNode(), and StopNode().
|
static |
Definition at line 1452 of file net.cpp.
References CNode::nLastRecv.
Referenced by StartSync().
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().
|
static |
Definition at line 1230 of file net.cpp.
References AddOneShot(), LOCK, and OpenNetworkConnection().
Referenced by ThreadOpenConnections().
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().
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().
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().
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().
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().
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().
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().
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().
|
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().
bool StopNode | ( | ) |
Definition at line 1751 of file net.cpp.
References DumpAddresses(), LogPrintf, MapPort(), MAX_OUTBOUND_CONNECTIONS, MilliSleep(), and CSemaphore::post().
Referenced by Shutdown().
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().
void ThreadGetMyExternalIP | ( | ) |
Definition at line 386 of file net.cpp.
References AddLocal(), GetMyExternalIP(), LOCAL_HTTP, LogPrintf, and CNetAddr::ToStringIP().
Referenced by Discover().
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().
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().
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().
void ThreadSocketHandler | ( | ) |
Definition at line 738 of file net.cpp.
References CNode::AddRef(), CNode::Cleanup(), closesocket, CNode::CloseSocketDisconnect(), CNode::cs_inventory, CNode::cs_vRecvMsg, CNode::cs_vSend, CDataStream::empty(), CNode::fDisconnect, CNode::fInbound, CNode::fNetworkNode, CNode::GetRefCount(), GetTime(), CNode::GetTotalRecvSize(), CNode::grantOutbound, CNode::hSocket, INVALID_SOCKET, CNode::IsBanned(), LOCK, LogPrint(), LogPrintf, MilliSleep(), NetworkErrorString(), CNode::nLastRecv, CNode::nLastSend, CNode::nLastSendEmpty, CClientUIInterface::NotifyNumConnectionsChanged, CNode::nRecvBytes, CNode::nSendSize, CNode::nTimeConnected, ReceiveFloodSize(), CNode::ReceiveMsgBytes(), CNode::RecordBytesRecv(), CSemaphoreGrant::Release(), CNode::Release(), CService::SetSockAddr(), SOCKET_ERROR, SocketSendData(), CNode::ssSend, CService::ToString(), TRY_LOCK, uiInterface, vNodes, vNodesDisconnected, CNode::vRecvMsg, CNode::vSendMsg, WSAEINPROGRESS, WSAEINTR, WSAEMSGSIZE, WSAEWOULDBLOCK, and WSAGetLastError.
Referenced by StartNode().
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 |
CCriticalSection cs_setservAddNodeAddresses |
CCriticalSection cs_vAddedNodes |
Definition at line 77 of file net.cpp.
Referenced by addnode(), and getaddednodeinfo().
CCriticalSection cs_vNodes |
Definition at line 64 of file net.cpp.
Referenced by AcceptBlock(), CopyNodeStats(), getaddednodeinfo(), getconnectioncount(), ClientModel::getNumConnections(), ping(), ProcessMessage(), and SendMessages().
CCriticalSection cs_vOneShots |
bool fDiscover = true |
Definition at line 50 of file net.cpp.
Referenced by AddLocal(), AppInit2(), BindListenPort(), and Discover().
|
static |
Definition at line 85 of file net.cpp.
Referenced by AcceptToMemoryPool(), AddToBlockIndex(), ConnectBlock(), GetNodeSignals(), ProcessGetData(), ProcessMessage(), RegisterWallet(), SendMessages(), SyncWithWallets(), UnregisterAllWallets(), UnregisterWallet(), and UpdateTip().
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().
|
static |
Definition at line 42 of file net.cpp.
Referenced by StopNode().
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().
|
static |
Definition at line 56 of file net.cpp.
Referenced by CNetCleanup::~CNetCleanup().
|
static |
Definition at line 57 of file net.cpp.
Referenced by CNode::copyStats().
|
static |
Definition at line 82 of file net.cpp.
Referenced by CNetCleanup::~CNetCleanup().
vector<std::string> vAddedNodes |
Definition at line 76 of file net.cpp.
Referenced by addnode(), and getaddednodeinfo().
|
static |
Definition at line 55 of file net.cpp.
Referenced by IsLimited(), IsReachable(), and SetLimited().
|
static |
Definition at line 54 of file net.cpp.
Referenced by IsReachable(), and SetReachable().
vector<CNode*> vNodes |
Definition at line 63 of file net.cpp.
Referenced by AcceptBlock(), CopyNodeStats(), getaddednodeinfo(), getblocktemplate(), getconnectioncount(), getinfo(), getnetworkinfo(), ClientModel::getNumConnections(), ping(), ProcessMessage(), SendMessages(), ThreadMessageHandler(), and ThreadSocketHandler().
|
static |
Definition at line 736 of file net.cpp.
Referenced by ThreadSocketHandler().