summaryrefslogtreecommitdiff
path: root/client/src/leap/soledad
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-11-30 12:21:56 -0400
committerKali Kaneko <kali@leap.se>2015-12-10 03:30:10 -0400
commit2ed8f2b64f3093255d03f282917eb88aac9ab124 (patch)
tree16c93d635b077af61019d74a8a81456bccea24ae /client/src/leap/soledad
parent27bda0ac201e236e3a2c9671462a337f2970e993 (diff)
[feat] use uuid in events, multi-user aware
- Resolves: #7656 - Releases: 0.8.0
Diffstat (limited to 'client/src/leap/soledad')
-rw-r--r--client/src/leap/soledad/client/api.py6
-rw-r--r--client/src/leap/soledad/client/http_target/__init__.py1
-rw-r--r--client/src/leap/soledad/client/http_target/api.py5
-rw-r--r--client/src/leap/soledad/client/http_target/fetch.py12
-rw-r--r--client/src/leap/soledad/client/http_target/send.py13
5 files changed, 28 insertions, 9 deletions
diff --git a/client/src/leap/soledad/client/api.py b/client/src/leap/soledad/client/api.py
index 8c5f7f1b..0d0d636c 100644
--- a/client/src/leap/soledad/client/api.py
+++ b/client/src/leap/soledad/client/api.py
@@ -102,11 +102,11 @@ class Soledad(object):
soledad starts to retrieve keys from server.
SOLEDAD_DONE_DOWNLOADING_KEYS: emitted during bootstrap sequence when
soledad finishes downloading keys from server.
- SOLEDAD_NEW_DATA_TO_SYNC: emitted upon call to C{need_sync()} when
- there's indeed new data to be synchronized between local database
- replica and server's replica.
SOLEDAD_DONE_DATA_SYNC: emitted inside C{sync()} method when it has
finished synchronizing with remote replica.
+ SOLEDAD_NEW_DATA_TO_SYNC: emitted upon call to C{need_sync()} when
+ there's indeed new data to be synchronized between local database
+ replica and server's replica. --- not used right now.
"""
implements(soledad_interfaces.ILocalStorage,
soledad_interfaces.ISyncableStorage,
diff --git a/client/src/leap/soledad/client/http_target/__init__.py b/client/src/leap/soledad/client/http_target/__init__.py
index 498fb6e7..a16531ef 100644
--- a/client/src/leap/soledad/client/http_target/__init__.py
+++ b/client/src/leap/soledad/client/http_target/__init__.py
@@ -79,6 +79,7 @@ class SoledadHTTPSyncTarget(SyncTargetAPI, HTTPDocSender, HTTPDocFetcher):
self._url = str(url) + "/sync-from/" + str(source_replica_uid)
self.source_replica_uid = source_replica_uid
self._auth_header = None
+ self._uuid = None
self.set_creds(creds)
self._crypto = crypto
self._sync_db = sync_db
diff --git a/client/src/leap/soledad/client/http_target/api.py b/client/src/leap/soledad/client/http_target/api.py
index dcc762f6..94354092 100644
--- a/client/src/leap/soledad/client/http_target/api.py
+++ b/client/src/leap/soledad/client/http_target/api.py
@@ -40,6 +40,10 @@ class SyncTargetAPI(SyncTarget):
self._sync_decr_pool.stop()
yield self._http.close()
+ @property
+ def uuid(self):
+ return self._uuid
+
def set_creds(self, creds):
"""
Update credentials.
@@ -49,6 +53,7 @@ class SyncTargetAPI(SyncTarget):
"""
uuid = creds['token']['uuid']
token = creds['token']['token']
+ self._uuid = uuid
auth = '%s:%s' % (uuid, token)
b64_token = base64.b64encode(auth)
self._auth_header = {'Authorization': ['Token %s' % b64_token]}
diff --git a/client/src/leap/soledad/client/http_target/fetch.py b/client/src/leap/soledad/client/http_target/fetch.py
index 65e576d9..087da3a3 100644
--- a/client/src/leap/soledad/client/http_target/fetch.py
+++ b/client/src/leap/soledad/client/http_target/fetch.py
@@ -39,6 +39,12 @@ class HTTPDocFetcher(object):
So we parse, decrypt and insert locally as they arrive.
"""
+ # The uuid of the local replica.
+ # Any class inheriting from this one should provide a meaningful attribute
+ # if the sync status event is meant to be used somewhere else.
+
+ uuid = 'undefined'
+
@defer.inlineCallbacks
def _receive_docs(self, last_known_generation, last_known_trans_id,
ensure_callback, sync_id, defer_decryption):
@@ -176,7 +182,7 @@ class HTTPDocFetcher(object):
# end of symmetric decryption
# -------------------------------------------------------------
self._received_docs += 1
- _emit_receive_status(self._received_docs, total)
+ _emit_receive_status(self.uuid, self._received_docs, total)
return number_of_changes, new_generation, new_transaction_id
def _parse_received_doc_response(self, response):
@@ -243,9 +249,9 @@ class HTTPDocFetcher(object):
source_replica_uid=self.source_replica_uid)
-def _emit_receive_status(received_docs, total):
+def _emit_receive_status(uuid, received_docs, total):
content = {'received': received_docs, 'total': total}
- emit_async(SOLEDAD_SYNC_RECEIVE_STATUS, content)
+ emit_async(SOLEDAD_SYNC_RECEIVE_STATUS, uuid, content)
if received_docs % 20 == 0:
msg = "%d/%d" % (received_docs, total)
diff --git a/client/src/leap/soledad/client/http_target/send.py b/client/src/leap/soledad/client/http_target/send.py
index e8abf35b..3fc5a171 100644
--- a/client/src/leap/soledad/client/http_target/send.py
+++ b/client/src/leap/soledad/client/http_target/send.py
@@ -31,6 +31,12 @@ class HTTPDocSender(object):
MAX_BATCH_SIZE = 0 # disabled by now, this is being tested yet
+ # The uuid of the local replica.
+ # Any class inheriting from this one should provide a meaningful attribute
+ # if the sync status event is meant to be used somewhere else.
+
+ uuid = 'undefined'
+
@defer.inlineCallbacks
def _send_docs(self, docs_by_generation, last_known_generation,
last_known_trans_id, sync_id):
@@ -71,7 +77,8 @@ class HTTPDocSender(object):
result = yield self._send_request(body.pop())
if self._defer_encryption:
self._delete_sent(sent)
- _emit_send_status(body.consumed, total)
+
+ _emit_send_status(self.uuid, body.consumed, total)
defer.returnValue(result)
def _send_request(self, body):
@@ -112,9 +119,9 @@ class HTTPDocSender(object):
return d
-def _emit_send_status(idx, total):
+def _emit_send_status(uuid, idx, total):
content = {'sent': idx, 'total': total}
- emit_async(SOLEDAD_SYNC_SEND_STATUS, content)
+ emit_async(SOLEDAD_SYNC_SEND_STATUS, uuid, content)
msg = "%d/%d" % (idx, total)
logger.debug("Sync send status: %s" % msg)