* 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:
drbob 2008-08-16 15:02:24 +00:00
parent 483118daec
commit 33032e8a83
20 changed files with 882 additions and 141 deletions

View file

@ -7,17 +7,15 @@ RS_TOP_DIR = ..
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
#ftcontroller.o pqitestor.o
RSOBJ = ftdata.o ftfileprovider.o ftfilecreator.o ftextralist.o \
ftdatamultiplex.o ftfilesearch.o fttransfermodule.o ftdbase.o ftserver.o \
ftcontroller.o pqitestor.o
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o
#ftserver1test.o
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o ftserver1test.o
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest
#ftserver1test
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest ftserver1test
all: librs tests

View file

@ -197,8 +197,8 @@ bool loadConfigMap(std::map<std::string, std::string> &configMap);
private:
/**** INTERNAL FUNCTIONS ***/
virtual int reScanDirs();
virtual int check_dBUpdate();
//virtual int reScanDirs();
//virtual int check_dBUpdate();
private:

View 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

View 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;
}

View 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