Skip to content

Commit

Permalink
Remove ipv6 and onion from pex result if not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Feb 24, 2019
1 parent 9d849a1 commit 81bf349
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Peer/Peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit 81bf349

Please sign in to comment.