2007-03-29 21:01:28 +00:00
|
|
|
#! /usr/bin/env python
|
2006-12-05 19:25:23 +00:00
|
|
|
|
2007-04-27 06:14:13 +00:00
|
|
|
import os, subprocess, sys, signal, time
|
2007-06-26 23:19:18 +00:00
|
|
|
from cStringIO import StringIO
|
2006-12-05 19:25:23 +00:00
|
|
|
from twisted.python import usage
|
|
|
|
|
2007-04-27 06:14:13 +00:00
|
|
|
from twisted.python.procutils import which
|
|
|
|
|
|
|
|
def testtwistd(loc):
|
|
|
|
try:
|
|
|
|
return subprocess.call(["python", loc,], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
except:
|
|
|
|
return -1
|
|
|
|
|
|
|
|
twistd = None
|
|
|
|
if not twistd:
|
|
|
|
for maybetwistd in which("twistd"):
|
|
|
|
ret = testtwistd(maybetwistd)
|
|
|
|
if ret == 0:
|
|
|
|
twistd = maybetwistd
|
|
|
|
break
|
|
|
|
|
|
|
|
if not twistd:
|
|
|
|
for maybetwistd in which("twistd.py"):
|
|
|
|
ret = testtwistd(maybetwistd)
|
|
|
|
if ret == 0:
|
|
|
|
twistd = maybetwistd
|
|
|
|
break
|
|
|
|
|
|
|
|
if not twistd:
|
|
|
|
maybetwistd = os.path.join(sys.prefix, 'Scripts', 'twistd')
|
|
|
|
ret = testtwistd(maybetwistd)
|
|
|
|
if ret == 0:
|
|
|
|
twistd = maybetwistd
|
|
|
|
|
|
|
|
if not twistd:
|
|
|
|
maybetwistd = os.path.join(sys.prefix, 'Scripts', 'twistd.py')
|
|
|
|
ret = testtwistd(maybetwistd)
|
|
|
|
if ret == 0:
|
|
|
|
twistd = maybetwistd
|
|
|
|
|
|
|
|
if not twistd:
|
|
|
|
print "Can't find twistd (it comes with Twisted). Aborting."
|
|
|
|
sys.exit(1)
|
2007-05-24 18:20:39 +00:00
|
|
|
|
|
|
|
class BasedirMixin:
|
2007-06-06 21:06:57 +00:00
|
|
|
optFlags = [
|
|
|
|
["multiple", "m", "allow multiple basedirs to be specified at once"],
|
|
|
|
]
|
|
|
|
|
2007-05-24 18:20:39 +00:00
|
|
|
def postOptions(self):
|
2007-06-06 21:06:57 +00:00
|
|
|
if not self.basedirs:
|
2007-05-24 18:20:39 +00:00
|
|
|
raise usage.UsageError("<basedir> parameter is required")
|
2007-06-06 21:06:57 +00:00
|
|
|
if self['basedir']:
|
|
|
|
del self['basedir']
|
|
|
|
self['basedirs'] = [os.path.abspath(os.path.expanduser(b))
|
|
|
|
for b in self.basedirs]
|
2007-05-24 18:20:39 +00:00
|
|
|
|
2007-06-06 18:37:19 +00:00
|
|
|
def parseArgs(self, *args):
|
2007-06-06 21:06:57 +00:00
|
|
|
self.basedirs = []
|
|
|
|
if self['basedir']:
|
|
|
|
self.basedirs.append(self['basedir'])
|
|
|
|
if self['multiple']:
|
|
|
|
self.basedirs.extend(args)
|
|
|
|
else:
|
|
|
|
if len(args) == 0 and not self.basedirs:
|
|
|
|
self.basedirs.append(".")
|
|
|
|
if len(args) > 0:
|
|
|
|
self.basedirs.append(args[0])
|
|
|
|
if len(args) > 1:
|
|
|
|
raise usage.UsageError("I wasn't expecting so many arguments")
|
|
|
|
|
|
|
|
class NoDefaultBasedirMixin(BasedirMixin):
|
|
|
|
def parseArgs(self, *args):
|
|
|
|
# create-client won't default to --basedir=.
|
|
|
|
self.basedirs = []
|
|
|
|
if self['basedir']:
|
|
|
|
self.basedirs.append(self['basedir'])
|
|
|
|
if self['multiple']:
|
|
|
|
self.basedirs.extend(args)
|
|
|
|
else:
|
|
|
|
if len(args) > 0:
|
|
|
|
self.basedirs.append(args[0])
|
|
|
|
if len(args) > 1:
|
|
|
|
raise usage.UsageError("I wasn't expecting so many arguments")
|
|
|
|
if not self.basedirs:
|
|
|
|
raise usage.UsageError("--basedir must be provided")
|
2007-06-06 18:37:19 +00:00
|
|
|
|
2007-05-24 18:20:39 +00:00
|
|
|
class StartOptions(BasedirMixin, usage.Options):
|
2006-12-05 19:25:23 +00:00
|
|
|
optParameters = [
|
2007-06-06 21:06:57 +00:00
|
|
|
["basedir", "C", None, "which directory to start the node in"],
|
2006-12-05 19:25:23 +00:00
|
|
|
]
|
|
|
|
|
2007-05-24 18:20:39 +00:00
|
|
|
class StopOptions(BasedirMixin, usage.Options):
|
2006-12-05 19:25:23 +00:00
|
|
|
optParameters = [
|
2007-06-06 21:06:57 +00:00
|
|
|
["basedir", "C", None, "which directory to stop the node in"],
|
2006-12-05 19:25:23 +00:00
|
|
|
]
|
|
|
|
|
2007-05-24 18:20:39 +00:00
|
|
|
class RestartOptions(BasedirMixin, usage.Options):
|
2006-12-05 19:25:23 +00:00
|
|
|
optParameters = [
|
2007-06-06 21:06:57 +00:00
|
|
|
["basedir", "C", None, "which directory to restart the node in"],
|
2006-12-05 19:25:23 +00:00
|
|
|
]
|
2007-07-07 18:17:32 +00:00
|
|
|
optFlags = [
|
|
|
|
["force", "f", "if the node is not already running, start it "
|
|
|
|
"instead of complaining that you should have used 'start' instead "
|
|
|
|
"of 'restart'"],
|
|
|
|
]
|
2006-12-05 19:25:23 +00:00
|
|
|
|
2007-06-06 21:06:57 +00:00
|
|
|
class CreateClientOptions(NoDefaultBasedirMixin, usage.Options):
|
2006-12-05 19:25:23 +00:00
|
|
|
optParameters = [
|
2006-12-05 19:35:15 +00:00
|
|
|
["basedir", "C", None, "which directory to create the client in"],
|
2006-12-05 19:25:23 +00:00
|
|
|
]
|
2006-12-05 19:35:15 +00:00
|
|
|
|
2007-06-06 21:06:57 +00:00
|
|
|
class CreateIntroducerOptions(NoDefaultBasedirMixin, usage.Options):
|
2006-12-05 19:25:23 +00:00
|
|
|
optParameters = [
|
2007-04-20 00:30:21 +00:00
|
|
|
["basedir", "C", None, "which directory to create the introducer in"],
|
2006-12-05 19:25:23 +00:00
|
|
|
]
|
|
|
|
|
2007-06-12 01:38:21 +00:00
|
|
|
class DumpOptions(usage.Options):
|
|
|
|
optParameters = [
|
|
|
|
["filename", "f", None, "which file to dump"],
|
|
|
|
]
|
|
|
|
|
|
|
|
def parseArgs(self, filename=None):
|
|
|
|
if filename:
|
|
|
|
self['filename'] = filename
|
|
|
|
|
|
|
|
def postOptions(self):
|
|
|
|
if not self['filename']:
|
|
|
|
raise usage.UsageError("<filename> parameter is required")
|
|
|
|
|
2007-06-25 20:23:51 +00:00
|
|
|
class DumpRootDirnodeOptions(BasedirMixin, usage.Options):
|
|
|
|
optParameters = [
|
|
|
|
["basedir", "C", None, "the vdrive-server's base directory"],
|
|
|
|
]
|
|
|
|
|
|
|
|
class DumpDirnodeOptions(BasedirMixin, usage.Options):
|
|
|
|
optParameters = [
|
|
|
|
["uri", "u", None, "the URI of the dirnode to dump."],
|
|
|
|
["basedir", "C", None, "which directory to create the introducer in"],
|
|
|
|
]
|
|
|
|
optFlags = [
|
|
|
|
["verbose", "v", "be extra noisy (show encrypted data)"],
|
|
|
|
]
|
|
|
|
def parseArgs(self, *args):
|
|
|
|
if len(args) == 1:
|
|
|
|
self['uri'] = args[-1]
|
|
|
|
args = args[:-1]
|
|
|
|
BasedirMixin.parseArgs(self, *args)
|
|
|
|
|
|
|
|
def postOptions(self):
|
|
|
|
BasedirMixin.postOptions(self)
|
|
|
|
if not self['uri']:
|
|
|
|
raise usage.UsageError("<uri> parameter is required")
|
|
|
|
|
2006-12-05 19:25:23 +00:00
|
|
|
client_tac = """
|
|
|
|
# -*- python -*-
|
|
|
|
|
|
|
|
from allmydata import client
|
|
|
|
from twisted.application import service
|
|
|
|
|
|
|
|
c = client.Client()
|
|
|
|
|
|
|
|
application = service.Application("allmydata_client")
|
|
|
|
c.setServiceParent(application)
|
|
|
|
"""
|
|
|
|
|
2007-04-20 00:30:21 +00:00
|
|
|
introducer_tac = """
|
2006-12-05 19:25:23 +00:00
|
|
|
# -*- python -*-
|
|
|
|
|
2007-04-30 16:57:52 +00:00
|
|
|
from allmydata import introducer_and_vdrive
|
2006-12-05 19:25:23 +00:00
|
|
|
from twisted.application import service
|
|
|
|
|
2007-04-30 16:57:52 +00:00
|
|
|
c = introducer_and_vdrive.IntroducerAndVdrive()
|
2006-12-05 19:25:23 +00:00
|
|
|
|
2007-04-20 00:30:21 +00:00
|
|
|
application = service.Application("allmydata_introducer")
|
2006-12-05 19:25:23 +00:00
|
|
|
c.setServiceParent(application)
|
|
|
|
"""
|
|
|
|
|
|
|
|
class Options(usage.Options):
|
|
|
|
synopsis = "Usage: allmydata <command> [command options]"
|
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
optFlags = [
|
|
|
|
["quiet", "q", "operate silently"],
|
|
|
|
]
|
|
|
|
|
2006-12-05 19:35:15 +00:00
|
|
|
subCommands = [
|
|
|
|
["create-client", None, CreateClientOptions, "Create a client node."],
|
2007-04-20 00:30:21 +00:00
|
|
|
["create-introducer", None, CreateIntroducerOptions, "Create a introducer node."],
|
2006-12-05 19:35:15 +00:00
|
|
|
["start", None, StartOptions, "Start a node (of any type)."],
|
|
|
|
["stop", None, StopOptions, "Stop a node."],
|
|
|
|
["restart", None, RestartOptions, "Restart a node."],
|
2007-06-12 01:38:21 +00:00
|
|
|
["dump-uri-extension", None, DumpOptions,
|
|
|
|
"Unpack and display the contents of a uri_extension file."],
|
2007-06-25 20:23:51 +00:00
|
|
|
["dump-root-dirnode", None, DumpRootDirnodeOptions,
|
|
|
|
"Compute most of the URI for the vdrive server's root dirnode."],
|
|
|
|
["dump-dirnode", None, DumpDirnodeOptions,
|
2007-06-15 07:47:05 +00:00
|
|
|
"Unpack and display the contents of a vdrive DirectoryNode."],
|
2006-12-05 19:25:23 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
def postOptions(self):
|
|
|
|
if not hasattr(self, 'subOptions'):
|
|
|
|
raise usage.UsageError("must specify a command")
|
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def runner(argv, run_by_human=True, stdout=sys.stdout, stderr=sys.stderr):
|
2006-12-05 19:25:23 +00:00
|
|
|
config = Options()
|
|
|
|
try:
|
2007-04-20 01:56:45 +00:00
|
|
|
config.parseOptions(argv)
|
2006-12-05 19:25:23 +00:00
|
|
|
except usage.error, e:
|
2007-04-24 04:28:19 +00:00
|
|
|
if not run_by_human:
|
|
|
|
raise
|
2006-12-05 19:25:23 +00:00
|
|
|
print "%s: %s" % (sys.argv[0], e)
|
|
|
|
print
|
|
|
|
c = getattr(config, 'subOptions', config)
|
|
|
|
print str(c)
|
2007-04-20 01:56:45 +00:00
|
|
|
return 1
|
2006-12-05 19:25:23 +00:00
|
|
|
|
|
|
|
command = config.subCommand
|
|
|
|
so = config.subOptions
|
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
if config['quiet']:
|
|
|
|
stdout = StringIO()
|
|
|
|
|
2007-06-06 21:06:57 +00:00
|
|
|
rc = 0
|
2006-12-05 19:25:23 +00:00
|
|
|
if command == "create-client":
|
2007-06-06 21:06:57 +00:00
|
|
|
for basedir in so.basedirs:
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = create_client(basedir, so, stdout, stderr) or rc
|
2007-04-20 00:30:21 +00:00
|
|
|
elif command == "create-introducer":
|
2007-06-06 21:06:57 +00:00
|
|
|
for basedir in so.basedirs:
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = create_introducer(basedir, so, stdout, stderr) or rc
|
2006-12-05 19:25:23 +00:00
|
|
|
elif command == "start":
|
2007-06-06 21:06:57 +00:00
|
|
|
for basedir in so.basedirs:
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = start(basedir, so, stdout, stderr) or rc
|
2006-12-05 19:25:23 +00:00
|
|
|
elif command == "stop":
|
2007-06-06 21:06:57 +00:00
|
|
|
for basedir in so.basedirs:
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = stop(basedir, so, stdout, stderr) or rc
|
2006-12-05 19:25:23 +00:00
|
|
|
elif command == "restart":
|
2007-06-06 21:06:57 +00:00
|
|
|
for basedir in so.basedirs:
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = stop(basedir, so, stdout, stderr) or rc
|
2007-07-07 18:17:32 +00:00
|
|
|
if rc == 2 and so['force']:
|
|
|
|
print >>stderr, "ignoring couldn't-stop"
|
|
|
|
rc = 0
|
2007-06-06 21:06:57 +00:00
|
|
|
if rc:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>stderr, "not restarting"
|
2007-06-06 21:06:57 +00:00
|
|
|
return rc
|
|
|
|
for basedir in so.basedirs:
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = start(basedir, so, stdout, stderr) or rc
|
2007-06-12 01:38:21 +00:00
|
|
|
elif command == "dump-uri-extension":
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = dump_uri_extension(so, stdout, stderr)
|
2007-06-25 20:23:51 +00:00
|
|
|
elif command == "dump-root-dirnode":
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = dump_root_dirnode(so.basedirs[0], so, stdout, stderr)
|
2007-06-25 20:23:51 +00:00
|
|
|
elif command == "dump-dirnode":
|
2007-06-26 23:19:18 +00:00
|
|
|
rc = dump_directory_node(so.basedirs[0], so, stdout, stderr)
|
2007-04-20 01:56:45 +00:00
|
|
|
return rc
|
|
|
|
|
|
|
|
def run():
|
|
|
|
rc = runner(sys.argv[1:])
|
2006-12-05 19:25:23 +00:00
|
|
|
sys.exit(rc)
|
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def create_client(basedir, config, out=sys.stdout, err=sys.stderr):
|
2007-03-29 21:32:28 +00:00
|
|
|
if os.path.exists(basedir):
|
|
|
|
if os.listdir(basedir):
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>err, "The base directory already exists: %s" % basedir
|
|
|
|
print >>err, "To avoid clobbering anything, I am going to quit now"
|
|
|
|
print >>err, "Please use a different directory, or delete this one"
|
2007-03-29 21:32:28 +00:00
|
|
|
return -1
|
|
|
|
# we're willing to use an empty directory
|
|
|
|
else:
|
|
|
|
os.mkdir(basedir)
|
2006-12-05 19:25:23 +00:00
|
|
|
f = open(os.path.join(basedir, "client.tac"), "w")
|
|
|
|
f.write(client_tac)
|
|
|
|
f.close()
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "client created in %s" % basedir
|
|
|
|
print >>out, " please copy introducer.furl and vdrive.furl into the directory"
|
2006-12-05 19:25:23 +00:00
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr):
|
2007-03-29 21:32:28 +00:00
|
|
|
if os.path.exists(basedir):
|
|
|
|
if os.listdir(basedir):
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>err, "The base directory already exists: %s" % basedir
|
|
|
|
print >>err, "To avoid clobbering anything, I am going to quit now"
|
|
|
|
print >>err, "Please use a different directory, or delete this one"
|
2007-03-29 21:32:28 +00:00
|
|
|
return -1
|
|
|
|
# we're willing to use an empty directory
|
|
|
|
else:
|
|
|
|
os.mkdir(basedir)
|
2007-04-20 00:30:21 +00:00
|
|
|
f = open(os.path.join(basedir, "introducer.tac"), "w")
|
|
|
|
f.write(introducer_tac)
|
2006-12-05 19:25:23 +00:00
|
|
|
f.close()
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "introducer created in %s" % basedir
|
2006-12-05 19:25:23 +00:00
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def start(basedir, config, out=sys.stdout, err=sys.stderr):
|
|
|
|
print >>out, "STARTING", basedir
|
2006-12-05 19:25:23 +00:00
|
|
|
if os.path.exists(os.path.join(basedir, "client.tac")):
|
|
|
|
tac = "client.tac"
|
|
|
|
type = "client"
|
2007-04-20 00:30:21 +00:00
|
|
|
elif os.path.exists(os.path.join(basedir, "introducer.tac")):
|
|
|
|
tac = "introducer.tac"
|
|
|
|
type = "introducer"
|
2006-12-05 19:25:23 +00:00
|
|
|
else:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>err, "%s does not look like a node directory" % basedir
|
2007-05-24 18:20:39 +00:00
|
|
|
if not os.path.isdir(basedir):
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>err, " in fact, it doesn't look like a directory at all!"
|
2006-12-05 19:25:23 +00:00
|
|
|
sys.exit(1)
|
2007-06-06 21:06:57 +00:00
|
|
|
rc = subprocess.call(["python", twistd, "-y", tac,], cwd=basedir)
|
2006-12-05 19:25:23 +00:00
|
|
|
if rc == 0:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "%s node probably started" % type
|
2006-12-06 02:43:52 +00:00
|
|
|
return 0
|
2006-12-05 19:25:23 +00:00
|
|
|
else:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>err, "%s node probably not started" % type
|
2006-12-06 02:43:52 +00:00
|
|
|
return 1
|
2006-12-05 19:25:23 +00:00
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def stop(basedir, config, out=sys.stdout, err=sys.stderr):
|
|
|
|
print >>out, "STOPPING", basedir
|
2006-12-05 19:25:23 +00:00
|
|
|
pidfile = os.path.join(basedir, "twistd.pid")
|
|
|
|
if not os.path.exists(pidfile):
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>err, "%s does not look like a running node directory (no twistd.pid)" % basedir
|
2007-07-07 18:17:32 +00:00
|
|
|
return 2
|
2006-12-05 19:25:23 +00:00
|
|
|
pid = open(pidfile, "r").read()
|
|
|
|
pid = int(pid)
|
|
|
|
|
|
|
|
timer = 0
|
2006-12-05 19:37:58 +00:00
|
|
|
os.kill(pid, signal.SIGTERM)
|
2006-12-05 19:25:23 +00:00
|
|
|
time.sleep(0.1)
|
|
|
|
while timer < 5:
|
|
|
|
# poll once per second until twistd.pid goes away, up to 5 seconds
|
|
|
|
try:
|
|
|
|
os.kill(pid, 0)
|
|
|
|
except OSError:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "process %d is dead" % pid
|
2006-12-05 19:25:23 +00:00
|
|
|
return
|
|
|
|
timer += 1
|
|
|
|
time.sleep(1)
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>err, "never saw process go away"
|
2006-12-05 19:25:23 +00:00
|
|
|
return 1
|
2007-06-12 01:38:21 +00:00
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def dump_uri_extension(config, out=sys.stdout, err=sys.stderr):
|
2007-06-12 01:38:21 +00:00
|
|
|
from allmydata import uri
|
|
|
|
|
|
|
|
filename = config['filename']
|
|
|
|
unpacked = uri.unpack_extension_readable(open(filename,"rb").read())
|
|
|
|
keys1 = ("size", "num_segments", "segment_size",
|
|
|
|
"needed_shares", "total_shares")
|
|
|
|
keys2 = ("codec_name", "codec_params", "tail_codec_params")
|
|
|
|
keys3 = ("plaintext_hash", "plaintext_root_hash",
|
|
|
|
"crypttext_hash", "crypttext_root_hash",
|
|
|
|
"share_root_hash")
|
|
|
|
for k in keys1:
|
|
|
|
if k in unpacked:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "%19s: %s" % (k, unpacked[k])
|
|
|
|
print >>out
|
2007-06-12 01:38:21 +00:00
|
|
|
for k in keys2:
|
|
|
|
if k in unpacked:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "%19s: %s" % (k, unpacked[k])
|
|
|
|
print >>out
|
2007-06-12 01:38:21 +00:00
|
|
|
for k in keys3:
|
|
|
|
if k in unpacked:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "%19s: %s" % (k, unpacked[k])
|
2007-06-12 01:38:21 +00:00
|
|
|
|
|
|
|
leftover = set(unpacked.keys()) - set(keys1 + keys2 + keys3)
|
|
|
|
if leftover:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out
|
2007-06-12 01:38:21 +00:00
|
|
|
for k in sorted(leftover):
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "%s: %s" % (k, unpacked[k])
|
2007-06-12 01:38:21 +00:00
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out
|
2007-06-12 01:38:21 +00:00
|
|
|
return 0
|
2007-06-15 07:47:05 +00:00
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def dump_root_dirnode(basedir, config, out=sys.stdout, err=sys.stderr):
|
2007-06-25 20:23:51 +00:00
|
|
|
from allmydata import uri
|
2007-06-15 07:47:05 +00:00
|
|
|
|
2007-06-25 20:23:51 +00:00
|
|
|
root_dirnode_file = os.path.join(basedir, "vdrive", "root")
|
|
|
|
try:
|
|
|
|
f = open(root_dirnode_file, "rb")
|
|
|
|
key = f.read()
|
|
|
|
rooturi = uri.pack_dirnode_uri("fakeFURL", key)
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, rooturi
|
2007-06-25 20:23:51 +00:00
|
|
|
return 0
|
|
|
|
except EnvironmentError:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "unable to read root dirnode file from %s" % \
|
2007-06-26 22:36:46 +00:00
|
|
|
root_dirnode_file
|
2007-06-25 20:23:51 +00:00
|
|
|
return 1
|
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
def dump_directory_node(basedir, config, out=sys.stdout, err=sys.stderr):
|
2007-06-27 00:16:58 +00:00
|
|
|
from allmydata import uri, dirnode
|
2007-06-25 20:23:51 +00:00
|
|
|
from allmydata.util import hashutil, idlib
|
|
|
|
dir_uri = config['uri']
|
|
|
|
verbose = config['verbose']
|
|
|
|
|
|
|
|
furl, key = uri.unpack_dirnode_uri(dir_uri)
|
|
|
|
if uri.is_mutable_dirnode_uri(dir_uri):
|
|
|
|
wk, we, rk, index = hashutil.generate_dirnode_keys_from_writekey(key)
|
|
|
|
else:
|
|
|
|
wk, we, rk, index = hashutil.generate_dirnode_keys_from_readkey(key)
|
|
|
|
|
|
|
|
filename = os.path.join(basedir, "vdrive", idlib.b2a(index))
|
2007-06-15 07:47:05 +00:00
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out
|
|
|
|
print >>out, "dirnode uri: %s" % dir_uri
|
|
|
|
print >>out, "filename : %s" % filename
|
|
|
|
print >>out, "index : %s" % idlib.b2a(index)
|
2007-06-25 20:23:51 +00:00
|
|
|
if wk:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "writekey : %s" % idlib.b2a(wk)
|
|
|
|
print >>out, "write_enabler: %s" % idlib.b2a(we)
|
2007-06-25 20:23:51 +00:00
|
|
|
else:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "writekey : None"
|
|
|
|
print >>out, "write_enabler: None"
|
|
|
|
print >>out, "readkey : %s" % idlib.b2a(rk)
|
2007-06-15 07:47:05 +00:00
|
|
|
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out
|
2007-06-15 07:47:05 +00:00
|
|
|
|
2007-06-27 00:16:58 +00:00
|
|
|
vds = dirnode.VirtualDriveServer(os.path.join(basedir, "vdrive"), False)
|
2007-06-25 20:23:51 +00:00
|
|
|
data = vds._read_from_file(index)
|
|
|
|
if we:
|
|
|
|
if we != data[0]:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, "ERROR: write_enabler does not match"
|
2007-06-25 20:23:51 +00:00
|
|
|
|
|
|
|
for (H_key, E_key, E_write, E_read) in data[1]:
|
|
|
|
if verbose:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, " H_key %s" % idlib.b2a(H_key)
|
|
|
|
print >>out, " E_key %s" % idlib.b2a(E_key)
|
|
|
|
print >>out, " E_write %s" % idlib.b2a(E_write)
|
|
|
|
print >>out, " E_read %s" % idlib.b2a(E_read)
|
2007-06-27 00:16:58 +00:00
|
|
|
key = dirnode.decrypt(rk, E_key)
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, " key %s" % key
|
2007-06-25 20:23:51 +00:00
|
|
|
if hashutil.dir_name_hash(rk, key) != H_key:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, " ERROR: H_key does not match"
|
2007-06-25 20:23:51 +00:00
|
|
|
if wk and E_write:
|
|
|
|
if len(E_write) < 14:
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, " ERROR: write data is short:", idlib.b2a(E_write)
|
2007-06-27 00:16:58 +00:00
|
|
|
write = dirnode.decrypt(wk, E_write)
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, " write: %s" % write
|
2007-06-27 00:16:58 +00:00
|
|
|
read = dirnode.decrypt(rk, E_read)
|
2007-06-26 23:19:18 +00:00
|
|
|
print >>out, " read: %s" % read
|
|
|
|
print >>out
|
2007-06-25 20:23:51 +00:00
|
|
|
|
|
|
|
return 0
|