2019-03-24 13:14:00 +00:00
|
|
|
from __future__ import print_function
|
2007-07-11 01:41:52 +00:00
|
|
|
|
2020-11-29 20:48:26 +00:00
|
|
|
try:
|
|
|
|
from allmydata.scripts.types_ import SubCommands
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2020-12-21 18:12:01 +00:00
|
|
|
from future.utils import bchr
|
2021-02-23 17:02:08 +00:00
|
|
|
from past.builtins import unicode
|
2020-12-21 18:12:01 +00:00
|
|
|
|
2007-07-13 23:58:08 +00:00
|
|
|
# do not import any allmydata modules at this level. Do that from inside
|
|
|
|
# individual functions instead.
|
2011-01-18 20:46:59 +00:00
|
|
|
import struct, time, os, sys
|
2008-10-29 22:10:10 +00:00
|
|
|
from twisted.python import usage, failure
|
|
|
|
from twisted.internet import defer
|
2012-03-31 22:41:22 +00:00
|
|
|
from foolscap.logging import cli as foolscap_cli
|
2012-06-18 17:43:49 +00:00
|
|
|
from allmydata.scripts.common import BaseOptions
|
2007-07-11 01:41:52 +00:00
|
|
|
|
2010-07-22 00:14:18 +00:00
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class DumpOptions(BaseOptions):
|
2008-08-12 20:37:32 +00:00
|
|
|
def getSynopsis(self):
|
2015-05-26 18:31:06 +00:00
|
|
|
return "Usage: tahoe [global-options] debug dump-share SHARE_FILENAME"
|
2008-08-12 20:37:32 +00:00
|
|
|
|
2008-08-12 21:46:56 +00:00
|
|
|
optFlags = [
|
2010-08-03 08:48:01 +00:00
|
|
|
["offsets", None, "Display a table of section offsets."],
|
|
|
|
["leases-only", None, "Dump leases but not CHK contents."],
|
2008-08-12 21:46:56 +00:00
|
|
|
]
|
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2008-08-12 20:37:32 +00:00
|
|
|
Print lots of information about the given share, by parsing the share's
|
|
|
|
contents. This includes share type, lease information, encoding parameters,
|
|
|
|
hash-tree roots, public keys, and segment sizes. This command also emits a
|
|
|
|
verify-cap for the file that uses the share.
|
|
|
|
|
|
|
|
tahoe debug dump-share testgrid/node-3/storage/shares/4v/4vozh77tsrw7mdhnj7qvp5ky74/0
|
|
|
|
"""
|
2007-07-11 01:41:52 +00:00
|
|
|
|
2008-02-06 21:15:33 +00:00
|
|
|
def parseArgs(self, filename):
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.encodingutil import argv_to_abspath
|
|
|
|
self['filename'] = argv_to_abspath(filename)
|
2007-07-11 01:41:52 +00:00
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
def dump_share(options):
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata.storage.mutable import MutableShareFile
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.encodingutil import quote_output
|
2007-07-11 01:41:52 +00:00
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
out = options.stdout
|
|
|
|
|
2007-11-07 01:55:55 +00:00
|
|
|
# check the version, to see if we have a mutable or immutable share
|
2019-03-24 13:14:00 +00:00
|
|
|
print("share filename: %s" % quote_output(options['filename']), file=out)
|
2008-02-06 20:19:51 +00:00
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
f = open(options['filename'], "rb")
|
2007-11-07 01:55:55 +00:00
|
|
|
prefix = f.read(32)
|
|
|
|
f.close()
|
2009-02-18 21:46:55 +00:00
|
|
|
if prefix == MutableShareFile.MAGIC:
|
2008-08-12 20:52:42 +00:00
|
|
|
return dump_mutable_share(options)
|
2007-11-07 01:55:55 +00:00
|
|
|
# otherwise assume it's immutable
|
2008-08-12 20:55:17 +00:00
|
|
|
return dump_immutable_share(options)
|
|
|
|
|
|
|
|
def dump_immutable_share(options):
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata.storage.immutable import ShareFile
|
2008-08-12 20:55:17 +00:00
|
|
|
|
|
|
|
out = options.stdout
|
2009-02-18 21:46:55 +00:00
|
|
|
f = ShareFile(options['filename'])
|
2009-03-07 05:45:17 +00:00
|
|
|
if not options["leases-only"]:
|
|
|
|
dump_immutable_chk_share(f, out, options)
|
|
|
|
dump_immutable_lease_info(f, out)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
2009-03-07 05:45:17 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
def dump_immutable_chk_share(f, out, options):
|
|
|
|
from allmydata import uri
|
|
|
|
from allmydata.util import base32
|
|
|
|
from allmydata.immutable.layout import ReadBucketProxy
|
2020-08-14 17:49:48 +00:00
|
|
|
from allmydata.util.encodingutil import quote_output, to_bytes
|
2010-07-22 00:14:18 +00:00
|
|
|
|
2007-07-13 23:58:08 +00:00
|
|
|
# use a ReadBucketProxy to parse the bucket and find the uri extension
|
2011-08-01 22:43:07 +00:00
|
|
|
bp = ReadBucketProxy(None, None, '')
|
2008-10-10 01:34:22 +00:00
|
|
|
offsets = bp._parse_offsets(f.read_share_data(0, 0x44))
|
2019-03-24 13:14:00 +00:00
|
|
|
print("%20s: %d" % ("version", bp._version), file=out)
|
2007-09-02 21:48:20 +00:00
|
|
|
seek = offsets['uri_extension']
|
2008-10-10 01:34:22 +00:00
|
|
|
length = struct.unpack(bp._fieldstruct,
|
|
|
|
f.read_share_data(seek, bp._fieldsize))[0]
|
|
|
|
seek += bp._fieldsize
|
2008-02-06 19:48:19 +00:00
|
|
|
UEB_data = f.read_share_data(seek, length)
|
2007-07-13 23:58:08 +00:00
|
|
|
|
2008-02-06 19:48:19 +00:00
|
|
|
unpacked = uri.unpack_extension_readable(UEB_data)
|
2007-07-11 01:41:52 +00:00
|
|
|
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",
|
2008-02-06 19:48:19 +00:00
|
|
|
"share_root_hash", "UEB_hash")
|
2007-09-26 22:00:59 +00:00
|
|
|
display_keys = {"size": "file_size"}
|
2021-02-23 17:02:08 +00:00
|
|
|
|
|
|
|
def to_string(v):
|
|
|
|
if isinstance(v, bytes):
|
|
|
|
return unicode(v, "utf-8")
|
|
|
|
else:
|
|
|
|
return str(v)
|
|
|
|
|
2007-07-11 01:41:52 +00:00
|
|
|
for k in keys1:
|
|
|
|
if k in unpacked:
|
2007-09-26 22:00:59 +00:00
|
|
|
dk = display_keys.get(k, k)
|
2021-02-23 17:02:08 +00:00
|
|
|
print("%20s: %s" % (dk, to_string(unpacked[k])), file=out)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
2007-07-11 01:41:52 +00:00
|
|
|
for k in keys2:
|
|
|
|
if k in unpacked:
|
2007-09-26 22:00:59 +00:00
|
|
|
dk = display_keys.get(k, k)
|
2021-02-23 17:02:08 +00:00
|
|
|
print("%20s: %s" % (dk, to_string(unpacked[k])), file=out)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
2007-07-11 01:41:52 +00:00
|
|
|
for k in keys3:
|
|
|
|
if k in unpacked:
|
2007-09-26 22:00:59 +00:00
|
|
|
dk = display_keys.get(k, k)
|
2021-02-23 17:02:08 +00:00
|
|
|
print("%20s: %s" % (dk, to_string(unpacked[k])), file=out)
|
2007-07-11 01:41:52 +00:00
|
|
|
|
|
|
|
leftover = set(unpacked.keys()) - set(keys1 + keys2 + keys3)
|
|
|
|
if leftover:
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
|
|
|
print("LEFTOVER:", file=out)
|
2007-07-11 01:41:52 +00:00
|
|
|
for k in sorted(leftover):
|
2021-02-23 17:02:08 +00:00
|
|
|
print("%20s: %s" % (k, to_string(unpacked[k])), file=out)
|
2007-07-11 01:41:52 +00:00
|
|
|
|
2008-07-07 21:11:02 +00:00
|
|
|
# the storage index isn't stored in the share itself, so we depend upon
|
|
|
|
# knowing the parent directory name to get it
|
2008-08-12 20:52:42 +00:00
|
|
|
pieces = options['filename'].split(os.sep)
|
2010-07-22 00:14:18 +00:00
|
|
|
if len(pieces) >= 2:
|
2020-08-14 17:49:48 +00:00
|
|
|
piece = to_bytes(pieces[-2])
|
2010-07-22 00:14:18 +00:00
|
|
|
if base32.could_be_base32_encoded(piece):
|
|
|
|
storage_index = base32.a2b(piece)
|
|
|
|
uri_extension_hash = base32.a2b(unpacked["UEB_hash"])
|
|
|
|
u = uri.CHKFileVerifierURI(storage_index, uri_extension_hash,
|
|
|
|
unpacked["needed_shares"],
|
|
|
|
unpacked["total_shares"], unpacked["size"])
|
|
|
|
verify_cap = u.to_string()
|
2019-03-24 13:14:00 +00:00
|
|
|
print("%20s: %s" % ("verify-cap", quote_output(verify_cap, quotemarks=False)), file=out)
|
2008-07-07 21:11:02 +00:00
|
|
|
|
2007-08-27 06:42:39 +00:00
|
|
|
sizes = {}
|
immutable: refactor downloader to be more reusable for checker/verifier/repairer (and better)
The code for validating the share hash tree and the block hash tree has been rewritten to make sure it handles all cases, to share metadata about the file (such as the share hash tree, block hash trees, and UEB) among different share downloads, and not to require hashes to be stored on the server unnecessarily, such as the roots of the block hash trees (not needed since they are also the leaves of the share hash tree), and the root of the share hash tree (not needed since it is also included in the UEB). It also passes the latest tests including handling corrupted shares well.
ValidatedReadBucketProxy takes a share_hash_tree argument to its constructor, which is a reference to a share hash tree shared by all ValidatedReadBucketProxies for that immutable file download.
ValidatedReadBucketProxy requires the block_size and share_size to be provided in its constructor, and it then uses those to compute the offsets and lengths of blocks when it needs them, instead of reading those values out of the share. The user of ValidatedReadBucketProxy therefore has to have first used a ValidatedExtendedURIProxy to compute those two values from the validated contents of the URI. This is pleasingly simplifies safety analysis: the client knows which span of bytes corresponds to a given block from the validated URI data, rather than from the unvalidated data stored on the storage server. It also simplifies unit testing of verifier/repairer, because now it doesn't care about the contents of the "share size" and "block size" fields in the share. It does not relieve the need for share data v2 layout, because we still need to store and retrieve the offsets of the fields which come after the share data, therefore we still need to use share data v2 with its 8-byte fields if we want to store share data larger than about 2^32.
Specify which subset of the block hashes and share hashes you need while downloading a particular share. In the future this will hopefully be used to fetch only a subset, for network efficiency, but currently all of them are fetched, regardless of which subset you specify.
ReadBucketProxy hides the question of whether it has "started" or not (sent a request to the server to get metadata) from its user.
Download is optimized to do as few roundtrips and as few requests as possible, hopefully speeding up download a bit.
2009-01-05 16:51:45 +00:00
|
|
|
sizes['data'] = (offsets['plaintext_hash_tree'] -
|
|
|
|
offsets['data'])
|
2007-08-27 06:42:39 +00:00
|
|
|
sizes['validation'] = (offsets['uri_extension'] -
|
|
|
|
offsets['plaintext_hash_tree'])
|
2008-02-06 19:48:19 +00:00
|
|
|
sizes['uri-extension'] = len(UEB_data)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
|
|
|
print(" Size of data within the share:", file=out)
|
2007-08-27 06:42:39 +00:00
|
|
|
for k in sorted(sizes):
|
2019-03-24 13:14:00 +00:00
|
|
|
print("%20s: %s" % (k, sizes[k]), file=out)
|
2007-08-27 06:42:39 +00:00
|
|
|
|
2008-08-12 21:46:56 +00:00
|
|
|
if options['offsets']:
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
|
|
|
print(" Section Offsets:", file=out)
|
|
|
|
print("%20s: %s" % ("share data", f._data_offset), file=out)
|
2008-08-12 21:46:56 +00:00
|
|
|
for k in ["data", "plaintext_hash_tree", "crypttext_hash_tree",
|
|
|
|
"block_hashes", "share_hashes", "uri_extension"]:
|
|
|
|
name = {"data": "block data"}.get(k,k)
|
|
|
|
offset = f._data_offset + offsets[k]
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" %20s: %s (0x%x)" % (name, offset, offset), file=out)
|
|
|
|
print("%20s: %s" % ("leases", f._lease_offset), file=out)
|
2008-08-12 21:46:56 +00:00
|
|
|
|
2009-03-07 05:45:17 +00:00
|
|
|
def dump_immutable_lease_info(f, out):
|
2007-09-02 21:48:20 +00:00
|
|
|
# display lease information too
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
2009-03-07 05:45:17 +00:00
|
|
|
leases = list(f.get_leases())
|
2007-09-02 21:48:20 +00:00
|
|
|
if leases:
|
|
|
|
for i,lease in enumerate(leases):
|
2008-07-10 01:06:55 +00:00
|
|
|
when = format_expiration_time(lease.expiration_time)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" Lease #%d: owner=%d, expire in %s" \
|
|
|
|
% (i, lease.owner_num, when), file=out)
|
2007-09-02 21:48:20 +00:00
|
|
|
else:
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" No leases.", file=out)
|
2007-09-02 21:48:20 +00:00
|
|
|
|
2007-11-07 01:55:55 +00:00
|
|
|
def format_expiration_time(expiration_time):
|
|
|
|
now = time.time()
|
|
|
|
remains = expiration_time - now
|
|
|
|
when = "%ds" % remains
|
|
|
|
if remains > 24*3600:
|
|
|
|
when += " (%d days)" % (remains / (24*3600))
|
|
|
|
elif remains > 3600:
|
|
|
|
when += " (%d hours)" % (remains / 3600)
|
|
|
|
return when
|
|
|
|
|
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
def dump_mutable_share(options):
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata.storage.mutable import MutableShareFile
|
2008-02-15 02:27:47 +00:00
|
|
|
from allmydata.util import base32, idlib
|
2008-08-12 20:52:42 +00:00
|
|
|
out = options.stdout
|
2009-02-18 21:46:55 +00:00
|
|
|
m = MutableShareFile(options['filename'])
|
2008-08-12 20:52:42 +00:00
|
|
|
f = open(options['filename'], "rb")
|
2007-11-07 01:55:55 +00:00
|
|
|
WE, nodeid = m._read_write_enabler_and_nodeid(f)
|
|
|
|
num_extra_leases = m._read_num_extra_leases(f)
|
|
|
|
data_length = m._read_data_length(f)
|
|
|
|
extra_lease_offset = m._read_extra_lease_offset(f)
|
2007-11-07 02:31:22 +00:00
|
|
|
container_size = extra_lease_offset - m.DATA_OFFSET
|
2007-11-07 01:55:55 +00:00
|
|
|
leases = list(m._enumerate_leases(f))
|
2007-11-07 02:46:31 +00:00
|
|
|
|
|
|
|
share_type = "unknown"
|
|
|
|
f.seek(m.DATA_OFFSET)
|
2011-08-28 07:38:34 +00:00
|
|
|
version = f.read(1)
|
2020-11-09 19:40:29 +00:00
|
|
|
if version == b"\x00":
|
2007-11-07 02:46:31 +00:00
|
|
|
# this slot contains an SMDF share
|
|
|
|
share_type = "SDMF"
|
2020-11-09 19:40:29 +00:00
|
|
|
elif version == b"\x01":
|
2011-08-28 07:38:34 +00:00
|
|
|
share_type = "MDMF"
|
2007-11-07 01:55:55 +00:00
|
|
|
f.close()
|
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
|
|
|
print("Mutable slot found:", file=out)
|
|
|
|
print(" share_type: %s" % share_type, file=out)
|
2021-02-23 17:02:08 +00:00
|
|
|
print(" write_enabler: %s" % unicode(base32.b2a(WE), "utf-8"), file=out)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" WE for nodeid: %s" % idlib.nodeid_b2a(nodeid), file=out)
|
|
|
|
print(" num_extra_leases: %d" % num_extra_leases, file=out)
|
|
|
|
print(" container_size: %d" % container_size, file=out)
|
|
|
|
print(" data_length: %d" % data_length, file=out)
|
2007-11-07 01:55:55 +00:00
|
|
|
if leases:
|
2008-07-10 01:06:55 +00:00
|
|
|
for (leasenum, lease) in leases:
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
|
|
|
print(" Lease #%d:" % leasenum, file=out)
|
|
|
|
print(" ownerid: %d" % lease.owner_num, file=out)
|
2008-07-10 01:06:55 +00:00
|
|
|
when = format_expiration_time(lease.expiration_time)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" expires in %s" % when, file=out)
|
2021-02-23 17:02:08 +00:00
|
|
|
print(" renew_secret: %s" % unicode(base32.b2a(lease.renew_secret), "utf-8"), file=out)
|
|
|
|
print(" cancel_secret: %s" % unicode(base32.b2a(lease.cancel_secret), "utf-8"), file=out)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" secrets are for nodeid: %s" % idlib.nodeid_b2a(lease.nodeid), file=out)
|
2007-11-07 01:55:55 +00:00
|
|
|
else:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("No leases.", file=out)
|
|
|
|
print(file=out)
|
2007-11-07 02:46:31 +00:00
|
|
|
|
|
|
|
if share_type == "SDMF":
|
2008-08-12 21:46:56 +00:00
|
|
|
dump_SDMF_share(m, data_length, options)
|
2011-08-28 07:38:34 +00:00
|
|
|
elif share_type == "MDMF":
|
|
|
|
dump_MDMF_share(m, data_length, options)
|
2007-11-07 02:46:31 +00:00
|
|
|
|
2007-11-07 01:55:55 +00:00
|
|
|
return 0
|
|
|
|
|
2008-08-12 21:46:56 +00:00
|
|
|
def dump_SDMF_share(m, length, options):
|
|
|
|
from allmydata.mutable.layout import unpack_share, unpack_header
|
2008-04-11 21:31:16 +00:00
|
|
|
from allmydata.mutable.common import NeedMoreDataError
|
2008-07-07 21:11:02 +00:00
|
|
|
from allmydata.util import base32, hashutil
|
|
|
|
from allmydata.uri import SSKVerifierURI
|
2020-08-14 17:49:48 +00:00
|
|
|
from allmydata.util.encodingutil import quote_output, to_bytes
|
2007-11-07 02:46:31 +00:00
|
|
|
|
2008-08-12 21:46:56 +00:00
|
|
|
offset = m.DATA_OFFSET
|
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
out = options.stdout
|
|
|
|
|
|
|
|
f = open(options['filename'], "rb")
|
2007-11-07 02:46:31 +00:00
|
|
|
f.seek(offset)
|
|
|
|
data = f.read(min(length, 2000))
|
|
|
|
f.close()
|
|
|
|
|
2007-11-08 00:52:09 +00:00
|
|
|
try:
|
2008-04-11 21:31:16 +00:00
|
|
|
pieces = unpack_share(data)
|
2019-03-28 11:45:28 +00:00
|
|
|
except NeedMoreDataError as e:
|
2007-11-08 00:52:09 +00:00
|
|
|
# retry once with the larger size
|
|
|
|
size = e.needed_bytes
|
2008-08-12 20:52:42 +00:00
|
|
|
f = open(options['filename'], "rb")
|
2007-11-08 00:52:09 +00:00
|
|
|
f.seek(offset)
|
|
|
|
data = f.read(min(length, size))
|
|
|
|
f.close()
|
2008-04-11 21:31:16 +00:00
|
|
|
pieces = unpack_share(data)
|
2007-11-07 02:46:31 +00:00
|
|
|
|
|
|
|
(seqnum, root_hash, IV, k, N, segsize, datalen,
|
|
|
|
pubkey, signature, share_hash_chain, block_hash_tree,
|
|
|
|
share_data, enc_privkey) = pieces
|
2008-08-12 21:46:56 +00:00
|
|
|
(ig_version, ig_seqnum, ig_roothash, ig_IV, ig_k, ig_N, ig_segsize,
|
|
|
|
ig_datalen, offsets) = unpack_header(data)
|
2007-11-07 02:46:31 +00:00
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" SDMF contents:", file=out)
|
|
|
|
print(" seqnum: %d" % seqnum, file=out)
|
2021-02-23 17:02:08 +00:00
|
|
|
print(" root_hash: %s" % unicode(base32.b2a(root_hash), "utf-8"), file=out)
|
|
|
|
print(" IV: %s" % unicode(base32.b2a(IV), "utf-8"), file=out)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" required_shares: %d" % k, file=out)
|
|
|
|
print(" total_shares: %d" % N, file=out)
|
|
|
|
print(" segsize: %d" % segsize, file=out)
|
|
|
|
print(" datalen: %d" % datalen, file=out)
|
|
|
|
print(" enc_privkey: %d bytes" % len(enc_privkey), file=out)
|
|
|
|
print(" pubkey: %d bytes" % len(pubkey), file=out)
|
|
|
|
print(" signature: %d bytes" % len(signature), file=out)
|
2007-11-14 06:08:15 +00:00
|
|
|
share_hash_ids = ",".join(sorted([str(hid)
|
|
|
|
for hid in share_hash_chain.keys()]))
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" share_hash_chain: %s" % share_hash_ids, file=out)
|
|
|
|
print(" block_hash_tree: %d nodes" % len(block_hash_tree), file=out)
|
2007-11-07 02:46:31 +00:00
|
|
|
|
2008-07-07 21:11:02 +00:00
|
|
|
# the storage index isn't stored in the share itself, so we depend upon
|
|
|
|
# knowing the parent directory name to get it
|
2008-08-12 20:52:42 +00:00
|
|
|
pieces = options['filename'].split(os.sep)
|
2010-07-22 00:14:18 +00:00
|
|
|
if len(pieces) >= 2:
|
2020-08-14 17:49:48 +00:00
|
|
|
piece = to_bytes(pieces[-2])
|
2010-07-22 00:14:18 +00:00
|
|
|
if base32.could_be_base32_encoded(piece):
|
|
|
|
storage_index = base32.a2b(piece)
|
|
|
|
fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey)
|
|
|
|
u = SSKVerifierURI(storage_index, fingerprint)
|
|
|
|
verify_cap = u.to_string()
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" verify-cap:", quote_output(verify_cap, quotemarks=False), file=out)
|
2008-07-07 21:11:02 +00:00
|
|
|
|
2008-08-12 21:46:56 +00:00
|
|
|
if options['offsets']:
|
|
|
|
# NOTE: this offset-calculation code is fragile, and needs to be
|
|
|
|
# merged with MutableShareFile's internals.
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
|
|
|
print(" Section Offsets:", file=out)
|
2008-08-12 21:46:56 +00:00
|
|
|
def printoffset(name, value, shift=0):
|
2019-03-24 13:14:00 +00:00
|
|
|
print("%s%20s: %s (0x%x)" % (" "*shift, name, value, value), file=out)
|
2008-08-12 21:46:56 +00:00
|
|
|
printoffset("first lease", m.HEADER_SIZE)
|
|
|
|
printoffset("share data", m.DATA_OFFSET)
|
|
|
|
o_seqnum = m.DATA_OFFSET + struct.calcsize(">B")
|
|
|
|
printoffset("seqnum", o_seqnum, 2)
|
|
|
|
o_root_hash = m.DATA_OFFSET + struct.calcsize(">BQ")
|
|
|
|
printoffset("root_hash", o_root_hash, 2)
|
|
|
|
for k in ["signature", "share_hash_chain", "block_hash_tree",
|
|
|
|
"share_data",
|
|
|
|
"enc_privkey", "EOF"]:
|
|
|
|
name = {"share_data": "block data",
|
|
|
|
"EOF": "end of share data"}.get(k,k)
|
|
|
|
offset = m.DATA_OFFSET + offsets[k]
|
|
|
|
printoffset(name, offset, 2)
|
|
|
|
f = open(options['filename'], "rb")
|
|
|
|
printoffset("extra leases", m._read_extra_lease_offset(f) + 4)
|
|
|
|
f.close()
|
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
2007-11-07 02:46:31 +00:00
|
|
|
|
2011-08-28 07:38:34 +00:00
|
|
|
def dump_MDMF_share(m, length, options):
|
|
|
|
from allmydata.mutable.layout import MDMFSlotReadProxy
|
|
|
|
from allmydata.util import base32, hashutil
|
|
|
|
from allmydata.uri import MDMFVerifierURI
|
2020-08-14 17:49:48 +00:00
|
|
|
from allmydata.util.encodingutil import quote_output, to_bytes
|
2011-08-28 07:38:34 +00:00
|
|
|
|
|
|
|
offset = m.DATA_OFFSET
|
|
|
|
out = options.stdout
|
|
|
|
|
|
|
|
f = open(options['filename'], "rb")
|
|
|
|
storage_index = None; shnum = 0
|
|
|
|
|
|
|
|
class ShareDumper(MDMFSlotReadProxy):
|
|
|
|
def _read(self, readvs, force_remote=False, queue=False):
|
|
|
|
data = []
|
|
|
|
for (where,length) in readvs:
|
|
|
|
f.seek(offset+where)
|
|
|
|
data.append(f.read(length))
|
|
|
|
return defer.succeed({shnum: data})
|
|
|
|
|
|
|
|
p = ShareDumper(None, storage_index, shnum)
|
|
|
|
def extract(func):
|
|
|
|
stash = []
|
|
|
|
# these methods return Deferreds, but we happen to know that they run
|
|
|
|
# synchronously when not actually talking to a remote server
|
|
|
|
d = func()
|
|
|
|
d.addCallback(stash.append)
|
|
|
|
return stash[0]
|
|
|
|
|
|
|
|
verinfo = extract(p.get_verinfo)
|
|
|
|
encprivkey = extract(p.get_encprivkey)
|
|
|
|
signature = extract(p.get_signature)
|
|
|
|
pubkey = extract(p.get_verification_key)
|
|
|
|
block_hash_tree = extract(p.get_blockhashes)
|
|
|
|
share_hash_chain = extract(p.get_sharehashes)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
(seqnum, root_hash, salt_to_use, segsize, datalen, k, N, prefix,
|
|
|
|
offsets) = verinfo
|
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" MDMF contents:", file=out)
|
|
|
|
print(" seqnum: %d" % seqnum, file=out)
|
2021-02-23 17:02:08 +00:00
|
|
|
print(" root_hash: %s" % unicode(base32.b2a(root_hash), "utf-8"), file=out)
|
2020-09-11 14:28:22 +00:00
|
|
|
#print(" IV: %s" % base32.b2a(IV), file=out)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" required_shares: %d" % k, file=out)
|
|
|
|
print(" total_shares: %d" % N, file=out)
|
|
|
|
print(" segsize: %d" % segsize, file=out)
|
|
|
|
print(" datalen: %d" % datalen, file=out)
|
|
|
|
print(" enc_privkey: %d bytes" % len(encprivkey), file=out)
|
|
|
|
print(" pubkey: %d bytes" % len(pubkey), file=out)
|
|
|
|
print(" signature: %d bytes" % len(signature), file=out)
|
2011-08-28 07:38:34 +00:00
|
|
|
share_hash_ids = ",".join([str(hid)
|
|
|
|
for hid in sorted(share_hash_chain.keys())])
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" share_hash_chain: %s" % share_hash_ids, file=out)
|
|
|
|
print(" block_hash_tree: %d nodes" % len(block_hash_tree), file=out)
|
2011-08-28 07:38:34 +00:00
|
|
|
|
|
|
|
# the storage index isn't stored in the share itself, so we depend upon
|
|
|
|
# knowing the parent directory name to get it
|
|
|
|
pieces = options['filename'].split(os.sep)
|
|
|
|
if len(pieces) >= 2:
|
2020-08-14 17:49:48 +00:00
|
|
|
piece = to_bytes(pieces[-2])
|
2011-08-28 07:38:34 +00:00
|
|
|
if base32.could_be_base32_encoded(piece):
|
|
|
|
storage_index = base32.a2b(piece)
|
|
|
|
fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey)
|
2011-10-01 23:35:53 +00:00
|
|
|
u = MDMFVerifierURI(storage_index, fingerprint)
|
2011-08-28 07:38:34 +00:00
|
|
|
verify_cap = u.to_string()
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" verify-cap:", quote_output(verify_cap, quotemarks=False), file=out)
|
2011-08-28 07:38:34 +00:00
|
|
|
|
|
|
|
if options['offsets']:
|
|
|
|
# NOTE: this offset-calculation code is fragile, and needs to be
|
|
|
|
# merged with MutableShareFile's internals.
|
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
|
|
|
print(" Section Offsets:", file=out)
|
2011-08-28 07:38:34 +00:00
|
|
|
def printoffset(name, value, shift=0):
|
2019-03-24 13:14:00 +00:00
|
|
|
print("%s%.20s: %s (0x%x)" % (" "*shift, name, value, value), file=out)
|
2011-08-28 07:38:34 +00:00
|
|
|
printoffset("first lease", m.HEADER_SIZE, 2)
|
|
|
|
printoffset("share data", m.DATA_OFFSET, 2)
|
|
|
|
o_seqnum = m.DATA_OFFSET + struct.calcsize(">B")
|
|
|
|
printoffset("seqnum", o_seqnum, 4)
|
|
|
|
o_root_hash = m.DATA_OFFSET + struct.calcsize(">BQ")
|
|
|
|
printoffset("root_hash", o_root_hash, 4)
|
|
|
|
for k in ["enc_privkey", "share_hash_chain", "signature",
|
|
|
|
"verification_key", "verification_key_end",
|
|
|
|
"share_data", "block_hash_tree", "EOF"]:
|
|
|
|
name = {"share_data": "block data",
|
|
|
|
"verification_key": "pubkey",
|
|
|
|
"verification_key_end": "end of pubkey",
|
|
|
|
"EOF": "end of share data"}.get(k,k)
|
|
|
|
offset = m.DATA_OFFSET + offsets[k]
|
|
|
|
printoffset(name, offset, 4)
|
|
|
|
f = open(options['filename'], "rb")
|
|
|
|
printoffset("extra leases", m._read_extra_lease_offset(f) + 4, 2)
|
|
|
|
f.close()
|
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
2011-08-28 07:38:34 +00:00
|
|
|
|
2007-11-07 01:55:55 +00:00
|
|
|
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class DumpCapOptions(BaseOptions):
|
2008-08-12 20:37:32 +00:00
|
|
|
def getSynopsis(self):
|
2015-05-26 18:31:06 +00:00
|
|
|
return "Usage: tahoe [global-options] debug dump-cap [options] FILECAP"
|
2008-01-14 20:43:25 +00:00
|
|
|
optParameters = [
|
2008-08-12 20:37:32 +00:00
|
|
|
["nodeid", "n",
|
2010-08-03 08:48:01 +00:00
|
|
|
None, "Specify the storage server nodeid (ASCII), to construct WE and secrets."],
|
2008-08-12 20:37:32 +00:00
|
|
|
["client-secret", "c", None,
|
2010-08-03 08:48:01 +00:00
|
|
|
"Specify the client's base secret (ASCII), to construct secrets."],
|
2008-08-12 20:37:32 +00:00
|
|
|
["client-dir", "d", None,
|
2010-08-03 08:48:01 +00:00
|
|
|
"Specify the client's base directory, from which a -c secret will be read."],
|
2008-01-14 20:43:25 +00:00
|
|
|
]
|
|
|
|
def parseArgs(self, cap):
|
|
|
|
self.cap = cap
|
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2008-08-12 20:37:32 +00:00
|
|
|
Print information about the given cap-string (aka: URI, file-cap, dir-cap,
|
|
|
|
read-cap, write-cap). The URI string is parsed and unpacked. This prints the
|
|
|
|
type of the cap, its storage index, and any derived keys.
|
|
|
|
|
|
|
|
tahoe debug dump-cap URI:SSK-Verifier:4vozh77tsrw7mdhnj7qvp5ky74:q7f3dwz76sjys4kqfdt3ocur2pay3a6rftnkqmi2uxu3vqsdsofq
|
|
|
|
|
|
|
|
This may be useful to determine if a read-cap and a write-cap refer to the
|
|
|
|
same time, or to extract the storage-index from a file-cap (to then use with
|
|
|
|
find-shares)
|
|
|
|
|
|
|
|
If additional information is provided (storage server nodeid and/or client
|
|
|
|
base secret), this command will compute the shared secrets used for the
|
|
|
|
write-enabler and for lease-renewal.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
def dump_cap(options):
|
2008-01-14 20:43:25 +00:00
|
|
|
from allmydata import uri
|
2008-02-15 02:27:47 +00:00
|
|
|
from allmydata.util import base32
|
2008-01-14 20:43:25 +00:00
|
|
|
from base64 import b32decode
|
2008-01-14 21:12:27 +00:00
|
|
|
import urlparse, urllib
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
out = options.stdout
|
|
|
|
cap = options.cap
|
2008-01-14 20:43:25 +00:00
|
|
|
nodeid = None
|
2008-08-12 20:52:42 +00:00
|
|
|
if options['nodeid']:
|
|
|
|
nodeid = b32decode(options['nodeid'].upper())
|
2008-01-14 20:43:25 +00:00
|
|
|
secret = None
|
2008-08-12 20:52:42 +00:00
|
|
|
if options['client-secret']:
|
|
|
|
secret = base32.a2b(options['client-secret'])
|
|
|
|
elif options['client-dir']:
|
|
|
|
secretfile = os.path.join(options['client-dir'], "private", "secret")
|
2008-01-14 20:43:25 +00:00
|
|
|
try:
|
2008-02-15 02:27:47 +00:00
|
|
|
secret = base32.a2b(open(secretfile, "r").read().strip())
|
2008-01-14 20:43:25 +00:00
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
|
|
|
|
2008-01-14 21:12:27 +00:00
|
|
|
if cap.startswith("http"):
|
|
|
|
scheme, netloc, path, params, query, fragment = urlparse.urlparse(cap)
|
|
|
|
assert path.startswith("/uri/")
|
|
|
|
cap = urllib.unquote(path[len("/uri/"):])
|
|
|
|
|
|
|
|
u = uri.from_string(cap)
|
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print(file=out)
|
2008-08-12 20:52:42 +00:00
|
|
|
dump_uri_instance(u, nodeid, secret, out)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
def _dump_secrets(storage_index, secret, nodeid, out):
|
|
|
|
from allmydata.util import hashutil
|
2008-02-15 02:27:47 +00:00
|
|
|
from allmydata.util import base32
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
if secret:
|
|
|
|
crs = hashutil.my_renewal_secret_hash(secret)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" client renewal secret:", base32.b2a(crs), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
frs = hashutil.file_renewal_secret_hash(crs, storage_index)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" file renewal secret:", base32.b2a(frs), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
if nodeid:
|
|
|
|
renew = hashutil.bucket_renewal_secret_hash(frs, nodeid)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" lease renewal secret:", base32.b2a(renew), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
ccs = hashutil.my_cancel_secret_hash(secret)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" client cancel secret:", base32.b2a(ccs), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
fcs = hashutil.file_cancel_secret_hash(ccs, storage_index)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" file cancel secret:", base32.b2a(fcs), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
if nodeid:
|
|
|
|
cancel = hashutil.bucket_cancel_secret_hash(fcs, nodeid)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" lease cancel secret:", base32.b2a(cancel), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
def dump_uri_instance(u, nodeid, secret, out, show_header=True):
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata import uri
|
|
|
|
from allmydata.storage.server import si_b2a
|
2008-02-15 02:27:47 +00:00
|
|
|
from allmydata.util import base32, hashutil
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.encodingutil import quote_output
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
if isinstance(u, uri.CHKFileURI):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("CHK File:", file=out)
|
|
|
|
print(" key:", base32.b2a(u.key), file=out)
|
|
|
|
print(" UEB hash:", base32.b2a(u.uri_extension_hash), file=out)
|
|
|
|
print(" size:", u.size, file=out)
|
|
|
|
print(" k/N: %d/%d" % (u.needed_shares, u.total_shares), file=out)
|
|
|
|
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
|
2010-02-22 02:45:04 +00:00
|
|
|
_dump_secrets(u.get_storage_index(), secret, nodeid, out)
|
2008-01-14 20:43:25 +00:00
|
|
|
elif isinstance(u, uri.CHKFileVerifierURI):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("CHK Verifier URI:", file=out)
|
|
|
|
print(" UEB hash:", base32.b2a(u.uri_extension_hash), file=out)
|
|
|
|
print(" size:", u.size, file=out)
|
|
|
|
print(" k/N: %d/%d" % (u.needed_shares, u.total_shares), file=out)
|
|
|
|
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
|
|
|
elif isinstance(u, uri.LiteralFileURI):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Literal File URI:", file=out)
|
|
|
|
print(" data:", quote_output(u.data), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2011-08-27 19:50:48 +00:00
|
|
|
elif isinstance(u, uri.WriteableSSKFileURI): # SDMF
|
2008-01-14 20:43:25 +00:00
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("SDMF Writeable URI:", file=out)
|
|
|
|
print(" writekey:", base32.b2a(u.writekey), file=out)
|
|
|
|
print(" readkey:", base32.b2a(u.readkey), file=out)
|
|
|
|
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
|
|
|
|
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
|
|
|
|
print(file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
if nodeid:
|
|
|
|
we = hashutil.ssk_write_enabler_hash(u.writekey, nodeid)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" write_enabler:", base32.b2a(we), file=out)
|
|
|
|
print(file=out)
|
2010-02-22 02:45:04 +00:00
|
|
|
_dump_secrets(u.get_storage_index(), secret, nodeid, out)
|
2008-01-14 20:43:25 +00:00
|
|
|
elif isinstance(u, uri.ReadonlySSKFileURI):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("SDMF Read-only URI:", file=out)
|
|
|
|
print(" readkey:", base32.b2a(u.readkey), file=out)
|
|
|
|
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
|
|
|
|
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
elif isinstance(u, uri.SSKVerifierURI):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("SDMF Verifier URI:", file=out)
|
|
|
|
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
|
|
|
|
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2011-08-27 19:50:48 +00:00
|
|
|
elif isinstance(u, uri.WriteableMDMFFileURI): # MDMF
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("MDMF Writeable URI:", file=out)
|
|
|
|
print(" writekey:", base32.b2a(u.writekey), file=out)
|
|
|
|
print(" readkey:", base32.b2a(u.readkey), file=out)
|
|
|
|
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
|
|
|
|
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
|
|
|
|
print(file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
if nodeid:
|
|
|
|
we = hashutil.ssk_write_enabler_hash(u.writekey, nodeid)
|
2019-03-24 13:14:00 +00:00
|
|
|
print(" write_enabler:", base32.b2a(we), file=out)
|
|
|
|
print(file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
_dump_secrets(u.get_storage_index(), secret, nodeid, out)
|
|
|
|
elif isinstance(u, uri.ReadonlyMDMFFileURI):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("MDMF Read-only URI:", file=out)
|
|
|
|
print(" readkey:", base32.b2a(u.readkey), file=out)
|
|
|
|
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
|
|
|
|
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
elif isinstance(u, uri.MDMFVerifierURI):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("MDMF Verifier URI:", file=out)
|
|
|
|
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
|
|
|
|
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
elif isinstance(u, uri.ImmutableDirectoryURI): # CHK-based directory
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("CHK Directory URI:", file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
dump_uri_instance(u._filenode_uri, nodeid, secret, out, False)
|
|
|
|
elif isinstance(u, uri.ImmutableDirectoryURIVerifier):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("CHK Directory Verifier URI:", file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
dump_uri_instance(u._filenode_uri, nodeid, secret, out, False)
|
|
|
|
|
|
|
|
elif isinstance(u, uri.DirectoryURI): # SDMF-based directory
|
2008-01-14 20:43:25 +00:00
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Directory Writeable URI:", file=out)
|
2008-08-12 20:52:42 +00:00
|
|
|
dump_uri_instance(u._filenode_uri, nodeid, secret, out, False)
|
2009-07-17 01:01:03 +00:00
|
|
|
elif isinstance(u, uri.ReadonlyDirectoryURI):
|
2008-01-14 20:43:25 +00:00
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Directory Read-only URI:", file=out)
|
2008-08-12 20:52:42 +00:00
|
|
|
dump_uri_instance(u._filenode_uri, nodeid, secret, out, False)
|
2009-07-17 01:01:03 +00:00
|
|
|
elif isinstance(u, uri.DirectoryURIVerifier):
|
2008-01-14 20:43:25 +00:00
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Directory Verifier URI:", file=out)
|
2008-08-12 20:52:42 +00:00
|
|
|
dump_uri_instance(u._filenode_uri, nodeid, secret, out, False)
|
2011-08-27 19:50:48 +00:00
|
|
|
|
|
|
|
elif isinstance(u, uri.MDMFDirectoryURI): # MDMF-based directory
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Directory Writeable URI:", file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
dump_uri_instance(u._filenode_uri, nodeid, secret, out, False)
|
|
|
|
elif isinstance(u, uri.ReadonlyMDMFDirectoryURI):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Directory Read-only URI:", file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
dump_uri_instance(u._filenode_uri, nodeid, secret, out, False)
|
|
|
|
elif isinstance(u, uri.MDMFDirectoryURIVerifier):
|
|
|
|
if show_header:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Directory Verifier URI:", file=out)
|
2011-08-27 19:50:48 +00:00
|
|
|
dump_uri_instance(u._filenode_uri, nodeid, secret, out, False)
|
|
|
|
|
2008-01-14 20:43:25 +00:00
|
|
|
else:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("unknown cap type", file=out)
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class FindSharesOptions(BaseOptions):
|
2008-08-12 20:37:32 +00:00
|
|
|
def getSynopsis(self):
|
2015-05-26 18:31:06 +00:00
|
|
|
return "Usage: tahoe [global-options] debug find-shares STORAGE_INDEX NODEDIRS.."
|
2010-07-22 00:14:18 +00:00
|
|
|
|
2008-02-06 20:19:51 +00:00
|
|
|
def parseArgs(self, storage_index_s, *nodedirs):
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.encodingutil import argv_to_abspath
|
2008-02-06 20:19:51 +00:00
|
|
|
self.si_s = storage_index_s
|
2010-07-22 00:14:18 +00:00
|
|
|
self.nodedirs = map(argv_to_abspath, nodedirs)
|
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2008-08-12 20:37:32 +00:00
|
|
|
Locate all shares for the given storage index. This command looks through one
|
|
|
|
or more node directories to find the shares. It returns a list of filenames,
|
|
|
|
one per line, for each share file found.
|
|
|
|
|
|
|
|
tahoe debug find-shares 4vozh77tsrw7mdhnj7qvp5ky74 testgrid/node-*
|
|
|
|
|
|
|
|
It may be useful during testing, when running a test grid in which all the
|
|
|
|
nodes are on a local disk. The share files thus located can be counted,
|
|
|
|
examined (with dump-share), or corrupted/deleted to test checker/repairer.
|
|
|
|
"""
|
2008-02-06 20:19:51 +00:00
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
def find_shares(options):
|
2008-02-06 20:19:51 +00:00
|
|
|
"""Given a storage index and a list of node directories, emit a list of
|
|
|
|
all matching shares to stdout, one per line. For example:
|
|
|
|
|
|
|
|
find-shares.py 44kai1tui348689nrw8fjegc8c ~/testnet/node-*
|
|
|
|
|
|
|
|
gives:
|
|
|
|
|
|
|
|
/home/warner/testnet/node-1/storage/shares/44k/44kai1tui348689nrw8fjegc8c/5
|
|
|
|
/home/warner/testnet/node-1/storage/shares/44k/44kai1tui348689nrw8fjegc8c/9
|
|
|
|
/home/warner/testnet/node-2/storage/shares/44k/44kai1tui348689nrw8fjegc8c/2
|
|
|
|
"""
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata.storage.server import si_a2b, storage_index_to_dir
|
2015-01-30 00:04:11 +00:00
|
|
|
from allmydata.util.encodingutil import listdir_unicode, quote_local_unicode_path
|
2008-02-06 20:19:51 +00:00
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
out = options.stdout
|
2021-02-03 16:24:47 +00:00
|
|
|
sharedir = storage_index_to_dir(si_a2b(options.si_s.encode("utf-8")))
|
2008-08-12 20:52:42 +00:00
|
|
|
for d in options.nodedirs:
|
2015-01-30 00:05:14 +00:00
|
|
|
d = os.path.join(d, "storage", "shares", sharedir)
|
2008-02-06 20:19:51 +00:00
|
|
|
if os.path.exists(d):
|
2010-07-22 00:14:18 +00:00
|
|
|
for shnum in listdir_unicode(d):
|
2019-03-24 13:14:00 +00:00
|
|
|
print(quote_local_unicode_path(os.path.join(d, shnum), quotemarks=False), file=out)
|
2008-02-06 20:19:51 +00:00
|
|
|
|
|
|
|
return 0
|
2008-01-14 20:43:25 +00:00
|
|
|
|
2008-02-12 01:17:01 +00:00
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class CatalogSharesOptions(BaseOptions):
|
2008-02-12 01:17:01 +00:00
|
|
|
def parseArgs(self, *nodedirs):
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.encodingutil import argv_to_abspath
|
|
|
|
self.nodedirs = map(argv_to_abspath, nodedirs)
|
2008-08-12 20:37:32 +00:00
|
|
|
if not nodedirs:
|
|
|
|
raise usage.UsageError("must specify at least one node directory")
|
|
|
|
|
|
|
|
def getSynopsis(self):
|
2015-05-26 18:31:06 +00:00
|
|
|
return "Usage: tahoe [global-options] debug catalog-shares NODEDIRS.."
|
2008-08-12 20:37:32 +00:00
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2008-08-12 20:37:32 +00:00
|
|
|
Locate all shares in the given node directories, and emit a one-line summary
|
|
|
|
of each share. Run it like this:
|
|
|
|
|
|
|
|
tahoe debug catalog-shares testgrid/node-* >allshares.txt
|
|
|
|
|
|
|
|
The lines it emits will look like the following:
|
|
|
|
|
|
|
|
CHK $SI $k/$N $filesize $UEB_hash $expiration $abspath_sharefile
|
|
|
|
SDMF $SI $k/$N $filesize $seqnum/$roothash $expiration $abspath_sharefile
|
|
|
|
UNKNOWN $abspath_sharefile
|
|
|
|
|
|
|
|
This command can be used to build up a catalog of shares from many storage
|
|
|
|
servers and then sort the results to compare all shares for the same file. If
|
|
|
|
you see shares with the same SI but different parameters/filesize/UEB_hash,
|
|
|
|
then something is wrong. The misc/find-share/anomalies.py script may be
|
|
|
|
useful for purpose.
|
|
|
|
"""
|
2008-02-12 01:17:01 +00:00
|
|
|
|
2008-10-29 22:10:10 +00:00
|
|
|
def call(c, *args, **kwargs):
|
|
|
|
# take advantage of the fact that ImmediateReadBucketProxy returns
|
|
|
|
# Deferreds that are already fired
|
|
|
|
results = []
|
2008-10-30 19:06:51 +00:00
|
|
|
failures = []
|
2008-10-29 22:10:10 +00:00
|
|
|
d = defer.maybeDeferred(c, *args, **kwargs)
|
2008-10-30 19:06:51 +00:00
|
|
|
d.addCallbacks(results.append, failures.append)
|
|
|
|
if failures:
|
|
|
|
failures[0].raiseException()
|
2008-10-29 22:10:10 +00:00
|
|
|
return results[0]
|
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
def describe_share(abs_sharefile, si_s, shnum_s, now, out):
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata import uri
|
|
|
|
from allmydata.storage.mutable import MutableShareFile
|
|
|
|
from allmydata.storage.immutable import ShareFile
|
2008-04-11 21:31:16 +00:00
|
|
|
from allmydata.mutable.layout import unpack_share
|
|
|
|
from allmydata.mutable.common import NeedMoreDataError
|
2008-10-10 00:08:00 +00:00
|
|
|
from allmydata.immutable.layout import ReadBucketProxy
|
2008-02-15 02:27:47 +00:00
|
|
|
from allmydata.util import base32
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.encodingutil import quote_output
|
2008-02-12 01:17:01 +00:00
|
|
|
import struct
|
|
|
|
|
|
|
|
f = open(abs_sharefile, "rb")
|
|
|
|
prefix = f.read(32)
|
|
|
|
|
2009-02-18 21:46:55 +00:00
|
|
|
if prefix == MutableShareFile.MAGIC:
|
2008-02-12 01:17:01 +00:00
|
|
|
# mutable share
|
2009-02-18 21:46:55 +00:00
|
|
|
m = MutableShareFile(abs_sharefile)
|
2008-02-12 01:17:01 +00:00
|
|
|
WE, nodeid = m._read_write_enabler_and_nodeid(f)
|
|
|
|
data_length = m._read_data_length(f)
|
2009-03-07 05:45:17 +00:00
|
|
|
expiration_time = min( [lease.expiration_time
|
|
|
|
for (i,lease) in m._enumerate_leases(f)] )
|
2008-02-12 01:44:54 +00:00
|
|
|
expiration = max(0, expiration_time - now)
|
2008-02-12 01:17:01 +00:00
|
|
|
|
|
|
|
share_type = "unknown"
|
|
|
|
f.seek(m.DATA_OFFSET)
|
2011-08-28 08:09:31 +00:00
|
|
|
version = f.read(1)
|
2020-11-09 19:40:29 +00:00
|
|
|
if version == b"\x00":
|
2008-02-12 01:17:01 +00:00
|
|
|
# this slot contains an SMDF share
|
|
|
|
share_type = "SDMF"
|
2020-11-09 19:40:29 +00:00
|
|
|
elif version == b"\x01":
|
2011-08-28 08:09:31 +00:00
|
|
|
share_type = "MDMF"
|
2008-02-12 01:17:01 +00:00
|
|
|
|
|
|
|
if share_type == "SDMF":
|
|
|
|
f.seek(m.DATA_OFFSET)
|
|
|
|
data = f.read(min(data_length, 2000))
|
|
|
|
|
|
|
|
try:
|
2008-04-11 21:31:16 +00:00
|
|
|
pieces = unpack_share(data)
|
2019-03-28 11:45:28 +00:00
|
|
|
except NeedMoreDataError as e:
|
2008-02-12 01:17:01 +00:00
|
|
|
# retry once with the larger size
|
|
|
|
size = e.needed_bytes
|
|
|
|
f.seek(m.DATA_OFFSET)
|
|
|
|
data = f.read(min(data_length, size))
|
2008-04-11 21:31:16 +00:00
|
|
|
pieces = unpack_share(data)
|
2008-02-12 01:17:01 +00:00
|
|
|
(seqnum, root_hash, IV, k, N, segsize, datalen,
|
|
|
|
pubkey, signature, share_hash_chain, block_hash_tree,
|
|
|
|
share_data, enc_privkey) = pieces
|
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print("SDMF %s %d/%d %d #%d:%s %d %s" % \
|
2008-02-13 22:12:06 +00:00
|
|
|
(si_s, k, N, datalen,
|
2021-02-23 17:02:08 +00:00
|
|
|
seqnum, unicode(base32.b2a(root_hash), "utf-8"),
|
2019-03-24 13:14:00 +00:00
|
|
|
expiration, quote_output(abs_sharefile)), file=out)
|
2011-08-28 08:09:31 +00:00
|
|
|
elif share_type == "MDMF":
|
|
|
|
from allmydata.mutable.layout import MDMFSlotReadProxy
|
|
|
|
fake_shnum = 0
|
|
|
|
# TODO: factor this out with dump_MDMF_share()
|
|
|
|
class ShareDumper(MDMFSlotReadProxy):
|
|
|
|
def _read(self, readvs, force_remote=False, queue=False):
|
|
|
|
data = []
|
|
|
|
for (where,length) in readvs:
|
|
|
|
f.seek(m.DATA_OFFSET+where)
|
|
|
|
data.append(f.read(length))
|
|
|
|
return defer.succeed({fake_shnum: data})
|
|
|
|
|
|
|
|
p = ShareDumper(None, "fake-si", fake_shnum)
|
|
|
|
def extract(func):
|
|
|
|
stash = []
|
|
|
|
# these methods return Deferreds, but we happen to know that
|
|
|
|
# they run synchronously when not actually talking to a
|
|
|
|
# remote server
|
|
|
|
d = func()
|
|
|
|
d.addCallback(stash.append)
|
|
|
|
return stash[0]
|
|
|
|
|
|
|
|
verinfo = extract(p.get_verinfo)
|
|
|
|
(seqnum, root_hash, salt_to_use, segsize, datalen, k, N, prefix,
|
|
|
|
offsets) = verinfo
|
2019-03-24 13:14:00 +00:00
|
|
|
print("MDMF %s %d/%d %d #%d:%s %d %s" % \
|
2011-08-28 08:09:31 +00:00
|
|
|
(si_s, k, N, datalen,
|
2021-02-23 17:02:08 +00:00
|
|
|
seqnum, unicode(base32.b2a(root_hash), "utf-8"),
|
2019-03-24 13:14:00 +00:00
|
|
|
expiration, quote_output(abs_sharefile)), file=out)
|
2008-02-12 01:17:01 +00:00
|
|
|
else:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("UNKNOWN mutable %s" % quote_output(abs_sharefile), file=out)
|
2008-02-12 01:17:01 +00:00
|
|
|
|
|
|
|
elif struct.unpack(">L", prefix[:4]) == (1,):
|
|
|
|
# immutable
|
|
|
|
|
2008-10-29 22:10:10 +00:00
|
|
|
class ImmediateReadBucketProxy(ReadBucketProxy):
|
|
|
|
def __init__(self, sf):
|
|
|
|
self.sf = sf
|
2011-08-01 22:43:07 +00:00
|
|
|
ReadBucketProxy.__init__(self, None, None, "")
|
2008-10-29 22:10:10 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return "<ImmediateReadBucketProxy>"
|
|
|
|
def _read(self, offset, size):
|
|
|
|
return defer.succeed(sf.read_share_data(offset, size))
|
|
|
|
|
2008-02-12 01:17:01 +00:00
|
|
|
# use a ReadBucketProxy to parse the bucket and find the uri extension
|
2009-02-18 21:46:55 +00:00
|
|
|
sf = ShareFile(abs_sharefile)
|
2008-10-29 22:10:10 +00:00
|
|
|
bp = ImmediateReadBucketProxy(sf)
|
|
|
|
|
2008-07-10 01:06:55 +00:00
|
|
|
expiration_time = min( [lease.expiration_time
|
2009-03-07 05:45:17 +00:00
|
|
|
for lease in sf.get_leases()] )
|
2008-02-12 01:44:54 +00:00
|
|
|
expiration = max(0, expiration_time - now)
|
2008-02-12 01:17:01 +00:00
|
|
|
|
2008-10-29 22:10:10 +00:00
|
|
|
UEB_data = call(bp.get_uri_extension)
|
2008-02-12 01:17:01 +00:00
|
|
|
unpacked = uri.unpack_extension_readable(UEB_data)
|
2008-10-29 22:10:10 +00:00
|
|
|
|
2008-02-12 01:17:01 +00:00
|
|
|
k = unpacked["needed_shares"]
|
|
|
|
N = unpacked["total_shares"]
|
|
|
|
filesize = unpacked["size"]
|
|
|
|
ueb_hash = unpacked["UEB_hash"]
|
|
|
|
|
2019-03-24 13:14:00 +00:00
|
|
|
print("CHK %s %d/%d %d %s %d %s" % (si_s, k, N, filesize,
|
2021-02-23 17:02:08 +00:00
|
|
|
unicode(ueb_hash, "utf-8"), expiration,
|
|
|
|
quote_output(abs_sharefile)), file=out)
|
2008-02-12 01:17:01 +00:00
|
|
|
|
|
|
|
else:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("UNKNOWN really-unknown %s" % quote_output(abs_sharefile), file=out)
|
2008-02-12 01:17:01 +00:00
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
def catalog_shares(options):
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.encodingutil import listdir_unicode, quote_output
|
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
out = options.stdout
|
2008-10-29 22:10:10 +00:00
|
|
|
err = options.stderr
|
2008-02-12 01:44:54 +00:00
|
|
|
now = time.time()
|
2008-08-12 20:52:42 +00:00
|
|
|
for d in options.nodedirs:
|
2015-01-30 00:05:14 +00:00
|
|
|
d = os.path.join(d, "storage", "shares")
|
2008-06-26 18:23:44 +00:00
|
|
|
try:
|
2010-07-22 00:14:18 +00:00
|
|
|
abbrevs = listdir_unicode(d)
|
2008-06-26 18:23:44 +00:00
|
|
|
except EnvironmentError:
|
|
|
|
# ignore nodes that have storage turned off altogether
|
|
|
|
pass
|
|
|
|
else:
|
2011-01-17 09:59:32 +00:00
|
|
|
for abbrevdir in sorted(abbrevs):
|
2008-06-26 18:23:44 +00:00
|
|
|
if abbrevdir == "incoming":
|
|
|
|
continue
|
2008-02-12 01:17:01 +00:00
|
|
|
abbrevdir = os.path.join(d, abbrevdir)
|
2008-10-30 21:54:47 +00:00
|
|
|
# this tool may get run against bad disks, so we can't assume
|
2010-07-22 00:14:18 +00:00
|
|
|
# that listdir_unicode will always succeed. Try to catalog as much
|
2008-10-30 21:54:47 +00:00
|
|
|
# as possible.
|
|
|
|
try:
|
2010-07-22 00:14:18 +00:00
|
|
|
sharedirs = listdir_unicode(abbrevdir)
|
2011-01-17 09:59:32 +00:00
|
|
|
for si_s in sorted(sharedirs):
|
2008-10-30 21:54:47 +00:00
|
|
|
si_dir = os.path.join(abbrevdir, si_s)
|
|
|
|
catalog_shares_one_abbrevdir(si_s, si_dir, now, out,err)
|
|
|
|
except:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Error processing %s" % quote_output(abbrevdir), file=err)
|
2008-10-30 21:54:47 +00:00
|
|
|
failure.Failure().printTraceback(err)
|
|
|
|
|
2008-02-12 01:17:01 +00:00
|
|
|
return 0
|
|
|
|
|
2011-01-17 09:59:32 +00:00
|
|
|
def _as_number(s):
|
|
|
|
try:
|
|
|
|
return int(s)
|
|
|
|
except ValueError:
|
|
|
|
return "not int"
|
|
|
|
|
2008-10-30 21:54:47 +00:00
|
|
|
def catalog_shares_one_abbrevdir(si_s, si_dir, now, out, err):
|
2010-07-22 00:14:18 +00:00
|
|
|
from allmydata.util.encodingutil import listdir_unicode, quote_output
|
|
|
|
|
2008-10-30 21:54:47 +00:00
|
|
|
try:
|
2011-01-17 09:59:32 +00:00
|
|
|
for shnum_s in sorted(listdir_unicode(si_dir), key=_as_number):
|
2008-10-30 21:54:47 +00:00
|
|
|
abs_sharefile = os.path.join(si_dir, shnum_s)
|
|
|
|
assert os.path.isfile(abs_sharefile)
|
|
|
|
try:
|
|
|
|
describe_share(abs_sharefile, si_s, shnum_s, now,
|
|
|
|
out)
|
|
|
|
except:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Error processing %s" % quote_output(abs_sharefile), file=err)
|
2008-10-30 21:54:47 +00:00
|
|
|
failure.Failure().printTraceback(err)
|
|
|
|
except:
|
2019-03-24 13:14:00 +00:00
|
|
|
print("Error processing %s" % quote_output(si_dir), file=err)
|
2008-10-30 21:54:47 +00:00
|
|
|
failure.Failure().printTraceback(err)
|
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class CorruptShareOptions(BaseOptions):
|
2008-08-13 00:05:01 +00:00
|
|
|
def getSynopsis(self):
|
2015-05-26 18:31:06 +00:00
|
|
|
return "Usage: tahoe [global-options] debug corrupt-share SHARE_FILENAME"
|
2008-08-13 00:05:01 +00:00
|
|
|
|
|
|
|
optParameters = [
|
2010-08-03 08:48:01 +00:00
|
|
|
["offset", "o", "block-random", "Specify which bit to flip."],
|
2008-08-13 00:05:01 +00:00
|
|
|
]
|
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
description = """
|
2008-08-13 00:05:01 +00:00
|
|
|
Corrupt the given share by flipping a bit. This will cause a
|
|
|
|
verifying/downloading client to log an integrity-check failure incident, and
|
|
|
|
downloads will proceed with a different share.
|
|
|
|
|
|
|
|
The --offset parameter controls which bit should be flipped. The default is
|
|
|
|
to flip a single random bit of the block data.
|
|
|
|
|
|
|
|
tahoe debug corrupt-share testgrid/node-3/storage/shares/4v/4vozh77tsrw7mdhnj7qvp5ky74/0
|
|
|
|
|
|
|
|
Obviously, this command should not be used in normal operation.
|
|
|
|
"""
|
|
|
|
def parseArgs(self, filename):
|
|
|
|
self['filename'] = filename
|
|
|
|
|
|
|
|
def corrupt_share(options):
|
|
|
|
import random
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata.storage.mutable import MutableShareFile
|
|
|
|
from allmydata.storage.immutable import ShareFile
|
2008-08-13 00:05:01 +00:00
|
|
|
from allmydata.mutable.layout import unpack_header
|
2008-10-10 00:29:22 +00:00
|
|
|
from allmydata.immutable.layout import ReadBucketProxy
|
2008-08-13 00:05:01 +00:00
|
|
|
out = options.stdout
|
|
|
|
fn = options['filename']
|
|
|
|
assert options["offset"] == "block-random", "other offsets not implemented"
|
|
|
|
# first, what kind of share is it?
|
|
|
|
|
|
|
|
def flip_bit(start, end):
|
|
|
|
offset = random.randrange(start, end)
|
|
|
|
bit = random.randrange(0, 8)
|
2019-03-24 13:14:00 +00:00
|
|
|
print("[%d..%d): %d.b%d" % (start, end, offset, bit), file=out)
|
2008-08-13 00:05:01 +00:00
|
|
|
f = open(fn, "rb+")
|
|
|
|
f.seek(offset)
|
|
|
|
d = f.read(1)
|
2020-12-21 18:12:01 +00:00
|
|
|
d = bchr(ord(d) ^ 0x01)
|
2008-08-13 00:05:01 +00:00
|
|
|
f.seek(offset)
|
|
|
|
f.write(d)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
f = open(fn, "rb")
|
|
|
|
prefix = f.read(32)
|
|
|
|
f.close()
|
2009-02-18 21:46:55 +00:00
|
|
|
if prefix == MutableShareFile.MAGIC:
|
2008-08-13 00:05:01 +00:00
|
|
|
# mutable
|
2009-02-18 21:46:55 +00:00
|
|
|
m = MutableShareFile(fn)
|
2008-08-13 00:05:01 +00:00
|
|
|
f = open(fn, "rb")
|
|
|
|
f.seek(m.DATA_OFFSET)
|
|
|
|
data = f.read(2000)
|
|
|
|
# make sure this slot contains an SMDF share
|
2020-12-21 18:12:01 +00:00
|
|
|
assert data[0:1] == b"\x00", "non-SDMF mutable shares not supported"
|
2008-08-13 00:05:01 +00:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
(version, ig_seqnum, ig_roothash, ig_IV, ig_k, ig_N, ig_segsize,
|
|
|
|
ig_datalen, offsets) = unpack_header(data)
|
|
|
|
|
|
|
|
assert version == 0, "we only handle v0 SDMF files"
|
|
|
|
start = m.DATA_OFFSET + offsets["share_data"]
|
|
|
|
end = m.DATA_OFFSET + offsets["enc_privkey"]
|
|
|
|
flip_bit(start, end)
|
|
|
|
else:
|
|
|
|
# otherwise assume it's immutable
|
2009-02-18 21:46:55 +00:00
|
|
|
f = ShareFile(fn)
|
2011-08-01 22:43:07 +00:00
|
|
|
bp = ReadBucketProxy(None, None, '')
|
2008-08-13 00:05:01 +00:00
|
|
|
offsets = bp._parse_offsets(f.read_share_data(0, 0x24))
|
|
|
|
start = f._data_offset + offsets["data"]
|
|
|
|
end = f._data_offset + offsets["plaintext_hash_tree"]
|
|
|
|
flip_bit(start, end)
|
|
|
|
|
|
|
|
|
2008-02-12 01:17:01 +00:00
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class ReplOptions(BaseOptions):
|
2010-08-03 08:54:16 +00:00
|
|
|
def getSynopsis(self):
|
2016-09-09 22:37:28 +00:00
|
|
|
return "Usage: tahoe debug repl (OBSOLETE)"
|
2008-08-12 20:40:17 +00:00
|
|
|
|
2008-08-12 20:52:42 +00:00
|
|
|
def repl(options):
|
2019-03-24 13:14:00 +00:00
|
|
|
print("'tahoe debug repl' is obsolete. Please run 'python' in a virtualenv.", file=options.stderr)
|
2016-09-09 22:37:28 +00:00
|
|
|
return 1
|
2008-08-12 20:40:17 +00:00
|
|
|
|
|
|
|
|
2011-01-18 20:46:59 +00:00
|
|
|
DEFAULT_TESTSUITE = 'allmydata'
|
|
|
|
|
2016-09-09 22:37:28 +00:00
|
|
|
class TrialOptions(BaseOptions):
|
2011-01-18 20:46:59 +00:00
|
|
|
def getSynopsis(self):
|
2016-09-09 22:37:28 +00:00
|
|
|
return "Usage: tahoe debug trial (OBSOLETE)"
|
2011-01-18 20:46:59 +00:00
|
|
|
|
|
|
|
def trial(config):
|
2019-03-24 13:14:00 +00:00
|
|
|
print("'tahoe debug trial' is obsolete. Please run 'tox', or use 'trial' in a virtualenv.", file=config.stderr)
|
2016-09-09 22:37:28 +00:00
|
|
|
return 1
|
2011-01-18 20:46:59 +00:00
|
|
|
|
2019-04-12 14:18:36 +00:00
|
|
|
def fixOptionsClass(args):
|
|
|
|
(subcmd, shortcut, OptionsClass, desc) = args
|
2012-03-31 22:41:22 +00:00
|
|
|
class FixedOptionsClass(OptionsClass):
|
|
|
|
def getSynopsis(self):
|
|
|
|
t = OptionsClass.getSynopsis(self)
|
|
|
|
i = t.find("Usage: flogtool ")
|
|
|
|
if i >= 0:
|
2015-05-26 18:31:06 +00:00
|
|
|
return "Usage: tahoe [global-options] debug flogtool " + t[i+len("Usage: flogtool "):]
|
2012-03-31 22:41:22 +00:00
|
|
|
else:
|
2015-05-26 18:31:06 +00:00
|
|
|
return "Usage: tahoe [global-options] debug flogtool %s [options]" % (subcmd,)
|
2012-03-31 22:41:22 +00:00
|
|
|
return (subcmd, shortcut, FixedOptionsClass, desc)
|
|
|
|
|
|
|
|
class FlogtoolOptions(foolscap_cli.Options):
|
|
|
|
def __init__(self):
|
|
|
|
super(FlogtoolOptions, self).__init__()
|
|
|
|
self.subCommands = map(fixOptionsClass, self.subCommands)
|
|
|
|
|
|
|
|
def getSynopsis(self):
|
2015-05-26 18:31:06 +00:00
|
|
|
return "Usage: tahoe [global-options] debug flogtool COMMAND [flogtool-options]"
|
2012-03-31 22:41:22 +00:00
|
|
|
|
|
|
|
def parseOptions(self, all_subargs, *a, **kw):
|
|
|
|
self.flogtool_args = list(all_subargs)
|
|
|
|
return super(FlogtoolOptions, self).parseOptions(self.flogtool_args, *a, **kw)
|
|
|
|
|
|
|
|
def getUsage(self, width=None):
|
|
|
|
t = super(FlogtoolOptions, self).getUsage(width)
|
|
|
|
t += """
|
|
|
|
The 'tahoe debug flogtool' command uses the correct imports for this instance
|
|
|
|
of Tahoe-LAFS.
|
|
|
|
|
2015-05-26 18:31:06 +00:00
|
|
|
Please run 'tahoe debug flogtool COMMAND --help' for more details on each
|
2012-03-31 22:41:22 +00:00
|
|
|
subcommand.
|
|
|
|
"""
|
|
|
|
return t
|
|
|
|
|
|
|
|
def opt_help(self):
|
2019-03-24 13:14:00 +00:00
|
|
|
print(str(self))
|
2012-03-31 22:41:22 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
def flogtool(config):
|
|
|
|
sys.argv = ['flogtool'] + config.flogtool_args
|
|
|
|
return foolscap_cli.run_flogtool()
|
|
|
|
|
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class DebugCommand(BaseOptions):
|
2008-08-12 20:37:32 +00:00
|
|
|
subCommands = [
|
|
|
|
["dump-share", None, DumpOptions,
|
|
|
|
"Unpack and display the contents of a share (uri_extension and leases)."],
|
2010-08-03 08:48:01 +00:00
|
|
|
["dump-cap", None, DumpCapOptions, "Unpack a read-cap or write-cap."],
|
|
|
|
["find-shares", None, FindSharesOptions, "Locate sharefiles in node dirs."],
|
|
|
|
["catalog-shares", None, CatalogSharesOptions, "Describe all shares in node dirs."],
|
|
|
|
["corrupt-share", None, CorruptShareOptions, "Corrupt a share by flipping a bit."],
|
2016-09-09 22:37:28 +00:00
|
|
|
["repl", None, ReplOptions, "OBSOLETE"],
|
|
|
|
["trial", None, TrialOptions, "OBSOLETE"],
|
2012-03-31 22:41:22 +00:00
|
|
|
["flogtool", None, FlogtoolOptions, "Utilities to access log files."],
|
2008-08-12 20:37:32 +00:00
|
|
|
]
|
|
|
|
def postOptions(self):
|
|
|
|
if not hasattr(self, 'subOptions'):
|
|
|
|
raise usage.UsageError("must specify a subcommand")
|
2015-05-26 18:31:06 +00:00
|
|
|
synopsis = "COMMAND"
|
|
|
|
|
2008-08-12 20:37:32 +00:00
|
|
|
def getUsage(self, width=None):
|
2015-05-26 18:31:06 +00:00
|
|
|
t = BaseOptions.getUsage(self, width)
|
|
|
|
t += """\
|
2008-08-12 20:37:32 +00:00
|
|
|
|
|
|
|
Please run e.g. 'tahoe debug dump-share --help' for more details on each
|
|
|
|
subcommand.
|
2011-07-24 16:25:30 +00:00
|
|
|
"""
|
2008-08-12 20:37:32 +00:00
|
|
|
return t
|
|
|
|
|
|
|
|
subDispatch = {
|
|
|
|
"dump-share": dump_share,
|
|
|
|
"dump-cap": dump_cap,
|
|
|
|
"find-shares": find_shares,
|
|
|
|
"catalog-shares": catalog_shares,
|
2008-08-13 00:05:01 +00:00
|
|
|
"corrupt-share": corrupt_share,
|
2008-08-12 20:40:17 +00:00
|
|
|
"repl": repl,
|
2011-01-18 20:46:59 +00:00
|
|
|
"trial": trial,
|
2012-03-31 22:41:22 +00:00
|
|
|
"flogtool": flogtool,
|
2008-08-12 20:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def do_debug(options):
|
|
|
|
so = options.subOptions
|
2008-08-12 20:52:42 +00:00
|
|
|
so.stdout = options.stdout
|
|
|
|
so.stderr = options.stderr
|
2008-08-12 20:37:32 +00:00
|
|
|
f = subDispatch[options.subCommand]
|
2008-08-12 20:52:42 +00:00
|
|
|
return f(so)
|
2008-08-12 20:37:32 +00:00
|
|
|
|
2008-02-12 01:17:01 +00:00
|
|
|
|
2007-07-11 01:41:52 +00:00
|
|
|
subCommands = [
|
2020-11-29 20:48:26 +00:00
|
|
|
("debug", None, DebugCommand, "debug subcommands: use 'tahoe debug' for a list."),
|
|
|
|
] # type: SubCommands
|
2007-07-11 01:41:52 +00:00
|
|
|
|
|
|
|
dispatch = {
|
2008-08-12 20:37:32 +00:00
|
|
|
"debug": do_debug,
|
2007-07-11 01:41:52 +00:00
|
|
|
}
|