MCPcopy Create free account
hub / github.com/HelloZeroNet/ZeroNet / findOptionalHashIds

Method findOptionalHashIds

src/Worker/WorkerManager.py:239–253  ·  view source on GitHub ↗
(self, optional_hash_ids, limit=0)

Source from the content-addressed store, hash-verified

237
238 # Find peers for optional hash ids in local hash tables
239 def findOptionalHashIds(self, optional_hash_ids, limit=0):
240 found = collections.defaultdict(list) # { found_hash_id: [peer1, peer2...], ...}
241
242 for peer in list(self.site.peers.values()):
243 if not peer.has_hashfield:
244 continue
245
246 hashfield_set = set(peer.hashfield) # Finding in set is much faster
247 for optional_hash_id in optional_hash_ids:
248 if optional_hash_id in hashfield_set:
249 found[optional_hash_id].append(peer)
250 if limit and len(found[optional_hash_id]) >= limit:
251 optional_hash_ids.remove(optional_hash_id)
252
253 return found
254
255 # Add peers to tasks from found result
256 def addOptionalPeers(self, found_ips):

Callers 1

findHashIdsMethod · 0.80

Calls 2

valuesMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected