MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / updater

Method updater

src/Site/Site.py:368–400  ·  view source on GitHub ↗
(self, peers_try, queried, since)

Source from the content-addressed store, hash-verified

366
367 # Update worker, try to find client that supports listModifications command
368 def updater(self, peers_try, queried, since):
369 while 1:
370 if not peers_try or len(queried) >= 3: # Stop after 3 successful query
371 break
372 peer = peers_try.pop(0)
373 if config.verbose:
374 self.log.debug("Try to get updates from: %s Left: %s" % (peer, peers_try))
375
376 res = None
377 with gevent.Timeout(20, exception=False):
378 res = peer.listModified(since)
379
380 if not res or "modified_files" not in res:
381 continue # Failed query
382
383 queried.append(peer)
384 modified_contents = []
385 my_modified = self.content_manager.listModified(since)
386 for inner_path, modified in res["modified_files"].items(): # Check if the peer has newer files than we
387 has_newer = int(modified) > my_modified.get(inner_path, 0)
388 has_older = int(modified) < my_modified.get(inner_path, 0)
389 if inner_path not in self.bad_files and not self.content_manager.isArchived(inner_path, modified):
390 if has_newer:
391 # We dont have this file or we have older
392 modified_contents.append(inner_path)
393 self.bad_files[inner_path] = self.bad_files.get(inner_path, 0) + 1
394 if has_older:
395 self.log.debug("%s client has older version of %s, publishing there..." % (peer, inner_path))
396 gevent.spawn(self.publisher, inner_path, [peer], [], 1)
397 if modified_contents:
398 self.log.debug("%s new modified file from %s" % (len(modified_contents), peer))
399 modified_contents.sort(key=lambda inner_path: 0 - res["modified_files"][inner_path]) # Download newest first
400 gevent.spawn(self.pooledDownloadContent, modified_contents, only_if_bad=True)
401
402 # Check modified content.json files from peers and add modified files to bad_files
403 # Return: Successfully queried peers [Peer, Peer...]

Callers

nothing calls this directly

Calls 4

itemsMethod · 0.80
isArchivedMethod · 0.80
listModifiedMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected