Added External DHT Interface to display Connection Information.

* added retroshare/rsdht.h
 * extended p3bitdht to provide RsDht interface. (p3bitdht_interface.cc)
 * added UdpRelay to networking stack. 
 * started expansion of p3bitdht to handle connections.
 * added <string> header to rsthreads.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4399 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-06 13:04:50 +00:00
parent 5e691935fd
commit 11cc3fce04
7 changed files with 479 additions and 8 deletions

View File

@ -29,6 +29,9 @@
#include "bitdht/bdstddht.h"
#include "pqi/p3connmgr.h"
#include "tcponudp/udprelay.h"
#include "tcponudp/udpstunner.h"
#include <openssl/sha.h>
@ -37,6 +40,9 @@
*
*/
/**** EXTERNAL INTERFACE DHT POINTER *****/
RsDht *rsDht = NULL;
class p3BdCallback: public BitDhtCallback
{
public:
@ -74,6 +80,10 @@ virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdI
p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, UdpStack *udpstack, std::string bootstrapfile)
:pqiNetAssistConnect(id, cb), dhtMtx("p3BitDht")
{
mDhtStunner = NULL;
mProxyStunner = NULL;
mRelay = NULL;
std::string dhtVersion = "RS51"; // should come from elsewhere!
bdNodeId ownId;
@ -122,6 +132,15 @@ p3BitDht::~p3BitDht()
delete mUdpBitDht;
}
void p3BitDht::setupConnectBits(UdpStunner *dhtStunner, UdpStunner *proxyStunner, UdpRelayReceiver *relay)
{
mDhtStunner = dhtStunner;
mProxyStunner = proxyStunner;
mRelay = relay;
}
void p3BitDht::start()
{
#ifdef DEBUG_BITDHT

View File

@ -28,6 +28,7 @@
#define MRK_P3_BITDHT_H
#include "pqi/pqiassist.h"
#include "retroshare/rsdht.h"
#include <string>
#include <map>
@ -39,14 +40,54 @@
#include "udp/udpbitdht.h"
#include "bitdht/bdiface.h"
class p3BitDht: public pqiNetAssistConnect
class DhtPeerDetails
{
public:
bdId mDhtId;
std::string mRsId;
};
class UdpRelayReceiver;
class UdpStunner;
class p3BitDht: public pqiNetAssistConnect, public RsDht
{
public:
p3BitDht(std::string id, pqiConnectCb *cb,
UdpStack *udpstack, std::string bootstrapfile);
virtual ~p3BitDht();
/***********************************************************************************************
********** 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);
void start(); /* starts up the bitdht thread */
/* pqiNetAssist - external interface functions */
@ -94,12 +135,16 @@ int ValueCallback(const bdNodeId *id, std::string key, uint32_t status);
int removeTranslation(const std::string pid);
UdpBitDht *mUdpBitDht; /* has own mutex, is static except for creation/destruction */
UdpStunner *mDhtStunner;
UdpStunner *mProxyStunner;
UdpRelayReceiver *mRelay;
RsMutex dhtMtx;
/* translation maps */
std::map<std::string, bdNodeId> mTransToNodeId;
std::map<bdNodeId, std::string> mTransToRsId;
std::map<std::string, DhtPeerDetails> mPeers;
};
#endif /* MRK_P3_BITDHT_H */

View File

@ -0,0 +1,262 @@
/*
* libretroshare/src/dht: p3bitdht.h
*
* BitDht interface for RetroShare.
*
* Copyright 2009-2011 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".
*
*/
#include "util/rsnet.h"
#include "dht/p3bitdht.h"
#include "tcponudp/udprelay.h"
#include "bitdht/bdstddht.h"
#include <sstream>
void convertBdPeerToRsDhtPeer(RsDhtPeer &peer, const bdPeer &int_peer);
void convertDhtPeerDetailsToRsDhtNetPeer(RsDhtNetPeer &status, const DhtPeerDetails &details);
void convertUdpRelayEndtoRsDhtRelayEnd(RsDhtRelayEnd &end, const UdpRelayEnd &int_end);
void convertUdpRelayProxytoRsDhtRelayProxy(RsDhtRelayProxy &proxy, const UdpRelayProxy &int_proxy);
/***********************************************************************************************
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
************************************************************************************************/
uint32_t p3BitDht::getNetState(uint32_t type)
{
return 1;
}
int p3BitDht::getDhtPeers(int lvl, std::list<RsDhtPeer> &peers)
{
/* this function we can actually implement! */
bdBucket int_peers;
std::list<bdPeer>::iterator it;
mUdpBitDht->getDhtBucket(lvl, int_peers);
for(it = int_peers.entries.begin(); it != int_peers.entries.end(); it++)
{
RsDhtPeer peer;
convertBdPeerToRsDhtPeer(peer, *it);
peer.mBucket = lvl;
peers.push_back(peer);
}
return (int_peers.entries.size() > 0);
}
int p3BitDht::getNetPeerList(std::list<std::string> &peerIds)
{
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/
std::map<std::string, DhtPeerDetails>::iterator it;
for(it = mPeers.begin(); it != mPeers.end(); it++)
{
peerIds.push_back(it->first);
}
return 1;
}
int p3BitDht::getNetPeerStatus(std::string peerId, RsDhtNetPeer &status)
{
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/
std::map<std::string, DhtPeerDetails>::iterator it;
it = mPeers.find(peerId);
if (it == mPeers.end())
{
return 0;
}
convertDhtPeerDetailsToRsDhtNetPeer(status, it->second);
return 1;
}
int p3BitDht::getRelayEnds(std::list<RsDhtRelayEnd> &relayEnds)
{
/* no need for mutex as mRelayReceiver is protected */
if (!mRelay)
{
return 0;
}
std::list<UdpRelayEnd> int_relayEnds;
std::list<UdpRelayEnd>::iterator it;
mRelay->getRelayEnds(int_relayEnds);
for(it = int_relayEnds.begin(); it != int_relayEnds.end(); it++)
{
RsDhtRelayEnd end;
convertUdpRelayEndtoRsDhtRelayEnd(end, *it);
relayEnds.push_back(end);
}
return 1;
}
int p3BitDht::getRelayProxies(std::list<RsDhtRelayProxy> &relayProxies)
{
/* no need for mutex as mRelayReceiver is protected */
if (!mRelay)
{
return 0;
}
std::list<UdpRelayProxy> int_relayProxies;
std::list<UdpRelayProxy>::iterator it;
mRelay->getRelayProxies(int_relayProxies);
for(it = int_relayProxies.begin(); it != int_relayProxies.end(); it++)
{
RsDhtRelayProxy proxy;
convertUdpRelayProxytoRsDhtRelayProxy(proxy, *it);
relayProxies.push_back(proxy);
}
return 1;
}
#if 0
int p3BitDht::getNetFailedPeer(std::string peerId, PeerStatus &status)
{
return 1;
}
#endif
/***********************************************************************************************
********** External RsDHT Interface (defined in libretroshare/src/retroshare/rsdht.h) *********
************************************************************************************************/
void convertBdPeerToRsDhtPeer(RsDhtPeer &peer, const bdPeer &int_peer)
{
std::ostringstream out;
bdStdPrintNodeId(out, &(int_peer.mPeerId.id));
peer.mDhtId = out.str();
std::ostringstream addr;
addr << rs_inet_ntoa(int_peer.mPeerId.addr.sin_addr) << ":" << ntohs(int_peer.mPeerId.addr.sin_port);
peer.mAddr = addr.str();
peer.mLastSendTime = int_peer.mLastSendTime;
peer.mLastRecvTime = int_peer.mLastRecvTime;
peer.mFoundTime = int_peer.mFoundTime;
peer.mPeerFlags = int_peer.mPeerFlags;
peer.mExtraFlags = int_peer.mExtraFlags;
}
void convertDhtPeerDetailsToRsDhtNetPeer(RsDhtNetPeer &status, const DhtPeerDetails &details)
{
std::ostringstream out;
bdStdPrintNodeId(out, &(details.mDhtId.id));
status.mDhtId = out.str();
status.mRsId = details.mRsId;
return;
}
void convertUdpRelayEndtoRsDhtRelayEnd(RsDhtRelayEnd &end, const UdpRelayEnd &int_end)
{
std::ostringstream addr;
addr << rs_inet_ntoa(int_end.mLocalAddr.sin_addr) << ":" << ntohs(int_end.mLocalAddr.sin_port);
end.mLocalAddr = addr.str();
addr.clear();
addr << rs_inet_ntoa(int_end.mProxyAddr.sin_addr) << ":" << ntohs(int_end.mProxyAddr.sin_port);
end.mProxyAddr = addr.str();
addr.clear();
addr << rs_inet_ntoa(int_end.mRemoteAddr.sin_addr) << ":" << ntohs(int_end.mRemoteAddr.sin_port);
end.mRemoteAddr = addr.str();
end.mCreateTS = 0;
return;
}
void convertUdpRelayProxytoRsDhtRelayProxy(RsDhtRelayProxy &proxy, const UdpRelayProxy &int_proxy)
{
std::ostringstream addr;
addr << rs_inet_ntoa(int_proxy.mAddrs.mSrcAddr.sin_addr) << ":" << ntohs(int_proxy.mAddrs.mSrcAddr.sin_port);
proxy.mSrcAddr = addr.str();
addr.clear();
addr << rs_inet_ntoa(int_proxy.mAddrs.mDestAddr.sin_addr) << ":" << ntohs(int_proxy.mAddrs.mDestAddr.sin_port);
proxy.mDestAddr = addr.str();
proxy.mBandwidth = int_proxy.mBandwidth;
proxy.mRelayClass = int_proxy.mRelayClass;
proxy.mLastTS = int_proxy.mLastTS;
proxy.mCreateTS = 0;
//proxy.mDataSize = int_proxy.mDataSize;
//proxy.mLastBandwidthTS = int_proxy.mLastBandwidthTS;
}
RsDhtPeer::RsDhtPeer()
{
mBucket = 0;
//std::string mDhtId;
mLastSendTime = 0;
mLastRecvTime = 0;
mFoundTime = 0;
mPeerFlags = 0;
mExtraFlags = 0;
}
RsDhtNetPeer::RsDhtNetPeer()
{
return;
}
RsDhtRelayEnd::RsDhtRelayEnd()
{
mCreateTS = 0;
}
RsDhtRelayProxy::RsDhtRelayProxy()
{
mBandwidth = 0;
mRelayClass = 0;
mLastTS = 0;
mCreateTS = 0;
//uint32_t mDataSize;
//time_t mLastBandwidthTS;
}

View File

@ -65,8 +65,8 @@ debug {
bitdht {
HEADERS += dht/p3bitdht.h
SOURCES += dht/p3bitdht.cc
SOURCES += dht/p3bitdht.cc \
dht/p3bitdht_interface.cc
HEADERS += tcponudp/udppeer.h \
tcponudp/bio_tou.h \
@ -139,7 +139,8 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \
retroshare/rsrank.h \
retroshare/rsstatus.h \
retroshare/rsturtle.h \
retroshare/rstypes.h
retroshare/rstypes.h \
retroshare/rsdht.h
HEADERS += plugins/pluginmanager.h \
plugins/dlfcn_win32.h \

View File

@ -0,0 +1,136 @@
#ifndef RETROSHARE_DHT_GUI_INTERFACE_H
#define RETROSHARE_DHT_GUI_INTERFACE_H
/*
* libretroshare/src/rsiface: rsdht.h
*
* RetroShare C++ Interface.
*
* Copyright 2011-2011 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".
*
*/
#include <inttypes.h>
#include <string>
#include <list>
/* The Main Interface Class - for information about your Peers */
class RsDht;
extern RsDht *rsDht;
//std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail);
//std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
#define RS_DHT_NETSTART_NETWORKMODE 0x0001
#define RS_DHT_NETSTART_NATTYPE 0x0002
#define RS_DHT_NETSTART_NATHOLE 0x0003
#define RS_DHT_NETSTART_CONNECTMODES 0x0004
#define RS_DHT_NETSTART_NETSTATE 0x0005
class RsDhtPeer
{
public:
RsDhtPeer();
int mBucket;
std::string mDhtId;
std::string mAddr;
time_t mLastSendTime;
time_t mLastRecvTime;
time_t mFoundTime;
uint32_t mPeerFlags;
uint32_t mExtraFlags;
};
class RsDhtNetPeer
{
public:
RsDhtNetPeer();
std::string mDhtId;
std::string mRsId;
};
class RsDhtRelayEnd
{
public:
RsDhtRelayEnd();
std::string mLocalAddr;
std::string mProxyAddr;
std::string mRemoteAddr;
time_t mCreateTS;
};
class RsDhtRelayProxy
{
public:
RsDhtRelayProxy();
std::string mSrcAddr;
std::string mDestAddr;
double mBandwidth;
int mRelayClass;
time_t mLastTS;
time_t mCreateTS;
//uint32_t mDataSize;
//time_t mLastBandwidthTS;
};
class RsDht
{
public:
RsDht() { return; }
virtual ~RsDht() { return; }
virtual uint32_t getNetState(uint32_t type) = 0;
virtual int getDhtPeers(int lvl, std::list<RsDhtPeer> &peers) = 0;
virtual int getNetPeerList(std::list<std::string> &peerIds) = 0;
virtual int getNetPeerStatus(std::string peerId, RsDhtNetPeer &status) = 0;
virtual int getRelayEnds(std::list<RsDhtRelayEnd> &relayEnds) = 0;
virtual int getRelayProxies(std::list<RsDhtRelayProxy> &relayProxies) = 0;
//virtual int getNetFailedPeer(std::string peerId, PeerStatus &status);
#if 0
virtual std::string getPeerStatusString();
virtual std::string getPeerAddressString();
virtual std::string getDhtStatusString();
virtual int get_dht_queries(std::map<bdNodeId, bdQueryStatus> &queries);
virtual int get_query_status(std::string id, bdQuerySummary &query);
virtual int get_peer_status(std::string peerId, PeerStatus &status);
virtual int get_net_failedpeers(std::list<std::string> &peerIds);
virtual int get_failedpeer_status(std::string peerId, PeerStatus &status);
#endif
};
#endif

View File

@ -1900,12 +1900,14 @@ int RsServer::StartupRetroShare()
// NEXT BITDHT.
p3BitDht *mBitDht = new p3BitDht(ownId, mConnMgr, mUdpStack, bootstrapfile);
/* install external Pointer for Interface */
rsDht = mBitDht;
// NEXT THE RELAY (NEED to keep a reference for installing RELAYS)
//UdpRelayReceiver *mRelayRecver = new UdpRelayReceiver(mUdpStack);
//udpReceivers[2] = mRelayRecver; /* RELAY Connections (DHT Port) */
//udpTypes[2] = TOU_RECEIVER_TYPE_UDPRELAY;
//mUdpStack->addReceiver(udpReceivers[2]);
UdpRelayReceiver *mRelayRecver = new UdpRelayReceiver(mUdpStack);
udpReceivers[2] = mRelayRecver; /* RELAY Connections (DHT Port) */
udpTypes[2] = TOU_RECEIVER_TYPE_UDPRELAY;
mUdpStack->addReceiver(udpReceivers[2]);
// LAST ON THIS STACK IS STANDARD DIRECT TOU
udpReceivers[0] = new UdpPeerReceiver(mUdpStack); /* standard DIRECT Connections (DHT Port) */
@ -1938,6 +1940,11 @@ int RsServer::StartupRetroShare()
// REAL INITIALISATION - WITH THREE MODES - FOR LATER.
//tou_init((void **) udpReceivers, udpTypes, 3);
//mBitDht->setupConnectBits(mDhtStunner, mProxyStunner, mRelayRecver);
mBitDht->setupConnectBits(mDhtStunner, NULL, mRelayRecver);
#else
/* install NULL Pointer for rsDht Interface */
rsDht = NULL;
#endif

View File

@ -33,6 +33,7 @@
#include <pthread.h>
#include <inttypes.h>
#include <string>
/* RsIface Thread Wrappers */