* Moved final serialiser test over, and test notes from ft.

* removed tests from lib directories for serialiser / dbase / ft



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3177 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-06-20 12:37:04 +00:00
parent 05bc4ba76e
commit 3855be974b
29 changed files with 1 additions and 4669 deletions

View file

@ -1,50 +0,0 @@
RS_TOP_DIR = ..
##### Define any flags that are needed for this section #######
###############################################################
###############################################################
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 ftdwlqueue.o
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o ftserver1test.o ftserver2test.o fttransfermoduletest.o ftserver3test.o
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest ftserver1test ftserver2test fttransfermoduletest ftserver3test
all: librs tests
ftfilecreatortest : ftfilecreatortest.o
$(CC) $(CFLAGS) -o ftfilecreatortest ftfilecreatortest.o $(LIBS)
ftfileprovidertest : ftfileprovidertest.o
$(CC) $(CFLAGS) -o ftfileprovidertest ftfileprovidertest.o $(LIBS)
fttransfermoduletest : fttransfermoduletest.o
$(CC) $(CFLAGS) -o fttransfermoduletest fttransfermoduletest.o $(LIBS)
ftextralisttest : ftextralisttest.o
$(CC) $(CFLAGS) -o ftextralisttest ftextralisttest.o $(LIBS)
ftdataplextest : ftdataplextest.o
$(CC) $(CFLAGS) -o ftdataplextest ftdataplextest.o $(LIBS)
ftserver1test : ftserver1test.o
$(CC) $(CFLAGS) -o ftserver1test ftserver1test.o $(LIBS)
ftserver2test : ftserver2test.o
$(CC) $(CFLAGS) -o ftserver2test ftserver2test.o $(LIBS)
ftserver3test : ftserver3test.o
$(CC) $(CFLAGS) -o ftserver3test ftserver3test.o $(LIBS)
###############################################################
include $(RS_TOP_DIR)/scripts/rules.mk
###############################################################

View file

@ -1,54 +0,0 @@
Features that need to be tested, and which test checks it.
-----------------------------------------------------------
(*) Transfer Related
(*) Search Related
(*) ExtraList Related
(*) Cache Related
(*) Config / Storage.
Change Config Directory works dynamically. (no restart required).
(*) Miscelleous
-----------------------------------------------------------
-----------------------------------------------------------
Actual Tests, and what they check.
-----------------------------------------------------------
ftserver1test.cc
==================
Used to develop test framework.
Tests.
1) Test Framework. OK
2) File Indexing. OK
3) Cache Packet Exchange. OK
4) Cache downloads (including loopback). FAILS
5) FileIndex Store loading.
6) Basic Search.
ftserver2test.cc
==================
Test out the ExtraList functions.
Demonstrates the use of libretroshare/src/util/utest.h
Tests.
1) Load ExtraList path OK
2) Hashing of ExtraList File OK
3) ExtraHashDone. OK
4) Local Search for ExtraList Data. OK
5) Remote Search of ExtraList (should Fail) OK
6) Transfer of ExtraList File (Local) TODO
7) Transfer of ExtraList File (Remote) TODO

View file

