Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 2,743 Lines • ▼ Show 20 Lines | CSerializedNetMsg msg = CNetMsgMaker(peer.GetCommonVersion()) | ||||
.Make(NetMsgType::CFCHECKPT, filter_type_ser, | .Make(NetMsgType::CFCHECKPT, filter_type_ser, | ||||
stop_index->GetBlockHash(), headers); | stop_index->GetBlockHash(), headers); | ||||
connman.PushMessage(&peer, std::move(msg)); | connman.PushMessage(&peer, std::move(msg)); | ||||
} | } | ||||
bool IsAvalancheMessageType(const std::string &msg_type) { | bool IsAvalancheMessageType(const std::string &msg_type) { | ||||
return msg_type == NetMsgType::AVAHELLO || | return msg_type == NetMsgType::AVAHELLO || | ||||
msg_type == NetMsgType::AVAPOLL || | msg_type == NetMsgType::AVAPOLL || | ||||
msg_type == NetMsgType::AVARESPONSE; | msg_type == NetMsgType::AVARESPONSE || | ||||
msg_type == NetMsgType::AVAPROOF; | |||||
} | } | ||||
void PeerManager::ProcessMessage(const Config &config, CNode &pfrom, | void PeerManager::ProcessMessage(const Config &config, CNode &pfrom, | ||||
const std::string &msg_type, | const std::string &msg_type, | ||||
CDataStream &vRecv, | CDataStream &vRecv, | ||||
const std::chrono::microseconds time_received, | const std::chrono::microseconds time_received, | ||||
const std::atomic<bool> &interruptMsgProc) { | const std::atomic<bool> &interruptMsgProc) { | ||||
LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", | LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", | ||||
▲ Show 20 Lines • Show All 1,531 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::AVARESPONSE) { | ||||
LogPrint(BCLog::NET, "failed to activate chain (%s)\n", | LogPrint(BCLog::NET, "failed to activate chain (%s)\n", | ||||
state.ToString()); | state.ToString()); | ||||
} | } | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
if (msg_type == NetMsgType::AVAPROOF) { | |||||
auto proof = std::make_shared<avalanche::Proof>(); | |||||
vRecv >> *proof; | |||||
const avalanche::ProofId &proofid = proof->getId(); | |||||
pfrom.AddKnownProof(proofid); | |||||
const NodeId nodeid = pfrom.GetId(); | |||||
{ | |||||
LOCK(cs_proofrequest); | |||||
m_proofrequest.ReceivedResponse(nodeid, proofid); | |||||
if (AlreadyHaveProof(proofid)) { | |||||
m_proofrequest.ForgetInvId(proofid); | |||||
return; | |||||
} | |||||
} | |||||
// addProof should not be called while cs_proofrequest because it holds | |||||
// cs_main and that creates a potential deadlock during shutdown | |||||
if (g_avalanche->addProof(proof)) { | |||||
WITH_LOCK(cs_proofrequest, m_proofrequest.ForgetInvId(proofid)); | |||||
RelayProof(proofid, m_connman); | |||||
LogPrint(BCLog::NET, "New avalanche proof: peer=%d, proofid %s\n", | |||||
nodeid, proofid.ToString()); | |||||
} else { | |||||
// If the proof couldn't be added, it can be either orphan or | |||||
// invalid. In the latter case we should increase the ban score. | |||||
// TODO improve the ban reason by printing the validation state | |||||
if (!g_avalanche->getOrphan(proofid)) { | |||||
Misbehaving(nodeid, 100, "invalid-avaproof"); | |||||
} | |||||
} | |||||
return; | |||||
} | |||||
if (msg_type == NetMsgType::GETADDR) { | if (msg_type == NetMsgType::GETADDR) { | ||||
// This asymmetric behavior for inbound and outbound connections was | // This asymmetric behavior for inbound and outbound connections was | ||||
// introduced to prevent a fingerprinting attack: an attacker can send | // introduced to prevent a fingerprinting attack: an attacker can send | ||||
// specific fake addresses to users' AddrMan and later request them by | // specific fake addresses to users' AddrMan and later request them by | ||||
// sending getaddr messages. Making nodes which are behind NAT and can | // sending getaddr messages. Making nodes which are behind NAT and can | ||||
// only make outgoing connections ignore the getaddr message mitigates | // only make outgoing connections ignore the getaddr message mitigates | ||||
// the attack. | // the attack. | ||||
if (!pfrom.IsInboundConn()) { | if (!pfrom.IsInboundConn()) { | ||||
▲ Show 20 Lines • Show All 1,469 Lines • Show Last 20 Lines |