MCPcopy Create free account
hub / github.com/ElementsProject/elements / ProcessMessage

Method ProcessMessage

src/net_processing.cpp:2584–4147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2582}
2583
2584void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
2585 const std::chrono::microseconds time_received,
2586 const std::atomic<bool>& interruptMsgProc)
2587{
2588 LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom.GetId());
2589
2590 PeerRef peer = GetPeerRef(pfrom.GetId());
2591 if (peer == nullptr) return;
2592
2593 if (msg_type == NetMsgType::VERSION) {
2594 if (pfrom.nVersion != 0) {
2595 LogPrint(BCLog::NET, "redundant version message from peer=%d\n", pfrom.GetId());
2596 return;
2597 }
2598
2599 int64_t nTime;
2600 CService addrMe;
2601 uint64_t nNonce = 1;
2602 ServiceFlags nServices;
2603 int nVersion;
2604 std::string cleanSubVer;
2605 int starting_height = -1;
2606 bool fRelay = true;
2607
2608 vRecv >> nVersion >> Using<CustomUintFormatter<8>>(nServices) >> nTime;
2609 if (nTime < 0) {
2610 nTime = 0;
2611 }
2612 vRecv.ignore(8); // Ignore the addrMe service bits sent by the peer
2613 vRecv >> addrMe;
2614 if (!pfrom.IsInboundConn())
2615 {
2616 m_addrman.SetServices(pfrom.addr, nServices);
2617 }
2618 if (pfrom.ExpectServicesFromConn() && !HasAllDesirableServiceFlags(nServices))
2619 {
2620 LogPrint(BCLog::NET, "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom.GetId(), nServices, GetDesirableServiceFlags(nServices));
2621 pfrom.fDisconnect = true;
2622 return;
2623 }
2624
2625 if (nVersion < MIN_PEER_PROTO_VERSION) {
2626 // disconnect from peers older than this proto version
2627 LogPrint(BCLog::NET, "peer=%d using obsolete version %i; disconnecting\n", pfrom.GetId(), nVersion);
2628 pfrom.fDisconnect = true;
2629 return;
2630 }
2631
2632 if (!vRecv.empty()) {
2633 // The version message includes information about the sending node which we don't use:
2634 // - 8 bytes (service bits)
2635 // - 16 bytes (ipv6 address)
2636 // - 2 bytes (port)
2637 vRecv.ignore(26);
2638 vRecv >> nNonce;
2639 }
2640 if (!vRecv.empty()) {
2641 std::string strSubVer;

Callers 2

BOOST_AUTO_TEST_CASEFunction · 0.80
fuzz_targetFunction · 0.80

Calls 15

SanitizeStringFunction · 0.85
GetDesirableServiceFlagsFunction · 0.85
SeenLocalFunction · 0.85
GetLocalAddressFunction · 0.85
PushAddressFunction · 0.85
IsPeerAddrLocalGoodFunction · 0.85
CNetMsgMakerClass · 0.85
GetTimeFunction · 0.85
AddTimeDataFunction · 0.85
ParseHexFunction · 0.85
GetAdjustedTimeFunction · 0.85

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.64
fuzz_targetFunction · 0.64