@ -1,411 +0,0 @@
/*
* 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".
*
*/
/*
* ftServer2Test - Demonstrates how to check for test stuff.
*/
#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 "util/rsdebug.h"
#include "ft/pqitestor.h"
#include "util/rsdir.h"
#include "util/utest.h"
#include <sstream>
class TestData
{
public:
ftServer *loadServer;
std::list<ftServer *> otherServers;
std::list<std::string> extraList;
};
extern "C" void *do_server_test_thread(void *p);
void usage(char *name)
{
std::cerr << "Usage: " << name << " [-sa] [-p <peerId>] [-d <debugLvl>] [-e <extrafile>] [<path> [<path2> ... ]] ";
std::cerr << std::endl;
}
int main(int argc, char **argv)
{
int c;
uint32_t period = 1;
uint32_t debugLevel = 5;
bool debugStderr = true;
bool loadAll = false;
std::list<std::string> fileList;
std::list<std::string> extraList;
std::list<std::string> peerIds;
std::map<std::string, ftServer *> mFtServers;
std::map<std::string, p3ConnectMgr *> mConnMgrs;
ftServer *mLoadServer = NULL;
std::list<ftServer *> mOtherServers;
std::list<std::string>::iterator eit;
while(-1 != (c = getopt(argc, argv, "asd:p:e:")))
{
switch (c)
{
case 'p':
peerIds.push_back(optarg);
break;
case 'd':
debugLevel = atoi(optarg);
break;
case 's':
debugStderr = true;
break;
case 'e':
extraList.push_back(optarg);
break;
case 'a':
loadAll = true;
break;
default:
usage(argv[0]);
break;
}
}
/* do logging */
setOutputLevel(debugLevel);
if (optind >= argc)
{
std::cerr << "Missing Shared Directories" << 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;
P3Hub *testHub = new P3Hub();
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;
}
std::ostringstream pname;
pname << "/tmp/rstst-" << time(NULL);
std::string basepath = pname.str();
RsDirUtil::checkCreateDirectory(basepath);
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);
mConnMgrs[*it] = connMgr;
for(fit = friendList.begin(); fit != friendList.end(); fit++)
{
/* add as peer to authMgr */
connMgr->addFriend(fit->id);
}
P3Pipe *pipe = new P3Pipe(); //(*it);
/* add server */
ftServer *server;
server = new ftServer(authMgr, connMgr);
mFtServers[*it] = server;
if (!mLoadServer)
{
mLoadServer = server;
}
else
{
mOtherServers.push_back(server);
}
server->setP3Interface(pipe);
std::string configpath = basepath + "/" + *it;
RsDirUtil::checkCreateDirectory(configpath);
std::string cachepath = configpath + "/cache";
RsDirUtil::checkCreateDirectory(cachepath);
std::string localpath = cachepath + "/local";
RsDirUtil::checkCreateDirectory(localpath);
std::string remotepath = cachepath + "/remote";
RsDirUtil::checkCreateDirectory(remotepath);
server->setConfigDirectory(configpath);
NotifyBase *base = NULL;
server->SetupFtServer(base);
testHub->addP3Pipe(*it, pipe, connMgr);
server->StartupThreads();
/* setup any extra bits */
if (loadAll)
{
server->setSharedDirectories(fileList);
for(eit = extraList.begin(); eit != extraList.end(); eit++)
{
server->ExtraFileHash(*eit, 3600, 0);
}
}
}
if (mLoadServer)
{
mLoadServer->setSharedDirectories(fileList);
for(eit = extraList.begin(); eit != extraList.end(); eit++)
{
mLoadServer->ExtraFileHash(*eit, 3600, 0);
}
}
/* stick your real test here */
std::map<std::string, ftServer *>::iterator sit;
std::map<std::string, p3ConnectMgr *>::iterator cit;
/* Start up test thread */
pthread_t tid;
TestData *mFt = new TestData;
/* set data */
mFt->loadServer = mLoadServer;
mFt->otherServers = mOtherServers;
mFt->extraList = extraList;
void *data = (void *) mFt;
pthread_create(&tid, 0, &do_server_test_thread, data);
pthread_detach(tid); /* so memory is reclaimed in linux */
while(1)
{
std::cerr << "ftserver2test::sleep()";
std::cerr << std::endl;
sleep(1);
/* tick the connmgrs */
for(sit = mFtServers.begin(); sit != mFtServers.end(); sit++)
{
/* update */
(sit->second)->tick();
}
for(cit = mConnMgrs.begin(); cit != mConnMgrs.end(); cit++)
{
/* update */
(cit->second)->tick();
}
}
}
/* So our actual test can run here.....
*
*/
INITTEST();
void *do_server_test_thread(void *data)
{
TestData *mFt = (TestData *) data;
std::cerr << "do_server_test_thread() running";
std::cerr << std::endl;
/************************* TEST 1 **********************
* Check that the extra List has been processed.
*/
time_t start = time(NULL);
FileInfo info, info2;
time_t now = time(NULL);
std::list<std::string>::iterator eit;
for(eit = mFt->extraList.begin(); eit != mFt->extraList.end(); eit++)
{
while(!mFt->loadServer->ExtraFileStatus(*eit, info))
{
/* max of 30 seconds */
now = time(NULL);
if (now - start > 30)
{
/* FAIL */
REPORT2( false, "Extra File Hashing");
}
sleep(1);
}
/* Got ExtraFileStatus */
REPORT("Successfully Found ExtraFile");
/* now we can try a search (should succeed) */
uint32_t hintflags = 0;
if (mFt->loadServer->FileDetails(info.hash, hintflags, info2))
{
CHECK(info2.hash == info.hash);
CHECK(info2.size == info.size);
CHECK(info2.fname == info.fname);
}
else
{
REPORT2( false, "Search for Extra File (Basic)");
}
/* search with flags (should succeed) */
hintflags = RS_FILE_HINTS_EXTRA;
if (mFt->loadServer->FileDetails(info.hash, hintflags, info2))
{
CHECK(info2.hash == info.hash);
CHECK(info2.size == info.size);
CHECK(info2.fname == info.fname);
}
else
{
REPORT2( false, "Search for Extra File (Extra Flag)");
}
/* search with other flags (should fail) */
hintflags = RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY;
if (mFt->loadServer->FileDetails(info.hash, hintflags, info2))
{
REPORT2( false, "Search for Extra File (Fail Flags)");
}
else
{
REPORT("Search for Extra File (Fail Flags)");
}
/* if we try to download it ... should just find existing one*/
REPORT("Testing with Extra File");
}
FINALREPORT("ExtraList Hashing, Searching and Downloading");
/************************* TEST 2 **********************
* test ftController and ftTransferModule
*/
ftServer *server=mFt->loadServer;
std::string fname,filehash,destination;
uint32_t size,flags;
std::list<std::string> srcIds;
/* select a file from otherServers */
if (mFt->otherServers == NULL)
{
REPORT2(false,"No otherServers available");
exit(1);
}
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS | DIR_FLAGS_REMOTE;
void *ref = NULL;
if(!server->RequestDirDetails(ref,details,flags))
{
REPORT2(false,"fail to call RequestDirDetails");
}
if (details.type == DIR_TYPE_FILE)
{
REPORT("RemoteDirModel::downloadSelected() Calling File Request");
std::list<std::string> srcIds;
srcIds.push_back(details.id);
server->FileRequest(details.name, details.hash,
details.count, "", 0, srcIds);
}
exit(1);
}

View file

