From 25ef5733a7ecc59f60d2015ab356e44d413b3498 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 23 Aug 2021 23:12:52 +0200 Subject: [PATCH] Skip duplicates in the saved peers list --- src/p2p_server.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 50bcdaf..0879bee 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -310,7 +310,18 @@ void P2PServer::load_saved_peer_list() p.m_port = port; p.m_numFailedConnections = 0; } - m_peerList.push_back(p); + + bool already_added = false; + for (const Peer& peer : m_peerList) { + if ((peer.m_isV6 == p.m_isV6) && (peer.m_addr == p.m_addr)) { + already_added = true; + break; + } + } + + if (!already_added) { + m_peerList.push_back(p); + } }); LOGINFO(5, "peer list loaded (" << m_peerList.size() << " peers)"); }