summaryrefslogtreecommitdiff
path: root/server/src/leap/soledad
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2016-09-21 16:51:07 -0300
committerdrebs <drebs@leap.se>2016-12-12 09:11:58 -0200
commit16f73007db6ec74435a25a95ba2150d5d14d8138 (patch)
tree59a91f8bd80f0c282b4ab5df710e642ebeaddbd7 /server/src/leap/soledad
parenta8182bb4f954c02d53d699bfe2a645667d770269 (diff)
[feature] make the test accept large uploads
We enabled chunking, which means that a use can upload his entire db on a single request. This commit makes server enable this and throttle download as Twisted cant control the payload producer code as its synchronous and blocking code.
Diffstat (limited to 'server/src/leap/soledad')
-rw-r--r--server/src/leap/soledad/server/sync.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/server/src/leap/soledad/server/sync.py b/server/src/leap/soledad/server/sync.py
index 0bf7b236..bc977210 100644
--- a/server/src/leap/soledad/server/sync.py
+++ b/server/src/leap/soledad/server/sync.py
@@ -17,14 +17,16 @@
"""
Server side synchronization infrastructure.
"""
-from leap.soledad.common.l2db import sync, Document
+import time
+from leap.soledad.common.l2db import sync
from leap.soledad.common.l2db.remote import http_app
from leap.soledad.server.caching import get_cache_for
from leap.soledad.server.state import ServerSyncState
+from leap.soledad.common.document import ServerDocument
from itertools import izip
-MAX_REQUEST_SIZE = 200 # in Mb
+MAX_REQUEST_SIZE = 6000 # in Mb
MAX_ENTRY_SIZE = 200 # in Mb
@@ -236,7 +238,8 @@ class SyncResource(http_app.SyncResource):
:param doc_idx: The index of the current document.
:type doc_idx: int
"""
- doc = Document(id, rev, content)
+ doc = ServerDocument(id, rev)
+ doc._json = content
self.sync_exch.insert_doc_from_source(
doc, gen, trans_id, number_of_docs=None,
doc_idx=None, sync_id=None)
@@ -255,10 +258,15 @@ class SyncResource(http_app.SyncResource):
entry = dict(id=doc.doc_id, rev=doc.rev,
gen=gen, trans_id=trans_id)
self.responder.stream_entry(entry)
- content = doc.get_json()
- if content:
- self.responder.stream_entry(content.read())
- content.close()
+ content_reader = doc.get_json()
+ if content_reader:
+ content = content_reader.read()
+ self.responder.stream_entry(content)
+ content_reader.close()
+ # throttle at 5mb/s
+ # FIXME: twistd cant control througput
+ # we need to either use gunicorn or go async
+ time.sleep(len(content) / (5.0 * 1024 * 1024))
else:
self.responder.stream_entry('')