Remove legacy support for endpoint dissemination:

Support for IPv6 messages was added with commit 08382d866b
and version 1.1.0. No peer presently connected to the network in a useful capacity fails
to understand v2 messages.

This commit removes the code that generates and processes v1 messages and deletes legacy
messages from the protocol buffer definition file.
This commit is contained in:
Nik Bougalis
2020-07-21 20:39:33 -07:00
parent ab4102a632
commit 85fc1e8235
4 changed files with 31 additions and 118 deletions

View File

@@ -1371,84 +1371,34 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMPeerShardInfo> const& m)
void
PeerImp::onMessage(std::shared_ptr<protocol::TMEndpoints> 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<PeerFinder::Endpoint> 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())

View File

@@ -598,13 +598,6 @@ private:
void
getLedger(std::shared_ptr<protocol::TMGetLedger> const& packet);
// Called when we receive tx set data.
void
peerTXData(
uint256 const& hash,
std::shared_ptr<protocol::TMLedgerData> 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<std::uint32_t>(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);

View File

@@ -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

View File

@@ -180,15 +180,12 @@ public:
buildEndpoints(int n)
{
auto endpoints = std::make_shared<protocol::TMEndpoints>();
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);