class MutableFileNode:
implements(IMutableFileNode)
+ publish_class = Publish
+ retrieve_class = Retrieve
def __init__(self, client):
self._client = client
"""
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
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
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