Developers.Hash.TigerTree.Sample
Server and client TigerTree sample
Imagine there are two computers running peer-to-peer software. The server has a file, and the client is downloading it. Here's how they can both use TigerTree to exchange the file. They can do this without ever directly connecting to one another. They can do this on a network where some computers are lying about hashes and sending bad data as file parts.
The server has:
- A maximum height for generating trees, like 9
- A file
- The file size
Using TigerTree, it wants:
- The entire tree, including a way to find out how big it is first
- More statistics about the tree, like its height, and the block size used
The client has:
- A maximum height for using trees, like 9
- The file size
- The entire tree
- Parts of the file it downloaded
It needs to figure out
- If the tree is valid
- What block size the tree uses
- If a block it has downloaded is valid
I'm going to write a sample that demonstrates these tasks using first the Shareaza 2.0 code. Then, I'll adapt it for camper's new code.
I've setup Shareaza so it calls Test when I right-click on the About box. The Test function calls TigerTest twice, passing it the path to two small test files on my hard drive.
TigerTest calls TigerServer and TigerClient. Both take the maximum tree height, the bytes of the file, and the bytes of the tree. The server function reads the file and generates the tree. The client function reads the tree, and then simulates downloading the file by using the tree to check the validity of parts of it.
Both TigerServer and TigerClient take the maximum tree height. In Shareaza, this is 9 for both the server and client roles. The server function doesn't generate a tree higher than this limit. The client function can take trees of any height. It uses the limit to shorten trees that are too tall.
FileToBuffer is just a helper function that wraps some Win32 file functions. It copies the contents of a file into a Shareaza CBuffer object.