@ -1,178 +0,0 @@
/*
* libretroshare/src/ft: ftextralisttest.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 Multiplexor.....
* As this is a key middle component, it is hard to test without other bits.
* It relies on ftFileProvider/ftFileCreator/ftTransferModule...
*
* And has dummy ftDataSend and ftSearch.
*
*/
#ifdef WIN32
#include "util/rswin.h"
#endif
#include "ft/ftextralist.h"
#include "ft/ftdatamultiplex.h"
#include "ft/ftfilesearch.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;
while(-1 != (c = getopt(argc, argv, "d:p:")))
{
switch (c)
{
case 'p':
period = atoi(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]));
}
ftExtraList *eList = new ftExtraList();
eList->start();
ftSearch *ftsd = new ftSearchDummy();
ftFileSearch *ftfs = new ftFileSearch();
ftfs-> addSearchMode(ftsd, RS_FILE_HINTS_LOCAL);
ftfs-> addSearchMode(eList, RS_FILE_HINTS_EXTRA);
ftDataSend *ftds = new ftDataSendDummy();
/* setup Actual Test bit */
ftDataMultiplex *ftmplex = new ftDataMultiplex("ownId", ftds, ftfs);
ftmplex->start();
/* Setup Search with some valid results */
/* Request Data */
/* now work the thread */
std::list<std::string>::iterator it;
uint32_t flags = 0;
for(it = fileList.begin(); it != fileList.end(); it++)
{
eList->hashExtraFile(*it, dPeriod, flags);
}
/* now request files from ftDataMultiplex */
/* just request random data packets first */
do_random_server_test(ftmplex, eList, fileList);
}
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);
}
}

View file

@ -1,166 +0,0 @@
/*
* libretroshare/src/ft: ftextralisttest.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".
*
*/
#ifdef WIN32
#include "util/rswin.h"
#endif
#include "ft/ftextralist.h"
extern "C" void* runExtraList(void* p)
{
ftExtraList *eList = (ftExtraList *) p;
if (!eList)
{
pthread_exit(NULL);
}
while (1)
{
//eList->tick();
sleep(1);
}
delete eList;
pthread_exit(NULL);
return NULL;
}
void displayExtraListDetails(ftExtraList *eList, std::list<std::string> toHash, std::list<std::string> hashed);
void usage(char *name)
{
std::cerr << "Usage: " << name << " -h <path> -p <period> -d <dperiod>";
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> hashList;
while(-1 != (c = getopt(argc, argv, "h:p:d:")))
{
switch (c)
{
case 'h':
hashList.push_back(std::string(optarg));
break;
case 'p':
period = atoi(optarg);
break;
case 'd':
dPeriod = atoi(optarg);
break;
default:
usage(argv[0]);
break;
}
}
ftExtraList *eList = new ftExtraList();
/* now startup background thread to keep it reunning */
eList->start();
/* now work the thread */
std::list<std::string> toHash;
std::list<std::string> hashed;
std::list<std::string>::iterator it;
uint32_t flags = 0;
for(it = hashList.begin(); it != hashList.end(); it++)
{
sleep(period);
/* load up file */
//eList->addExtraFile(*it);
eList->hashExtraFile(*it, dPeriod, flags);
toHash.push_back(*it);
displayExtraListDetails(eList, toHash, hashed);
}
while(1)
{
sleep(period);
displayExtraListDetails(eList, toHash, hashed);
}
}
void displayExtraListDetails(ftExtraList *eList, std::list<std::string> toHash, std::list<std::string> hashed)
{
std::cerr << "displayExtraListDetails()";
std::cerr << std::endl;
std::list<std::string>::iterator it;
for(it = toHash.begin(); it != toHash.end(); it++)
{
FileInfo info;
if (eList->hashExtraFileDone(*it, info))
{
std::cerr << "displayExtraListDetails() Hash Completed for: " << *it;
std::cerr << std::endl;
std::cerr << info << std::endl;
}
else
{
std::cerr << "displayExtraListDetails() Hash Not Done for: " << *it;
std::cerr << std::endl;
}
}
for(it = hashed.begin(); it != hashed.end(); it++)
{
FileInfo info;
if (eList->search(*it, 0, 0, info))
{
std::cerr << "displayExtraListDetails() Found Hash: " << *it;
std::cerr << std::endl;
std::cerr << info << std::endl;
}
else
{
std::cerr << "displayExtraListDetails() Hash Not Found: " << *it;
std::cerr << std::endl;
}
}
}

View file

@ -1,122 +0,0 @@
#include "ftfilecreator.h"
#include "util/utest.h"
#include <stdlib.h>
#include "util/rswin.h"
INITTEST();
static int test_timeout(ftFileCreator *creator);
static int test_fill(ftFileCreator *creator);
int main()
{
/* use ftcreator to create a file on tmp drive */
ftFileCreator fcreator("/tmp/rs-ftfc-test.dta",100000,"hash",0);
test_timeout(&fcreator);
test_fill(&fcreator);
FINALREPORT("RsTlvItem Stack Tests");
return TESTRESULT();
}
int test_timeout(ftFileCreator *creator)
{
uint32_t chunk = 1000;
uint64_t offset = 0;
int max_timeout = 30;
int max_offset = chunk * max_timeout;
int i;
std::cerr << "60 second test of chunk queue.";
std::cerr << std::endl;
for(i = 0; i < max_timeout; i++)
{
creator->getMissingChunk(offset, chunk);
std::cerr << "Allocated Offset: " << offset << " chunk: " << chunk << std::endl;
CHECK(offset <= max_offset);
sleep(1);
}
std::cerr << "Expect Repeats now";
std::cerr << std::endl;
for(i = 0; i < max_timeout; i++)
{
sleep(1);
creator->getMissingChunk(offset, chunk);
std::cerr << "Allocated Offset: " << offset << " chunk: " << chunk << std::endl;
CHECK(offset <= max_offset);
}
REPORT("Chunk Queue");
return 1;
}
int test_fill(ftFileCreator *creator)
{
uint32_t chunk = 1000;
uint64_t offset = 0;
uint64_t init_size = creator->getFileSize();
uint64_t init_trans = creator->getRecvd();
std::cerr << "Initial FileSize: " << init_size << std::endl;
std::cerr << "Initial Transferred:" << init_trans << std::endl;
while(creator->getMissingChunk(offset, chunk))
{
if (chunk == 0)
{
std::cerr << "Missing Data already Alloced... wait";
std::cerr << std::endl;
sleep(1);
chunk = 1000;
continue;
}
/* give it to them */
void *data = malloc(chunk);
/* fill with ascending numbers */
for(int i = 0; i < chunk; i++)
{
((uint8_t *) data)[i] = 'a' + i % 27;
if (i % 27 == 26)
{
((uint8_t *) data)[i] = '\n';
}
}
creator->addFileData(offset, chunk, data);
free(data);
#ifndef WINDOWS_SYS
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
usleep(250000); /* 1/4 of sec */
#else
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
Sleep(250); /* 1/4 of sec */
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
chunk = 1000; /* reset chunk size */
}
uint64_t end_size = creator->getFileSize();
uint64_t end_trans = creator->getRecvd();
std::cerr << "End FileSize: " << end_size << std::endl;
std::cerr << "End Transferred:" << end_trans << std::endl;
CHECK(init_size == end_size);
CHECK(end_trans == end_size);
REPORT("Test Fill");
return 1;
}

