Article View: news.software.nntp
Article #62439Re: xBin (Power-Post 2003 - requesting input from authorities..)
From: Rene
Date: Tue, 24 Dec 2002 15:10
Date: Tue, 24 Dec 2002 15:10
134 lines
7355 bytes
7355 bytes
curt@kcwc.com (Curt Welch) wrote:
> Ok, I put that article (as is in ascii) on http://xbin.org/
> It's not much, but it's a start.
To follow up on that, I've been thinking on some pseudo code for a xBin
decoder.
I've thinking it through and I think it works - with some caveats. First:
The pseudo code assumes tree structure has already been built up in memory.
Second, the tree at this point must have a power of two number of leaves.
(Ie a fully loaded, balanced binary tree) Third, when the pseudo code
fetches another hash out of the xBin header, it also pulls those that it
got before (for articles containing more than 1 block of data) which are
not saved a second time in the header.
Vocabulary used: (might as well define first about what I ramble :) )
This is all "very drafty". I use a vocabulary as I see fit. If there is a
better suited word that's been longer in use, please suggest / correct my
draft. After all, all this here screams for discussion, addenums,
corrections and suggestions.
article = one single usenet post
block = one atomic unit of (binary) data that gets hashed. Several blocks
per article are allowed, but one block may not be split over several
articles. Max length of a block not yet defined (working size as for now:
4500 bytes) block hash = hash of the block. AKA: "leave node's hash"
hash tree = memory structure in form of a binary tree that saves hashes on
each of its nodes root node = distinct node which is the root of the hash
tree. AKA: "root" file hash = hash saved within the root node. AKA: "root
hash" parent = node above a node. The root node has no parent, every other
node does. AKA: "parent node" sibling = "brother" node, node on the same
level whose hash toghether with this node in the correct order produces the
parent node's hash. AKA: "brother node", "sister node"
I think that suffices for the moment. Also note that each node within the
hash tree has one of these three states:
UNKNOWN - the hash value of this node is as of yet unvalidated
KNOWN - the hash value of this node is known AND validated.
NOTEXISTING - this node does not really exist - necessary for trees which
are not created using a power-of-two leave nodes. Still they need to be
traversed...
Here's the pseudo-code. I've used more or less a Java notation. It should
be readable for any C, C++ programmer though. It IS still pseudo code, it
won't compile. It has the limitations outlined above, so it is not
complete. You probably best copy & paste it into your favorite editor, so
the comments get color coded and the code gets more readable
=================
Pseudo code, assumes a tree structure has been built up in memory.
function process-xBin-article(Article a) {
if(a.getFileHash() != searchedFileHash) {
throw_article_away;
return;
}
foreach (block b in a) do {
success = decode(block);
if(!success) {
complain("error decoding block" + b.num);
next; // proceed to next foreach iteration
}
bhash = hash(block); // get the hash from this block
siblingHash = a.getNextHashFromHeader(); // get the sibling's hash
actualNode = block.getNodeNr(); // set nodeptr to actual block nr.
repeat {
actualNode = actualNode.getParentNode(); // set nodeptr to parent
if(siblingIsLeftOfMe) // find out if we're "left" or "right"
phash = hash(siblingHash + bhash);
else // calculate the parent hash accordingly
phash = hash(bhash + siblinghash);
}
if(actualNode.State == KNOWN) && (phash == actualNode.getHash()){
// this parent's node has already been computed and the hashes
// match. Good so far
if(actualNode == rootNode) {
say("block OK!);
saveblock(file, block, offset);
setallnodesknown(); // this will flag all nodes on the path
// from this block's leave node up to the root node to known
// where they have formerly been in unknown state
next; // proceed to next foreach iteration
}
if(actualNode.State == KNOWN) && (phash != actualNode.getHash()) {
complain("error, hash does not match along the path!");
next; // proceed to next foreach iteration
}
if(actualNode.State == UNKNOWN) {
markthisnode(); // this saves this node's just calculated hash
// the value gets written if setallnodesknown()
// is called later. Otherwise discarded
}
siblingHash = a.getNextHashFromHeader(); // need next sibling
// to be able to calculate next parent node
bhash = phash; // new "block hash" is this parent's hash
} // end repeat
} // end foreach block
} // end function
=================
For reference, here follows Kjetil T.'s ASCII so you can play that
pseudocode through in your mind:
l
+----------------------------+
j k
+--------------+ +---------+
| | | |
g h i |
+------+ +------+ +------+ |
| | | | | | |
a b c d e f |
+--+ +--+ +--+ +--+ +--+ +--+ |
| | | | | | | | | | | | |
1 2 3 4 5 6 7 8 9 10 11 12 13
I think it works IF the tree has a power-of-two leaves and I can always
pull the sibling's hashes from the header (which is actually incorrect,
some of the values would need to be "cached" and not fetched from the
header again). You can "insert" parts out of order, so I'm assuming the
algorithm will be working in a multi-threading enviroment and out of order
insertion of blocks WILL happen. The tree operations should be synchronized
/ atomic though.
Curt, you may want to add the pseudo code to your site. If you can spare
the time, a colorization of the comments wouldn't do any bad...
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
Technical Details
Message-ID:
<20021224101001.750$zN@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!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mailReferences:
<cdda0v4h6t52ov7abf1j0qkpo843itf4se@4ax.com> <cfka0vsbjdlbdmtv2gg8qnehok033qh5f1@4ax.com> <20021223041127.986$6M_-_@newsreader.com> <au92tp$cou$1@puck.litech.org> <20021224041138.040$dr@newsreader.com>Show Full Headers
Complete Article Headers
Message-ID: <20021224101001.750$zN@newsreader.com> Subject: Re: xBin (Power-Post 2003 - requesting input from authorities..) Date: Tue, 24 Dec 2002 15:10:01 +0000 From: Rene <invalid@email.addr> References: <cdda0v4h6t52ov7abf1j0qkpo843itf4se@4ax.com> <cfka0vsbjdlbdmtv2gg8qnehok033qh5f1@4ax.com> <20021223041127.986$6M_-_@newsreader.com> <au92tp$cou$1@puck.litech.org> <20021224041138.040$dr@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!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail Organization: NewsReader.Com Subscriber Newsgroups: news.software.nntp X-Trace: NewsReader.Com TM7I2WfRtv1@2akAA3=fJBy1ZO7GhQh/cGGxEK.iKVe/sh Lines: 133