Fix for known peers blank ip issue (#352)

Co-authored-by: ravinsp <33562092+ravinsp@users.noreply.github.com>
This commit is contained in:
Chalith Desaman
2021-11-25 11:53:32 +05:30
committed by GitHub
parent 6d158a9583
commit a2e85551b4
6 changed files with 26 additions and 7 deletions

View File

@@ -648,8 +648,14 @@ namespace msg::fbuf::p2pmsg
{
std::vector<flatbuffers::Offset<PeerProperties>> fbvec;
fbvec.reserve(peers.size());
for (auto peer : peers)
for (const auto &peer : peers)
{
if (peer.ip_port.host_address.empty())
{
LOG_DEBUG << "Skip sending peer with blank host address : " << peer.ip_port.to_string();
continue;
}
// Skipping the requestedc peer from the peer list response.
if (!skipping_ip_port.has_value() || peer.ip_port != skipping_ip_port.value())
fbvec.push_back(CreatePeerProperties(

View File

@@ -125,8 +125,9 @@ namespace p2p
ctx.server->req_known_remotes.erase(std::remove_if(ctx.server->req_known_remotes.begin(), ctx.server->req_known_remotes.end(),
[&](const p2p::peer_properties &peer)
{
return peer.ip_port.port == session.known_ipport->port;
}));
return peer.ip_port == session.known_ipport;
}),
ctx.server->req_known_remotes.end());
ctx.server->known_remote_count = ctx.server->req_known_remotes.size();
}
LOG_DEBUG << "Loopback connection detected: Removed self from the peer list.";
@@ -465,7 +466,7 @@ namespace p2p
* @param remove_peers Peers that must be removed from existing known peers.
* @param from The session that sent us the peer list.
*/
void merge_peer_list(const std::vector<peer_properties> *merge_peers, const std::vector<peer_properties> *remove_peers, const p2p::peer_comm_session *from)
void merge_peer_list(const std::string &caller, const std::vector<peer_properties> *merge_peers, const std::vector<peer_properties> *remove_peers, const p2p::peer_comm_session *from)
{
std::scoped_lock<std::mutex> lock(ctx.server->req_known_remotes_mutex);
@@ -473,6 +474,12 @@ namespace p2p
{
for (const peer_properties &peer : *merge_peers)
{
if (peer.ip_port.host_address.empty())
{
LOG_DEBUG << caller << " : Skip received peer with blank host address " << peer.ip_port.to_string() << " from " << peer.ip_port.to_string();
continue;
}
// If the peer address is indicated as empty, that is the entry for the peer who sent us this.
// We then fill that up with the host address we see for that peer.
// if (from && peer.ip_port.host_address.empty())

View File

@@ -237,7 +237,7 @@ namespace p2p
void update_known_peer_available_capacity(const conf::peer_ip_port &ip_port, const int16_t available_capacity, const uint64_t &timestamp);
void merge_peer_list(const std::vector<peer_properties> *merge_peers, const std::vector<peer_properties> *remove_peers, const p2p::peer_comm_session *from = NULL);
void merge_peer_list(const std::string &caller, const std::vector<peer_properties> *merge_peers, const std::vector<peer_properties> *remove_peers, const p2p::peer_comm_session *from = NULL);
void sort_known_remotes();

View File

@@ -151,6 +151,12 @@ namespace p2p
if (peer.available_capacity == 0)
continue;
if (peer.ip_port.host_address.empty())
{
LOG_DEBUG << "Skip connecting to known peer with blank host address " << peer.ip_port.to_string();
continue;
}
// Check if we are already connected to this remote party.
if (std::find(known_remotes.begin(), known_remotes.end(), peer.ip_port) != known_remotes.end())
continue;

View File

@@ -150,7 +150,7 @@ namespace p2p
if (mi.type == p2pmsg::P2PMsgContent_PeerListResponseMsg)
{
const std::vector<p2p::peer_properties> merge_peers = p2pmsg::create_peer_list_response_from_msg(mi);
p2p::merge_peer_list(&merge_peers, NULL, &session);
p2p::merge_peer_list("Peer_Discovery", &merge_peers, NULL, &session);
}
else if (mi.type == p2pmsg::P2PMsgContent_PeerListRequestMsg)
{

View File

@@ -1099,7 +1099,7 @@ namespace sc
std::vector<p2p::peer_properties> added_peers;
std::vector<p2p::peer_properties> removed_peers;
if (parser.extract_peer_changeset(added_peers, removed_peers) != -1)
p2p::merge_peer_list(&added_peers, &removed_peers);
p2p::merge_peer_list("Control_MSG", &added_peers, &removed_peers);
}
}