View file

@ -1,93 +0,0 @@
#include "ftfileprovider.h"
#include "ftfilecreator.h"
#include "util/utest.h"
#include <stdlib.h>
#include "util/rswin.h"
INITTEST()
int main()
{
/* create a random file */
uint64_t size = 100000;
uint32_t max_chunk = 10000;
uint32_t chunk = 1000;
uint64_t offset = 0;
std::string filename = "/tmp/ft_test.dta";
std::string filename2 = "/tmp/ft_test.dta.dup";
/* use creator to make it */
void *data = malloc(max_chunk);
for(int i = 0; i < max_chunk; i++)
{
((uint8_t *) data)[i] = 'a' + i % 27;
if (i % 27 == 26)
{
((uint8_t *) data)[i] = '\n';
}
}
ftFileCreator *creator = new ftFileCreator(filename, size, "hash", 0);
for(offset = 0; offset != size; offset += chunk)
{
if (!creator->addFileData(offset, chunk, data))
{
FAILED("Create Test Data File");
std::cerr << "Failed to add data (CREATE)";
std::cerr << std::endl;
}
}
delete creator;
std::cerr << "Created file: " << filename << " of size: " << size;
std::cerr << std::endl;
/* load it with file provider */
creator = new ftFileCreator(filename2, size, "hash", 0);
ftFileProvider *provider = new ftFileProvider(filename, size, "hash");
/* create duplicate with file creator */
while(creator->getMissingChunk(offset, chunk))
{
if (chunk == 0)
{
std::cerr << "All currently allocated .... waiting";
std::cerr << std::endl;
sleep(1);
/* reset chunk size */
chunk = (uint64_t) max_chunk * (rand() / (1.0 + RAND_MAX));
std::cerr << "ChunkSize = " << chunk << std::endl;
continue;
}
if (!provider->getFileData(offset, chunk, data))
{
FAILED("Read from Test Data File");
std::cerr << "Failed to get data";
std::cerr << std::endl;
}
if (!creator->addFileData(offset, chunk, data))
{
FAILED("Write to Duplicate");
std::cerr << "Failed to add data";
std::cerr << std::endl;
}
std::cerr << "Transferred: " << chunk << " @ " << offset;
std::cerr << std::endl;
/* reset chunk size */
chunk = (uint64_t) max_chunk * (rand() / (1.0 + RAND_MAX));
std::cerr << "ChunkSize = " << chunk << std::endl;
}
return 1;
}

View file

