| 2582 | } |
| 2583 | |
| 2584 | void 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; |