Addition of libbitdht.

============================================================

This is intended to be a completely independent library from RS, 
(hosted at sf.net/projects/bitdht) hence is being commited at the top level.

As initial further development / testing will be driven by RS integration
it is being added to the RS repository. Equally important is ensuring
that RS can compile without requiring aux libraries.

Once libbitdht is further developed, this section of the repository
is expected to be removed... But that will not be for a while, I expect.

drbob.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3276 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-07-10 11:48:24 +00:00
parent 9b72977bba
commit c415bb6158
56 changed files with 11344 additions and 0 deletions

View file

@ -0,0 +1,96 @@
#ifndef UDP_BIT_DHT_CLASS_H
#define UDP_BIT_DHT_CLASS_H
/*
* bitdht/udpbitdht.h
*
* BitDHT: An Flexible DHT library.
*
* Copyright 2010 by Robert Fernie
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 3 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "bitdht@lunamutt.com".
*
*/
#include <iosfwd>
#include <map>
#include <string>
#include "udp/udpstack.h"
#include "bitdht/bdiface.h"
#include "bitdht/bdmanager.h"
/*
* This implements a UdpSubReceiver class to allow the DHT to talk to the network.
* The parser is very strict - and will try to not pick up anyone else's messages.
*
* Mutexes are implemented at this level protecting the whole of the DHT code.
* This class is also a thread - enabling it to do callback etc.
*/
// class BitDhtCallback defined in bdiface.h
class UdpBitDht: public UdpSubReceiver, public bdThread, public BitDhtInterface
{
public:
UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string dhtVersion, std::string bootstrapfile, bdDhtFunctions *fns);
virtual ~UdpBitDht();
/*********** External Interface to the World (BitDhtInterface) ************/
/***** Functions to Call down to bdNodeManager ****/
/* Request DHT Peer Lookup */
/* Request Keyword Lookup */
virtual void addFindNode(bdNodeId *id, uint32_t mode);
virtual void removeFindNode(bdNodeId *id);
virtual void findDhtValue(bdNodeId *id, std::string key, uint32_t mode);
/***** Add / Remove Callback Clients *****/
virtual void addCallback(BitDhtCallback *cb);
virtual void removeCallback(BitDhtCallback *cb);
/***** Get Results Details *****/
virtual int getDhtPeerAddress(bdNodeId *id, struct sockaddr_in &from);
virtual int getDhtValue(bdNodeId *id, std::string key, std::string &value);
/******************* Internals *************************/
/***** Iteration / Loop Management *****/
/*** Overloaded from UdpSubReceiver ***/
virtual int recvPkt(void *data, int size, struct sockaddr_in &from);
virtual int status(std::ostream &out);
/*** Overloaded from iThread ***/
virtual void run();
/**** do whats to be done ***/
int tick();
private:
bdMutex dhtMtx; /* for all class data (below) */
bdNodeManager *mBitDhtManager;
bdDhtFunctions *mFns;
};
#endif