def __init__(self, basedir="."):
node.Node.__init__(self, basedir)
+ self.upload_ready_d = defer.Deferred()
self.started_timestamp = time.time()
self.logSource="Client"
self.encoding_params = self.DEFAULT_ENCODING_PARAMETERS.copy()
def init_client_storage_broker(self):
# create a StorageFarmBroker object, for use by Uploader/Downloader
# (and everybody else who wants to use storage servers)
- sb = storage_client.StorageFarmBroker(self.tub, permute_peers=True)
+
+ connection_threshold = min(self.encoding_params["k"],
+ self.encoding_params["happy"] + 1)
+
+ sb = storage_client.StorageFarmBroker(self.tub, True, connection_threshold,
+ self.upload_ready_d)
self.storage_broker = sb
# load static server specifications from tahoe.cfg, if any.
s = drop_upload.DropUploader(self, upload_dircap, local_dir_utf8, dbfile)
s.setServiceParent(self)
s.startService()
+
+ # start processing the upload queue when we've connected to enough servers
+ self.upload_ready_d.addCallback(s.upload_ready)
except Exception, e:
self.log("couldn't start drop-uploader: %r", args=(e,))
self._local_dir = unicode(local_dir, 'UTF-8')
self._dbfile = dbfile
+ self.is_upload_ready = False
+
if inotify is None:
from twisted.internet import inotify
self._inotify = inotify
#print "adding file to upload queue %s" % (path,)
pass
+ def upload_ready(self):
+ """upload_ready is used to signal us to start
+ processing the upload items...
+ """
+ self.is_upload_ready = True
+
def _notify(self, opaque, path, events_mask):
self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask))))
I'm also responsible for subscribing to the IntroducerClient to find out
about new servers as they are announced by the Introducer.
"""
- def __init__(self, tub, permute_peers):
+ def __init__(self, tub, permute_peers, connected_threshold, connected_d):
self.tub = tub
assert permute_peers # False not implemented yet
self.permute_peers = permute_peers
+ self.connected_threshold = connected_threshold
+ self.connected_d = connected_d
# self.servers maps serverid -> IServer, and keeps track of all the
# storage servers that we've heard about. Each descriptor manages its
# own Reconnector, and will give us a RemoteReference when we ask
# these two are used in unit tests
def test_add_rref(self, serverid, rref, ann):
- s = NativeStorageServer(serverid, ann.copy())
+ s = NativeStorageServer(serverid, ann.copy(), self)
s.rref = rref
s._is_connected = True
self.servers[serverid] = s
precondition(isinstance(key_s, str), key_s)
precondition(key_s.startswith("v0-"), key_s)
assert ann["service-name"] == "storage"
- s = NativeStorageServer(key_s, ann)
+ s = NativeStorageServer(key_s, ann, self)
serverid = s.get_serverid()
old = self.servers.get(serverid)
if old:
for dsc in self.servers.values():
dsc.try_to_connect()
+ def check_enough_connected(self):
+ if (self.connected_d is not None and
+ len(self.get_connected_servers()) >= self.connected_threshold):
+ d = self.connected_d
+ self.connected_d = None
+ d.callback(None)
+
def get_servers_for_psi(self, peer_selection_index):
# return a list of server objects (IServers)
assert self.permute_peers == True
"application-version": "unknown: no get_version()",
}
- def __init__(self, key_s, ann):
+ def __init__(self, key_s, ann, broker):
self.key_s = key_s
self.announcement = ann
+ self.broker = broker
assert "anonymous-storage-FURL" in ann, ann
furl = str(ann["anonymous-storage-FURL"])
default = self.VERSION_DEFAULTS
d = add_version_to_remote_reference(rref, default)
d.addCallback(self._got_versioned_service, lp)
+ d.addCallback(lambda ign: self.broker.check_enough_connected())
d.addErrback(log.err, format="storageclient._got_connection",
name=self.get_name(), umid="Sdq3pg")
class WebResultsRendering(unittest.TestCase, WebRenderingMixin):
def create_fake_client(self):
- sb = StorageFarmBroker(None, True)
+ sb = StorageFarmBroker(None, True, 0, None)
# s.get_name() (the "short description") will be "v0-00000000".
# s.get_longname() will include the -long suffix.
# s.get_peerid() (i.e. tubid) will be "aaa.." or "777.." or "ceir.."
"my-version": "ver",
"oldest-supported": "oldest",
}
- s = NativeStorageServer(key_s, ann)
+ s = NativeStorageServer(key_s, ann, sb)
sb.test_add_server(peerid, s) # XXX: maybe use key_s?
c = FakeClient()
c.storage_broker = sb
return [ s.get_longname() for s in sb.get_servers_for_psi(key) ]
def test_permute(self):
- sb = StorageFarmBroker(None, True)
+ sb = StorageFarmBroker(None, True, 0, None)
for k in ["%d" % i for i in range(5)]:
ann = {"anonymous-storage-FURL": "pb://abcde@nowhere/fake",
"permutation-seed-base32": base32.b2a(k) }
self.upload_dircap = n.get_uri()
self.uploader = DropUploader(self.client, self.upload_dircap, self.local_dir.encode('utf-8'),
"magicfolderdb.sqlite", inotify=self.inotify)
- return self.uploader.startService()
+ self.uploader.setServiceParent(self.client)
+ self.uploader.startService()
+ self.uploader.upload_ready()
+ return None
d.addCallback(_made_upload_dir)
# Write something short enough for a LIT file.
timeout = 240 # It takes longer than 120 seconds on Francois's arm box.
def setUp(self):
self.s = FakeClient()
- self.s.storage_broker = StorageFarmBroker(None, True)
+ self.s.storage_broker = StorageFarmBroker(None, True, 0, None)
self.s.secret_holder = client.SecretHolder("lease secret", "converge")
self.s.startService()
s = FakeStorage()
peerids = [tagged_hash("peerid", "%d" % i)[:20]
for i in range(num_peers)]
- storage_broker = StorageFarmBroker(None, True)
+ storage_broker = StorageFarmBroker(None, True, 0, None)
for peerid in peerids:
fss = FakeStorageServer(peerid, s)
ann = {"anonymous-storage-FURL": "pb://%s@nowhere/fake" % base32.b2a(peerid),
mode = dict([i,mode] for i in range(num_servers))
servers = [ ("%20d"%fakeid, FakeStorageServer(mode[fakeid]))
for fakeid in range(self.num_servers) ]
- self.storage_broker = StorageFarmBroker(None, permute_peers=True)
+ self.storage_broker = StorageFarmBroker(None, True, 0, None)
for (serverid, rref) in servers:
ann = {"anonymous-storage-FURL": "pb://%s@nowhere/fake" % base32.b2a(serverid),
"permutation-seed-base32": base32.b2a(serverid) }
self._secret_holder = SecretHolder("lease secret", "convergence secret")
self.helper = None
self.convergence = "some random string"
- self.storage_broker = StorageFarmBroker(None, permute_peers=True)
+ self.storage_broker = StorageFarmBroker(None, True, 0, None)
# fake knowledge of another server
self.storage_broker.test_add_server("other_nodeid",
FakeDisplayableServer("other_nodeid", u"other_nickname \u263B"))