Save last received update time from peer to avoid send the same update on publish
This commit is contained in:
parent
646eba930f
commit
c8b949cef5
3 changed files with 11 additions and 2 deletions
|
@ -117,6 +117,7 @@ class FileRequest(object):
|
|||
else:
|
||||
peer = site.addPeer(self.connection.ip, self.connection.port, return_peer=True) # Add or get peer
|
||||
if peer:
|
||||
peer.last_content_json_update = site.content_manager.contents[params["inner_path"]]["modified"]
|
||||
if config.verbose:
|
||||
self.log.debug(
|
||||
"Same version, adding new peer for locked files: %s, tasks: %s" %
|
||||
|
@ -130,7 +131,7 @@ class FileRequest(object):
|
|||
self.response({"ok": "File not changed"})
|
||||
self.connection.badAction()
|
||||
|
||||
else: # Invalid sign or sha1 hash
|
||||
else: # Invalid sign or sha hash
|
||||
self.log.debug("Update for %s is invalid" % params["inner_path"])
|
||||
self.response({"error": "File invalid"})
|
||||
self.connection.badAction(5)
|
||||
|
|
|
@ -18,7 +18,7 @@ if config.use_tempfiles:
|
|||
class Peer(object):
|
||||
__slots__ = (
|
||||
"ip", "port", "site", "key", "connection", "connection_server", "time_found", "time_response", "time_hashfield", "time_added",
|
||||
"time_my_hashfield_sent", "last_ping", "hashfield", "connection_error", "hash_failed", "download_bytes", "download_time"
|
||||
"time_my_hashfield_sent", "last_ping", "last_content_json_update", "hashfield", "connection_error", "hash_failed", "download_bytes", "download_time"
|
||||
)
|
||||
|
||||
def __init__(self, ip, port, site=None, connection_server=None):
|
||||
|
@ -36,6 +36,7 @@ class Peer(object):
|
|||
self.time_response = None # Time of last successful response from peer
|
||||
self.time_added = time.time()
|
||||
self.last_ping = None # Last response time for ping
|
||||
self.last_content_json_update = 0.0 # Modify date of last received content.json
|
||||
|
||||
self.connection_error = 0 # Series of connection error
|
||||
self.hash_failed = 0 # Number of bad files from peer
|
||||
|
|
|
@ -123,6 +123,9 @@ class Site(object):
|
|||
self.log.debug("Got %s" % inner_path)
|
||||
changed, deleted = self.content_manager.loadContent(inner_path, load_includes=False)
|
||||
|
||||
if peer: # Update last received update from peer to prevent re-sending the same update to it
|
||||
peer.last_content_json_update = self.content_manager.contents[inner_path]["modified"]
|
||||
|
||||
# Start download files
|
||||
file_threads = []
|
||||
if download_files:
|
||||
|
@ -309,6 +312,7 @@ class Site(object):
|
|||
# Publish worker
|
||||
def publisher(self, inner_path, peers, published, limit, event_done=None):
|
||||
file_size = self.storage.getSize(inner_path)
|
||||
content_json_modified = self.content_manager.contents[inner_path]["modified"]
|
||||
body = self.storage.read(inner_path)
|
||||
|
||||
# Find out my ip and port
|
||||
|
@ -333,6 +337,9 @@ class Site(object):
|
|||
peer = peers.pop(0)
|
||||
if peer in published:
|
||||
continue
|
||||
if peer.last_content_json_update == content_json_modified:
|
||||
self.log.debug("%s already received this update for %s, skipping" % (peer, inner_path))
|
||||
continue
|
||||
|
||||
if peer.connection and peer.connection.last_ping_delay: # Peer connected
|
||||
# Timeout: 5sec + size in kb + last_ping
|
||||
|
|
Loading…
Reference in a new issue