2010-07-17 13:00:19 -04:00
|
|
|
/*
|
|
|
|
* libretroshare/src/dht: p3bitdht.h
|
|
|
|
*
|
|
|
|
* BitDht interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2009-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 2 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 "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MRK_P3_BITDHT_H
|
|
|
|
#define MRK_P3_BITDHT_H
|
|
|
|
|
|
|
|
#include "pqi/pqiassist.h"
|
2011-07-06 09:04:50 -04:00
|
|
|
#include "retroshare/rsdht.h"
|
2010-07-17 13:00:19 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include "pqi/pqinetwork.h"
|
|
|
|
#include "pqi/pqimonitor.h"
|
|
|
|
#include "util/rsthreads.h"
|
|
|
|
|
|
|
|
#include "udp/udpstack.h"
|
|
|
|
#include "udp/udpbitdht.h"
|
|
|
|
#include "bitdht/bdiface.h"
|
|
|
|
|
2011-07-06 09:04:50 -04:00
|
|
|
|
|
|
|
class DhtPeerDetails
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
bdId mDhtId;
|
|
|
|
std::string mRsId;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class UdpRelayReceiver;
|
|
|
|
class UdpStunner;
|
|
|
|
|
|
|
|
|
|
|
|
class p3BitDht: public pqiNetAssistConnect, public RsDht
|
2010-07-17 13:00:19 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
p3BitDht(std::string id, pqiConnectCb *cb,
|
|
|
|
UdpStack *udpstack, std::string bootstrapfile);
|
|
|
|
|
2011-07-06 09:04:50 -04:00
|
|
|
|
2010-07-17 13:00:19 -04:00
|
|
|
virtual ~p3BitDht();
|
|
|
|
|
2011-07-06 09:04:50 -04:00
|
|
|
|
|
|
|
/***********************************************************************************************
|
|
|
|
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
|
|
|
|
************************************************************************************************/
|
|
|
|
|
|
|
|
virtual uint32_t getNetState(uint32_t type);
|
|
|
|
virtual int getDhtPeers(int lvl, std::list<RsDhtPeer> &peers);
|
|
|
|
virtual int getNetPeerList(std::list<std::string> &peerIds);
|
|
|
|
virtual int getNetPeerStatus(std::string peerId, RsDhtNetPeer &status);
|
|
|
|
|
|
|
|
virtual int getRelayEnds(std::list<RsDhtRelayEnd> &relayEnds);
|
|
|
|
virtual int getRelayProxies(std::list<RsDhtRelayProxy> &relayProxies);
|
|
|
|
|
|
|
|
//virtual int getNetFailedPeer(std::string peerId, PeerStatus &status);
|
|
|
|
|
|
|
|
/***********************************************************************************************
|
|
|
|
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
|
|
|
|
************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
void setupConnectBits(UdpStunner *dhtStunner, UdpStunner *proxyStunner, UdpRelayReceiver *relay);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
void start(); /* starts up the bitdht thread */
|
|
|
|
|
2010-07-17 13:00:19 -04:00
|
|
|
/* pqiNetAssist - external interface functions */
|
|
|
|
virtual void enable(bool on);
|
|
|
|
virtual void shutdown(); /* blocking call */
|
|
|
|
virtual void restart();
|
|
|
|
|
|
|
|
virtual bool getEnabled();
|
|
|
|
virtual bool getActive();
|
2010-10-31 09:53:28 -04:00
|
|
|
virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize);
|
2010-07-17 13:00:19 -04:00
|
|
|
|
|
|
|
/* pqiNetAssistConnect - external interface functions */
|
|
|
|
|
|
|
|
/* add / remove peers */
|
|
|
|
virtual bool findPeer(std::string id);
|
|
|
|
virtual bool dropPeer(std::string id);
|
|
|
|
|
|
|
|
/* extract current peer status */
|
2010-07-31 14:14:10 -04:00
|
|
|
virtual bool getPeerStatus(std::string id,
|
|
|
|
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
|
|
|
|
uint32_t &type, uint32_t &mode);
|
2010-07-17 13:00:19 -04:00
|
|
|
|
|
|
|
virtual bool getExternalInterface(struct sockaddr_in &raddr,
|
|
|
|
uint32_t &mode);
|
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
/* notifyPeer/setExtInterface/Bootstrap/Stun
|
|
|
|
* hould all be removed from NetAssist?
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* pqiNetAssistConnect - external interface functions */
|
|
|
|
|
|
|
|
|
2010-07-17 13:00:19 -04:00
|
|
|
/* Callback functions - from bitdht */
|
|
|
|
int NodeCallback(const bdId *id, uint32_t peerflags);
|
2010-11-22 19:06:54 -05:00
|
|
|
int PeerCallback(const bdId *id, uint32_t status);
|
2010-07-17 13:00:19 -04:00
|
|
|
int ValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* translation stuff */
|
|
|
|
int calculateNodeId(const std::string pid, bdNodeId *id);
|
|
|
|
|
|
|
|
int lookupNodeId(const std::string pid, bdNodeId *id);
|
|
|
|
int lookupRsId(const bdNodeId *id, std::string &pid);
|
|
|
|
int storeTranslation(const std::string pid);
|
|
|
|
int removeTranslation(const std::string pid);
|
|
|
|
|
2010-11-22 19:06:54 -05:00
|
|
|
UdpBitDht *mUdpBitDht; /* has own mutex, is static except for creation/destruction */
|
2011-07-06 09:04:50 -04:00
|
|
|
UdpStunner *mDhtStunner;
|
|
|
|
UdpStunner *mProxyStunner;
|
|
|
|
UdpRelayReceiver *mRelay;
|
2010-07-17 13:00:19 -04:00
|
|
|
|
|
|
|
RsMutex dhtMtx;
|
|
|
|
/* translation maps */
|
|
|
|
std::map<std::string, bdNodeId> mTransToNodeId;
|
|
|
|
std::map<bdNodeId, std::string> mTransToRsId;
|
|
|
|
|
2011-07-06 09:04:50 -04:00
|
|
|
std::map<std::string, DhtPeerDetails> mPeers;
|
2010-07-17 13:00:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* MRK_P3_BITDHT_H */
|
|
|
|
|