summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/leap/soledad/client/sync.py2
-rw-r--r--client/src/leap/soledad/client/target.py34
2 files changed, 16 insertions, 20 deletions
diff --git a/client/src/leap/soledad/client/sync.py b/client/src/leap/soledad/client/sync.py
index 5d545a77..c158f2a7 100644
--- a/client/src/leap/soledad/client/sync.py
+++ b/client/src/leap/soledad/client/sync.py
@@ -29,8 +29,6 @@ Extend u1db Synchronizer with the ability to:
"""
-import json
-
import logging
import traceback
from threading import Lock
diff --git a/client/src/leap/soledad/client/target.py b/client/src/leap/soledad/client/target.py
index 01e1231a..12175f48 100644
--- a/client/src/leap/soledad/client/target.py
+++ b/client/src/leap/soledad/client/target.py
@@ -28,12 +28,10 @@ import logging
import re
import urllib
import threading
-import urlparse
from collections import defaultdict
from time import sleep
from uuid import uuid4
-from contextlib import contextmanager
import simplejson as json
from taskthread import TimerTask
@@ -44,7 +42,6 @@ from u1db.remote.http_client import _encode_query_parameter, HTTPClientBase
from zope.proxy import ProxyBase
from zope.proxy import sameProxiedObjects, setProxiedObject
-from leap.soledad.common import soledad_assert
from leap.soledad.common.document import SoledadDocument
from leap.soledad.client.auth import TokenBasedAuth
from leap.soledad.client.crypto import is_symmetrically_encrypted
@@ -87,7 +84,7 @@ class DocumentSyncerThread(threading.Thread):
"""
def __init__(self, doc_syncer, release_method, failed_method,
- idx, total, last_request_lock=None, last_callback_lock=None):
+ idx, total, last_request_lock=None, last_callback_lock=None):
"""
Initialize a new syncer thread.
@@ -246,7 +243,7 @@ class DocumentSyncerPool(object):
"""
def __init__(self, raw_url, raw_creds, query_string, headers,
- ensure_callback, stop_method):
+ ensure_callback, stop_method):
"""
Initialize the document syncer pool.
@@ -279,7 +276,7 @@ class DocumentSyncerPool(object):
self._threads = []
def new_syncer_thread(self, idx, total, last_request_lock=None,
- last_callback_lock=None):
+ last_callback_lock=None):
"""
Yield a new document syncer thread.
@@ -619,7 +616,7 @@ class HTTPDocumentSyncer(HTTPClientBase, TokenBasedAuth):
self._conn.endheaders()
def _get_doc(self, received, sync_id, last_known_generation,
- last_known_trans_id):
+ last_known_trans_id):
"""
Get a sync document from server by means of a POST request.
@@ -658,7 +655,7 @@ class HTTPDocumentSyncer(HTTPClientBase, TokenBasedAuth):
return self._response()
def _put_doc(self, sync_id, last_known_generation, last_known_trans_id,
- id, rev, content, gen, trans_id, number_of_docs, doc_idx):
+ id, rev, content, gen, trans_id, number_of_docs, doc_idx):
"""
Put a sync document on server by means of a POST request.
@@ -765,7 +762,7 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
#
def __init__(self, url, source_replica_uid=None, creds=None, crypto=None,
- sync_db=None, sync_db_write_lock=None):
+ sync_db=None, sync_db_write_lock=None):
"""
Initialize the SoledadSyncTarget.
@@ -925,7 +922,7 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
"""
new_generation, new_transaction_id, number_of_changes, doc_id, \
rev, content, gen, trans_id = \
- self._parse_received_doc_response(response)
+ self._parse_received_doc_response(response)
if doc_id is not None:
# decrypt incoming document and insert into local database
# -------------------------------------------------------------
@@ -1134,11 +1131,14 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
"""
self._ensure_callback = ensure_callback
- if defer_decryption:
+ if defer_decryption and self._sync_db is not None:
self._sync_exchange_lock.acquire()
self._setup_sync_decr_pool(last_known_generation)
self._setup_sync_watcher()
self._defer_decryption = True
+ else:
+ # fall back
+ defer_decryption = False
self.start()
@@ -1149,7 +1149,7 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
setProxiedObject(self._insert_doc_cb[source_replica_uid],
return_doc_cb)
- if not self.clear_to_sync():
+ if defer_decryption is True and not self.clear_to_sync():
raise PendingReceivedDocsSyncError
self._ensure_connection()
@@ -1171,7 +1171,6 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
self._raw_url, self._raw_creds, url, headers, ensure_callback,
self.stop)
threads = []
- last_request_lock = None
last_callback_lock = None
sent = 0
total = len(docs_by_generations)
@@ -1227,7 +1226,8 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
t.doc_syncer.set_request_method(
'put', sync_id, cur_target_gen, cur_target_trans_id,
id=doc.doc_id, rev=doc.rev, content=doc_json, gen=gen,
- trans_id=trans_id, number_of_docs=number_of_docs, doc_idx=sent + 1)
+ trans_id=trans_id, number_of_docs=number_of_docs,
+ doc_idx=sent + 1)
# set the success calback
def _success_callback(idx, total, response):
@@ -1251,7 +1251,6 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
# save thread and append
t.start()
threads.append((t, doc))
- last_request_lock = t.request_lock
last_callback_lock = t.callback_lock
sent += 1
@@ -1275,7 +1274,7 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
if last_successful_thread is not None:
response_dict = json.loads(last_successful_thread.response[0])[0]
gen_after_send = response_dict['new_generation']
- trans_id_after_send = response_dict['new_transaction_id']
+ trans_id_after_send = response_dict['new_transaction_id']
# get docs from target
if self.stopped is False:
@@ -1356,7 +1355,6 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
# no doc found
return None
-
def delete_encrypted_docs_from_db(self, docs_ids):
"""
Delete several encrypted documents from the database of symmetrically
@@ -1467,7 +1465,7 @@ class SoledadSyncTarget(HTTPSyncTarget, TokenBasedAuth):
decrypter = self._sync_decr_pool
decrypter.decrypt_received_docs()
- done = decrypter.process_decrypted()
+ decrypter.process_decrypted()
def _sign_request(self, method, url_query, params):
"""