Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 928 Lines • ▼ Show 20 Lines | |||||
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) { | void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CNodeState *state = State(node); | CNodeState *state = State(node); | ||||
if (state) { | if (state) { | ||||
state->m_last_block_announcement = time_in_seconds; | state->m_last_block_announcement = time_in_seconds; | ||||
} | } | ||||
} | } | ||||
// Returns true for outbound peers, excluding manual connections, feelers, and | |||||
// one-shots. | |||||
static bool IsOutboundDisconnectionCandidate(const CNode &node) { | static bool IsOutboundDisconnectionCandidate(const CNode &node) { | ||||
return !(node.fInbound || node.m_manual_connection || node.fFeeler || | return !(node.fInbound || node.IsManualConn() || node.fFeeler || | ||||
node.m_addr_fetch); | node.m_addr_fetch); | ||||
} | } | ||||
void PeerLogicValidation::InitializeNode(const Config &config, CNode *pnode) { | void PeerLogicValidation::InitializeNode(const Config &config, CNode *pnode) { | ||||
CAddress addr = pnode->addr; | CAddress addr = pnode->addr; | ||||
std::string addrName = pnode->GetAddrName(); | std::string addrName = pnode->GetAddrName(); | ||||
NodeId nodeid = pnode->GetId(); | NodeId nodeid = pnode->GetId(); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
mapNodeState.emplace_hint( | mapNodeState.emplace_hint( | ||||
mapNodeState.end(), std::piecewise_construct, | mapNodeState.end(), std::piecewise_construct, | ||||
std::forward_as_tuple(nodeid), | std::forward_as_tuple(nodeid), | ||||
std::forward_as_tuple(addr, std::move(addrName), pnode->fInbound, | std::forward_as_tuple(addr, std::move(addrName), pnode->fInbound, | ||||
pnode->m_manual_connection)); | pnode->IsManualConn())); | ||||
} | } | ||||
if (!pnode->fInbound) { | if (!pnode->fInbound) { | ||||
PushNodeVersion(config, *pnode, *connman, GetTime()); | PushNodeVersion(config, *pnode, *connman, GetTime()); | ||||
} | } | ||||
} | } | ||||
void PeerLogicValidation::FinalizeNode(const Config &config, NodeId nodeid, | void PeerLogicValidation::FinalizeNode(const Config &config, NodeId nodeid, | ||||
bool &fUpdateConnectionTime) { | bool &fUpdateConnectionTime) { | ||||
▲ Show 20 Lines • Show All 1,571 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::VERSION) { | ||||
bool fRelay = true; | bool fRelay = true; | ||||
vRecv >> nVersion >> nServiceInt >> nTime >> addrMe; | vRecv >> nVersion >> nServiceInt >> nTime >> addrMe; | ||||
nSendVersion = std::min(nVersion, PROTOCOL_VERSION); | nSendVersion = std::min(nVersion, PROTOCOL_VERSION); | ||||
nServices = ServiceFlags(nServiceInt); | nServices = ServiceFlags(nServiceInt); | ||||
if (!pfrom.fInbound) { | if (!pfrom.fInbound) { | ||||
connman.SetServices(pfrom.addr, nServices); | connman.SetServices(pfrom.addr, nServices); | ||||
} | } | ||||
if (!pfrom.fInbound && !pfrom.fFeeler && !pfrom.m_manual_connection && | if (!pfrom.fInbound && !pfrom.fFeeler && !pfrom.IsManualConn() && | ||||
!HasAllDesirableServiceFlags(nServices)) { | !HasAllDesirableServiceFlags(nServices)) { | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"peer=%d does not offer the expected services " | "peer=%d does not offer the expected services " | ||||
"(%08x offered, %08x expected); disconnecting\n", | "(%08x offered, %08x expected); disconnecting\n", | ||||
pfrom.GetId(), nServices, | pfrom.GetId(), nServices, | ||||
GetDesirableServiceFlags(nServices)); | GetDesirableServiceFlags(nServices)); | ||||
pfrom.fDisconnect = true; | pfrom.fDisconnect = true; | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 1,645 Lines • ▼ Show 20 Lines | bool PeerLogicValidation::CheckIfBanned(CNode &pnode) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
CNodeState &state = *State(pnode.GetId()); | CNodeState &state = *State(pnode.GetId()); | ||||
if (state.m_should_discourage) { | if (state.m_should_discourage) { | ||||
state.m_should_discourage = false; | state.m_should_discourage = false; | ||||
if (pnode.HasPermission(PF_NOBAN)) { | if (pnode.HasPermission(PF_NOBAN)) { | ||||
LogPrintf("Warning: not punishing whitelisted peer %s!\n", | LogPrintf("Warning: not punishing whitelisted peer %s!\n", | ||||
pnode.addr.ToString()); | pnode.addr.ToString()); | ||||
} else if (pnode.m_manual_connection) { | } else if (pnode.IsManualConn()) { | ||||
LogPrintf("Warning: not punishing manually-connected peer %s!\n", | LogPrintf("Warning: not punishing manually-connected peer %s!\n", | ||||
pnode.addr.ToString()); | pnode.addr.ToString()); | ||||
} else if (pnode.addr.IsLocal()) { | } else if (pnode.addr.IsLocal()) { | ||||
// Disconnect but don't discourage this local node | // Disconnect but don't discourage this local node | ||||
LogPrintf( | LogPrintf( | ||||
"Warning: disconnecting but not discouraging local peer %s!\n", | "Warning: disconnecting but not discouraging local peer %s!\n", | ||||
pnode.addr.ToString()); | pnode.addr.ToString()); | ||||
pnode.fDisconnect = true; | pnode.fDisconnect = true; | ||||
▲ Show 20 Lines • Show All 1,075 Lines • Show Last 20 Lines |