mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 13:07:56 +00:00
uri.py: get keys and index from the URI instance
This commit is contained in:
parent
9cac3261a7
commit
2bc3c163b6
@ -32,14 +32,12 @@ class VirtualDriveServer(service.MultiService, Referenceable):
|
||||
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()
|
||||
@ -170,10 +168,11 @@ class ImmutableDirectoryNode:
|
||||
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):
|
||||
@ -362,9 +361,7 @@ class ImmutableDirectoryNode:
|
||||
|
||||
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:
|
||||
@ -386,26 +383,24 @@ class MutableDirectoryNode(ImmutableDirectoryNode):
|
||||
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)
|
||||
|
@ -114,6 +114,7 @@ class DirnodeURI(_BaseURI):
|
||||
assert writekey is not None
|
||||
self.furl = furl
|
||||
self.writekey = writekey
|
||||
self._derive_values()
|
||||
|
||||
def init_from_string(self, uri):
|
||||
# URI:DIR:furl:key
|
||||
@ -124,8 +125,16 @@ class DirnodeURI(_BaseURI):
|
||||
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))
|
||||
|
||||
@ -134,10 +143,7 @@ class DirnodeURI(_BaseURI):
|
||||
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)
|
||||
@ -148,6 +154,7 @@ class ReadOnlyDirnodeURI(_BaseURI):
|
||||
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
|
||||
@ -158,8 +165,16 @@ class ReadOnlyDirnodeURI(_BaseURI):
|
||||
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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user