Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
// | // | ||||
bool fDiscover = true; | bool fDiscover = true; | ||||
bool fListen = true; | bool fListen = true; | ||||
bool fRelayTxes = true; | bool fRelayTxes = true; | ||||
CCriticalSection cs_mapLocalHost; | CCriticalSection cs_mapLocalHost; | ||||
std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); | std::map<CNetAddr, LocalServiceInfo> mapLocalHost GUARDED_BY(cs_mapLocalHost); | ||||
static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {}; | static bool vfLimited[NET_MAX] GUARDED_BY(cs_mapLocalHost) = {}; | ||||
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ); | |||||
void CConnman::AddOneShot(const std::string &strDest) { | void CConnman::AddOneShot(const std::string &strDest) { | ||||
LOCK(cs_vOneShots); | LOCK(cs_vOneShots); | ||||
vOneShots.push_back(strDest); | vOneShots.push_back(strDest); | ||||
} | } | ||||
unsigned short GetListenPort() { | unsigned short GetListenPort() { | ||||
return (unsigned short)(gArgs.GetArg("-port", Params().GetDefaultPort())); | return (unsigned short)(gArgs.GetArg("-port", Params().GetDefaultPort())); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,589 Lines • ▼ Show 20 Lines | if (fLogIPs) { | ||||
LogPrint(BCLog::NET, "Added connection peer=%d\n", id); | LogPrint(BCLog::NET, "Added connection peer=%d\n", id); | ||||
} | } | ||||
} | } | ||||
CNode::~CNode() { | CNode::~CNode() { | ||||
CloseSocket(hSocket); | CloseSocket(hSocket); | ||||
} | } | ||||
void CNode::AskFor(const CInv &inv) { | |||||
if (mapAskFor.size() > MAPASKFOR_MAX_SZ || | |||||
setAskFor.size() > SETASKFOR_MAX_SZ) { | |||||
return; | |||||
} | |||||
// a peer may not have multiple non-responded queue positions for a single | |||||
// inv item. | |||||
if (!setAskFor.insert(inv.hash).second) { | |||||
return; | |||||
} | |||||
// We're using mapAskFor as a priority queue, the key is the earliest time | |||||
// the request can be sent. | |||||
int64_t nRequestTime; | |||||
limitedmap<uint256, int64_t>::const_iterator it = | |||||
mapAlreadyAskedFor.find(inv.hash); | |||||
if (it != mapAlreadyAskedFor.end()) { | |||||
nRequestTime = it->second; | |||||
} else { | |||||
nRequestTime = 0; | |||||
} | |||||
LogPrint(BCLog::NET, "askfor %s %d (%s) peer=%d\n", inv.ToString(), | |||||
nRequestTime, FormatISO8601DateTime(nRequestTime / 1000000), id); | |||||
// Make sure not to reuse time indexes to keep things in the same order | |||||
int64_t nNow = GetTimeMicros() - 1000000; | |||||
static int64_t nLastTime; | |||||
++nLastTime; | |||||
nNow = std::max(nNow, nLastTime); | |||||
nLastTime = nNow; | |||||
// Each retry is 2 minutes after the last | |||||
nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow); | |||||
if (it != mapAlreadyAskedFor.end()) { | |||||
mapAlreadyAskedFor.update(it, nRequestTime); | |||||
} else { | |||||
mapAlreadyAskedFor.insert(std::make_pair(inv.hash, nRequestTime)); | |||||
} | |||||
mapAskFor.insert(std::make_pair(nRequestTime, inv)); | |||||
} | |||||
bool CConnman::NodeFullyConnected(const CNode *pnode) { | bool CConnman::NodeFullyConnected(const CNode *pnode) { | ||||
return pnode && pnode->fSuccessfullyConnected && !pnode->fDisconnect; | return pnode && pnode->fSuccessfullyConnected && !pnode->fDisconnect; | ||||
} | } | ||||
void CConnman::PushMessage(CNode *pnode, CSerializedNetMsg &&msg) { | void CConnman::PushMessage(CNode *pnode, CSerializedNetMsg &&msg) { | ||||
size_t nMessageSize = msg.data.size(); | size_t nMessageSize = msg.data.size(); | ||||
size_t nTotalSize = nMessageSize + CMessageHeader::HEADER_SIZE; | size_t nTotalSize = nMessageSize + CMessageHeader::HEADER_SIZE; | ||||
LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", | LogPrint(BCLog::NET, "sending %s (%d bytes) peer=%d\n", | ||||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |