]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
dump-share: emit SDMF information too
authorBrian Warner <warner@allmydata.com>
Wed, 7 Nov 2007 02:46:31 +0000 (19:46 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 7 Nov 2007 02:46:31 +0000 (19:46 -0700)
src/allmydata/scripts/debug.py
src/allmydata/test/test_system.py

index 92ea94b86bb6a4f63bad970df07e76561eec88a7..936e84a6ee158d91a832c83ae4349fedb4d74973 100644 (file)
@@ -137,10 +137,17 @@ def dump_mutable_share(config, out, err):
     extra_lease_offset = m._read_extra_lease_offset(f)
     container_size = extra_lease_offset - m.DATA_OFFSET
     leases = list(m._enumerate_leases(f))
+
+    share_type = "unknown"
+    f.seek(m.DATA_OFFSET)
+    if f.read(1) == "\x00":
+        # this slot contains an SMDF share
+        share_type = "SDMF"
     f.close()
 
     print >>out
     print >>out, "Mutable slot found:"
+    print >>out, " share_type: %s" % share_type
     print >>out, " write_enabler: %s" % idlib.b2a(WE)
     print >>out, " WE for nodeid: %s" % idlib.nodeid_b2a(nodeid)
     print >>out, " num_extra_leases: %d" % num_extra_leases
@@ -159,8 +166,41 @@ def dump_mutable_share(config, out, err):
     else:
         print >>out, "No leases."
     print >>out
+
+    if share_type == "SDMF":
+        dump_SDMF_share(m.DATA_OFFSET, data_length, config, out, err)
+
     return 0
 
+def dump_SDMF_share(offset, length, config, out, err):
+    from allmydata import mutable
+    from allmydata.util import idlib
+
+    f = open(config['filename'], "rb")
+    f.seek(offset)
+    data = f.read(min(length, 2000))
+    f.close()
+
+    pieces = mutable.unpack_share(data)
+
+    (seqnum, root_hash, IV, k, N, segsize, datalen,
+     pubkey, signature, share_hash_chain, block_hash_tree,
+     share_data, enc_privkey) = pieces
+
+    print >>out, " SDMF contents:"
+    print >>out, "  seqnum: %d" % seqnum
+    print >>out, "  root_hash: %s" % idlib.b2a(root_hash)
+    print >>out, "  IV: %s" % idlib.b2a(IV)
+    print >>out, "  required_shares: %d" % k
+    print >>out, "  total_shares: %d" % N
+    print >>out, "  segsize: %d" % segsize
+    print >>out, "  datalen: %d" % datalen
+    share_hash_ids = ",".join([str(hid) for (hid,hash) in share_hash_chain])
+    print >>out, "  share_hash_chain: %s" % share_hash_ids
+    print >>out, "  block_hash_tree: %d nodes" % len(block_hash_tree)
+
+    print >>out
+
 
 def dump_root_dirnode(config, out=sys.stdout, err=sys.stderr):
     from allmydata import uri
index 384dc3ce8ade4ccfad6b6a1d9626d59b869009f4..c0628cc75d53089dafc1b2dc0f36e2786c4002a4 100644 (file)
@@ -287,12 +287,23 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
             output = out.getvalue()
             self.failUnlessEqual(rc, 0)
             self.failUnless("Mutable slot found:\n" in output)
+            self.failUnless("share_type: SDMF\n" in output)
             peerid = idlib.nodeid_b2a(self.clients[client_num].nodeid)
             self.failUnless(" WE for nodeid: %s\n" % peerid in output)
             self.failUnless(" num_extra_leases: 0\n" in output)
             self.failUnless(" container_size: 381\n" in output)
             self.failUnless(" data_length: 381\n" in output)
             self.failUnless("  secrets are for nodeid: %s\n" % peerid in output)
+            self.failUnless(" SDMF contents:\n" in output)
+            self.failUnless("  seqnum: 1\n" in output)
+            self.failUnless("  required_shares: 3\n" in output)
+            self.failUnless("  total_shares: 10\n" in output)
+            self.failUnless("  segsize: 24\n" in output)
+            self.failUnless("  datalen: 24\n" in output)
+            # the exact share_hash_chain nodes depends upon the sharenum, and
+            # is more of a hassle to compute than I want to deal with now
+            self.failUnless("  share_hash_chain: " in output)
+            self.failUnless("  block_hash_tree: 1 nodes\n" in output)
         d.addCallback(_test_debug)
 
         return d