summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2016-09-21 16:51:07 -0300
committerVictor Shyba <victor1984@riseup.net>2016-11-18 15:55:52 -0300
commit37f56e1d58a2c466a074018b51bf7db29ae09fe0 (patch)
treed662b56e3e8df57766816d0467d9db7cbd93c2a9 /server
parentb401f5cdcf3c9daca22beef0217e25c2b8d0e5eb (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')
-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('')