(self, since=None)
| 402 | # Check modified content.json files from peers and add modified files to bad_files |
| 403 | # Return: Successfully queried peers [Peer, Peer...] |
| 404 | def checkModifications(self, since=None): |
| 405 | s = time.time() |
| 406 | peers_try = [] # Try these peers |
| 407 | queried = [] # Successfully queried from these peers |
| 408 | limit = 5 |
| 409 | |
| 410 | # Wait for peers |
| 411 | if not self.peers: |
| 412 | self.announce() |
| 413 | for wait in range(10): |
| 414 | time.sleep(5 + wait) |
| 415 | self.log.debug("Waiting for peers...") |
| 416 | if self.peers: |
| 417 | break |
| 418 | |
| 419 | peers_try = self.getConnectedPeers() |
| 420 | peers_connected_num = len(peers_try) |
| 421 | if peers_connected_num < limit * 2: # Add more, non-connected peers if necessary |
| 422 | peers_try += self.getRecentPeers(limit * 5) |
| 423 | |
| 424 | if since is None: # No since defined, download from last modification time-1day |
| 425 | since = self.settings.get("modified", 60 * 60 * 24) - 60 * 60 * 24 |
| 426 | |
| 427 | if config.verbose: |
| 428 | self.log.debug( |
| 429 | "Try to get listModifications from peers: %s, connected: %s, since: %s" % |
| 430 | (peers_try, peers_connected_num, since) |
| 431 | ) |
| 432 | |
| 433 | updaters = [] |
| 434 | for i in range(3): |
| 435 | updaters.append(gevent.spawn(self.updater, peers_try, queried, since)) |
| 436 | |
| 437 | gevent.joinall(updaters, timeout=10) # Wait 10 sec to workers done query modifications |
| 438 | |
| 439 | if not queried: # Start another 3 thread if first 3 is stuck |
| 440 | peers_try[0:0] = [peer for peer in self.getConnectedPeers() if peer.connection.connected] # Add connected peers |
| 441 | for _ in range(10): |
| 442 | gevent.joinall(updaters, timeout=10) # Wait another 10 sec if none of updaters finished |
| 443 | if queried: |
| 444 | break |
| 445 | |
| 446 | self.log.debug("Queried listModifications from: %s in %.3fs since %s" % (queried, time.time() - s, since)) |
| 447 | time.sleep(0.1) |
| 448 | return queried |
| 449 | |
| 450 | # Update content.json from peers and download changed files |
| 451 | # Return: None |
no test coverage detected