if offer_public_root:
rootfile = os.path.join(self._basedir, "root")
if not os.path.exists(rootfile):
- write_key = hashutil.random_key()
- (wk, we, rk, index) = \
- hashutil.generate_dirnode_keys_from_writekey(write_key)
- self.create_directory(index, we)
+ u = uri.DirnodeURI("fakefurl", hashutil.random_key())
+ self.create_directory(u.storage_index, u.write_enabler)
f = open(rootfile, "wb")
- f.write(wk)
+ f.write(u.writekey)
f.close()
- self._root = wk
+ self._root = u.writekey
else:
f = open(rootfile, "rb")
self._root = f.read()
self._client = client
self._tub = client.tub
self._rref = rref
+
self._readkey = u.readkey
- self._writekey = None
- self._write_enabler = None
- self._index = hashutil.dir_index_hash(self._readkey)
+ self._writekey = u.writekey
+ self._write_enabler = u.write_enabler
+ self._index = u.storage_index
self._mutable = False
def dump(self):
def get_refresh_capability(self):
u = IDirnodeURI(self._uri).get_readonly()
- rk = u.readkey
- wk, we, rk, index = hashutil.generate_dirnode_keys_from_readkey(rk)
- return "DIR-REFRESH:%s" % idlib.b2a(index)
+ return "DIR-REFRESH:%s" % idlib.b2a(u.storage_index)
def get_child_at_path(self, path):
if not path:
def __init__(self, myuri, client, rref):
u = IDirnodeURI(myuri)
assert not u.is_readonly()
- self._writekey = u.writekey
- self._write_enabler = hashutil.dir_write_enabler_hash(u.writekey)
- readkey = hashutil.dir_read_key_hash(u.writekey)
self._uri = u.to_string()
self._client = client
self._tub = client.tub
self._rref = rref
- self._readkey = readkey
- self._index = hashutil.dir_index_hash(self._readkey)
+
+ self._readkey = u.readkey
+ self._writekey = u.writekey
+ self._write_enabler = u.write_enabler
+ self._index = u.storage_index
self._mutable = True
def create_directory(client, furl):
- write_key = hashutil.random_key()
- (wk, we, rk, index) = \
- hashutil.generate_dirnode_keys_from_writekey(write_key)
- u = uri.DirnodeURI(furl, wk)
+ u = uri.DirnodeURI(furl, hashutil.random_key())
d = client.tub.getReference(furl)
def _got_vdrive_server(vdrive_server):
node = MutableDirectoryNode(u, client, vdrive_server)
- d2 = vdrive_server.callRemote("create_directory", index, we)
+ d2 = vdrive_server.callRemote("create_directory",
+ u.storage_index, u.write_enabler)
d2.addCallback(lambda res: node)
return d2
d.addCallback(_got_vdrive_server)
assert writekey is not None
self.furl = furl
self.writekey = writekey
+ self._derive_values()
def init_from_string(self, uri):
# URI:DIR:furl:key
colon = uri.rindex(":")
self.furl = uri[:colon]
self.writekey = idlib.a2b(uri[colon+1:])
+ self._derive_values()
return self
+ def _derive_values(self):
+ wk, we, rk, index = \
+ hashutil.generate_dirnode_keys_from_writekey(self.writekey)
+ self.write_enabler = we
+ self.readkey = rk
+ self.storage_index = index
+
def to_string(self):
return "URI:DIR:%s:%s" % (self.furl, idlib.b2a(self.writekey))
def is_mutable(self):
return True
def get_readonly(self):
- u = ReadOnlyDirnodeURI()
- u.furl = self.furl
- u.readkey = hashutil.dir_read_key_hash(self.writekey)
- return u
+ return ReadOnlyDirnodeURI(self.furl, self.readkey)
class ReadOnlyDirnodeURI(_BaseURI):
implements(IURI, IDirnodeURI)
assert readkey is not None
self.furl = furl
self.readkey = readkey
+ self._derive_values()
def init_from_string(self, uri):
# URI:DIR-RO:furl:key
colon = uri.rindex(":")
self.furl = uri[:colon]
self.readkey = idlib.a2b(uri[colon+1:])
+ self._derive_values()
return self
+ def _derive_values(self):
+ wk, we, rk, index = \
+ hashutil.generate_dirnode_keys_from_readkey(self.readkey)
+ self.writekey = wk # None
+ self.write_enabler = we # None
+ self.storage_index = index
+
def to_string(self):
return "URI:DIR-RO:%s:%s" % (self.furl, idlib.b2a(self.readkey))