@ -1,329 +0,0 @@
/*
* 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.
*/
#ifdef WIN32
#include "util/rswin.h"
#endif
#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 "util/rsdebug.h"
#include "ft/pqitestor.h"
#include "util/rsdir.h"
#include <sstream>
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 debugLevel = 5;
bool debugStderr = true;
std::list<std::string> fileList;
std::list<std::string> peerIds;
std::map<std::string, ftServer *> mFtServers;
std::map<std::string, p3ConnectMgr *> mConnMgrs;
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
#endif
#ifdef WIN32
// Windows Networking Init.
WORD wVerReq = MAKEWORD(2,2);
WSADATA wsaData;
if (0 != WSAStartup(wVerReq, &wsaData))
{
std::cerr << "Failed to Startup Windows Networking";
std::cerr << std::endl;
}
else
{
std::cerr << "Started Windows Networking";
std::cerr << std::endl;
}
#endif
while(-1 != (c = getopt(argc, argv, "d:p:s")))
{
switch (c)
{
case 'p':
peerIds.push_back(optarg);
break;
case 'd':
debugLevel = atoi(optarg);
break;
case 's':
debugStderr = true;
break;
default:
usage(argv[0]);
break;
}
}
/* do logging */
setOutputLevel(debugLevel);
if (optind >= argc)
{
std::cerr << "Missing Files" << std::endl;
usage(argv[0]);
}
std::cerr << "Point 1" << std::endl;
for(; optind < argc; optind++)
{
std::cerr << "Adding: " << argv[optind] << std::endl;
fileList.push_back(std::string(argv[optind]));
}
std::cerr << "Point 2" << std::endl;
/* 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;
std::cerr << "Point 3" << std::endl;
P3Hub *testHub = new P3Hub(0, NULL);
testHub->start();
std::cerr << "Point 4" << std::endl;
/* 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;
}
std::cerr << "Point 5" << std::endl;
std::ostringstream pname;
pname << "/tmp/rstst-" << time(NULL);
std::string basepath = pname.str();
RsDirUtil::checkCreateDirectory(basepath);
std::cerr << "Point 6" << 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);
mConnMgrs[*it] = connMgr;
for(fit = friendList.begin(); fit != friendList.end(); fit++)
{
/* add as peer to authMgr */
connMgr->addFriend(fit->id);
}
P3Pipe *pipe = new P3Pipe(); //(*it);
/* add server */
ftServer *server;
server = new ftServer(authMgr, connMgr);
mFtServers[*it] = server;
server->setP3Interface(pipe);
std::string configpath = basepath + "/" + *it;
RsDirUtil::checkCreateDirectory(configpath);
std::string cachepath = configpath + "/cache";
RsDirUtil::checkCreateDirectory(cachepath);
std::string partialspath = configpath + "/partials";
RsDirUtil::checkCreateDirectory(partialspath);
std::string downloadpath = configpath + "/downloads";
RsDirUtil::checkCreateDirectory(downloadpath);
std::string localpath = cachepath + "/local";
RsDirUtil::checkCreateDirectory(localpath);
std::string remotepath = cachepath + "/remote";
RsDirUtil::checkCreateDirectory(remotepath);
server->setConfigDirectory(configpath);
//sleep(60);
NotifyBase *base = NULL;
server->SetupFtServer(base);
testHub->addP3Pipe(*it, pipe, connMgr);
server->StartupThreads();
/* setup any extra bits */
server->setPartialsDirectory(partialspath);
server->setDownloadDirectory(downloadpath);
server->setSharedDirectories(fileList);
}
/* stick your real test here */
std::map<std::string, ftServer *>::iterator sit;
std::map<std::string, p3ConnectMgr *>::iterator cit;
while(1)
{
std::cerr << "ftserver1test::sleep()";
std::cerr << std::endl;
sleep(1);
/* tick the connmgrs */
for(sit = mFtServers.begin(); sit != mFtServers.end(); sit++)
{
/* update */
(sit->second)->tick();
}
for(cit = mConnMgrs.begin(); cit != mConnMgrs.end(); cit++)
{
/* update */
(cit->second)->tick();
}
}
}
#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

