🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #64289

xBin library header

#64289
From: Chris
Date: Thu, 06 Mar 2003 16:36
138 lines
4692 bytes
To facilitate incorporation into existing news clients, I figured writing
an xBin library would be the best way to get xBin in use out there in the
real world.  Here is the interface I'm working with so far.  I have a few
concerns right now...It's obviously a c++ header, would there be much of a
need for a C library, or C wrappers for these functions?  Also I'd like
the return type of base64decode to be something like a
basic_string<unsigned char*>, but I couldn't get that to work.  Anyway,
here it is:

#ifndef __xbin_h__
#define __xbin_h__

#include <string>
#include <vector>

const unsigned int xBinBlockSize = 22500;
const unsigned int xBinArticleSize = 1024 * 512000;

//
// Probably need something more intelligent for other platforms
//
typedef unsigned long long int uint64_t;
typedef unsigned int uint32_t;

//
// xBin uses SHA1 hashes which are 160 bits (20 bytes) long
//
typedef unsigned char hashT[20];

//
// A HashNode is an individual node in a hash tree
//
class HashNode
{
public:
	//
	// Make this node using the given data to create the hash
	//
	HashNode(const unsigned char* data, int bytes);

	//
	// Make this node with the given hash
	//
	HashNode(const hashT hash);

	//
	// Make this node the parent of the two given nodes
	//
	HashNode(HashNode *lChild, HashNode *rChild);

	//
	// Deleting a HashNode deletes its children as well!
	//
	~HashNode();

	//
	// Get the node that covers this block
	//
	HashNode* getNode(uint64_t block);

	HashNode *lChild, *rChild, *parent;
	uint64_t firstBlock, lastBlock;
	hashT hash;
};

//
// encode data in base64, without = padding
//
std::string base64encode(const unsigned char* input, int bytes);
std::string base64encode(const uint64_t input);

//
// decode a base64 string
// returns a new[]'d buffer
// size of the buffer is placed in bytes
//
unsigned char* base64decode(const char* input, int& bytes);

//
// decode a base64 string as an integer
//
uint64_t base64decodeInt(const char* input, int bytes);

//
// MessageInfo contains all of the information that goes into a
// xBin Message-ID header
//
struct MessageInfo
{
	uint64_t fileSize; // size of file in bytes
	uint64_t offset; // offset of this article in blocks
	uint64_t nBlocks; // size of this article in blocks
	hashT hash; // root hash
};

//
// Generates an xBin message id string that can be included in the
// Message-ID header
//
std::string xBinGetMessageId(const MessageInfo& m);

//
// Parses Message-ID header for xBin tags
// Returns 1 on success, and fills in m appropriately
// Returns 0 on failure
//
int xBinParseMessageId(const std::string& header, MessageInfo& m);

//
// Builds a hashtree from the given file
//
HashNode* xBinBuildHashTree(const char* filename);

//
// Returns a list of base64 encoded hash values to include in the
// Content-SHA1-Tree header
//
std::string xBinBuildContentTree(const HashNode* root, uint64_t
	firstBlock, uint64_t lastblock);

//
// Verifies that a Content-SHA1-Tree header is valid
// Returns 1 on success
// Returns 0 on failure
//
// dataNodes is a list of hashnodes representing the hashes of the data
// being verified
//
// nBlocks is the total number of blocks in the file (leaves on the tree)
//  (nBlocks == root->lastBlock + 1)
//
// begin and end specify what range of data is covered by dataNodes
//
int xBinVerifyContentTree(const std::string& header, 
		std::vector<HashNode*> dataNodes, uint64_t nBlocks, 
		uint64_t begin, uint64_t end);
#endif // __xbin_h__
Technical Details
Message-ID: <pan.2003.03.06.16.36.27.43643@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!nntp.cs.ubc.ca!logbridge.uoregon.edu!snoopy.risq.qc.ca!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!news03.bloor.is.net.cable.rogers.com!news04.bloor.is.net.cable.rogers.com.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <pan.2003.03.06.16.36.27.43643@rogers.com>
Subject: xBin library header
Date: Thu, 06 Mar 2003 16:36:31 GMT
From: "Chris" <nobody@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!nntp.cs.ubc.ca!logbridge.uoregon.edu!snoopy.risq.qc.ca!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!news03.bloor.is.net.cable.rogers.com!news04.bloor.is.net.cable.rogers.com.POSTED!not-for-mail
User-Agent: Pan/0.13.4 (She had eyes like strange sins. (Debian GNU/Linux))
Newsgroups: news.software.nntp
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 137
NNTP-Posting-Host: 24.114.32.59
X-Complaints-To: abuse@rogers.com
X-Trace: news04.bloor.is.net.cable.rogers.com 1046968591 24.114.32.59 (Thu, 06 Mar 2003 11:36:31 EST)
NNTP-Posting-Date: Thu, 06 Mar 2003 11:36:31 EST