Support ipv6 in findHashIds response parsing

This commit is contained in:
shortcutme 2019-01-20 16:27:12 +01:00
parent 33cf30a07b
commit 06d679d1ca
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -310,13 +310,23 @@ class Peer(object):
res = self.request("findHashIds", {"site": self.site.address, "hash_ids": hash_ids}) res = self.request("findHashIds", {"site": self.site.address, "hash_ids": hash_ids})
if not res or "error" in res or type(res) is not dict: if not res or "error" in res or type(res) is not dict:
return False return False
# Unpack IP4
back = {key: map(helper.unpackAddress, val) for key, val in res["peers"].items()[0:30]} back = {}
# Unpack onion
for hash, onion_peers in res.get("peers_onion", {}).items()[0:30]: for ip_type in ["ipv4", "ipv6", "onion"]:
if ip_type == "ipv4":
key = "peers"
else:
key = "peers_%s" % ip_type
for hash, peers in res.get(key, {}).items()[0:30]:
if hash not in back: if hash not in back:
back[hash] = [] back[hash] = []
back[hash] += map(helper.unpackOnionAddress, onion_peers) if ip_type == "onion":
unpacker_func = helper.unpackOnionAddress
else:
unpacker_func = helper.unpackAddress
back[hash] += map(unpacker_func, peers)
return back return back