@ -1,424 +0,0 @@
/*
* 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".
*
*/
/*
* ftServer2Test - Demonstrates how to check for test stuff.
* This tests hashing of files using extraList.
*/
#ifdef WIN32
#include "util/rswin.h"
#endif
#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 "util/rsdebug.h"
#include "ft/pqitestor.h"
#include "util/rsdir.h"
#include "util/utest.h"
#include <sstream>
class TestData
{
public:
ftServer *loadServer;
std::list<ftServer *> otherServers;
std::list<std::string> extraList;
};
extern "C" void *do_server_test_thread(void *p);
void usage(char *name)
{
std::cerr << "Usage: " << name << " [-sa] [-p <peerId>] [-d <debugLvl>] [-e <extrafile>] [<path> [<path2> ... ]] ";
std::cerr << std::endl;
}
int main(int argc, char **argv)
{
int c;
uint32_t period = 1;
uint32_t debugLevel = 5;
bool debugStderr = true;
bool loadAll = false;
std::list<std::string> fileList;
std::list<std::string> extraList;
std::list<std::string> peerIds;
std::map<std::string, ftServer *> mFtServers;
std::map<std::string, p3ConnectMgr *> mConnMgrs;
ftServer *mLoadServer = NULL;
std::list<ftServer *> mOtherServers;
std::list<std::string>::iterator eit;
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
#endif
#ifdef WIN32
// Windows Networking Init.
WORD wVerReq = MAKEWORD(2,2);
WSADATA wsaData;
if (0 != WSAStartup(wVerReq, &wsaData))
{
std::cerr << "Failed to Startup Windows Networking";
std::cerr << std::endl;
}
else
{
std::cerr << "Started Windows Networking";
std::cerr << std::endl;
}
#endif
while(-1 != (c = getopt(argc, argv, "asd:p:e:")))
{
switch (c)
{
case 'p':
peerIds.push_back(optarg);
break;
case 'd':
debugLevel = atoi(optarg);
break;
case 's':
debugStderr = true;
break;
case 'e':
extraList.push_back(optarg);
break;
case 'a':
loadAll = true;
break;
default:
usage(argv[0]);
break;
}
}
/* do logging */
setOutputLevel(debugLevel);
if (optind >= argc)
{
std::cerr << "Missing Shared Directories" << 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;
/* Add in serialiser */
RsSerialiser *rss = new RsSerialiser();
rss->addSerialType(new RsFileItemSerialiser());
rss->addSerialType(new RsCacheItemSerialiser());
rss->addSerialType(new RsServiceSerialiser());
P3Hub *testHub = new P3Hub(0, rss);
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;
}
std::ostringstream pname;
pname << "/tmp/rstst-" << time(NULL);
std::string basepath = pname.str();
RsDirUtil::checkCreateDirectory(basepath);
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);
mConnMgrs[*it] = connMgr;
for(fit = friendList.begin(); fit != friendList.end(); fit++)
{
/* add as peer to authMgr */
connMgr->addFriend(fit->id);
}
P3Pipe *pipe = new P3Pipe(); //(*it);
/* add server */
ftServer *server;
server = new ftServer(authMgr, connMgr);
mFtServers[*it] = server;
if (!mLoadServer)
{
mLoadServer = server;
}
else
{
mOtherServers.push_back(server);
}
server->setP3Interface(pipe);
std::string configpath = basepath + "/" + *it;
RsDirUtil::checkCreateDirectory(configpath);
std::string cachepath = configpath + "/cache";
RsDirUtil::checkCreateDirectory(cachepath);
std::string partialspath = configpath + "/partials";
RsDirUtil::checkCreateDirectory(partialspath);
std::string downloadpath = configpath + "/downloads";
RsDirUtil::checkCreateDirectory(downloadpath);
std::string localpath = cachepath + "/local";
RsDirUtil::checkCreateDirectory(localpath);
std::string remotepath = cachepath + "/remote";
RsDirUtil::checkCreateDirectory(remotepath);
server->setConfigDirectory(configpath);
NotifyBase *base = NULL;
server->SetupFtServer(base);
testHub->addP3Pipe(*it, pipe, connMgr);
server->StartupThreads();
/* setup any extra bits */
/* everyone gets download directories */
server->setPartialsDirectory(partialspath);
server->setDownloadDirectory(downloadpath);
if (loadAll)
{
server->setSharedDirectories(fileList);
for(eit = extraList.begin(); eit != extraList.end(); eit++)
{
server->ExtraFileHash(*eit, 3600, 0);
}
}
}
if (mLoadServer)
{
mLoadServer->setSharedDirectories(fileList);
for(eit = extraList.begin(); eit != extraList.end(); eit++)
{
mLoadServer->ExtraFileHash(*eit, 3600, 0);
}
}
/* stick your real test here */
std::map<std::string, ftServer *>::iterator sit;
std::map<std::string, p3ConnectMgr *>::iterator cit;
/* Start up test thread */
pthread_t tid;
TestData *mFt = new TestData;
/* set data */
mFt->loadServer = mLoadServer;
mFt->otherServers = mOtherServers;
mFt->extraList = extraList;
void *data = (void *) mFt;
pthread_create(&tid, 0, &do_server_test_thread, data);
pthread_detach(tid); /* so memory is reclaimed in linux */
while(1)
{
std::cerr << "ftserver2test::sleep()";
std::cerr << std::endl;
sleep(1);
/* tick the connmgrs */
for(sit = mFtServers.begin(); sit != mFtServers.end(); sit++)
{
/* update */
(sit->second)->tick();
}
for(cit = mConnMgrs.begin(); cit != mConnMgrs.end(); cit++)
{
/* update */
(cit->second)->tick();
}
}
}
/* So our actual test can run here.....
*
*/
INITTEST();
void *do_server_test_thread(void *data)
{
TestData *mFt = (TestData *) data;
std::cerr << "do_server_test_thread() running";
std::cerr << std::endl;
/************************* TEST 1 **********************
* Check that the extra List has been processed.
*/
time_t start = time(NULL);
FileInfo info, info2;
time_t now = time(NULL);
std::list<std::string>::iterator eit;
for(eit = mFt->extraList.begin(); eit != mFt->extraList.end(); eit++)
{
while(!mFt->loadServer->ExtraFileStatus(*eit, info))
{
/* max of 30 seconds */
now = time(NULL);
if (now - start > 30)
{
/* FAIL */
REPORT2( false, "Extra File Hashing");
}
sleep(1);
}
/* Got ExtraFileStatus */
REPORT("Successfully Found ExtraFile");
/* now we can try a search (should succeed) */
uint32_t hintflags = 0;
if (mFt->loadServer->FileDetails(info.hash, hintflags, info2))
{
CHECK(info2.hash == info.hash);
CHECK(info2.size == info.size);
CHECK(info2.fname == info.fname);
}
else
{
REPORT2( false, "Search for Extra File (Basic)");
}
/* search with flags (should succeed) */
hintflags = RS_FILE_HINTS_EXTRA;
if (mFt->loadServer->FileDetails(info.hash, hintflags, info2))
{
CHECK(info2.hash == info.hash);
CHECK(info2.size == info.size);
CHECK(info2.fname == info.fname);
}
else
{
REPORT2( false, "Search for Extra File (Extra Flag)");
}
/* search with other flags (should fail) */
hintflags = RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY;
if (mFt->loadServer->FileDetails(info.hash, hintflags, info2))
{
REPORT2( false, "Search for Extra File (Fail Flags)");
}
else
{
REPORT("Search for Extra File (Fail Flags)");
}
/* if we try to download it ... should just find existing one*/
REPORT("Testing with Extra File");
}
FINALREPORT("ExtraList Hashing, Searching and Downloading");
exit(1);
}

View file

