Changes to get DHT On/Off working, and get DHT status working too:

* Plumbed stats through the the retroshare interface.
  * Also changed Channel store period back to 10 minutes.... (Reduce overall file count).
    	This must be done some time before the any changes are made to Channels periods.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3721 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-10-31 13:53:28 +00:00
parent 89ca27ef66
commit 519075c70b
10 changed files with 126 additions and 64 deletions

View file

@ -146,6 +146,9 @@ pqiNetStatus::pqiNetStatus()
:mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false),
mUpnpOk(false), mDhtOk(false), mResetReq(false)
{
mDhtNetworkSize = 0;
mDhtRsNetworkSize = 0;
sockaddr_clear(&mLocalAddr);
sockaddr_clear(&mExtAddr);
return;
@ -164,6 +167,8 @@ void pqiNetStatus::print(std::ostream &out)
out << " mDhtOk: " << mDhtOk;
out << " mResetReq: " << mResetReq;
out << std::endl;
out << "mDhtNetworkSize: " << mDhtNetworkSize << " mDhtRsNetworkSize: " << mDhtRsNetworkSize;
out << std::endl;
out << "mLocalAddr: " << rs_inet_ntoa(mLocalAddr.sin_addr) << ":" << ntohs(mLocalAddr.sin_port) << " ";
out << "mExtAddr: " << rs_inet_ntoa(mExtAddr.sin_addr) << ":" << ntohs(mExtAddr.sin_port) << " ";
out << " NetOk: " << NetOk();
@ -3117,15 +3122,20 @@ bool p3ConnectMgr::setLocation(std::string id, std::string location)
bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
if (id == AuthSSL::getAuthSSL()->OwnId())
{
mOwnState.visState = visState;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
uint32_t netMode;
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
netMode = mOwnState.netMode;
}
setOwnNetConfig(netMode, visState);
return true;
}
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */
std::map<std::string, peerConnectState>::iterator it;
bool isFriend = false;
@ -3742,6 +3752,12 @@ void p3ConnectMgr::addNetAssistConnect(uint32_t id, pqiNetAssistConnect *dht)
bool p3ConnectMgr::enableNetAssistConnect(bool on)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::enableNetAssistConnect(" << on << ")";
std::cerr << std::endl;
#endif
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
for(it = mDhts.begin(); it != mDhts.end(); it++)
{
@ -3757,9 +3773,20 @@ bool p3ConnectMgr::netAssistConnectEnabled()
{
if ((it->second)->getEnabled())
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::netAssistConnectEnabled() YES";
std::cerr << std::endl;
#endif
return true;
}
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::netAssistConnectEnabled() NO";
std::cerr << std::endl;
#endif
return false;
}
@ -3771,14 +3798,56 @@ bool p3ConnectMgr::netAssistConnectActive()
if ((it->second)->getActive())
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::netAssistConnectActive() ACTIVE";
std::cerr << std::endl;
#endif
return true;
}
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::netAssistConnectActive() INACTIVE";
std::cerr << std::endl;
#endif
return false;
}
bool p3ConnectMgr::netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize)
{
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
for(it = mDhts.begin(); it != mDhts.end(); it++)
{
if (((it->second)->getActive()) && ((it->second)->getNetworkStats(netsize, localnetsize)))
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::netAssistConnectStats(";
std::cerr << netsize << ", " << localnetsize << ")";
std::cerr << std::endl;
#endif
return true;
}
}
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::netAssistConnectStats() INACTIVE";
std::cerr << std::endl;
#endif
return false;
}
bool p3ConnectMgr::netAssistConnectShutdown()
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::netAssistConnectShutdown()";
std::cerr << std::endl;
#endif
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
for(it = mDhts.begin(); it != mDhts.end(); it++)
{
@ -3840,9 +3909,15 @@ bool p3ConnectMgr::getDHTEnabled()
return netAssistConnectEnabled();
}
void p3ConnectMgr::getNetStatus(pqiNetStatus &status)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* quick update of the stuff that can change! */
mNetFlags.mDhtOk = netAssistConnectActive();
netAssistConnectStats(mNetFlags.mDhtNetworkSize, mNetFlags.mDhtRsNetworkSize);
status = mNetFlags;
}

