From: Brian Warner Date: Wed, 18 Nov 2009 01:54:44 +0000 (-0800) Subject: move convergence secret into SecretHolder, next to lease secret X-Git-Tag: trac-4100~1 X-Git-Url: https://git.rkrishnan.org/vdrive/%22news.html/module-simplejson.scanner.html?a=commitdiff_plain;h=d2426ea3bd06b67da8c814b3aed8cb9d5b1be3db;p=tahoe-lafs%2Ftahoe-lafs.git move convergence secret into SecretHolder, next to lease secret --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 93e1eb4e..1cf1af57 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -38,8 +38,9 @@ def _make_secret(): return base32.b2a(os.urandom(hashutil.CRYPTO_VAL_SIZE)) + "\n" class SecretHolder: - def __init__(self, lease_secret): + def __init__(self, lease_secret, convergence_secret): self._lease_secret = lease_secret + self._convergence_secret = convergence_secret def get_renewal_secret(self): return hashutil.my_renewal_secret_hash(self._lease_secret) @@ -47,6 +48,9 @@ class SecretHolder: def get_cancel_secret(self): return hashutil.my_cancel_secret_hash(self._lease_secret) + def get_convergence_secret(self): + return self._convergence_secret + class KeyGenerator: def __init__(self): self._remote = None @@ -108,7 +112,7 @@ class Client(node.Node, pollmixin.PollMixin): self.DEFAULT_ENCODING_PARAMETERS = self.DEFAULT_ENCODING_PARAMETERS.copy() self.init_introducer_client() self.init_stats_provider() - self.init_lease_secret() + self.init_secrets() self.init_storage() self.init_control() self.helper = None @@ -179,10 +183,13 @@ class Client(node.Node, pollmixin.PollMixin): def get_stats(self): return { 'node.uptime': time.time() - self.started_timestamp } - def init_lease_secret(self): - secret_s = self.get_or_create_private_config("secret", _make_secret) - lease_secret = base32.a2b(secret_s) - self._secret_holder = SecretHolder(lease_secret) + def init_secrets(self): + lease_s = self.get_or_create_private_config("secret", _make_secret) + lease_secret = base32.a2b(lease_s) + convergence_s = self.get_or_create_private_config('convergence', + _make_secret) + self.convergence = base32.a2b(convergence_s) + self._secret_holder = SecretHolder(lease_secret, self.convergence) def init_storage(self): # should we run a storage server (and publish it for others to use)? @@ -255,8 +262,6 @@ class Client(node.Node, pollmixin.PollMixin): DEP["k"] = int(self.get_config("client", "shares.needed", DEP["k"])) DEP["n"] = int(self.get_config("client", "shares.total", DEP["n"])) DEP["happy"] = int(self.get_config("client", "shares.happy", DEP["happy"])) - convergence_s = self.get_or_create_private_config('convergence', _make_secret) - self.convergence = base32.a2b(convergence_s) self.init_client_storage_broker() self.history = History(self.stats_provider) diff --git a/src/allmydata/test/test_filenode.py b/src/allmydata/test/test_filenode.py index 1639c333..24aaa70a 100644 --- a/src/allmydata/test/test_filenode.py +++ b/src/allmydata/test/test_filenode.py @@ -21,7 +21,7 @@ class FakeClient: return None def get_history(self): return None - _secret_holder = client.SecretHolder("lease secret") + _secret_holder = client.SecretHolder("lease secret", "convergence secret") class Node(unittest.TestCase): def test_chk_filenode(self): diff --git a/src/allmydata/test/test_helper.py b/src/allmydata/test/test_helper.py index 4b0c16cb..399b2ec8 100644 --- a/src/allmydata/test/test_helper.py +++ b/src/allmydata/test/test_helper.py @@ -90,7 +90,7 @@ class AssistedUpload(unittest.TestCase): def setUp(self): self.s = FakeClient() self.storage_broker = StorageFarmBroker(None, True) - self.secret_holder = client.SecretHolder("lease secret") + self.secret_holder = client.SecretHolder("lease secret", "convergence") self.s.startService() self.tub = t = Tub() diff --git a/src/allmydata/test/test_mutable.py b/src/allmydata/test/test_mutable.py index 20d5f1cc..7b7c0990 100644 --- a/src/allmydata/test/test_mutable.py +++ b/src/allmydata/test/test_mutable.py @@ -196,7 +196,7 @@ def make_storagebroker(s=None, num_peers=10): def make_nodemaker(s=None, num_peers=10): storage_broker = make_storagebroker(s, num_peers) - sh = client.SecretHolder("lease secret") + sh = client.SecretHolder("lease secret", "convergence secret") keygen = client.KeyGenerator() keygen.set_default_keysize(522) nodemaker = NodeMaker(storage_broker, sh, None, diff --git a/src/allmydata/test/test_upload.py b/src/allmydata/test/test_upload.py index 8af3487e..c3b65eca 100644 --- a/src/allmydata/test/test_upload.py +++ b/src/allmydata/test/test_upload.py @@ -187,7 +187,7 @@ class FakeClient: return self.DEFAULT_ENCODING_PARAMETERS def get_storage_broker(self): return self.storage_broker - _secret_holder = client.SecretHolder("lease secret") + _secret_holder = client.SecretHolder("lease secret", "convergence secret") class GotTooFarError(Exception): pass diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 2555d17a..a2f52b1b 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -25,7 +25,7 @@ import common_util as testutil from allmydata.test.no_network import GridTestMixin from allmydata.test.common_web import HTTPClientGETFactory, \ HTTPClientHEADFactory -from allmydata.client import Client +from allmydata.client import Client, SecretHolder # create a fake uploader/downloader, and a couple of fake dirnodes, then # create a webserver that works against them @@ -93,7 +93,7 @@ class FakeClient(Client): self.nickname = "fake_nickname" self.introducer_furl = "None" self.stats_provider = FakeStatsProvider() - self._secret_holder = None + self._secret_holder = SecretHolder("lease secret", "convergence secret") self.helper = None self.convergence = "some random string" self.storage_broker = StorageFarmBroker(None, permute_peers=True) @@ -101,7 +101,7 @@ class FakeClient(Client): self.history = FakeHistory() self.uploader = FakeUploader() self.uploader.setServiceParent(self) - self.nodemaker = FakeNodeMaker(None, None, None, + self.nodemaker = FakeNodeMaker(None, self._secret_holder, None, self.uploader, None, None, None, None)