summaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2015-05-20 18:19:28 -0300
committerdrebs <drebs@leap.se>2015-05-21 09:16:24 -0300
commit33fa691e1df4d64d10313d5d192b3c064aafadb7 (patch)
tree0b73fa140cb9e9a70c382be20453224db0935a4e /client/src
parentce161f9623a1dea6eda9fc2350c60073dbcdce06 (diff)
[refactor] remove unneeded proxy for insert_doc_cb
When we initialized the async decrypter pool in the target's init method we needed a proxy to ensure we could update the insert doc callback with the correct method later on. Now we initialize the decrypter only when we need it, so we don't need this proxy anymore. This commit removes the unneeded proxy.
Diffstat (limited to 'client/src')
-rw-r--r--client/src/leap/soledad/client/encdecpool.py22
-rw-r--r--client/src/leap/soledad/client/http_target.py31
2 files changed, 13 insertions, 40 deletions
diff --git a/client/src/leap/soledad/client/encdecpool.py b/client/src/leap/soledad/client/encdecpool.py
index d9f3d28c..2f58d06c 100644
--- a/client/src/leap/soledad/client/encdecpool.py
+++ b/client/src/leap/soledad/client/encdecpool.py
@@ -28,8 +28,6 @@ import time
import json
import logging
-from zope.proxy import sameProxiedObjects
-
from twisted.internet import defer
from twisted.internet.threads import deferToThread
from twisted.python.failure import Failure
@@ -535,16 +533,6 @@ class SyncDecrypterPool(SyncEncryptDecryptPool):
decrypted and inserted in the sync db.
:rtype: twisted.internet.defer.Deferred
"""
- # insert_doc_cb is a proxy object that gets updated with the right
- # insert function only when the sync_target invokes the sync_exchange
- # method. so, if we don't still have a non-empty callback, we refuse
- # to proceed.
- if sameProxiedObjects(
- self._insert_doc_cb.get(self.source_replica_uid),
- None):
- logger.debug("Sync decrypter pool: no insert_doc_cb() yet.")
- return
-
soledad_assert(self._crypto is not None, "need a crypto object")
content = json.loads(content)
@@ -713,7 +701,7 @@ class SyncDecrypterPool(SyncEncryptDecryptPool):
gen, trans_id, idx):
"""
Insert the decrypted document into the local sqlcipher database.
- Makes use of the passed callback `return_doc_cb` passed to the caller
+ Makes use of the passed callback `insert_doc_cb` passed to the caller
by u1db sync.
:param doc_id: The document id.
@@ -730,7 +718,6 @@ class SyncDecrypterPool(SyncEncryptDecryptPool):
:type trans_id: str
"""
# could pass source_replica in params for callback chain
- insert_fun = self._insert_doc_cb[self.source_replica_uid]
logger.debug("Sync decrypter pool: inserting doc in local db: "
"%s:%s %s" % (doc_id, doc_rev, gen))
@@ -739,7 +726,7 @@ class SyncDecrypterPool(SyncEncryptDecryptPool):
content = None
doc = SoledadDocument(doc_id, doc_rev, content)
gen = int(gen)
- insert_fun(doc, gen, trans_id)
+ self._insert_doc_cb(doc, gen, trans_id)
# store info about processed docs
self._last_inserted_idx = idx
@@ -793,11 +780,6 @@ class SyncDecrypterPool(SyncEncryptDecryptPool):
# changes
while self._processed_docs < self._docs_to_process:
- if sameProxiedObjects(
- self._insert_doc_cb.get(self.source_replica_uid),
- None):
- continue
-
event.clear()
d = self._decrypt_received_docs()
diff --git a/client/src/leap/soledad/client/http_target.py b/client/src/leap/soledad/client/http_target.py
index bf397cfe..bf563b34 100644
--- a/client/src/leap/soledad/client/http_target.py
+++ b/client/src/leap/soledad/client/http_target.py
@@ -25,11 +25,8 @@ import json
import base64
import logging
-from zope.proxy import setProxiedObject
-from zope.proxy import ProxyBase
from uuid import uuid4
from functools import partial
-from collections import defaultdict
from twisted.internet import defer
from twisted.internet import reactor
@@ -79,10 +76,6 @@ class SoledadHTTPSyncTarget(SyncTarget):
written to the main database.
"""
- # will later keep a reference to the insert-doc callback
- # passed to sync_exchange
- _insert_doc_cb = defaultdict(lambda: ProxyBase(None))
-
def __init__(self, url, source_replica_uid, creds, crypto,
sync_db=None, sync_enc_pool=None):
"""
@@ -116,6 +109,7 @@ class SoledadHTTPSyncTarget(SyncTarget):
self._crypto = crypto
self._sync_db = sync_db
self._sync_enc_pool = sync_enc_pool
+ self._insert_doc_cb = None
# asynchronous encryption/decryption attributes
self._decryption_callback = None
self._sync_decr_pool = None
@@ -213,7 +207,7 @@ class SoledadHTTPSyncTarget(SyncTarget):
@defer.inlineCallbacks
def sync_exchange(self, docs_by_generation, source_replica_uid,
last_known_generation, last_known_trans_id,
- return_doc_cb, ensure_callback=None,
+ insert_doc_cb, ensure_callback=None,
defer_decryption=True, sync_id=None):
"""
Find out which documents the remote database does not know about,
@@ -235,11 +229,11 @@ class SoledadHTTPSyncTarget(SyncTarget):
:param last_known_trans_id: Target's last known transaction id.
:type last_known_trans_id: str
- :param return_doc_cb: A callback for inserting received documents from
+ :param insert_doc_cb: A callback for inserting received documents from
target. If not overriden, this will call u1db
insert_doc_from_target in synchronizer, which
implements the TAKE OTHER semantics.
- :type return_doc_cb: function
+ :type insert_doc_cb: function
:param ensure_callback: A callback that ensures we know the target
replica uid if the target replica was just
@@ -262,9 +256,8 @@ class SoledadHTTPSyncTarget(SyncTarget):
sync_id = str(uuid4())
self.source_replica_uid = source_replica_uid
- # let the decrypter pool access the passed callback to insert docs
- setProxiedObject(self._insert_doc_cb[source_replica_uid],
- return_doc_cb)
+ # save a reference to the callback so we can use it after decrypting
+ self._insert_doc_cb = insert_doc_cb
gen_after_send, trans_id_after_send = yield self._send_docs(
docs_by_generation,
@@ -274,7 +267,7 @@ class SoledadHTTPSyncTarget(SyncTarget):
cur_target_gen, cur_target_trans_id = yield self._receive_docs(
last_known_generation, last_known_trans_id,
- return_doc_cb, ensure_callback, sync_id,
+ ensure_callback, sync_id,
defer_decryption=defer_decryption)
# update gen and trans id info in case we just sent and did not
@@ -376,10 +369,8 @@ class SoledadHTTPSyncTarget(SyncTarget):
@defer.inlineCallbacks
def _receive_docs(self, last_known_generation, last_known_trans_id,
- return_doc_cb, ensure_callback, sync_id,
- defer_decryption):
- # we keep a reference to the callback in case we defer the decryption
- self._return_doc_cb = return_doc_cb
+ ensure_callback, sync_id, defer_decryption):
+
self._queue_for_decrypt = defer_decryption \
and self._sync_db is not None
@@ -534,7 +525,7 @@ class SoledadHTTPSyncTarget(SyncTarget):
else:
# defer_decryption is False or no-sync-db fallback
doc.set_json(decrypt_doc(self._crypto, doc))
- self._return_doc_cb(doc, gen, trans_id)
+ self._insert_doc_cb(doc, gen, trans_id)
else:
# not symmetrically encrypted doc, insert it directly
# or save it in the decrypted stage.
@@ -543,7 +534,7 @@ class SoledadHTTPSyncTarget(SyncTarget):
doc.doc_id, doc.rev, doc.content, gen, trans_id,
idx)
else:
- self._return_doc_cb(doc, gen, trans_id)
+ self._insert_doc_cb(doc, gen, trans_id)
# -------------------------------------------------------------
# end of symmetric decryption
# -------------------------------------------------------------