(self, optional_hash_ids, limit=0)
| 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): |
no test coverage detected