Pass diffs to other users

This commit is contained in:
HelloZeroNet 2016-04-06 13:59:53 +02:00
parent 7c3e470ea7
commit 82b960c641
2 changed files with 7 additions and 4 deletions

View file

@ -101,11 +101,11 @@ class FileRequest(object):
if params["inner_path"].endswith("content.json"): # Download every changed file from peer if params["inner_path"].endswith("content.json"): # Download every changed file from peer
peer = site.addPeer(self.connection.ip, self.connection.port, return_peer=True) # Add or get peer peer = site.addPeer(self.connection.ip, self.connection.port, return_peer=True) # Add or get peer
# On complete publish to other peers # On complete publish to other peers
site.onComplete.once(lambda: site.publish(inner_path=params["inner_path"]), "publish_%s" % params["inner_path"]) site.onComplete.once(lambda: site.publish(inner_path=params["inner_path"], diffs=params.get("diffs", {})), "publish_%s" % params["inner_path"])
# Load new content file and download changed files in new thread # Load new content file and download changed files in new thread
gevent.spawn( gevent.spawn(
lambda: site.downloadContent(params["inner_path"], peer=peer) lambda: site.downloadContent(params["inner_path"], peer=peer, diffs=params.get("diffs", {}))
) )
self.response({"ok": "Thanks, file %s updated!" % params["inner_path"]}) self.response({"ok": "Thanks, file %s updated!" % params["inner_path"]})

View file

@ -313,14 +313,14 @@ class Site(object):
gevent.joinall(content_threads) gevent.joinall(content_threads)
# Publish worker # Publish worker
def publisher(self, inner_path, peers, published, limit, event_done=None): def publisher(self, inner_path, peers, published, limit, event_done=None, diffs={}):
file_size = self.storage.getSize(inner_path) file_size = self.storage.getSize(inner_path)
content_json_modified = self.content_manager.contents[inner_path]["modified"] content_json_modified = self.content_manager.contents[inner_path]["modified"]
body = self.storage.read(inner_path) body = self.storage.read(inner_path)
# Find out my ip and port # Find out my ip and port
tor_manager = self.connection_server.tor_manager tor_manager = self.connection_server.tor_manager
if tor_manager.enabled and tor_manager.start_onions: if tor_manager and tor_manager.enabled and tor_manager.start_onions:
my_ip = tor_manager.getOnion(self.address) my_ip = tor_manager.getOnion(self.address)
if my_ip: if my_ip:
my_ip += ".onion" my_ip += ".onion"
@ -359,11 +359,13 @@ class Site(object):
"site": self.address, "site": self.address,
"inner_path": inner_path, "inner_path": inner_path,
"body": body, "body": body,
"diffs": diffs,
"peer": (my_ip, my_port) "peer": (my_ip, my_port)
}) })
if result: if result:
break break
except Exception, err: except Exception, err:
self.log.error("Publish error: %s" % Debug.formatException(err))
result = {"exception": Debug.formatException(err)} result = {"exception": Debug.formatException(err)}
if result and "ok" in result: if result and "ok" in result:
@ -373,6 +375,7 @@ class Site(object):
if result == {"exception": "Timeout"}: if result == {"exception": "Timeout"}:
peer.onConnectionError() peer.onConnectionError()
self.log.info("[FAILED] %s: %s" % (peer.key, result)) self.log.info("[FAILED] %s: %s" % (peer.key, result))
time.sleep(0.01)
# Update content.json on peers # Update content.json on peers
@util.Noparallel() @util.Noparallel()