diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index b2b1a8145b..c7d2a3aadf 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -1371,84 +1371,34 @@ PeerImp::onMessage(std::shared_ptr const& m) void PeerImp::onMessage(std::shared_ptr const& m) { - if (sanity_.load() != Sanity::sane) - { - // Don't allow endpoints from peer not known sane + // Don't allow endpoints from peers that are not known sane or are + // not using a version of the message that we support: + if (sanity_.load() != Sanity::sane || m->version() != 2) return; - } std::vector endpoints; + endpoints.reserve(m->endpoints_v2().size()); - if (m->endpoints_v2().size()) + for (auto const& tm : m->endpoints_v2()) { - endpoints.reserve(m->endpoints_v2().size()); - for (auto const& tm : m->endpoints_v2()) + auto result = beast::IP::Endpoint::from_string_checked(tm.endpoint()); + if (!result) { - // these endpoint strings support ipv4 and ipv6 - auto result = - beast::IP::Endpoint::from_string_checked(tm.endpoint()); - if (!result) - { - JLOG(p_journal_.error()) - << "failed to parse incoming endpoint: {" << tm.endpoint() - << "}"; - continue; - } - - // If hops == 0, this Endpoint describes the peer we are connected - // to -- in that case, we take the remote address seen on the - // socket and store that in the IP::Endpoint. If this is the first - // time, then we'll verify that their listener can receive incoming - // by performing a connectivity test. if hops > 0, then we just - // take the address/port we were given - - endpoints.emplace_back( - tm.hops() > 0 ? *result - : remote_address_.at_port(result->port()), - tm.hops()); - JLOG(p_journal_.trace()) - << "got v2 EP: " << endpoints.back().address - << ", hops = " << endpoints.back().hops; + JLOG(p_journal_.error()) << "failed to parse incoming endpoint: {" + << tm.endpoint() << "}"; + continue; } - } - else - { - // this branch can be removed once the entire network is operating with - // endpoint_v2() items (strings) - endpoints.reserve(m->endpoints().size()); - for (int i = 0; i < m->endpoints().size(); ++i) - { - PeerFinder::Endpoint endpoint; - protocol::TMEndpoint const& tm(m->endpoints(i)); - // hops - endpoint.hops = tm.hops(); + // If hops == 0, this Endpoint describes the peer we are connected + // to -- in that case, we take the remote address seen on the + // socket and store that in the IP::Endpoint. If this is the first + // time, then we'll verify that their listener can receive incoming + // by performing a connectivity test. if hops > 0, then we just + // take the address/port we were given - // ipv4 - if (endpoint.hops > 0) - { - in_addr addr; - addr.s_addr = tm.ipv4().ipv4(); - beast::IP::AddressV4 v4(ntohl(addr.s_addr)); - endpoint.address = - beast::IP::Endpoint(v4, tm.ipv4().ipv4port()); - } - else - { - // This Endpoint describes the peer we are connected to. - // We will take the remote address seen on the socket and - // store that in the IP::Endpoint. If this is the first time, - // then we'll verify that their listener can receive incoming - // by performing a connectivity test. - // - endpoint.address = - remote_address_.at_port(tm.ipv4().ipv4port()); - } - endpoints.push_back(endpoint); - JLOG(p_journal_.trace()) - << "got v1 EP: " << endpoints.back().address - << ", hops = " << endpoints.back().hops; - } + endpoints.emplace_back( + tm.hops() > 0 ? *result : remote_address_.at_port(result->port()), + tm.hops()); } if (!endpoints.empty()) diff --git a/src/ripple/overlay/impl/PeerImp.h b/src/ripple/overlay/impl/PeerImp.h index e9937cdb06..489ac21ec2 100644 --- a/src/ripple/overlay/impl/PeerImp.h +++ b/src/ripple/overlay/impl/PeerImp.h @@ -598,13 +598,6 @@ private: void getLedger(std::shared_ptr const& packet); - - // Called when we receive tx set data. - void - peerTXData( - uint256 const& hash, - std::shared_ptr const& pPacket, - beast::Journal journal); }; //------------------------------------------------------------------------------ @@ -661,24 +654,13 @@ void PeerImp::sendEndpoints(FwdIt first, FwdIt last) { protocol::TMEndpoints tm; - for (; first != last; ++first) - { - auto const& ep = *first; - // eventually remove endpoints and just keep endpoints_v2 - // (once we are sure the entire network understands endpoints_v2) - protocol::TMEndpoint& tme(*tm.add_endpoints()); - if (ep.address.is_v4()) - tme.mutable_ipv4()->set_ipv4(boost::endian::native_to_big( - static_cast(ep.address.to_v4().to_ulong()))); - else - tme.mutable_ipv4()->set_ipv4(0); - tme.mutable_ipv4()->set_ipv4port(ep.address.port()); - tme.set_hops(ep.hops); - // add v2 endpoints (strings) + while (first != last) + { auto& tme2(*tm.add_endpoints_v2()); - tme2.set_endpoint(ep.address.to_string()); - tme2.set_hops(ep.hops); + tme2.set_endpoint(first->address.to_string()); + tme2.set_hops(first->hops); + first++; } tm.set_version(2); diff --git a/src/ripple/proto/ripple.proto b/src/ripple/proto/ripple.proto index fea849d89c..5de1cdf397 100644 --- a/src/ripple/proto/ripple.proto +++ b/src/ripple/proto/ripple.proto @@ -225,32 +225,16 @@ message TMValidation optional uint32 hops = 3 [deprecated = true]; } -message TMIPv4Endpoint -{ - required uint32 ipv4 = 1; - - // VFALCO NOTE There is no uint16 in google protocol buffers, - // so we use a uint32 to represent the port. - // - required uint32 ipv4Port = 2; -} - -// An Endpoint describes a network peer that can accept incoming connections -message TMEndpoint -{ - required TMIPv4Endpoint ipv4 = 1; - required uint32 hops = 2; -} - // An array of Endpoint messages message TMEndpoints { + // Previously used - don't reuse. + reserved 2; + // This field is used to allow the TMEndpoints message format to be // modified as necessary in the future. required uint32 version = 1; - repeated TMEndpoint endpoints = 2; - // An update to the Endpoint type that uses a string // to represent endpoints, thus allowing ipv6 or ipv4 addresses message TMEndpointv2 diff --git a/src/test/overlay/compression_test.cpp b/src/test/overlay/compression_test.cpp index 454b10136f..965fc7d6d1 100644 --- a/src/test/overlay/compression_test.cpp +++ b/src/test/overlay/compression_test.cpp @@ -180,15 +180,12 @@ public: buildEndpoints(int n) { auto endpoints = std::make_shared(); - endpoints->mutable_endpoints()->Reserve(n); + endpoints->mutable_endpoints_v2()->Reserve(n); for (int i = 0; i < n; i++) { - auto* endpoint = endpoints->add_endpoints(); - endpoint->set_hops(i); - std::string addr = std::string("10.0.1.") + std::to_string(i); - endpoint->mutable_ipv4()->set_ipv4(boost::endian::native_to_big( - boost::asio::ip::address_v4::from_string(addr).to_uint())); - endpoint->mutable_ipv4()->set_ipv4port(i); + auto ep = endpoints->add_endpoints_v2(); + ep->set_endpoint(std::string("10.0.1.") + std::to_string(i)); + ep->set_hops(i); } endpoints->set_version(2);