Thread View: news.software.nntp
5 messages
5 total messages
Started by Chris
Tue, 25 Feb 2003 15:32
xBin Content-SHA1-Tree format
Author: Chris
Date: Tue, 25 Feb 2003 15:32
Date: Tue, 25 Feb 2003 15:32
68 lines
3631 bytes
3631 bytes
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.
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...)
What do people think?
Cheers,
Chris
Re: xBin Content-SHA1-Tree format
Author: Chris
Date: Tue, 25 Feb 2003 19:20
Date: Tue, 25 Feb 2003 19:20
16 lines
1575 bytes
1575 bytes
Here's a link to my implementation: http://atlee.ca/xbin-python.tgz You'll need python to get this working. The script xpost.py generates articles from files, and the script xverify.py verifies that articles are correct. The content-sha1-tree is generated using the second algorithm I mentioned in my previous post. Comments would be most welcome! I thought I'd try and kick-start some development on this. Cheers, Chris
Re: xBin Content-SHA1-Tree format
Author: 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/
Re: xBin Content-SHA1-Tree format
Author: Stephen Lee
Date: Wed, 26 Feb 2003 15:59
Date: Wed, 26 Feb 2003 15:59
103 lines
5137 bytes
5137 bytes
What is the status of xBin? Is it in final form yet? If so, where (the docs)? Thanks, Steve "Curt Welch" <curt@kcwc.com> wrote in message news:20030225183939.804$fz@newsreader.com... > "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/
Re: xBin Content-SHA1-Tree format
Author: Mirco Romanato
Date: Wed, 09 Apr 2003 10:09
Date: Wed, 09 Apr 2003 10:09
23 lines
1804 bytes
1804 bytes
Chris wrote: > Here's a link to my implementation: > http://atlee.ca/xbin-python.tgz > You'll need python to get this working. The script xpost.py generates > articles from files, and the script xverify.py verifies that articles > are correct. > The content-sha1-tree is generated using the second algorithm I > mentioned in my previous post. > Comments would be most welcome! I thought I'd try and kick-start some > development on this. Do you think is possible to add TigerTree hash support for generating TigerTreeHash root and full tree? This will help much the development of applications standardized with gnutella and standards. Mirco
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads