--- /dev/null
+
+from twisted.trial import unittest
+from twisted.application import service
+
+from foolscap import Tub, eventual
+from foolscap.logging import log
+
+from allmydata import upload, offloaded
+
+class FakeCHKUploadHelper(offloaded.CHKUploadHelper):
+ pass
+
+class FakeHelper(offloaded.Helper):
+ chk_upload_helper_class = FakeCHKUploadHelper
+
+class FakeClient(service.MultiService):
+ def log(self, msg, **kwargs):
+ return log.msg(msg, **kwargs)
+ def get_push_to_ourselves(self):
+ return True
+ def get_encoding_parameters(self):
+ return None
+
+def flush_but_dont_ignore(res):
+ d = eventual.flushEventualQueue()
+ def _done(ignored):
+ return res
+ d.addCallback(_done)
+ return d
+
+class AssistedUpload(unittest.TestCase):
+ def setUp(self):
+ self.s = FakeClient()
+ self.s.startService()
+
+ self.tub = t = Tub()
+ t.setServiceParent(self.s)
+ self.s.tub = t
+ # we never actually use this for network traffic, so it can use a
+ # bogus host/port
+ t.setLocation("bogus:1234")
+
+
+ h = FakeHelper(".")
+ h.setServiceParent(self.s)
+ self.helper_furl = t.registerReference(h)
+
+ def tearDown(self):
+ d = self.s.stopService()
+ d.addCallback(eventual.fireEventually)
+ d.addBoth(flush_but_dont_ignore)
+ return d
+
+
+ def test_one(self):
+ u = upload.Uploader(self.helper_furl)
+ u.setServiceParent(self.s)
+
+ # wait a few turns
+ d = eventual.fireEventually()
+ d.addCallback(eventual.fireEventually)
+ d.addCallback(eventual.fireEventually)
+
+ def _ready(res):
+ assert u._helper
+
+ DATA = "I need help\n" * 1000
+ return u.upload_data(DATA)
+ d.addCallback(_ready)
+ def _uploaded(uri):
+ assert "CHK" in uri
+ d.addCallback(_uploaded)
+
+ return d
+
import os
from zope.interface import implements
-from twisted.python import log, failure
+from twisted.python import failure
from twisted.internet import defer
from twisted.application import service
from foolscap import Referenceable
+from foolscap.logging import log
from allmydata.util.hashutil import file_renewal_secret_hash, \
file_cancel_secret_hash, bucket_renewal_secret_hash, \
)
return u.to_string()
+
def read_this_many_bytes(uploadable, size, prepend_data=[]):
if size == 0:
return defer.succeed([])
def __init__(self, helper, options={}):
self._helper = helper
self._options = options
- self._log_number = self._client.log("AssistedUploader starting")
+ self._log_number = log.msg("AssistedUploader starting")
+
+ def log(self, msg, parent=None, **kwargs):
+ if parent is None:
+ parent = self._log_number
+ return log.msg(msg, parent=parent, **kwargs)
def set_params(self, encoding_parameters):
- pass
+ self._needed_shares, happy, self._total_shares = encoding_parameters
def start(self, uploadable):
u = IUploadable(uploadable)
d = self._helper.callRemote("upload", self._storage_index)
d.addCallback(self._contacted_helper)
return d
- def _contacted_helper(self, upload_results, upload_helper):
+ def _contacted_helper(self, (upload_results, upload_helper)):
if upload_helper:
# we need to upload the file
reu = RemoteEncryptedUploabable(self._encuploadable)
uploader = LiteralUploader(self.parent, options,
wait_for_numpeers)
elif self._helper:
- uploader = AssistedUploader(self.parent, options)
+ uploader = AssistedUploader(self._helper, options)
else:
uploader = self.uploader_class(self.parent, options,
wait_for_numpeers)