summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2016-10-19 14:05:27 -0300
committerdrebs <drebs@leap.se>2016-12-12 09:12:00 -0200
commit2505f61f7374cd0afeb9392c03589607d7b63b64 (patch)
tree8265b46ca8ba5dc648436deec77b227950f5ae86
parent288434178a4e89f86b9740cfe77a4dc0ce9e45f7 (diff)
[refactor] stop using leap.common.http
We aren't using leap.common.http implementation and we need specific features from original Twisted Web Agent. This commit implements it on HTTP Targer.
-rw-r--r--client/src/leap/soledad/client/http_target/__init__.py8
-rw-r--r--client/src/leap/soledad/client/http_target/api.py22
-rw-r--r--client/src/leap/soledad/client/sqlcipher.py6
-rw-r--r--client/src/leap/soledad/client/sync.py6
-rw-r--r--testing/tests/sync/test_sync.py1
-rw-r--r--testing/tests/sync/test_sync_deferred.py1
-rw-r--r--testing/tests/sync/test_sync_target.py2
7 files changed, 14 insertions, 32 deletions
diff --git a/client/src/leap/soledad/client/http_target/__init__.py b/client/src/leap/soledad/client/http_target/__init__.py
index 5dc87fcb..17b7307c 100644
--- a/client/src/leap/soledad/client/http_target/__init__.py
+++ b/client/src/leap/soledad/client/http_target/__init__.py
@@ -25,8 +25,8 @@ after receiving.
import os
from leap.soledad.common.log import getLogger
-from leap.common.http import HTTPClient
-from twisted.web.client import HTTPConnectionPool
+from leap.common.certs import get_compatible_ssl_context_factory
+from twisted.web.client import Agent
from twisted.internet import reactor
from leap.soledad.client.http_target.send import HTTPDocSender
from leap.soledad.client.http_target.api import SyncTargetAPI
@@ -96,8 +96,8 @@ class SoledadHTTPSyncTarget(SyncTargetAPI, HTTPDocSender, HTTPDocFetcher):
# XXX Increasing timeout of simple requests to avoid chances of hitting
# the duplicated syncing bug. This could be reduced to the 30s default
# after implementing Cancellable Sync. See #7382
- self._http = HTTPClient(cert_file, timeout=90,
- pool=HTTPConnectionPool(reactor))
+ self._http = Agent(reactor,
+ get_compatible_ssl_context_factory(cert_file))
if DO_STATS:
self.sync_exchange_phase = [0]
diff --git a/client/src/leap/soledad/client/http_target/api.py b/client/src/leap/soledad/client/http_target/api.py
index 0e24b37f..1b086a00 100644
--- a/client/src/leap/soledad/client/http_target/api.py
+++ b/client/src/leap/soledad/client/http_target/api.py
@@ -18,11 +18,13 @@ import os
import json
import base64
+from StringIO import StringIO
from uuid import uuid4
from twisted.web.error import Error
from twisted.internet import defer
from twisted.web.http_headers import Headers
+from twisted.web.client import FileBodyProducer
from leap.soledad.client.http_target.support import readBody
from leap.soledad.common.errors import InvalidAuthTokenError
@@ -40,9 +42,6 @@ class SyncTargetAPI(SyncTarget):
Declares public methods and implements u1db.SyncTarget.
"""
- def close(self):
- return self._http.close()
-
@property
def uuid(self):
return self._uuid
@@ -71,17 +70,14 @@ class SyncTargetAPI(SyncTarget):
headers = headers or self._base_header
if content_type:
headers.update({'content-type': [content_type]})
- if not body_producer:
- d = self._http.request(url, method, body, headers, body_reader)
- else:
+ if not body_producer and body:
+ body = FileBodyProducer(StringIO(body))
+ elif body_producer:
# Upload case, check send.py
- # Used to lazy produce body from docs with a custom protocol
- # FIXME: _agent usage to bypass timeout, there is an ongoing
- # discussion on how to properly do it.
- d = self._http._agent.request(
- method, url, headers=Headers(headers),
- bodyProducer=body_producer(body))
- d.addCallback(body_reader)
+ body = body_producer(body)
+ d = self._http.request(
+ method, url, headers=Headers(headers), bodyProducer=body)
+ d.addCallback(body_reader)
d.addErrback(_unauth_to_invalid_token_error)
return d
diff --git a/client/src/leap/soledad/client/sqlcipher.py b/client/src/leap/soledad/client/sqlcipher.py
index bd7d2cc1..f4a3ba6e 100644
--- a/client/src/leap/soledad/client/sqlcipher.py
+++ b/client/src/leap/soledad/client/sqlcipher.py
@@ -533,11 +533,7 @@ class SQLCipherU1DBSync(SQLCipherDatabase):
"""
super(SQLCipherU1DBSync, self).close()
# close all open syncers
- for url in self._syncers.keys():
- _, syncer = self._syncers[url]
- syncer.close()
- del self._syncers[url]
- self.running = False
+ self._syncers = {}
class U1DBSQLiteBackend(sqlite_backend.SQLitePartialExpandDatabase):
diff --git a/client/src/leap/soledad/client/sync.py b/client/src/leap/soledad/client/sync.py
index 9d237d98..272b3f57 100644
--- a/client/src/leap/soledad/client/sync.py
+++ b/client/src/leap/soledad/client/sync.py
@@ -217,12 +217,6 @@ class SoledadSynchronizer(Synchronizer):
# if gapless record current reached generation with target
return self._record_sync_info_with_the_target(info["my_gen"])
- def close(self):
- """
- Close the synchronizer.
- """
- self.sync_target.close()
-
def _record_sync_info_with_the_target(self, start_generation):
"""
Store local replica metadata in server.
diff --git a/testing/tests/sync/test_sync.py b/testing/tests/sync/test_sync.py
index a7d0a92b..a434e944 100644
--- a/testing/tests/sync/test_sync.py
+++ b/testing/tests/sync/test_sync.py
@@ -184,7 +184,6 @@ class TestSoledadDbSync(
target = soledad_sync_target(
self, self.db2._dbname,
source_replica_uid=self._soledad._dbpool.replica_uid)
- self.addCleanup(target.close)
return sync.SoledadSynchronizer(
self.db,
target).sync()
diff --git a/testing/tests/sync/test_sync_deferred.py b/testing/tests/sync/test_sync_deferred.py
index eb71ea73..001612a6 100644
--- a/testing/tests/sync/test_sync_deferred.py
+++ b/testing/tests/sync/test_sync_deferred.py
@@ -142,7 +142,6 @@ class TestSoledadDbSyncDeferredEncDecr(
target = soledad_sync_target(
self, self.db2._dbname,
source_replica_uid=replica_uid)
- self.addCleanup(target.close)
return sync.SoledadSynchronizer(
dbsyncer,
target).sync()
diff --git a/testing/tests/sync/test_sync_target.py b/testing/tests/sync/test_sync_target.py
index 17223606..fd1d413e 100644
--- a/testing/tests/sync/test_sync_target.py
+++ b/testing/tests/sync/test_sync_target.py
@@ -168,7 +168,6 @@ class TestSoledadSyncTarget(
target = self.sync_target(
self, path,
source_replica_uid=source_replica_uid)
- self.addCleanup(target.close)
return target
def setUp(self):
@@ -389,7 +388,6 @@ class SoledadDatabaseSyncTargetTests(
def tearDown(self):
self.db.close()
- self.st.close()
tests.TestCaseWithServer.tearDown(self)
SoledadWithCouchServerMixin.tearDown(self)