Article View: news.software.nntp
Article #64183Re: xBin Content-SHA1-Tree format
From: Curt Welch
Date: Tue, 25 Feb 2003 23:39
Date: Tue, 25 Feb 2003 23:39
87 lines
4697 bytes
4697 bytes
"Chris" <nobody@rogers.com> wrote: > I've been writing an xBin implementation using python to see if I have my > head wrapped around everything. Pretty much everything is straight > forward except for how to include the necessary nodes from the complete > hashtree. I came up with two algorithms for doing this. > > The first one is a bit more intuitive, but I think is harder to contruct > and also makes verifying articles more complicated. Start out by making > a new tree of the same size as your hashtree, with the leaf nodes having > value 1 if that block is included in the article, and 0 if that block > isn't covered. Then combine pairs of nodes to create the next level as > in the hashtree. If either of the node's value is 1, then the parent's > value is 1 also. This tree is supposed to represent which nodes we have > knowledge about, or can generate its value from other known values. > (I apologize for my diagrams in advance) > > hashtree: > > root > /------\ > H | > /----\ | > F G | > /\ /\ | > a b c d e > > a-e represent the hashes of the original data blocks > F,G,H and root are the hashes we get when we combine the children. > > In this example, lets say we post an article containing blocks c,d. > > temporary tree: > > 1 > /------\ > 1 | > /----\ | > 0 1 | > /\ /\ | > 0 0 1 1 0 > > You then traverse the tree in a depth-first search. Any 0 you encounter > means that you should include the corresponding node from the hashtree > in the list of nodes in the header, and you can ignore any nodes below > that node. If you encounter a 0 on the last level, you must include that > node also. In this example, we must include nodes F and e in the xBin > header. I assume that the root node will always be present in the > header. > The order that the nodes appear in is the same order as they are found > in the depth first search. In this example it would be: > Content-SHA1-Tree: root F e > > The second algorithm is much like the first, except it doesn't do the > depth-first search. As you construct the temporary tree and combine > siblings to form parents, if you combine a 0 node with a 1 node, then 0 > node must be included in the headers. I believe this yields the same > list of nodes as the first algorithm, but in a potentially different > order. I think this algorithm is easier to implement. Both of these algorithms seem correct to me. > In either case it's important to have a well defined order for the > Content-SHA1-Tree (if that's even what it should be called...it's not a > tree anymore...) For sure. > What do people think? You did it in the same order I did. It's the obvious order. My posting code made one pass of the file and created the entire hash tree first in-memory. Then as it posts each article, it would use the in-core hash tree to generate the signature header. I wrote a recursive routine which did a depth-first scan like your first algorithm. But, instead of building your 1/0 nodes, it figured that out by keeping track of of the block range covered by each node. If you compare the range of blocks covered by the current hash node you can figure out if the node is a "1" node or a "0" node without wasting any time pre-calculating that for each post. A 0 node is any node which includes some of the blocks of the current article. All other nodes are 1 nodes. -- Curt Welch http://CurtWelch.Com/ curt@kcwc.com Webmaster for http://NewsReader.Com/
Technical Details
Message-ID:
<20030225183939.804$fz@newsreader.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mailReferences:
<pan.2003.02.25.15.32.50.152477@rogers.com>Show Full Headers
Complete Article Headers
Message-ID: <20030225183939.804$fz@newsreader.com>
Subject: Re: xBin Content-SHA1-Tree format
Date: Tue, 25 Feb 2003 23:39:39 +0000
From: curt@kcwc.com (Curt Welch)
References: <pan.2003.02.25.15.32.50.152477@rogers.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com ms_=yrEUxVsg.9.o80,gey2ANxt70bJxKmC8jzMsxSsh_eFkdY
X-Face: "p}G*1KH{+F7EYGKLb>ogDguabZ+%,?^epeFB!nzu`)`$=QcvL1KF6<0GH!Tbc!Sqo[|tV5
%IW48mQf3K=Ci&gZ7]]aazx@]Y-nq!r5{yH/#,?@lDdUDvOfByB2hVW0.@OM%{l/{cT'{w
X-Url: http://CurtWelch.Com/
User-Agent: NewsReader.Com
Lines: 86