From 81bf3498715e688d287c89ce2007f648212698ff Mon Sep 17 00:00:00 2001 From: shortcutme Date: Sun, 24 Feb 2019 02:29:08 +0100 Subject: [PATCH] Remove ipv6 and onion from pex result if not supported --- src/Peer/Peer.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Peer/Peer.py b/src/Peer/Peer.py index 814481877..b999257e5 100644 --- a/src/Peer/Peer.py +++ b/src/Peer/Peer.py @@ -267,16 +267,28 @@ def pex(self, site=None, need_num=5): request["peers_onion"] = packed_peers["onion"] if packed_peers["ipv6"]: request["peers_ipv6"] = packed_peers["ipv6"] + res = self.request("pex", request) + if not res or "error" in res: return False + added = 0 + # Remove unsupported peer types + if "peers_ipv6" in res and "ipv6" not in self.connection.server.supported_ip_types: + del res["peers_ipv6"] + + if "peers_onion" in res and "onion" not in self.connection.server.supported_ip_types: + del res["peers_onion"] + + # Add IPv4 + IPv6 for peer in itertools.chain(res.get("peers", []), res.get("peers_ipv6", [])): address = helper.unpackAddress(peer) if site.addPeer(*address, source="pex"): added += 1 - # Onion + + # Add Onion for peer in res.get("peers_onion", []): address = helper.unpackOnionAddress(peer) if site.addPeer(*address, source="pex"):