@ -1,464 +0,0 @@
/*
* libretroshare/src/ft: ftserver3test.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".
*
*/
/*
* ftServer3Test - Test of the file transfer from a server level.
* Steps:
* 1) load shared directories into others, and let them be
transferred between clients.
* 2) search for local item on others.
* 3) request item on load server.
should transfer from all others simultaneously.
*/
#ifdef WIN32
#include "util/rswin.h"
#endif
#include "rsiface/rsexpr.h"
#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 "util/rsdebug.h"
#include "ft/pqitestor.h"
#include "util/rsdir.h"
#include "util/utest.h"
#include <sstream>
class TestData
{
public:
ftServer *loadServer;
std::list<ftServer *> otherServers;
std::list<std::string> extraList;
};
extern "C" void *do_server_test_thread(void *p);
void usage(char *name)
{
std::cerr << "Usage: " << name << " [-soa] [-p <peerId>] [-d <debugLvl>] [-e <extrafile>] [<path> [<path2> ... ]] ";
std::cerr << std::endl;
}
int main(int argc, char **argv)
{
int c;
uint32_t period = 1;
uint32_t debugLevel = 5;
bool debugStderr = true;
bool loadAll = false;
bool loadOthers = false;
std::list<std::string> fileList;
std::list<std::string> extraList;
std::list<std::string> peerIds;
std::map<std::string, ftServer *> mFtServers;
std::map<std::string, p3ConnectMgr *> mConnMgrs;
ftServer *mLoadServer = NULL;
std::list<ftServer *> mOtherServers;
std::list<std::string>::iterator eit;
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
#endif
#ifdef WIN32
// Windows Networking Init.
WORD wVerReq = MAKEWORD(2,2);
WSADATA wsaData;
if (0 != WSAStartup(wVerReq, &wsaData))
{
std::cerr << "Failed to Startup Windows Networking";
std::cerr << std::endl;
}
else
{
std::cerr << "Started Windows Networking";
std::cerr << std::endl;
}
#endif
while(-1 != (c = getopt(argc, argv, "aosd:p:e:")))
{
switch (c)
{
case 'p':
peerIds.push_back(optarg);
break;
case 'd':
debugLevel = atoi(optarg);
break;
case 's':
debugStderr = true;
break;
case 'e':
extraList.push_back(optarg);
break;
case 'a':
loadAll = true;
break;
case 'o':
loadOthers = true;
break;
default:
usage(argv[0]);
break;
}
}
/* do logging */
setOutputLevel(debugLevel);
if (optind >= argc)
{
std::cerr << "Missing Shared Directories" << 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;
/* Add in Serialiser Test
*/
RsSerialiser *rss = new RsSerialiser();
rss->addSerialType(new RsFileItemSerialiser());
rss->addSerialType(new RsCacheItemSerialiser());
rss->addSerialType(new RsServiceSerialiser());
P3Hub *testHub = new P3Hub(0, rss);
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;
}
std::ostringstream pname;
pname << "/tmp/rstst-" << time(NULL);
std::string basepath = pname.str();
RsDirUtil::checkCreateDirectory(basepath);
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);
mConnMgrs[*it] = connMgr;
for(fit = friendList.begin(); fit != friendList.end(); fit++)
{
/* add as peer to authMgr */
connMgr->addFriend(fit->id);
}
P3Pipe *pipe = new P3Pipe(); //(*it);
/* add server */
ftServer *server;
server = new ftServer(authMgr, connMgr);
mFtServers[*it] = server;
bool isOther;
if (!mLoadServer)
{
mLoadServer = server;
isOther = false;
}
else
{
mOtherServers.push_back(server);
isOther = true;
}
server->setP3Interface(pipe);
std::string configpath = basepath + "/" + *it;
RsDirUtil::checkCreateDirectory(configpath);
std::string cachepath = configpath + "/cache";
RsDirUtil::checkCreateDirectory(cachepath);
std::string partialspath = configpath + "/partials";
RsDirUtil::checkCreateDirectory(partialspath);
std::string downloadpath = configpath + "/downloads";
RsDirUtil::checkCreateDirectory(downloadpath);
std::string localpath = cachepath + "/local";
RsDirUtil::checkCreateDirectory(localpath);
std::string remotepath = cachepath + "/remote";
RsDirUtil::checkCreateDirectory(remotepath);
server->setConfigDirectory(configpath);
NotifyBase *base = NULL;
server->SetupFtServer(base);
testHub->addP3Pipe(*it, pipe, connMgr);
server->StartupThreads();
/* setup any extra bits */
server->setPartialsDirectory(partialspath);
server->setDownloadDirectory(downloadpath);
if ((loadAll) || (isOther && loadOthers))
{
server->setSharedDirectories(fileList);
for(eit = extraList.begin(); eit != extraList.end(); eit++)
{
server->ExtraFileHash(*eit, 3600, 0);
}
}
}
if ((mLoadServer) && (!loadOthers))
{
mLoadServer->setSharedDirectories(fileList);
for(eit = extraList.begin(); eit != extraList.end(); eit++)
{
mLoadServer->ExtraFileHash(*eit, 3600, 0);
}
}
/* stick your real test here */
std::map<std::string, ftServer *>::iterator sit;
std::map<std::string, p3ConnectMgr *>::iterator cit;
/* Start up test thread */
pthread_t tid;
TestData *mFt = new TestData;
/* set data */
mFt->loadServer = mLoadServer;
mFt->otherServers = mOtherServers;
mFt->extraList = extraList;
void *data = (void *) mFt;
pthread_create(&tid, 0, &do_server_test_thread, data);
pthread_detach(tid); /* so memory is reclaimed in linux */
while(1)
{
//std::cerr << "ftserver3test::sleep()";
//std::cerr << std::endl;
sleep(1);
/* tick the connmgrs */
for(sit = mFtServers.begin(); sit != mFtServers.end(); sit++)
{
/* update */
(sit->second)->tick();
}
for(cit = mConnMgrs.begin(); cit != mConnMgrs.end(); cit++)
{
/* update */
(cit->second)->tick();
}
}
}
/* So our actual test can run here.....
*
*/
INITTEST();
void *do_server_test_thread(void *data)
{
TestData *mFt = (TestData *) data;
time_t startTS = time(NULL);
std::cerr << "do_server_test_thread() running";
std::cerr << std::endl;
/* search Others for a suitable file
* (Tests GUI search functionality)
*/
if (mFt->otherServers.size() < 1)
{
std::cerr << "no Other Servers to search on";
std::cerr << std::endl;
exit(1);
return NULL;
}
for(int i = 0; i < 90; i++)
{
int age = time(NULL) - startTS;
std::cerr << "Waited " << age << " seconds to share caches";
std::cerr << std::endl;
sleep(1);
}
ftServer *oServer = *(mFt->otherServers.begin());
std::string oId = oServer->OwnId();
/* create Expression */
uint64_t minFileSize = 100000;
//SizeExpression se(Greater, minFileSize);
SizeExpression se(Smaller, minFileSize);
Expression *expr = &se;
std::list<FileDetail> results;
std::list<FileDetail>::iterator it;
oServer->SearchBoolExp(expr, results);
if (results.size() < 1)
{
std::cerr << "no Shared Files > " << minFileSize;
std::cerr << std::endl;
exit(1);
return NULL;
}
/* find the first remote entry */
FileDetail sFile;
bool foundFile = false;
for(it = results.begin();
(it != results.end()); it++)
{
std::cerr << "Shared File: " << it->name;
std::cerr << std::endl;
if (!foundFile)
{
if (it->id != mFt->loadServer->OwnId())
{
std::cerr << "Selected: " << it->name;
std::cerr << std::endl;
foundFile = true;
sFile = *it;
}
else
{
std::cerr << "LoadId: ";
std::cerr << mFt->loadServer->OwnId();
std::cerr << "FileId: ";
std::cerr << it->id;
std::cerr << std::endl;
}
}
}
if (!foundFile)
{
std::cerr << "Not Found Suitable File";
std::cerr << std::endl;
}
/*** Now Download it! ***/
std::list<std::string> srcIds;
//srcIds.push_back(sFile.id);
// Don't add srcId - to test whether the search works - or not
//srcIds.push_back(oId);
if (foundFile)
{
mFt->loadServer->FileRequest(sFile.name, sFile.hash,
sFile.size, "", 0, srcIds);
}
/* Give it a while to transfer */
for(int i = 0; i < 100; i++)
{
int age = time(NULL) - startTS;
std::cerr << "Waited " << age << " seconds for tranfer";
std::cerr << std::endl;
sleep(1);
}
FINALREPORT("Shared Directories, Bool Search, multi-source transfers");
exit(1);
}