View file

@ -187,6 +187,9 @@ class pqiNetStatus
bool mUpnpOk; // upnp is ok.
bool mDhtOk; // dht is ok.
uint32_t mDhtNetworkSize;
uint32_t mDhtRsNetworkSize;
struct sockaddr_in mLocalAddr; // percieved ext addr.
struct sockaddr_in mExtAddr; // percieved ext addr.
@ -231,6 +234,7 @@ bool retryConnect(std::string id);
bool getUPnPState();
bool getUPnPEnabled();
bool getDHTEnabled();
bool getDHTStats(uint32_t &netsize, uint32_t &localnetsize);
bool getIPServersEnabled();
void setIPServersEnabled(bool b) ;
@ -320,6 +324,8 @@ virtual bool enableNetAssistConnect(bool on);
virtual bool netAssistConnectEnabled();
virtual bool netAssistConnectActive();
virtual bool netAssistConnectShutdown();
virtual bool netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize);
/* Assist Firewall */
bool netAssistExtAddress(struct sockaddr_in &extAddr);

View file

@ -94,15 +94,6 @@ class pqiNetAssistConnect: public pqiNetAssist
* for the DHT, and must be non-blocking and return quickly
*/
#if 0
virtual void setBootstrapAllowed(bool on) = 0;
virtual bool getBootstrapAllowed() = 0;
/* set key data */
virtual bool setExternalInterface(struct sockaddr_in laddr,
struct sockaddr_in raddr, uint32_t type) = 0;
#endif
/* add / remove peers */
virtual bool findPeer(std::string id) = 0;
virtual bool dropPeer(std::string id) = 0;
@ -112,15 +103,11 @@ virtual bool getPeerStatus(std::string id,
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
uint32_t &type, uint32_t &mode) = 0;
#if 0
//virtual bool getExternalInterface(struct sockaddr_in &raddr,
// uint32_t &mode) = 0;
/* post DHT key saying we should connect (callback when done) */
virtual bool notifyPeer(std::string id) = 0;
/* stun */
virtual bool enableStun(bool on) = 0;
virtual bool addStun(std::string id) = 0;
#endif
/***** Stats for Network / DHT *****/
virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize) = 0;
protected:
std::string mPeerId;
@ -128,38 +115,5 @@ virtual bool addStun(std::string id) = 0;
};
#if 0
class pqiNetAssistConnectBitDht: public pqiNetAssist
{
/*
*/
public:
pqiNetAssistConnectBitDht(std::string id, pqiConnectCb *cb)
:mPeerId(id), mConnCb(cb) { return; }
/********** External DHT Interface ************************
* These Functions are the external interface
* for the DHT, and must be non-blocking and return quickly
*/
/* add / remove peers */
virtual bool findPeer(std::string id) = 0;
virtual bool dropPeer(std::string id) = 0;
/* extract current peer status */
virtual bool getPeerStatus(std::string id, struct sockaddr_in &raddr,
uint32_t &mode) = 0;
virtual bool getExternalInterface(struct sockaddr_in &raddr,
uint32_t &mode) = 0;
protected:
std::string mPeerId;
pqiConnectCb *mConnCb;
};
#endif
#endif /* MRK_PQI_ASSIST_H */

View file

@ -44,7 +44,7 @@ static std::list<std::string> waitingIds;
/****
*#define PGRP_DEBUG 1
****/
#define PGRP_DEBUG 1
//#define PGRP_DEBUG 1
/* MUTEX NOTES:
* Functions like GetRsRawItem() lock itself (pqihandler) and