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

@ -118,35 +118,52 @@ void p3BitDht::start()
mUdpBitDht->start(); /* starts up the bitdht thread */ mUdpBitDht->start(); /* starts up the bitdht thread */
/* switch on the dht too */ /* dht switched on by config later. */
mUdpBitDht->startDht();
} }
/* pqiNetAssist - external interface functions */ /* pqiNetAssist - external interface functions */
void p3BitDht::enable(bool on) void p3BitDht::enable(bool on)
{ {
//mUdpBitDht->enable(on); std::cerr << "p3BitDht::enable(" << on << ")";
std::cerr << std::endl;
if (on)
{
mUdpBitDht->startDht();
}
else
{
mUdpBitDht->stopDht();
}
} }
void p3BitDht::shutdown() /* blocking call */ void p3BitDht::shutdown() /* blocking call */
{ {
//mUdpBitDht->shutdown(); mUdpBitDht->stopDht();
} }
void p3BitDht::restart() void p3BitDht::restart()
{ {
//mUdpBitDht->restart(); mUdpBitDht->stopDht();
mUdpBitDht->startDht();
} }
bool p3BitDht::getEnabled() bool p3BitDht::getEnabled()
{ {
return false; return (mUdpBitDht->stateDht() != 0);
} }
bool p3BitDht::getActive() bool p3BitDht::getActive()
{ {
return false; return (mUdpBitDht->stateDht() >= BITDHT_MGR_STATE_ACTIVE);
}
bool p3BitDht::getNetworkStats(uint32_t &netsize, uint32_t &localnetsize)
{
netsize = mUdpBitDht->statsNetworkSize();
localnetsize = mUdpBitDht->statsBDVersionSize();
return true;
} }
/* pqiNetAssistConnect - external interface functions */ /* pqiNetAssistConnect - external interface functions */

View File

@ -56,6 +56,7 @@ virtual void restart();
virtual bool getEnabled(); virtual bool getEnabled();
virtual bool getActive(); virtual bool getActive();
virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize);
/* pqiNetAssistConnect - external interface functions */ /* pqiNetAssistConnect - external interface functions */

View File

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

View File

@ -187,6 +187,9 @@ class pqiNetStatus
bool mUpnpOk; // upnp is ok. bool mUpnpOk; // upnp is ok.
bool mDhtOk; // dht is ok. bool mDhtOk; // dht is ok.
uint32_t mDhtNetworkSize;
uint32_t mDhtRsNetworkSize;
struct sockaddr_in mLocalAddr; // percieved ext addr. struct sockaddr_in mLocalAddr; // percieved ext addr.
struct sockaddr_in mExtAddr; // percieved ext addr. struct sockaddr_in mExtAddr; // percieved ext addr.
@ -231,6 +234,7 @@ bool retryConnect(std::string id);
bool getUPnPState(); bool getUPnPState();
bool getUPnPEnabled(); bool getUPnPEnabled();
bool getDHTEnabled(); bool getDHTEnabled();
bool getDHTStats(uint32_t &netsize, uint32_t &localnetsize);
bool getIPServersEnabled(); bool getIPServersEnabled();
void setIPServersEnabled(bool b) ; void setIPServersEnabled(bool b) ;
@ -320,6 +324,8 @@ virtual bool enableNetAssistConnect(bool on);
virtual bool netAssistConnectEnabled(); virtual bool netAssistConnectEnabled();
virtual bool netAssistConnectActive(); virtual bool netAssistConnectActive();
virtual bool netAssistConnectShutdown(); virtual bool netAssistConnectShutdown();
virtual bool netAssistConnectStats(uint32_t &netsize, uint32_t &localnetsize);
/* Assist Firewall */ /* Assist Firewall */
bool netAssistExtAddress(struct sockaddr_in &extAddr); 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 * 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 */ /* add / remove peers */
virtual bool findPeer(std::string id) = 0; virtual bool findPeer(std::string id) = 0;
virtual bool dropPeer(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, struct sockaddr_in &laddr, struct sockaddr_in &raddr,
uint32_t &type, uint32_t &mode) = 0; 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) */ /***** Stats for Network / DHT *****/
virtual bool notifyPeer(std::string id) = 0; virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize) = 0;
/* stun */
virtual bool enableStun(bool on) = 0;
virtual bool addStun(std::string id) = 0;
#endif
protected: protected:
std::string mPeerId; 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 */ #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 //#define PGRP_DEBUG 1
/* MUTEX NOTES: /* MUTEX NOTES:
* Functions like GetRsRawItem() lock itself (pqihandler) and * Functions like GetRsRawItem() lock itself (pqihandler) and

View File

@ -180,6 +180,10 @@ class RsConfig
bool netDhtOk; /* response from dht */ bool netDhtOk; /* response from dht */
bool netStunOk; /* recvd stun / udp packets */ bool netStunOk; /* recvd stun / udp packets */
bool netExtraAddressOk; /* recvd ip address with external finder*/ bool netExtraAddressOk; /* recvd ip address with external finder*/
uint32_t netDhtNetSize; /* response from dht */
uint32_t netDhtRsNetSize; /* response from dht */
}; };
/********************** For Search Interface *****************/ /********************** For Search Interface *****************/

