MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / findHashIds

Method findHashIds

src/Peer/Peer.py:321–344  ·  view source on GitHub ↗
(self, hash_ids)

Source from the content-addressed store, hash-verified

319 # Find peers for hashids
320 # Return: {hash1: ["ip:port", "ip:port",...],...}
321 def findHashIds(self, hash_ids):
322 res = self.request("findHashIds", {"site": self.site.address, "hash_ids": hash_ids})
323 if not res or "error" in res or type(res) is not dict:
324 return False
325
326 back = collections.defaultdict(list)
327
328 for ip_type in ["ipv4", "ipv6", "onion"]:
329 if ip_type == "ipv4":
330 key = "peers"
331 else:
332 key = "peers_%s" % ip_type
333 for hash, peers in list(res.get(key, {}).items())[0:30]:
334 if ip_type == "onion":
335 unpacker_func = helper.unpackOnionAddress
336 else:
337 unpacker_func = helper.unpackAddress
338
339 back[hash] += list(map(unpacker_func, peers))
340
341 for hash in res.get("my", []):
342 back[hash].append((self.connection.ip, self.connection.port))
343
344 return back
345
346 # Send my hashfield to peer
347 # Return: True if sent

Callers 2

testFindHashMethod · 0.45
testFindHashMethod · 0.45

Calls 3

requestMethod · 0.95
itemsMethod · 0.80
getMethod · 0.45

Tested by 2

testFindHashMethod · 0.36
testFindHashMethod · 0.36