mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-03 11:54:30 -04:00
* Modified p3ConnectMgr to enable Standalone testing of components.
* Created pqiNetAssist interfaces for DHT and UPnP. * Created PQIHub etc for standalone testing (in ft/pqitestor.h for now). * Add basics of first server test ... its not quite complete yet. * Improvements to ftserver. * Changes to many tests to match other mods. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@689 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
483118daec
commit
33032e8a83
20 changed files with 882 additions and 141 deletions
|
@ -229,7 +229,7 @@ int main()
|
|||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||
dhtTester.setDhtOn(true);
|
||||
dhtTester.enable(true);
|
||||
|
||||
std::cerr << "Adding a List of Peers" << std::endl;
|
||||
for(int i = 0; i < NumOfPeers; i++)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
||||
#include "tcponudp/tou.h"
|
||||
|
||||
#include "util/rsprint.h"
|
||||
|
@ -62,6 +63,7 @@ const uint32_t MAX_UPNP_INIT = 10; /* seconds UPnP timeout */
|
|||
* #define P3CONNMGR_NO_AUTO_CONNECTION 1
|
||||
***/
|
||||
|
||||
#define CONN_DEBUG 1
|
||||
const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
||||
const uint32_t P3CONNMGR_UDP_DHT_DELAY = DHT_NOTIFY_PERIOD + 60; /* + 1 minute for DHT POST */
|
||||
const uint32_t P3CONNMGR_UDP_PROXY_DELAY = 30; /* 30 seconds (NOT IMPLEMENTED YET!) */
|
||||
|
@ -105,7 +107,7 @@ peerConnectState::peerConnectState()
|
|||
|
||||
p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am)
|
||||
:p3Config(CONFIG_TYPE_PEERS),
|
||||
mAuthMgr(am), mDhtMgr(NULL), mUpnpMgr(NULL), mNetStatus(RS_NET_UNKNOWN),
|
||||
mAuthMgr(am), mNetStatus(RS_NET_UNKNOWN),
|
||||
mStunStatus(0), mStunFound(0), mStunMoreRequired(true),
|
||||
mStatusChanged(false)
|
||||
{
|
||||
|
@ -167,7 +169,7 @@ void p3ConnectMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
|
|||
/* if we've started up - then tweak Dht On/Off */
|
||||
if (mNetStatus != RS_NET_UNKNOWN)
|
||||
{
|
||||
mDhtMgr->setDhtOn(!(ownState.visState & RS_VIS_STATE_NODHT));
|
||||
enableNetAssistFirewall(!(ownState.visState & RS_VIS_STATE_NODHT));
|
||||
}
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
@ -307,8 +309,10 @@ bool p3ConnectMgr::shutdown() /* blocking shutdown call */
|
|||
|
||||
if (upnpActive)
|
||||
{
|
||||
mUpnpMgr->shutdownUPnP();
|
||||
netAssistFirewallShutdown();
|
||||
}
|
||||
netAssistConnectShutdown();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -465,7 +469,7 @@ void p3ConnectMgr::netDhtInit()
|
|||
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
mDhtMgr->setDhtOn(!(vs & RS_VIS_STATE_NODHT));
|
||||
enableNetAssistFirewall(!(vs & RS_VIS_STATE_NODHT));
|
||||
}
|
||||
|
||||
|
||||
|
@ -490,10 +494,8 @@ void p3ConnectMgr::netUpnpInit()
|
|||
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
mUpnpMgr->setInternalPort(iport);
|
||||
mUpnpMgr->setExternalPort(eport);
|
||||
|
||||
mUpnpMgr->enableUPnP(true);
|
||||
netAssistFirewallPorts(iport, eport);
|
||||
enableNetAssistFirewall(true);
|
||||
}
|
||||
|
||||
void p3ConnectMgr::netUpnpCheck()
|
||||
|
@ -506,7 +508,7 @@ void p3ConnectMgr::netUpnpCheck()
|
|||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
struct sockaddr_in extAddr;
|
||||
int upnpState = mUpnpMgr->getUPnPActive();
|
||||
int upnpState = netAssistFirewallActive();
|
||||
|
||||
if ((upnpState < 0) ||
|
||||
((upnpState == 0) && (delta > MAX_UPNP_INIT)))
|
||||
|
@ -525,7 +527,7 @@ void p3ConnectMgr::netUpnpCheck()
|
|||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
}
|
||||
else if ((upnpState > 0) &&
|
||||
mUpnpMgr->getExternalAddress(extAddr))
|
||||
netAssistExtAddress(extAddr))
|
||||
{
|
||||
/* switch to UDP startup */
|
||||
connMtx.lock(); /* LOCK MUTEX */
|
||||
|
@ -644,12 +646,12 @@ void p3ConnectMgr::netUdpCheck()
|
|||
|
||||
if (extValid)
|
||||
{
|
||||
mDhtMgr->setExternalInterface(iaddr, extAddr, mode);
|
||||
netAssistSetAddress(iaddr, extAddr, mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* mode = 0 for error */
|
||||
mDhtMgr->setExternalInterface(iaddr, extAddr, mode);
|
||||
netAssistSetAddress(iaddr, extAddr, mode);
|
||||
}
|
||||
|
||||
/* flag unreachables! */
|
||||
|
@ -809,11 +811,13 @@ void p3ConnectMgr::stunInit()
|
|||
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
netAssistStun(true);
|
||||
|
||||
/* push stun list to DHT */
|
||||
std::list<std::string>::iterator it;
|
||||
for(it = mStunList.begin(); it != mStunList.end(); it++)
|
||||
{
|
||||
mDhtMgr->addStun(*it);
|
||||
netAssistAddStun(*it);
|
||||
}
|
||||
mStunStatus = RS_STUN_DHT;
|
||||
mStunFound = 0;
|
||||
|
@ -849,7 +853,7 @@ bool p3ConnectMgr::stunCheck()
|
|||
if (udpExtAddressCheck() && (stunOk))
|
||||
{
|
||||
/* set external UDP address */
|
||||
mDhtMgr->doneStun();
|
||||
netAssistStun(false);
|
||||
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
|
@ -1338,17 +1342,14 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectResult() Failed, missing Friend ";
|
||||
std::cerr << " id: " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectResult() Success: ";
|
||||
std::cerr << " id: " << id;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << " Success: " << success;
|
||||
std::cerr << " flags: " << flags;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
it->second.inConnAttempt = false;
|
||||
|
||||
|
@ -1356,17 +1357,17 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||
{
|
||||
/* remove other attempts */
|
||||
it->second.connAddrs.clear();
|
||||
mDhtMgr->dropPeer(id);
|
||||
netAssistFriend(id, false);
|
||||
|
||||
/* update address (will come through from DISC) */
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectAttempt() Success: ";
|
||||
std::cerr << " id: " << id;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << " Success: " << success;
|
||||
std::cerr << " flags: " << flags;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3ConnectMgr::connectResult() Connect!: ";
|
||||
std::cerr << " id: " << id;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << " Success: " << success;
|
||||
std::cerr << " flags: " << flags;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1380,6 +1381,15 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||
return true;
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectResult() Disconnect/Fail: ";
|
||||
std::cerr << " id: " << id;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << " Success: " << success;
|
||||
std::cerr << " flags: " << flags;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* if currently connected -> flag as failed */
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
|
@ -1388,14 +1398,14 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||
|
||||
it->second.lastcontact = time(NULL); /* time of disconnect */
|
||||
|
||||
mDhtMgr->findPeer(id);
|
||||
netAssistFriend(id, true);
|
||||
if (it->second.visState & RS_VIS_STATE_NODHT)
|
||||
{
|
||||
/* hidden from DHT world */
|
||||
}
|
||||
else
|
||||
{
|
||||
mDhtMgr->findPeer(id);
|
||||
//netAssistFriend(id, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2103,11 +2113,11 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
|
|||
if (it->second.visState & RS_VIS_STATE_NODHT)
|
||||
{
|
||||
/* hidden from DHT world */
|
||||
mDhtMgr->dropPeer(id);
|
||||
netAssistFriend(id, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
mDhtMgr->findPeer(id);
|
||||
netAssistFriend(id, true);
|
||||
}
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
@ -2152,7 +2162,7 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
|
|||
mStatusChanged = true;
|
||||
|
||||
/* expect it to be a standard DHT */
|
||||
mDhtMgr->findPeer(id);
|
||||
netAssistFriend(id, true);
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
|
@ -2168,7 +2178,7 @@ bool p3ConnectMgr::removeFriend(std::string id)
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mDhtMgr->dropPeer(id);
|
||||
netAssistFriend(id, false);
|
||||
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
|
@ -2551,7 +2561,7 @@ bool p3ConnectMgr::retryConnectNotify(std::string id)
|
|||
}
|
||||
|
||||
/* attempt UDP connection */
|
||||
mDhtMgr->notifyPeer(id);
|
||||
netAssistNotify(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -2682,11 +2692,11 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
|
|||
if (it->second.visState & RS_VIS_STATE_NODHT)
|
||||
{
|
||||
/* hidden from DHT world */
|
||||
mDhtMgr->dropPeer(id);
|
||||
netAssistFriend(id, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
mDhtMgr->findPeer(id);
|
||||
netAssistFriend(id, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2698,22 +2708,6 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
|
|||
|
||||
|
||||
|
||||
bool p3ConnectMgr::getUPnPState()
|
||||
{
|
||||
return mUpnpMgr->getUPnPActive();
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::getUPnPEnabled()
|
||||
{
|
||||
return mUpnpMgr->getUPnPEnabled();
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::getDHTEnabled()
|
||||
{
|
||||
return mDhtMgr->getDhtOn();
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
bool p3ConnectMgr::checkNetAddress()
|
||||
|
@ -3016,6 +3010,193 @@ bool p3ConnectMgr::addBootstrapStunPeers()
|
|||
return true;
|
||||
}
|
||||
|
||||
/************************ INTERFACES ***********************/
|
||||
|
||||
|
||||
bool p3ConnectMgr::enableNetAssistFirewall(bool on)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
|
||||
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
|
||||
{
|
||||
(it->second)->enable(on);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3ConnectMgr::netAssistFirewallEnabled()
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
|
||||
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
|
||||
{
|
||||
if ((it->second)->getEnabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistFirewallActive()
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
|
||||
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
|
||||
{
|
||||
if ((it->second)->getActive())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistFirewallShutdown()
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
|
||||
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
|
||||
{
|
||||
(it->second)->shutdown();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistFirewallPorts(uint16_t iport, uint16_t eport)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
|
||||
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
|
||||
{
|
||||
(it->second)->setInternalPort(iport);
|
||||
(it->second)->setExternalPort(eport);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3ConnectMgr::netAssistExtAddress(struct sockaddr_in &extAddr)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistFirewall *>::iterator it;
|
||||
for(it = mFwAgents.begin(); it != mFwAgents.end(); it++)
|
||||
{
|
||||
if ((it->second)->getActive())
|
||||
{
|
||||
if ((it->second)->getExternalAddress(extAddr))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::enableNetAssistConnect(bool on)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
(it->second)->enable(on);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistConnectEnabled()
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
if ((it->second)->getEnabled())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistConnectActive()
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
if ((it->second)->getActive())
|
||||
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistConnectShutdown()
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
(it->second)->shutdown();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistFriend(std::string id, bool on)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
(it->second)->findPeer(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
(it->second)->dropPeer(id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistAddStun(std::string id)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
(it->second)->addStun(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3ConnectMgr::netAssistStun(bool on)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
(it->second)->enableStun(on);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::netAssistNotify(std::string id)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
(it->second)->notifyPeer(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool p3ConnectMgr::netAssistSetAddress( struct sockaddr_in &laddr,
|
||||
struct sockaddr_in &eaddr,
|
||||
uint32_t mode)
|
||||
{
|
||||
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
|
||||
for(it = mDhts.begin(); it != mDhts.end(); it++)
|
||||
{
|
||||
(it->second)->setExternalInterface(laddr, eaddr, mode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -27,10 +27,12 @@
|
|||
#define MRK_PQI_CONNECTION_MANAGER_HEADER
|
||||
|
||||
#include "pqi/pqimonitor.h"
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
#include "pqi/p3upnpmgr.h"
|
||||
#include "pqi/p3authmgr.h"
|
||||
|
||||
//#include "pqi/p3dhtmgr.h"
|
||||
//#include "pqi/p3upnpmgr.h"
|
||||
#include "pqi/pqiassist.h"
|
||||
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
#include "util/rsthreads.h"
|
||||
|
@ -160,8 +162,9 @@ class p3ConnectMgr: public pqiConnectCb, public p3Config
|
|||
void tick();
|
||||
|
||||
/*************** Setup ***************************/
|
||||
void setDhtMgr(p3DhtMgr *dmgr) { mDhtMgr = dmgr; }
|
||||
void setUpnpMgr(p3UpnpMgr *umgr) { mUpnpMgr = umgr; }
|
||||
void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *);
|
||||
void addNetAssistFirewall(uint32_t type, pqiNetAssistFirewall *);
|
||||
|
||||
bool checkNetAddress(); /* check our address is sensible */
|
||||
|
||||
/*************** External Control ****************/
|
||||
|
@ -221,6 +224,30 @@ bool connectResult(std::string id, bool success, uint32_t flags);
|
|||
|
||||
|
||||
protected:
|
||||
/****************** Internal Interface *******************/
|
||||
virtual bool enableNetAssistFirewall(bool on);
|
||||
virtual bool netAssistFirewallEnabled();
|
||||
virtual bool netAssistFirewallActive();
|
||||
virtual bool netAssistFirewallShutdown();
|
||||
|
||||
virtual bool enableNetAssistConnect(bool on);
|
||||
virtual bool netAssistConnectEnabled();
|
||||
virtual bool netAssistConnectActive();
|
||||
virtual bool netAssistConnectShutdown();
|
||||
|
||||
/* Assist Firewall */
|
||||
bool netAssistExtAddress(struct sockaddr_in &extAddr);
|
||||
bool netAssistFirewallPorts(uint16_t iport, uint16_t eport);
|
||||
|
||||
/* Assist Connect */
|
||||
virtual bool netAssistFriend(std::string id, bool on);
|
||||
virtual bool netAssistAddStun(std::string id);
|
||||
virtual bool netAssistStun(bool on);
|
||||
virtual bool netAssistNotify(std::string id);
|
||||
virtual bool netAssistSetAddress( struct sockaddr_in &laddr,
|
||||
struct sockaddr_in &eaddr,
|
||||
uint32_t mode);
|
||||
|
||||
|
||||
/* Internal Functions */
|
||||
void statusTick();
|
||||
|
@ -286,8 +313,9 @@ void addPeer(RsPeerConfigItem *item);
|
|||
private:
|
||||
|
||||
p3AuthMgr *mAuthMgr;
|
||||
p3DhtMgr *mDhtMgr;
|
||||
p3UpnpMgr *mUpnpMgr;
|
||||
|
||||
std::map<uint32_t, pqiNetAssistFirewall *> mFwAgents;
|
||||
std::map<uint32_t, pqiNetAssistConnect *> mDhts;
|
||||
|
||||
RsMutex connMtx; /* protects below */
|
||||
|
||||
|
@ -323,3 +351,7 @@ void addPeer(std::string id, std::string name); /* tmp fn */
|
|||
};
|
||||
|
||||
#endif // MRK_PQI_CONNECTION_MANAGER_HEADER
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include <openssl/sha.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "pqi/p3dhtmgr.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
@ -87,7 +88,7 @@ dhtPeerEntry::dhtPeerEntry()
|
|||
}
|
||||
|
||||
p3DhtMgr::p3DhtMgr(std::string id, pqiConnectCb *cb)
|
||||
:connCb(cb), mStunRequired(true)
|
||||
:pqiNetAssistConnect(id, cb), mStunRequired(true)
|
||||
{
|
||||
/* setup own entry */
|
||||
dhtMtx.lock(); /* LOCK MUTEX */
|
||||
|
@ -115,7 +116,21 @@ p3DhtMgr::p3DhtMgr(std::string id, pqiConnectCb *cb)
|
|||
return;
|
||||
}
|
||||
|
||||
void p3DhtMgr::setDhtOn(bool on)
|
||||
/* OVERLOADED from pqiNetAssistConnect
|
||||
*/
|
||||
|
||||
void p3DhtMgr::shutdown()
|
||||
{
|
||||
/* ??? */
|
||||
|
||||
}
|
||||
|
||||
void p3DhtMgr::restart()
|
||||
{
|
||||
/* ??? */
|
||||
}
|
||||
|
||||
void p3DhtMgr::enable(bool on)
|
||||
{
|
||||
dhtMtx.lock(); /* LOCK MUTEX */
|
||||
|
||||
|
@ -125,7 +140,7 @@ void p3DhtMgr::setDhtOn(bool on)
|
|||
dhtMtx.unlock(); /* UNLOCK MUTEX */
|
||||
}
|
||||
|
||||
bool p3DhtMgr::getDhtOn()
|
||||
bool p3DhtMgr::getEnabled()
|
||||
{
|
||||
dhtMtx.lock(); /* LOCK MUTEX */
|
||||
|
||||
|
@ -136,7 +151,7 @@ bool p3DhtMgr::getDhtOn()
|
|||
return on;
|
||||
}
|
||||
|
||||
bool p3DhtMgr::getDhtActive()
|
||||
bool p3DhtMgr::getActive()
|
||||
{
|
||||
dhtMtx.lock(); /* LOCK MUTEX */
|
||||
|
||||
|
@ -392,16 +407,19 @@ bool p3DhtMgr::addStun(std::string id)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3DhtMgr::doneStun()
|
||||
bool p3DhtMgr::enableStun(bool on)
|
||||
{
|
||||
dhtMtx.lock(); /* LOCK MUTEX */
|
||||
|
||||
mDhtModifications = true;
|
||||
|
||||
/* clear up */
|
||||
stunIds.clear();
|
||||
if (!on)
|
||||
{
|
||||
/* clear up */
|
||||
stunIds.clear();
|
||||
}
|
||||
|
||||
mStunRequired = false;
|
||||
mStunRequired = on;
|
||||
|
||||
dhtMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
|
@ -920,9 +938,9 @@ int p3DhtMgr::checkNotifyDHT()
|
|||
|
||||
/* feedback to say we started it! */
|
||||
#ifdef P3DHTMGR_USE_LOCAL_UDP_CONN
|
||||
connCb->peerConnectRequest(peer.id, peer.laddr, RS_CB_DHT);
|
||||
mConnCb->peerConnectRequest(peer.id, peer.laddr, RS_CB_DHT);
|
||||
#else
|
||||
connCb->peerConnectRequest(peer.id, peer.raddr, RS_CB_DHT);
|
||||
mConnCb->peerConnectRequest(peer.id, peer.raddr, RS_CB_DHT);
|
||||
#endif
|
||||
|
||||
return DHT_MIN_PERIOD;
|
||||
|
@ -1197,7 +1215,7 @@ void p3DhtMgr::checkDHTStatus()
|
|||
#ifdef DHT_DEBUG
|
||||
std::cerr << "p3DhtMgr::checkDhtStatus() toShutdown = true -> shutdown()" << std::endl;
|
||||
#endif
|
||||
if (shutdown())
|
||||
if (dhtShutdown())
|
||||
{
|
||||
clearDhtData();
|
||||
|
||||
|
@ -1215,9 +1233,9 @@ void p3DhtMgr::checkDHTStatus()
|
|||
if (toStartup)
|
||||
{
|
||||
#ifdef DHT_DEBUG
|
||||
std::cerr << "p3DhtMgr::checkDhtStatus() toStartup = true -> init()" << std::endl;
|
||||
std::cerr << "p3DhtMgr::checkDhtStatus() toStartup = true -> dhtInit()" << std::endl;
|
||||
#endif
|
||||
if (init())
|
||||
if (dhtInit())
|
||||
{
|
||||
|
||||
dhtMtx.lock(); /* LOCK MUTEX */
|
||||
|
@ -1287,15 +1305,15 @@ int p3DhtMgr::status(std::ostream &out)
|
|||
|
||||
|
||||
|
||||
bool p3DhtMgr::init()
|
||||
bool p3DhtMgr::dhtInit()
|
||||
{
|
||||
std::cerr << "p3DhtMgr::init() DUMMY FN" << std::endl;
|
||||
std::cerr << "p3DhtMgr::dhtInit() DUMMY FN" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3DhtMgr::shutdown()
|
||||
bool p3DhtMgr::dhtShutdown()
|
||||
{
|
||||
std::cerr << "p3DhtMgr::shutdown() DUMMY FN" << std::endl;
|
||||
std::cerr << "p3DhtMgr::dhtShutdown() DUMMY FN" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1734,13 +1752,13 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash,
|
|||
|
||||
if (doCb)
|
||||
{
|
||||
connCb->peerStatus(ent.id, ent.laddr, ent.raddr,
|
||||
mConnCb->peerStatus(ent.id, ent.laddr, ent.raddr,
|
||||
ent.type, 0, RS_CB_DHT);
|
||||
}
|
||||
|
||||
if (doStun)
|
||||
{
|
||||
connCb->stunStatus(idhash, raddr, type, stunFlags);
|
||||
mConnCb->stunStatus(idhash, raddr, type, stunFlags);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include "util/rsthreads.h"
|
||||
#include "pqi/pqimonitor.h"
|
||||
|
||||
#include "pqi/pqiassist.h"
|
||||
|
||||
/* All other #defs are in .cc */
|
||||
#define DHT_ADDR_INVALID 0xff
|
||||
#define DHT_ADDR_TCP 0x01
|
||||
|
@ -90,7 +92,7 @@ class dhtPeerEntry
|
|||
std::string hash2; /* SHA1 Hash of reverse Id */
|
||||
};
|
||||
|
||||
class p3DhtMgr: public RsThread
|
||||
class p3DhtMgr: public pqiNetAssistConnect, public RsThread
|
||||
{
|
||||
/*
|
||||
*/
|
||||
|
@ -102,32 +104,38 @@ class p3DhtMgr: public RsThread
|
|||
* for the DHT, and must be non-blocking and return quickly
|
||||
*/
|
||||
|
||||
void setDhtOn(bool on);
|
||||
bool getDhtOn();
|
||||
bool getDhtActive();
|
||||
/* OVERLOADED From pqiNetAssistConnect. */
|
||||
|
||||
void setBootstrapAllowed(bool on);
|
||||
bool getBootstrapAllowed();
|
||||
virtual void enable(bool on);
|
||||
virtual void shutdown();
|
||||
virtual void restart();
|
||||
|
||||
virtual bool getEnabled(); /* on */
|
||||
virtual bool getActive(); /* actually working */
|
||||
|
||||
virtual void setBootstrapAllowed(bool on);
|
||||
virtual bool getBootstrapAllowed();
|
||||
|
||||
/* set key data */
|
||||
bool setExternalInterface(struct sockaddr_in laddr,
|
||||
virtual bool setExternalInterface(struct sockaddr_in laddr,
|
||||
struct sockaddr_in raddr, uint32_t type);
|
||||
|
||||
/* add / remove peers */
|
||||
bool findPeer(std::string id);
|
||||
bool dropPeer(std::string id);
|
||||
virtual bool findPeer(std::string id);
|
||||
virtual bool dropPeer(std::string id);
|
||||
|
||||
/* post DHT key saying we should connect (callback when done) */
|
||||
bool notifyPeer(std::string id);
|
||||
virtual bool notifyPeer(std::string id);
|
||||
|
||||
/* extract current peer status */
|
||||
bool getPeerStatus(std::string id,
|
||||
virtual bool getPeerStatus(std::string id,
|
||||
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
|
||||
uint32_t &type, uint32_t &mode);
|
||||
|
||||
/* stun */
|
||||
bool addStun(std::string id);
|
||||
bool doneStun();
|
||||
virtual bool enableStun(bool on);
|
||||
virtual bool addStun(std::string id);
|
||||
//doneStun();
|
||||
|
||||
/********** Higher Level DHT Work Functions ************************
|
||||
* These functions translate from the strings/addresss to
|
||||
|
@ -177,8 +185,8 @@ virtual bool resultDHT(std::string key, std::string value);
|
|||
|
||||
protected:
|
||||
|
||||
virtual bool init();
|
||||
virtual bool shutdown();
|
||||
virtual bool dhtInit();
|
||||
virtual bool dhtShutdown();
|
||||
virtual bool dhtActive();
|
||||
virtual int status(std::ostream &out);
|
||||
|
||||
|
@ -214,7 +222,7 @@ std::string BootstrapId(uint32_t bin);
|
|||
std::string randomBootstrapId();
|
||||
|
||||
/* other feedback through callback */
|
||||
pqiConnectCb *connCb;
|
||||
// use pqiNetAssistConnect.. version pqiConnectCb *connCb;
|
||||
|
||||
/* protected by Mutex */
|
||||
RsMutex dhtMtx;
|
||||
|
|
|
@ -31,19 +31,19 @@
|
|||
#include "util/rsthreads.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
class p3UpnpMgr
|
||||
class p3UpnpMgr: public pqiNetAssistFirewall
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~p3UpnpMgr() { return; }
|
||||
|
||||
/* External Interface */
|
||||
virtual void enableUPnP(bool on) = 0; /* launches thread to start it up */
|
||||
virtual void shutdownUPnP() = 0; /* blocking shutdown call */
|
||||
virtual void restartUPnP() = 0; /* must be called if ports change */
|
||||
virtual void enable(bool on) = 0; /* launches thread to start it up */
|
||||
virtual void shutdown() = 0; /* blocking shutdown call */
|
||||
virtual void restart() = 0; /* must be called if ports change */
|
||||
|
||||
virtual bool getUPnPEnabled() = 0;
|
||||
virtual bool getUPnPActive() = 0;
|
||||
virtual bool getEnabled() = 0;
|
||||
virtual bool getActive() = 0;
|
||||
|
||||
/* the address that the listening port is on */
|
||||
virtual void setInternalPort(unsigned short iport_in) = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue