mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -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
@ -391,7 +391,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||||
dhtTester.setDhtOn(true);
|
dhtTester.enable(true);
|
||||||
|
|
||||||
/* wait loop */
|
/* wait loop */
|
||||||
while(1)
|
while(1)
|
||||||
|
@ -391,7 +391,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||||
dhtTester.setDhtOn(true);
|
dhtTester.enable(true);
|
||||||
|
|
||||||
std::cerr << "Adding a List of Peers" << std::endl;
|
std::cerr << "Adding a List of Peers" << std::endl;
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
@ -402,7 +402,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* switch off Stun/Bootstrap stuff */
|
/* switch off Stun/Bootstrap stuff */
|
||||||
dhtTester.doneStun();
|
dhtTester.enableStun(false);
|
||||||
dhtTester.setBootstrapAllowed(false);
|
dhtTester.setBootstrapAllowed(false);
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||||
dhtTester.setDhtOn(true);
|
dhtTester.enable(true);
|
||||||
|
|
||||||
std::cerr << "Adding a List of Peers" << std::endl;
|
std::cerr << "Adding a List of Peers" << std::endl;
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
|
@ -107,7 +107,7 @@ OpenDHTMgr::OpenDHTMgr(std::string ownId, pqiConnectCb* cb, std::string configdi
|
|||||||
|
|
||||||
|
|
||||||
/********** OVERLOADED FROM p3DhtMgr ***************/
|
/********** OVERLOADED FROM p3DhtMgr ***************/
|
||||||
bool OpenDHTMgr::init()
|
bool OpenDHTMgr::dhtInit()
|
||||||
{
|
{
|
||||||
std::string configpath = mConfigDir;
|
std::string configpath = mConfigDir;
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ bool OpenDHTMgr::init()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenDHTMgr::shutdown()
|
bool OpenDHTMgr::dhtShutdown()
|
||||||
{
|
{
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
if (mClient)
|
if (mClient)
|
||||||
|
@ -42,8 +42,8 @@ class OpenDHTMgr: public p3DhtMgr
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
/********** OVERLOADED FROM p3DhtMgr ***************/
|
/********** OVERLOADED FROM p3DhtMgr ***************/
|
||||||
virtual bool init();
|
virtual bool dhtInit();
|
||||||
virtual bool shutdown();
|
virtual bool dhtShutdown();
|
||||||
virtual bool dhtActive();
|
virtual bool dhtActive();
|
||||||
virtual int status(std::ostream &out);
|
virtual int status(std::ostream &out);
|
||||||
|
|
||||||
|
@ -7,17 +7,15 @@ RS_TOP_DIR = ..
|
|||||||
include $(RS_TOP_DIR)/scripts/config.mk
|
include $(RS_TOP_DIR)/scripts/config.mk
|
||||||
###############################################################
|
###############################################################
|
||||||
|
|
||||||
RSOBJ = ftdata.o ftfileprovider.o ftfilecreator.o ftextralist.o ftdatamultiplex.o ftfilesearch.o fttransfermodule.o ftdbase.o ftserver.o
|
RSOBJ = ftdata.o ftfileprovider.o ftfilecreator.o ftextralist.o \
|
||||||
|
ftdatamultiplex.o ftfilesearch.o fttransfermodule.o ftdbase.o ftserver.o \
|
||||||
#ftcontroller.o pqitestor.o
|
ftcontroller.o pqitestor.o
|
||||||
|
|
||||||
|
|
||||||
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o
|
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o ftserver1test.o
|
||||||
#ftserver1test.o
|
|
||||||
|
|
||||||
|
|
||||||
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest
|
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest ftserver1test
|
||||||
#ftserver1test
|
|
||||||
|
|
||||||
all: librs tests
|
all: librs tests
|
||||||
|
|
||||||
|
@ -197,8 +197,8 @@ bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
/**** INTERNAL FUNCTIONS ***/
|
/**** INTERNAL FUNCTIONS ***/
|
||||||
virtual int reScanDirs();
|
//virtual int reScanDirs();
|
||||||
virtual int check_dBUpdate();
|
//virtual int check_dBUpdate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
238
libretroshare/src/ft/ftserver1test.cc
Normal file
238
libretroshare/src/ft/ftserver1test.cc
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: ftserver1test.cc
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 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".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test for Whole Basic system.....
|
||||||
|
*
|
||||||
|
* Put it all together, and make it compile.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ft/ftserver.h"
|
||||||
|
|
||||||
|
#include "ft/ftextralist.h"
|
||||||
|
#include "ft/ftdatamultiplex.h"
|
||||||
|
#include "ft/ftfilesearch.h"
|
||||||
|
|
||||||
|
#include "pqi/p3authmgr.h"
|
||||||
|
#include "pqi/p3connmgr.h"
|
||||||
|
|
||||||
|
#include "ft/pqitestor.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void do_random_server_test(ftDataMultiplex *mplex, ftExtraList *eList, std::list<std::string> &files);
|
||||||
|
|
||||||
|
|
||||||
|
void usage(char *name)
|
||||||
|
{
|
||||||
|
std::cerr << "Usage: " << name << " [-p <period>] [-d <dperiod>] <path> [<path2> ... ] ";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
uint32_t period = 1;
|
||||||
|
uint32_t dPeriod = 600; /* default 10 minutes */
|
||||||
|
|
||||||
|
std::list<std::string> fileList;
|
||||||
|
std::list<std::string> peerIds;
|
||||||
|
std::list<ftServer *> mFtServers;
|
||||||
|
|
||||||
|
while(-1 != (c = getopt(argc, argv, "d:p:")))
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'p':
|
||||||
|
peerIds.push_back(optarg);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
dPeriod = atoi(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(argv[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind >= argc)
|
||||||
|
{
|
||||||
|
std::cerr << "Missing Files" << std::endl;
|
||||||
|
usage(argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(; optind < argc; optind++)
|
||||||
|
{
|
||||||
|
std::cerr << "Adding: " << argv[optind] << std::endl;
|
||||||
|
fileList.push_back(std::string(argv[optind]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We need to setup a series 2 - 4 different ftServers....
|
||||||
|
*
|
||||||
|
* Each one needs:
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* A List of peerIds...
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::list<std::string>::const_iterator it, jit;
|
||||||
|
|
||||||
|
std::list<pqiAuthDetails> baseFriendList, friendList;
|
||||||
|
std::list<pqiAuthDetails>::iterator fit;
|
||||||
|
|
||||||
|
PQIHub *testHub = new PQIHub();
|
||||||
|
testHub->start();
|
||||||
|
|
||||||
|
/* Setup Base Friend Info */
|
||||||
|
for(it = peerIds.begin(); it != peerIds.end(); it++)
|
||||||
|
{
|
||||||
|
pqiAuthDetails pad;
|
||||||
|
pad.id = *it;
|
||||||
|
pad.name = *it;
|
||||||
|
pad.trustLvl = 5;
|
||||||
|
pad.ownsign = true;
|
||||||
|
pad.trusted = false;
|
||||||
|
|
||||||
|
baseFriendList.push_back(pad);
|
||||||
|
|
||||||
|
std::cerr << "ftserver1test::setup peer: " << *it;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(it = peerIds.begin(); it != peerIds.end(); it++)
|
||||||
|
{
|
||||||
|
friendList = baseFriendList;
|
||||||
|
/* remove current one */
|
||||||
|
for(fit = friendList.begin(); fit != friendList.end(); fit++)
|
||||||
|
{
|
||||||
|
if (fit->id == *it)
|
||||||
|
{
|
||||||
|
friendList.erase(fit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p3AuthMgr *authMgr = new p3DummyAuthMgr(*it, friendList);
|
||||||
|
p3ConnectMgr *connMgr = new p3ConnectMgr(authMgr);
|
||||||
|
|
||||||
|
for(fit = friendList.begin(); fit != friendList.end(); fit++)
|
||||||
|
{
|
||||||
|
/* add as peer to authMgr */
|
||||||
|
connMgr->addFriend(fit->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
PQIPipe *pipe = new PQIPipe(*it);
|
||||||
|
|
||||||
|
/* add server */
|
||||||
|
ftServer *server;
|
||||||
|
server = new ftServer(authMgr, connMgr);
|
||||||
|
|
||||||
|
PQInterface *pqi = NULL;
|
||||||
|
server->setPQInterface(pipe);
|
||||||
|
|
||||||
|
NotifyBase *base = NULL;
|
||||||
|
server->SetupFtServer(base);
|
||||||
|
|
||||||
|
testHub->addPQIPipe(*it, pipe, connMgr);
|
||||||
|
server->StartupThreads();
|
||||||
|
|
||||||
|
//server->start();
|
||||||
|
/* setup any extra bits */
|
||||||
|
server->setSharedDirectories(fileList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* stick your real test here */
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
std::cerr << "ftserver1test::sleep()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
uint32_t do_random_server_iteration(ftDataMultiplex *mplex, ftExtraList *eList, std::list<std::string> &files)
|
||||||
|
{
|
||||||
|
std::cerr << "do_random_server_iteration()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
std::list<std::string>::iterator it;
|
||||||
|
uint32_t i = 0;
|
||||||
|
for(it = files.begin(); it != files.end(); it++)
|
||||||
|
{
|
||||||
|
FileInfo info;
|
||||||
|
if (eList->hashExtraFileDone(*it, info))
|
||||||
|
{
|
||||||
|
std::cerr << "Hash Done for: " << *it;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << info << std::endl;
|
||||||
|
|
||||||
|
std::cerr << "Requesting Data Packet";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
/* Server Recv */
|
||||||
|
uint64_t offset = 10000;
|
||||||
|
uint32_t chunk = 20000;
|
||||||
|
mplex->recvDataRequest("Peer", info.hash, info.size, offset, chunk);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "do_random_server_iteration() Hash Not Done for: " << *it;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void do_random_server_test(ftDataMultiplex *mplex, ftExtraList *eList, std::list<std::string> &files)
|
||||||
|
{
|
||||||
|
std::cerr << "do_random_server_test()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
uint32_t size = files.size();
|
||||||
|
while(size > do_random_server_iteration(mplex, eList, files))
|
||||||
|
{
|
||||||
|
std::cerr << "do_random_server_test() sleep";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
sleep(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
161
libretroshare/src/ft/pqitestor.cc
Normal file
161
libretroshare/src/ft/pqitestor.cc
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: pqitestor.cc
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 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 "ft/pqitestor.h"
|
||||||
|
#include "pqi/p3connmgr.h"
|
||||||
|
|
||||||
|
|
||||||
|
PQIHub::PQIHub()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PQIHub::addPQIPipe(std::string id, PQIPipe *pqi, p3ConnectMgr *mgr)
|
||||||
|
{
|
||||||
|
hubItem item(id, pqi, mgr);
|
||||||
|
|
||||||
|
std::map<std::string, hubItem>::iterator it;
|
||||||
|
for(it = mPeers.begin(); it != mPeers.end(); it++)
|
||||||
|
{
|
||||||
|
(it->second).mConnMgr->connectResult(id, true, 0);
|
||||||
|
mgr->connectResult(it->first, true, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
mPeers[id] = item;
|
||||||
|
|
||||||
|
/* tell all the other peers we are connected */
|
||||||
|
std::cerr << "PQIHub::addPQIPipe()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PQIHub::run()
|
||||||
|
{
|
||||||
|
RsItem *item;
|
||||||
|
std::list<RsItem *> recvdQ;
|
||||||
|
std::list<RsItem *>::iterator lit;
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
std::cerr << "PQIHub::run()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
std::map<std::string, hubItem>::iterator it;
|
||||||
|
for(it = mPeers.begin(); it != mPeers.end(); it++)
|
||||||
|
{
|
||||||
|
while (NULL != (item = it->second.mPQI->PopSentItem()))
|
||||||
|
{
|
||||||
|
std::cerr << "PQIHub::run() recvd msg from: ";
|
||||||
|
std::cerr << it->first;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
recvdQ.push_back(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* now send out */
|
||||||
|
for(lit = recvdQ.begin(); lit != recvdQ.end(); lit++)
|
||||||
|
{
|
||||||
|
std::string pId = (*lit)->PeerId();
|
||||||
|
if (mPeers.end() == (it = mPeers.find(pId)))
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to Find destination: " << pId;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
std::cerr << "PQIHub::run() sending msg to: ";
|
||||||
|
std::cerr << it->first;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
(it->second).mPQI->PushRecvdItem(*lit);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Tick the Connection Managers (normally done by rsserver)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* sleep a bit */
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PQIPipe::PQIPipe(std::string peerId)
|
||||||
|
:PQInterface(peerId)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PQIPipe::SendItem(RsItem *item)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||||
|
|
||||||
|
mSentItems.push_back(item);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsItem *PQIPipe::PopSentItem()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||||
|
|
||||||
|
if (mSentItems.size() == 0)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsItem *item = mSentItems.front();
|
||||||
|
mSentItems.pop_front();
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PQIPipe::PushRecvdItem(RsItem *item)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||||
|
|
||||||
|
mRecvdItems.push_back(item);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsItem *PQIPipe::GetItem()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||||
|
|
||||||
|
if (mRecvdItems.size() == 0)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsItem *item = mRecvdItems.front();
|
||||||
|
mRecvdItems.pop_front();
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
103
libretroshare/src/ft/pqitestor.h
Normal file
103
libretroshare/src/ft/pqitestor.h
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/ft: pqitestor.h
|
||||||
|
*
|
||||||
|
* File Transfer for RetroShare.
|
||||||
|
*
|
||||||
|
* Copyright 2008 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 PQI_HUB_TEST_H
|
||||||
|
#define PQI_HUB_TEST_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pqi Test Interface.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Structures for ftserver simulations
|
||||||
|
*
|
||||||
|
****/
|
||||||
|
|
||||||
|
#include "pqi/pqi.h"
|
||||||
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class hubItem;
|
||||||
|
class PQIPipe;
|
||||||
|
class PQIHub;
|
||||||
|
class p3ConnectMgr;
|
||||||
|
|
||||||
|
|
||||||
|
class hubItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
hubItem()
|
||||||
|
:mPQI(NULL), mConnMgr(NULL) { return; }
|
||||||
|
|
||||||
|
hubItem(std::string id, PQIPipe *pqi, p3ConnectMgr *mgr)
|
||||||
|
:mPeerId(id), mPQI(pqi), mConnMgr(mgr) { return; }
|
||||||
|
|
||||||
|
std::string mPeerId;
|
||||||
|
PQIPipe *mPQI;
|
||||||
|
p3ConnectMgr *mConnMgr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class PQIHub: public RsThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
PQIHub();
|
||||||
|
void addPQIPipe(std::string id, PQIPipe *, p3ConnectMgr *mgr);
|
||||||
|
|
||||||
|
virtual void run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string, hubItem> mPeers;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class PQIPipe: public PQInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PQIPipe(std::string peerId);
|
||||||
|
|
||||||
|
virtual int SendItem(RsItem *);
|
||||||
|
virtual RsItem *GetItem();
|
||||||
|
|
||||||
|
// PQIHub Interface.
|
||||||
|
RsItem *PopSentItem();
|
||||||
|
int PushRecvdItem(RsItem *);
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
RsMutex pipeMtx;
|
||||||
|
|
||||||
|
std::list<RsItem *> mSentItems;
|
||||||
|
std::list<RsItem *> mRecvdItems;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -229,7 +229,7 @@ int main()
|
|||||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||||
|
|
||||||
std::cerr << "Switching on DhtTester()" << std::endl;
|
std::cerr << "Switching on DhtTester()" << std::endl;
|
||||||
dhtTester.setDhtOn(true);
|
dhtTester.enable(true);
|
||||||
|
|
||||||
std::cerr << "Adding a List of Peers" << std::endl;
|
std::cerr << "Adding a List of Peers" << std::endl;
|
||||||
for(int i = 0; i < NumOfPeers; i++)
|
for(int i = 0; i < NumOfPeers; i++)
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3connmgr.h"
|
||||||
|
#include "pqi/p3dhtmgr.h" // Only need it for constants.
|
||||||
#include "tcponudp/tou.h"
|
#include "tcponudp/tou.h"
|
||||||
|
|
||||||
#include "util/rsprint.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 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_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_DHT_DELAY = DHT_NOTIFY_PERIOD + 60; /* + 1 minute for DHT POST */
|
||||||
const uint32_t P3CONNMGR_UDP_PROXY_DELAY = 30; /* 30 seconds (NOT IMPLEMENTED YET!) */
|
const uint32_t P3CONNMGR_UDP_PROXY_DELAY = 30; /* 30 seconds (NOT IMPLEMENTED YET!) */
|
||||||
@ -105,7 +107,7 @@ peerConnectState::peerConnectState()
|
|||||||
|
|
||||||
p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am)
|
p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am)
|
||||||
:p3Config(CONFIG_TYPE_PEERS),
|
: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),
|
mStunStatus(0), mStunFound(0), mStunMoreRequired(true),
|
||||||
mStatusChanged(false)
|
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 we've started up - then tweak Dht On/Off */
|
||||||
if (mNetStatus != RS_NET_UNKNOWN)
|
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! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
@ -307,8 +309,10 @@ bool p3ConnectMgr::shutdown() /* blocking shutdown call */
|
|||||||
|
|
||||||
if (upnpActive)
|
if (upnpActive)
|
||||||
{
|
{
|
||||||
mUpnpMgr->shutdownUPnP();
|
netAssistFirewallShutdown();
|
||||||
}
|
}
|
||||||
|
netAssistConnectShutdown();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +469,7 @@ void p3ConnectMgr::netDhtInit()
|
|||||||
|
|
||||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
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 */
|
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
|
|
||||||
mUpnpMgr->setInternalPort(iport);
|
netAssistFirewallPorts(iport, eport);
|
||||||
mUpnpMgr->setExternalPort(eport);
|
enableNetAssistFirewall(true);
|
||||||
|
|
||||||
mUpnpMgr->enableUPnP(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3ConnectMgr::netUpnpCheck()
|
void p3ConnectMgr::netUpnpCheck()
|
||||||
@ -506,7 +508,7 @@ void p3ConnectMgr::netUpnpCheck()
|
|||||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
|
|
||||||
struct sockaddr_in extAddr;
|
struct sockaddr_in extAddr;
|
||||||
int upnpState = mUpnpMgr->getUPnPActive();
|
int upnpState = netAssistFirewallActive();
|
||||||
|
|
||||||
if ((upnpState < 0) ||
|
if ((upnpState < 0) ||
|
||||||
((upnpState == 0) && (delta > MAX_UPNP_INIT)))
|
((upnpState == 0) && (delta > MAX_UPNP_INIT)))
|
||||||
@ -525,7 +527,7 @@ void p3ConnectMgr::netUpnpCheck()
|
|||||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
}
|
}
|
||||||
else if ((upnpState > 0) &&
|
else if ((upnpState > 0) &&
|
||||||
mUpnpMgr->getExternalAddress(extAddr))
|
netAssistExtAddress(extAddr))
|
||||||
{
|
{
|
||||||
/* switch to UDP startup */
|
/* switch to UDP startup */
|
||||||
connMtx.lock(); /* LOCK MUTEX */
|
connMtx.lock(); /* LOCK MUTEX */
|
||||||
@ -644,12 +646,12 @@ void p3ConnectMgr::netUdpCheck()
|
|||||||
|
|
||||||
if (extValid)
|
if (extValid)
|
||||||
{
|
{
|
||||||
mDhtMgr->setExternalInterface(iaddr, extAddr, mode);
|
netAssistSetAddress(iaddr, extAddr, mode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* mode = 0 for error */
|
/* mode = 0 for error */
|
||||||
mDhtMgr->setExternalInterface(iaddr, extAddr, mode);
|
netAssistSetAddress(iaddr, extAddr, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* flag unreachables! */
|
/* flag unreachables! */
|
||||||
@ -809,11 +811,13 @@ void p3ConnectMgr::stunInit()
|
|||||||
|
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
netAssistStun(true);
|
||||||
|
|
||||||
/* push stun list to DHT */
|
/* push stun list to DHT */
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
for(it = mStunList.begin(); it != mStunList.end(); it++)
|
for(it = mStunList.begin(); it != mStunList.end(); it++)
|
||||||
{
|
{
|
||||||
mDhtMgr->addStun(*it);
|
netAssistAddStun(*it);
|
||||||
}
|
}
|
||||||
mStunStatus = RS_STUN_DHT;
|
mStunStatus = RS_STUN_DHT;
|
||||||
mStunFound = 0;
|
mStunFound = 0;
|
||||||
@ -849,7 +853,7 @@ bool p3ConnectMgr::stunCheck()
|
|||||||
if (udpExtAddressCheck() && (stunOk))
|
if (udpExtAddressCheck() && (stunOk))
|
||||||
{
|
{
|
||||||
/* set external UDP address */
|
/* set external UDP address */
|
||||||
mDhtMgr->doneStun();
|
netAssistStun(false);
|
||||||
|
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
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);
|
it = mFriendList.find(id);
|
||||||
if (it == mFriendList.end())
|
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;
|
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;
|
it->second.inConnAttempt = false;
|
||||||
|
|
||||||
@ -1356,17 +1357,17 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||||||
{
|
{
|
||||||
/* remove other attempts */
|
/* remove other attempts */
|
||||||
it->second.connAddrs.clear();
|
it->second.connAddrs.clear();
|
||||||
mDhtMgr->dropPeer(id);
|
netAssistFriend(id, false);
|
||||||
|
|
||||||
/* update address (will come through from DISC) */
|
/* update address (will come through from DISC) */
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::connectAttempt() Success: ";
|
std::cerr << "p3ConnectMgr::connectResult() Connect!: ";
|
||||||
std::cerr << " id: " << id;
|
std::cerr << " id: " << id;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << " Success: " << success;
|
std::cerr << " Success: " << success;
|
||||||
std::cerr << " flags: " << flags;
|
std::cerr << " flags: " << flags;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -1380,6 +1381,15 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
|||||||
return true;
|
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 currently connected -> flag as failed */
|
||||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
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 */
|
it->second.lastcontact = time(NULL); /* time of disconnect */
|
||||||
|
|
||||||
mDhtMgr->findPeer(id);
|
netAssistFriend(id, true);
|
||||||
if (it->second.visState & RS_VIS_STATE_NODHT)
|
if (it->second.visState & RS_VIS_STATE_NODHT)
|
||||||
{
|
{
|
||||||
/* hidden from DHT world */
|
/* hidden from DHT world */
|
||||||
}
|
}
|
||||||
else
|
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)
|
if (it->second.visState & RS_VIS_STATE_NODHT)
|
||||||
{
|
{
|
||||||
/* hidden from DHT world */
|
/* hidden from DHT world */
|
||||||
mDhtMgr->dropPeer(id);
|
netAssistFriend(id, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mDhtMgr->findPeer(id);
|
netAssistFriend(id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
@ -2152,7 +2162,7 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
|
|||||||
mStatusChanged = true;
|
mStatusChanged = true;
|
||||||
|
|
||||||
/* expect it to be a standard DHT */
|
/* expect it to be a standard DHT */
|
||||||
mDhtMgr->findPeer(id);
|
netAssistFriend(id, true);
|
||||||
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
|
||||||
@ -2168,7 +2178,7 @@ bool p3ConnectMgr::removeFriend(std::string id)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mDhtMgr->dropPeer(id);
|
netAssistFriend(id, false);
|
||||||
|
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
@ -2551,7 +2561,7 @@ bool p3ConnectMgr::retryConnectNotify(std::string id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* attempt UDP connection */
|
/* attempt UDP connection */
|
||||||
mDhtMgr->notifyPeer(id);
|
netAssistNotify(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -2682,11 +2692,11 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
|
|||||||
if (it->second.visState & RS_VIS_STATE_NODHT)
|
if (it->second.visState & RS_VIS_STATE_NODHT)
|
||||||
{
|
{
|
||||||
/* hidden from DHT world */
|
/* hidden from DHT world */
|
||||||
mDhtMgr->dropPeer(id);
|
netAssistFriend(id, false);
|
||||||
}
|
}
|
||||||
else
|
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()
|
bool p3ConnectMgr::checkNetAddress()
|
||||||
@ -3016,6 +3010,193 @@ bool p3ConnectMgr::addBootstrapStunPeers()
|
|||||||
return true;
|
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
|
#define MRK_PQI_CONNECTION_MANAGER_HEADER
|
||||||
|
|
||||||
#include "pqi/pqimonitor.h"
|
#include "pqi/pqimonitor.h"
|
||||||
#include "pqi/p3dhtmgr.h"
|
|
||||||
#include "pqi/p3upnpmgr.h"
|
|
||||||
#include "pqi/p3authmgr.h"
|
#include "pqi/p3authmgr.h"
|
||||||
|
|
||||||
|
//#include "pqi/p3dhtmgr.h"
|
||||||
|
//#include "pqi/p3upnpmgr.h"
|
||||||
|
#include "pqi/pqiassist.h"
|
||||||
|
|
||||||
#include "pqi/p3cfgmgr.h"
|
#include "pqi/p3cfgmgr.h"
|
||||||
|
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
@ -160,8 +162,9 @@ class p3ConnectMgr: public pqiConnectCb, public p3Config
|
|||||||
void tick();
|
void tick();
|
||||||
|
|
||||||
/*************** Setup ***************************/
|
/*************** Setup ***************************/
|
||||||
void setDhtMgr(p3DhtMgr *dmgr) { mDhtMgr = dmgr; }
|
void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *);
|
||||||
void setUpnpMgr(p3UpnpMgr *umgr) { mUpnpMgr = umgr; }
|
void addNetAssistFirewall(uint32_t type, pqiNetAssistFirewall *);
|
||||||
|
|
||||||
bool checkNetAddress(); /* check our address is sensible */
|
bool checkNetAddress(); /* check our address is sensible */
|
||||||
|
|
||||||
/*************** External Control ****************/
|
/*************** External Control ****************/
|
||||||
@ -221,6 +224,30 @@ bool connectResult(std::string id, bool success, uint32_t flags);
|
|||||||
|
|
||||||
|
|
||||||
protected:
|
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 */
|
/* Internal Functions */
|
||||||
void statusTick();
|
void statusTick();
|
||||||
@ -286,8 +313,9 @@ void addPeer(RsPeerConfigItem *item);
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
p3AuthMgr *mAuthMgr;
|
p3AuthMgr *mAuthMgr;
|
||||||
p3DhtMgr *mDhtMgr;
|
|
||||||
p3UpnpMgr *mUpnpMgr;
|
std::map<uint32_t, pqiNetAssistFirewall *> mFwAgents;
|
||||||
|
std::map<uint32_t, pqiNetAssistConnect *> mDhts;
|
||||||
|
|
||||||
RsMutex connMtx; /* protects below */
|
RsMutex connMtx; /* protects below */
|
||||||
|
|
||||||
@ -323,3 +351,7 @@ void addPeer(std::string id, std::string name); /* tmp fn */
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif // MRK_PQI_CONNECTION_MANAGER_HEADER
|
#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 <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <openssl/sha.h>
|
||||||
|
|
||||||
|
#include "pqi/p3dhtmgr.h"
|
||||||
|
#include "pqi/p3connmgr.h"
|
||||||
|
|
||||||
#include "util/rsprint.h"
|
#include "util/rsprint.h"
|
||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
@ -87,7 +88,7 @@ dhtPeerEntry::dhtPeerEntry()
|
|||||||
}
|
}
|
||||||
|
|
||||||
p3DhtMgr::p3DhtMgr(std::string id, pqiConnectCb *cb)
|
p3DhtMgr::p3DhtMgr(std::string id, pqiConnectCb *cb)
|
||||||
:connCb(cb), mStunRequired(true)
|
:pqiNetAssistConnect(id, cb), mStunRequired(true)
|
||||||
{
|
{
|
||||||
/* setup own entry */
|
/* setup own entry */
|
||||||
dhtMtx.lock(); /* LOCK MUTEX */
|
dhtMtx.lock(); /* LOCK MUTEX */
|
||||||
@ -115,7 +116,21 @@ p3DhtMgr::p3DhtMgr(std::string id, pqiConnectCb *cb)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3DhtMgr::setDhtOn(bool on)
|
/* OVERLOADED from pqiNetAssistConnect
|
||||||
|
*/
|
||||||
|
|
||||||
|
void p3DhtMgr::shutdown()
|
||||||
|
{
|
||||||
|
/* ??? */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3DhtMgr::restart()
|
||||||
|
{
|
||||||
|
/* ??? */
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3DhtMgr::enable(bool on)
|
||||||
{
|
{
|
||||||
dhtMtx.lock(); /* LOCK MUTEX */
|
dhtMtx.lock(); /* LOCK MUTEX */
|
||||||
|
|
||||||
@ -125,7 +140,7 @@ void p3DhtMgr::setDhtOn(bool on)
|
|||||||
dhtMtx.unlock(); /* UNLOCK MUTEX */
|
dhtMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3DhtMgr::getDhtOn()
|
bool p3DhtMgr::getEnabled()
|
||||||
{
|
{
|
||||||
dhtMtx.lock(); /* LOCK MUTEX */
|
dhtMtx.lock(); /* LOCK MUTEX */
|
||||||
|
|
||||||
@ -136,7 +151,7 @@ bool p3DhtMgr::getDhtOn()
|
|||||||
return on;
|
return on;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3DhtMgr::getDhtActive()
|
bool p3DhtMgr::getActive()
|
||||||
{
|
{
|
||||||
dhtMtx.lock(); /* LOCK MUTEX */
|
dhtMtx.lock(); /* LOCK MUTEX */
|
||||||
|
|
||||||
@ -392,16 +407,19 @@ bool p3DhtMgr::addStun(std::string id)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3DhtMgr::doneStun()
|
bool p3DhtMgr::enableStun(bool on)
|
||||||
{
|
{
|
||||||
dhtMtx.lock(); /* LOCK MUTEX */
|
dhtMtx.lock(); /* LOCK MUTEX */
|
||||||
|
|
||||||
mDhtModifications = true;
|
mDhtModifications = true;
|
||||||
|
|
||||||
/* clear up */
|
if (!on)
|
||||||
stunIds.clear();
|
{
|
||||||
|
/* clear up */
|
||||||
|
stunIds.clear();
|
||||||
|
}
|
||||||
|
|
||||||
mStunRequired = false;
|
mStunRequired = on;
|
||||||
|
|
||||||
dhtMtx.unlock(); /* UNLOCK MUTEX */
|
dhtMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
|
|
||||||
@ -920,9 +938,9 @@ int p3DhtMgr::checkNotifyDHT()
|
|||||||
|
|
||||||
/* feedback to say we started it! */
|
/* feedback to say we started it! */
|
||||||
#ifdef P3DHTMGR_USE_LOCAL_UDP_CONN
|
#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
|
#else
|
||||||
connCb->peerConnectRequest(peer.id, peer.raddr, RS_CB_DHT);
|
mConnCb->peerConnectRequest(peer.id, peer.raddr, RS_CB_DHT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return DHT_MIN_PERIOD;
|
return DHT_MIN_PERIOD;
|
||||||
@ -1197,7 +1215,7 @@ void p3DhtMgr::checkDHTStatus()
|
|||||||
#ifdef DHT_DEBUG
|
#ifdef DHT_DEBUG
|
||||||
std::cerr << "p3DhtMgr::checkDhtStatus() toShutdown = true -> shutdown()" << std::endl;
|
std::cerr << "p3DhtMgr::checkDhtStatus() toShutdown = true -> shutdown()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (shutdown())
|
if (dhtShutdown())
|
||||||
{
|
{
|
||||||
clearDhtData();
|
clearDhtData();
|
||||||
|
|
||||||
@ -1215,9 +1233,9 @@ void p3DhtMgr::checkDHTStatus()
|
|||||||
if (toStartup)
|
if (toStartup)
|
||||||
{
|
{
|
||||||
#ifdef DHT_DEBUG
|
#ifdef DHT_DEBUG
|
||||||
std::cerr << "p3DhtMgr::checkDhtStatus() toStartup = true -> init()" << std::endl;
|
std::cerr << "p3DhtMgr::checkDhtStatus() toStartup = true -> dhtInit()" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (init())
|
if (dhtInit())
|
||||||
{
|
{
|
||||||
|
|
||||||
dhtMtx.lock(); /* LOCK MUTEX */
|
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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1734,13 +1752,13 @@ bool p3DhtMgr::dhtResultSearch(std::string idhash,
|
|||||||
|
|
||||||
if (doCb)
|
if (doCb)
|
||||||
{
|
{
|
||||||
connCb->peerStatus(ent.id, ent.laddr, ent.raddr,
|
mConnCb->peerStatus(ent.id, ent.laddr, ent.raddr,
|
||||||
ent.type, 0, RS_CB_DHT);
|
ent.type, 0, RS_CB_DHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doStun)
|
if (doStun)
|
||||||
{
|
{
|
||||||
connCb->stunStatus(idhash, raddr, type, stunFlags);
|
mConnCb->stunStatus(idhash, raddr, type, stunFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
#include "pqi/pqimonitor.h"
|
#include "pqi/pqimonitor.h"
|
||||||
|
|
||||||
|
#include "pqi/pqiassist.h"
|
||||||
|
|
||||||
/* All other #defs are in .cc */
|
/* All other #defs are in .cc */
|
||||||
#define DHT_ADDR_INVALID 0xff
|
#define DHT_ADDR_INVALID 0xff
|
||||||
#define DHT_ADDR_TCP 0x01
|
#define DHT_ADDR_TCP 0x01
|
||||||
@ -90,7 +92,7 @@ class dhtPeerEntry
|
|||||||
std::string hash2; /* SHA1 Hash of reverse Id */
|
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
|
* for the DHT, and must be non-blocking and return quickly
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void setDhtOn(bool on);
|
/* OVERLOADED From pqiNetAssistConnect. */
|
||||||
bool getDhtOn();
|
|
||||||
bool getDhtActive();
|
|
||||||
|
|
||||||
void setBootstrapAllowed(bool on);
|
virtual void enable(bool on);
|
||||||
bool getBootstrapAllowed();
|
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 */
|
/* set key data */
|
||||||
bool setExternalInterface(struct sockaddr_in laddr,
|
virtual bool setExternalInterface(struct sockaddr_in laddr,
|
||||||
struct sockaddr_in raddr, uint32_t type);
|
struct sockaddr_in raddr, uint32_t type);
|
||||||
|
|
||||||
/* add / remove peers */
|
/* add / remove peers */
|
||||||
bool findPeer(std::string id);
|
virtual bool findPeer(std::string id);
|
||||||
bool dropPeer(std::string id);
|
virtual bool dropPeer(std::string id);
|
||||||
|
|
||||||
/* post DHT key saying we should connect (callback when done) */
|
/* 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 */
|
/* extract current peer status */
|
||||||
bool getPeerStatus(std::string id,
|
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);
|
uint32_t &type, uint32_t &mode);
|
||||||
|
|
||||||
/* stun */
|
/* stun */
|
||||||
bool addStun(std::string id);
|
virtual bool enableStun(bool on);
|
||||||
bool doneStun();
|
virtual bool addStun(std::string id);
|
||||||
|
//doneStun();
|
||||||
|
|
||||||
/********** Higher Level DHT Work Functions ************************
|
/********** Higher Level DHT Work Functions ************************
|
||||||
* These functions translate from the strings/addresss to
|
* These functions translate from the strings/addresss to
|
||||||
@ -177,8 +185,8 @@ virtual bool resultDHT(std::string key, std::string value);
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool init();
|
virtual bool dhtInit();
|
||||||
virtual bool shutdown();
|
virtual bool dhtShutdown();
|
||||||
virtual bool dhtActive();
|
virtual bool dhtActive();
|
||||||
virtual int status(std::ostream &out);
|
virtual int status(std::ostream &out);
|
||||||
|
|
||||||
@ -214,7 +222,7 @@ std::string BootstrapId(uint32_t bin);
|
|||||||
std::string randomBootstrapId();
|
std::string randomBootstrapId();
|
||||||
|
|
||||||
/* other feedback through callback */
|
/* other feedback through callback */
|
||||||
pqiConnectCb *connCb;
|
// use pqiNetAssistConnect.. version pqiConnectCb *connCb;
|
||||||
|
|
||||||
/* protected by Mutex */
|
/* protected by Mutex */
|
||||||
RsMutex dhtMtx;
|
RsMutex dhtMtx;
|
||||||
|
@ -31,19 +31,19 @@
|
|||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
#include "pqi/pqinetwork.h"
|
#include "pqi/pqinetwork.h"
|
||||||
|
|
||||||
class p3UpnpMgr
|
class p3UpnpMgr: public pqiNetAssistFirewall
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~p3UpnpMgr() { return; }
|
virtual ~p3UpnpMgr() { return; }
|
||||||
|
|
||||||
/* External Interface */
|
/* External Interface */
|
||||||
virtual void enableUPnP(bool on) = 0; /* launches thread to start it up */
|
virtual void enable(bool on) = 0; /* launches thread to start it up */
|
||||||
virtual void shutdownUPnP() = 0; /* blocking shutdown call */
|
virtual void shutdown() = 0; /* blocking shutdown call */
|
||||||
virtual void restartUPnP() = 0; /* must be called if ports change */
|
virtual void restart() = 0; /* must be called if ports change */
|
||||||
|
|
||||||
virtual bool getUPnPEnabled() = 0;
|
virtual bool getEnabled() = 0;
|
||||||
virtual bool getUPnPActive() = 0;
|
virtual bool getActive() = 0;
|
||||||
|
|
||||||
/* the address that the listening port is on */
|
/* the address that the listening port is on */
|
||||||
virtual void setInternalPort(unsigned short iport_in) = 0;
|
virtual void setInternalPort(unsigned short iport_in) = 0;
|
||||||
|
@ -546,7 +546,7 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
rsNotify = new p3Notify();
|
rsNotify = new p3Notify();
|
||||||
|
|
||||||
mConnMgr = new p3ConnectMgr(mAuthMgr);
|
mConnMgr = new p3ConnectMgr(mAuthMgr);
|
||||||
p3UpnpMgr *mUpnpMgr = new upnphandler();
|
pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
|
||||||
p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, config->basedir);
|
p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, config->basedir);
|
||||||
|
|
||||||
CacheStrapper *mCacheStrapper = new CacheStrapper(mAuthMgr, mConnMgr);
|
CacheStrapper *mCacheStrapper = new CacheStrapper(mAuthMgr, mConnMgr);
|
||||||
@ -637,8 +637,8 @@ int RsServer::StartupRetroShare(RsInit *config)
|
|||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
mConnMgr->setDhtMgr(mDhtMgr);
|
mConnMgr->addNetAssistConnect(1, mDhtMgr);
|
||||||
mConnMgr->setUpnpMgr(mUpnpMgr);
|
mConnMgr->addNetAssistFirewall(1, mUpnpMgr);
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/* need to Monitor too! */
|
/* need to Monitor too! */
|
||||||
|
@ -412,7 +412,7 @@ upnphandler::~upnphandler()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* RsIface */
|
/* RsIface */
|
||||||
void upnphandler::enableUPnP(bool active)
|
void upnphandler::enable(bool active)
|
||||||
{
|
{
|
||||||
dataMtx.lock(); /*** LOCK MUTEX ***/
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
||||||
|
|
||||||
@ -443,7 +443,7 @@ void upnphandler::enableUPnP(bool active)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void upnphandler::shutdownUPnP()
|
void upnphandler::shutdown()
|
||||||
{
|
{
|
||||||
/* blocking call to shutdown upnp */
|
/* blocking call to shutdown upnp */
|
||||||
|
|
||||||
@ -451,7 +451,7 @@ void upnphandler::shutdownUPnP()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void upnphandler::restartUPnP()
|
void upnphandler::restart()
|
||||||
{
|
{
|
||||||
/* non-blocking call to shutdown upnp, and startup again. */
|
/* non-blocking call to shutdown upnp, and startup again. */
|
||||||
background_setup_upnp(true, true);
|
background_setup_upnp(true, true);
|
||||||
@ -459,7 +459,7 @@ void upnphandler::restartUPnP()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool upnphandler::getUPnPEnabled()
|
bool upnphandler::getEnabled()
|
||||||
{
|
{
|
||||||
dataMtx.lock(); /*** LOCK MUTEX ***/
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
||||||
|
|
||||||
@ -470,7 +470,7 @@ bool upnphandler::getUPnPEnabled()
|
|||||||
return on;
|
return on;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool upnphandler::getUPnPActive()
|
bool upnphandler::getActive()
|
||||||
{
|
{
|
||||||
dataMtx.lock(); /*** LOCK MUTEX ***/
|
dataMtx.lock(); /*** LOCK MUTEX ***/
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
|
|
||||||
/* platform independent networking... */
|
/* platform independent networking... */
|
||||||
#include "pqi/pqinetwork.h"
|
#include "pqi/pqinetwork.h"
|
||||||
#include "pqi/p3upnpmgr.h"
|
#include "pqi/pqiassist.h"
|
||||||
|
|
||||||
|
#include "util/rsthreads.h"
|
||||||
|
|
||||||
class upnpentry
|
class upnpentry
|
||||||
{
|
{
|
||||||
@ -42,20 +44,20 @@ class upnpforward
|
|||||||
|
|
||||||
class uPnPConfigData;
|
class uPnPConfigData;
|
||||||
|
|
||||||
class upnphandler: public p3UpnpMgr
|
class upnphandler: public pqiNetAssistFirewall
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
upnphandler();
|
upnphandler();
|
||||||
virtual ~upnphandler();
|
virtual ~upnphandler();
|
||||||
|
|
||||||
/* External Interface */
|
/* External Interface (pqiNetAssistFirewall) */
|
||||||
virtual void enableUPnP(bool active);
|
virtual void enable(bool active);
|
||||||
virtual void shutdownUPnP();
|
virtual void shutdown();
|
||||||
virtual void restartUPnP();
|
virtual void restart();
|
||||||
|
|
||||||
virtual bool getUPnPEnabled();
|
virtual bool getEnabled();
|
||||||
virtual bool getUPnPActive();
|
virtual bool getActive();
|
||||||
|
|
||||||
virtual void setInternalPort(unsigned short iport_in);
|
virtual void setInternalPort(unsigned short iport_in);
|
||||||
virtual void setExternalPort(unsigned short eport_in);
|
virtual void setExternalPort(unsigned short eport_in);
|
||||||
|
@ -64,20 +64,20 @@ int main(int argc, char **argv)
|
|||||||
if (i % 120 == 10)
|
if (i % 120 == 10)
|
||||||
{
|
{
|
||||||
/* start up a forward */
|
/* start up a forward */
|
||||||
upnp.enableUPnP(true);
|
upnp.enable(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i % 120 == 60)
|
if (i % 120 == 60)
|
||||||
{
|
{
|
||||||
/* shutdown a forward */
|
/* shutdown a forward */
|
||||||
upnp.restartUPnP();
|
upnp.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i % 120 == 100)
|
if (i % 120 == 100)
|
||||||
{
|
{
|
||||||
/* shutdown a forward */
|
/* shutdown a forward */
|
||||||
upnp.shutdownUPnP();
|
upnp.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user