(self, optional_tasks, reset_task=False)
| 216 | |
| 217 | # Find peers for optional hash in local hash tables and add to task peers |
| 218 | def findOptionalTasks(self, optional_tasks, reset_task=False): |
| 219 | found = collections.defaultdict(list) # { found_hash: [peer1, peer2...], ...} |
| 220 | |
| 221 | for peer in list(self.site.peers.values()): |
| 222 | if not peer.has_hashfield: |
| 223 | continue |
| 224 | |
| 225 | hashfield_set = set(peer.hashfield) # Finding in set is much faster |
| 226 | for task in optional_tasks: |
| 227 | optional_hash_id = task["optional_hash_id"] |
| 228 | if optional_hash_id in hashfield_set: |
| 229 | if reset_task and len(task["failed"]) > 0: |
| 230 | task["failed"] = [] |
| 231 | if peer in task["failed"]: |
| 232 | continue |
| 233 | if self.taskAddPeer(task, peer): |
| 234 | found[optional_hash_id].append(peer) |
| 235 | |
| 236 | return found |
| 237 | |
| 238 | # Find peers for optional hash ids in local hash tables |
| 239 | def findOptionalHashIds(self, optional_hash_ids, limit=0): |
no test coverage detected