View file

@ -1,180 +0,0 @@
/*
* libretroshare/src/ft: fttransfermoduletest.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 Multiplexor.....
* As this is a key middle component, it is hard to test without other bits.
* It relies on ftFileProvider/ftFileCreator/ftTransferModule...
*
* And has dummy ftDataSend and ftSearch.
*
*/
#ifdef WIN32
#include "util/rswin.h"
#endif
#include "ft/ftextralist.h"
#include "ft/ftdatamultiplex.h"
#include "ft/ftfilesearch.h"
#include "ftfileprovider.h"
#include "ftfilecreator.h"
#include "ftcontroller.h"
#include "fttransfermodule.h"
#include "util/utest.h"
INITTEST()
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;
while(-1 != (c = getopt(argc, argv, "d:p:")))
{
switch (c)
{
case 'p':
period = atoi(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]));
}
ftExtraList *eList = new ftExtraList();
eList->start();
ftSearch *ftsd = new ftSearchDummy();
ftFileSearch *ftfs = new ftFileSearch();
ftfs-> addSearchMode(ftsd, RS_FILE_HINTS_LOCAL);
ftfs-> addSearchMode(eList, RS_FILE_HINTS_EXTRA);
ftDataSendPair *ftds1 = new ftDataSendPair(NULL);
ftDataSendPair *ftds2 = new ftDataSendPair(NULL);
/* setup Actual Test bit */
ftDataMultiplex *ftmplex1 = new ftDataMultiplex("ownId", ftds2, ftfs);
ftDataMultiplex *ftmplex2 = new ftDataMultiplex("ownId", ftds1, ftfs);
ftds1->mDataRecv = ftmplex1;
ftds2->mDataRecv = ftmplex2;
ftmplex1->start();
ftmplex2->start();
/* Setup Search with some valid results */
/* Request Data */
/* now work the thread */
std::list<std::string>::iterator it;
uint32_t flags = 0;
for(it = fileList.begin(); it != fileList.end(); it++)
{
eList->hashExtraFile(*it, dPeriod, flags);
}
if (fileList.size() < 1)
{
std::cerr << "come on, give us some files...";
std::cerr << std::endl;
return 0;
}
/* now request files from ftDataMultiplex
* by adding in a ftTransferModule!
*/
std::string filename = *(fileList.begin());
/* wait for file to hash */
FileInfo info;
while(!eList->hashExtraFileDone(filename, info))
{
std::cerr << "Waiting for file to hash";
std::cerr << std::endl;
sleep(1);
}
std::string savename = "/tmp/" + info.fname;
ftFileCreator *creator = new ftFileCreator(savename, info.size, info.hash, 0);
ftController *controller = NULL;
ftTransferModule *transfer = new ftTransferModule(creator, ftmplex1, controller);
ftmplex1->addTransferModule(transfer, creator);
std::list<std::string> peerIds;
peerIds.push_back("ownId2");
transfer->setFileSources(peerIds);
transfer->setPeerState("ownId2", PQIPEER_IDLE, 1000);
//transfer->resumeTransfer();
/* check file progress */
while(1)
{
std::cerr << "File Transfer Status";
std::cerr << std::endl;
std::cerr << "Transfered: " << creator->getRecvd();
std::cerr << std::endl;
transfer->tick();
sleep(1);
}
}