Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 2,257 Lines • ▼ Show 20 Lines | void PeerManagerImpl::PushNodeVersion(const Config &config, CNode &pnode, | ||||
| uint64_t your_services{addr.nServices}; | uint64_t your_services{addr.nServices}; | ||||
| const bool tx_relay{!RejectIncomingTxs(pnode)}; | const bool tx_relay{!RejectIncomingTxs(pnode)}; | ||||
| m_connman.PushMessage( | m_connman.PushMessage( | ||||
| // your_services, addr_you: Together the pre-version-31402 serialization | // your_services, addr_you: Together the pre-version-31402 serialization | ||||
| // of CAddress "addrYou" (without nTime) | // of CAddress "addrYou" (without nTime) | ||||
| // my_services, CService(): Together the pre-version-31402 serialization | // my_services, CService(): Together the pre-version-31402 serialization | ||||
| // of CAddress "addrMe" (without nTime) | // of CAddress "addrMe" (without nTime) | ||||
| &pnode, CNetMsgMaker(INIT_PROTO_VERSION) | &pnode, | ||||
| .Make(NetMsgType::VERSION, PROTOCOL_VERSION, my_services, | CNetMsgMaker(INIT_PROTO_VERSION) | ||||
| nTime, your_services, addr_you, my_services, | .Make(NetMsgType::VERSION, PROTOCOL_VERSION, my_services, nTime, | ||||
| CService(), nonce, userAgent(config), | your_services, WithParams(CNetAddr::V1, addr_you), | ||||
| nNodeStartingHeight, tx_relay, extraEntropy)); | my_services, WithParams(CNetAddr::V1, CService{}), nonce, | ||||
| userAgent(config), nNodeStartingHeight, tx_relay, | |||||
| extraEntropy)); | |||||
| if (fLogIPs) { | if (fLogIPs) { | ||||
| LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
| "send version message: version %d, blocks=%d, them=%s, " | "send version message: version %d, blocks=%d, them=%s, " | ||||
| "txrelay=%d, peer=%d\n", | "txrelay=%d, peer=%d\n", | ||||
| PROTOCOL_VERSION, nNodeStartingHeight, addr_you.ToString(), | PROTOCOL_VERSION, nNodeStartingHeight, addr_you.ToString(), | ||||
| tx_relay, nodeid); | tx_relay, nodeid); | ||||
| } else { | } else { | ||||
| ▲ Show 20 Lines • Show All 2,677 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::VERSION) { | ||||
| uint64_t nExtraEntropy = 1; | uint64_t nExtraEntropy = 1; | ||||
| vRecv >> nVersion >> Using<CustomUintFormatter<8>>(nServices) >> nTime; | vRecv >> nVersion >> Using<CustomUintFormatter<8>>(nServices) >> nTime; | ||||
| if (nTime < 0) { | if (nTime < 0) { | ||||
| nTime = 0; | nTime = 0; | ||||
| } | } | ||||
| // Ignore the addrMe service bits sent by the peer | // Ignore the addrMe service bits sent by the peer | ||||
| vRecv.ignore(8); | vRecv.ignore(8); | ||||
| vRecv >> addrMe; | vRecv >> WithParams(CNetAddr::V1, addrMe); | ||||
| if (!pfrom.IsInboundConn()) { | if (!pfrom.IsInboundConn()) { | ||||
| m_addrman.SetServices(pfrom.addr, nServices); | m_addrman.SetServices(pfrom.addr, nServices); | ||||
| } | } | ||||
| if (pfrom.ExpectServicesFromConn() && | if (pfrom.ExpectServicesFromConn() && | ||||
| !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", | ||||
| ▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | void PeerManagerImpl::ProcessMessage( | ||||
| if (!pfrom.fSuccessfullyConnected) { | if (!pfrom.fSuccessfullyConnected) { | ||||
| // Must have a verack message before anything else | // Must have a verack message before anything else | ||||
| Misbehaving(*peer, "non-verack message before version handshake"); | Misbehaving(*peer, "non-verack message before version handshake"); | ||||
| return; | return; | ||||
| } | } | ||||
| if (msg_type == NetMsgType::ADDR || msg_type == NetMsgType::ADDRV2) { | if (msg_type == NetMsgType::ADDR || msg_type == NetMsgType::ADDRV2) { | ||||
| int stream_version = vRecv.GetVersion(); | const auto ser_params{ | ||||
| if (msg_type == NetMsgType::ADDRV2) { | msg_type == NetMsgType::ADDRV2 | ||||
| // Add ADDRV2_FORMAT to the version so that the CNetAddr and | ? | ||||
| // CAddress unserialize methods know that an address in v2 format is | // Set V2 param so that the CNetAddr and CAddress unserialize | ||||
| // coming. | // methods know that an address in v2 format is coming. | ||||
| stream_version |= ADDRV2_FORMAT; | CAddress::V2_NETWORK | ||||
| } | : CAddress::V1_NETWORK, | ||||
| }; | |||||
| OverrideStream<CDataStream> s(&vRecv, vRecv.GetType(), stream_version); | |||||
| std::vector<CAddress> vAddr; | std::vector<CAddress> vAddr; | ||||
| s >> vAddr; | vRecv >> WithParams(ser_params, vAddr); | ||||
| if (!SetupAddressRelay(pfrom, *peer)) { | if (!SetupAddressRelay(pfrom, *peer)) { | ||||
| LogPrint(BCLog::NET, "ignoring %s message from %s peer=%d\n", | LogPrint(BCLog::NET, "ignoring %s message from %s peer=%d\n", | ||||
| msg_type, pfrom.ConnectionTypeAsString(), pfrom.GetId()); | msg_type, pfrom.ConnectionTypeAsString(), pfrom.GetId()); | ||||
| return; | return; | ||||
| } | } | ||||
| if (vAddr.size() > m_opts.max_addr_to_send) { | if (vAddr.size() > m_opts.max_addr_to_send) { | ||||
| ▲ Show 20 Lines • Show All 3,259 Lines • ▼ Show 20 Lines | peer.m_addrs_to_send.erase(std::remove_if(peer.m_addrs_to_send.begin(), | ||||
| peer.m_addrs_to_send.end()); | peer.m_addrs_to_send.end()); | ||||
| // No addr messages to send | // No addr messages to send | ||||
| if (peer.m_addrs_to_send.empty()) { | if (peer.m_addrs_to_send.empty()) { | ||||
| return; | return; | ||||
| } | } | ||||
| const char *msg_type; | const char *msg_type; | ||||
| int make_flags; | CNetAddr::Encoding ser_enc; | ||||
| if (peer.m_wants_addrv2) { | if (peer.m_wants_addrv2) { | ||||
| msg_type = NetMsgType::ADDRV2; | msg_type = NetMsgType::ADDRV2; | ||||
| make_flags = ADDRV2_FORMAT; | ser_enc = CNetAddr::Encoding::V2; | ||||
| } else { | } else { | ||||
| msg_type = NetMsgType::ADDR; | msg_type = NetMsgType::ADDR; | ||||
| make_flags = 0; | ser_enc = CNetAddr::Encoding::V1; | ||||
| } | } | ||||
| m_connman.PushMessage( | m_connman.PushMessage( | ||||
| &node, CNetMsgMaker(node.GetCommonVersion()) | &node, | ||||
| .Make(make_flags, msg_type, peer.m_addrs_to_send)); | CNetMsgMaker(node.GetCommonVersion()) | ||||
| .Make(msg_type, | |||||
| WithParams( | |||||
| CAddress::SerParams{{ser_enc}, CAddress::Format::Network}, | |||||
| peer.m_addrs_to_send))); | |||||
| peer.m_addrs_to_send.clear(); | peer.m_addrs_to_send.clear(); | ||||
| // we only send the big addr message once | // we only send the big addr message once | ||||
| if (peer.m_addrs_to_send.capacity() > 40) { | if (peer.m_addrs_to_send.capacity() > 40) { | ||||
| peer.m_addrs_to_send.shrink_to_fit(); | peer.m_addrs_to_send.shrink_to_fit(); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 947 Lines • Show Last 20 Lines | |||||