From: Brian Warner Date: Tue, 6 Nov 2007 22:18:09 +0000 (-0700) Subject: mutable: parameterize Publish/Retrieve classes in MutableFileNode, for tests X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/flags/rgr-080307.php?a=commitdiff_plain;h=c595f6ccd036e025b211eaf7234e40b75d7e93e5;p=tahoe-lafs%2Ftahoe-lafs.git mutable: parameterize Publish/Retrieve classes in MutableFileNode, for tests --- diff --git a/src/allmydata/mutable.py b/src/allmydata/mutable.py index e2bd556a..ce9e081b 100644 --- a/src/allmydata/mutable.py +++ b/src/allmydata/mutable.py @@ -163,6 +163,8 @@ def pack_offsets(verification_key_length, signature_length, class MutableFileNode: implements(IMutableFileNode) + publish_class = Publish + retrieve_class = Retrieve def __init__(self, client): self._client = client @@ -195,28 +197,33 @@ class MutableFileNode: """ self._required_shares = 3 self._total_shares = 10 - self._pubkey, self._privkey = self._generate_pubprivkeys() - pubkey_s = self._pubkey.serialize() - privkey_s = self._privkey.serialize() - self._writekey = hashutil.ssk_writekey_hash(privkey_s) - self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s) - self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s) - self._uri = WriteableSSKFileURI(self._writekey, self._fingerprint) - self._readkey = self._uri.readkey - self._storage_index = self._uri.storage_index - self._current_seqnum = 0 # TODO: really we mean "doesn't matter - # since nobody knows about us yet" - self._current_roothash = "\x00"*32 - return self._publish(initial_contents) + d = defer.maybeDeferred(self._generate_pubprivkeys) + def _generated( (pubkey, privkey) ): + self._pubkey, self._privkey = pubkey, privkey + pubkey_s = self._pubkey.serialize() + privkey_s = self._privkey.serialize() + self._writekey = hashutil.ssk_writekey_hash(privkey_s) + self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s) + self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s) + self._uri = WriteableSSKFileURI(self._writekey, self._fingerprint) + self._readkey = self._uri.readkey + self._storage_index = self._uri.storage_index + # TODO: seqnum/roothash: really we mean "doesn't matter since + # nobody knows about us yet" + self._current_seqnum = 0 + self._current_roothash = "\x00"*32 + return self._publish(initial_contents) + d.addCallback(_generated) + return d def _generate_pubprivkeys(self): + # TODO: wire these up to pycryptopp privkey = "very private" pubkey = "public" return pubkey, privkey def _publish(self, initial_contents): - # TODO: actually do all that stuff - p = Publish(self) + p = self.publish_class(self) d = p.publish(initial_contents) d.addCallback(lambda res: self) return d diff --git a/src/allmydata/test/test_mutable.py b/src/allmydata/test/test_mutable.py index 4176b813..fdb5083b 100644 --- a/src/allmydata/test/test_mutable.py +++ b/src/allmydata/test/test_mutable.py @@ -82,6 +82,20 @@ class FakePublish(mutable.Publish): answer = (True, readv) return defer.succeed(answer) +class FakeRetrieve(mutable.Retrieve): + def _do_query(self, args): + pass + def _deserialize_pubkey(self, pubkey_s): + return FakePubKey(134) + +class LessFakeFilenode(mutable.MutableFileNode): + publish_class = FakePublish + retrieve_class = FakeRetrieve + + def _generate_pubprivkeys(self): + count = self.counter.next() + return FakePubKey(count), FakePrivKey(count) + class FakeNewDirectoryNode(dirnode2.NewDirectoryNode): filenode_class = FakeFilenode @@ -392,6 +406,9 @@ class FakePubKey: self.count = count def serialize(self): return "PUBKEY-%d" % self.count + def verify(self, msg, signature): + return True + class FakePrivKey: def __init__(self, count): self.count = count