View File

@ -129,12 +129,16 @@ int RsServer::UpdateAllConfig()
pqiNetStatus status; pqiNetStatus status;
mConnMgr->getNetStatus(status); mConnMgr->getNetStatus(status);
config.netLocalOk = status.mLocalAddrOk; config.netLocalOk = status.mLocalAddrOk;
config.netUpnpOk = status.mUpnpOk; config.netUpnpOk = status.mUpnpOk;
config.netDhtOk = status.mDhtOk;
config.netStunOk = false; config.netStunOk = false;
config.netExtraAddressOk = status.mExtAddrOk; config.netExtraAddressOk = status.mExtAddrOk;
config.netDhtOk = status.mDhtOk;
config.netDhtNetSize = status.mDhtNetworkSize;
config.netDhtRsNetSize = status.mDhtRsNetworkSize;
/* update DHT/UPnP config */ /* update DHT/UPnP config */
config.uPnPState = mConnMgr->getUPnPState(); config.uPnPState = mConnMgr->getUPnPState();

View File

@ -805,6 +805,7 @@ p3Peers::setVisState(std::string id, uint32_t extVisState)
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::setVisState() " << id << std::endl; std::cerr << "p3Peers::setVisState() " << id << std::endl;
#endif #endif
std::cerr << "p3Peers::setVisState() " << id << " " << extVisState << std::endl;
uint32_t visState = 0; uint32_t visState = 0;
if (!(extVisState & RS_VS_DHT_ON)) if (!(extVisState & RS_VS_DHT_ON))

View File

@ -66,7 +66,7 @@ RsChannels *rsChannels = NULL;
* PUBPERIOD * 2^16 = max STORE PERIOD */ * PUBPERIOD * 2^16 = max STORE PERIOD */
#define CHANNEL_STOREPERIOD (30*24*3600) /* 30 * 24 * 3600 - secs in a 30 day month */ #define CHANNEL_STOREPERIOD (30*24*3600) /* 30 * 24 * 3600 - secs in a 30 day month */
#define TEST_CHANNEL_STOREPERIOD (24*3600) /* one day */ #define TEST_CHANNEL_STOREPERIOD (24*3600) /* one day */
#define CHANNEL_PUBPERIOD 60 /* 1 minutes ... (max = 455 days) */ #define CHANNEL_PUBPERIOD 600 /* 10 minutes ... (max = 455 days) */
#define MAX_AUTO_DL 1E9 /* auto download of attachment limit; 1 GIG */ #define MAX_AUTO_DL 1E9 /* auto download of attachment limit; 1 GIG */
p3Channels::p3Channels(uint16_t type, CacheStrapper *cs, p3Channels::p3Channels(uint16_t type, CacheStrapper *cs,