* fixed ftdata testharness functions (ftdata.h)

* Added existing ft tests to tests directory (don't work yet!)
 * Added dbase tests to tests directory (don't work yet!)
 * moved net_setup test to tests/general directory (don't work yet!)



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3176 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-06-20 12:24:05 +00:00
parent bf6f74c16a
commit 05bc4ba76e
22 changed files with 3288 additions and 23 deletions

View File

@ -33,50 +33,89 @@ ftDataSendPair::ftDataSendPair(ftDataRecv *recv)
}
/* Client Send */
bool ftDataSendPair::sendDataRequest(std::string peerId, std::string hash,
bool ftDataSendPair::sendDataRequest(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize)
{
return mDataRecv->recvDataRequest(peerId,hash,size,offset,chunksize);
}
/* Server Send */
bool ftDataSendPair::sendData(std::string peerId,
std::string hash, uint64_t size,
uint64_t offset, uint32_t chunksize, void *data)
bool ftDataSendPair::sendData(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
{
return mDataRecv->recvData(peerId, hash,size,offset,chunksize,data);
}
/* Send a request for a chunk map */
bool ftDataSendPair::sendChunkMapRequest(const std::string& peer_id,const std::string& hash)
{
bool is_client = true; // What should this be???
return mDataRecv->recvChunkMapRequest(peer_id,hash,is_client);
}
/* Send a chunk map */
bool ftDataSendPair::sendChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap)
{
bool is_client = true; // What should this be???
return mDataRecv->recvChunkMap(peer_id,hash,cmap, is_client);
}
/* Client Send */
bool ftDataSendDummy::sendDataRequest(std::string peerId, std::string hash,
bool ftDataSendDummy::sendDataRequest(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize)
{
return true;
}
/* Server Send */
bool ftDataSendDummy::sendData(std::string peerId,
std::string hash, uint64_t size,
uint64_t offset, uint32_t chunksize, void *data)
bool ftDataSendDummy::sendData(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
{
return true;
}
/* Send a request for a chunk map */
bool ftDataSendDummy::sendChunkMapRequest(const std::string& peer_id,const std::string& hash)
{
return true;
}
/* Send a chunk map */
bool ftDataSendDummy::sendChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap)
{
return true;
}
/* Client Recv */
bool ftDataRecvDummy::recvData(std::string peerId,
std::string hash, uint64_t size,
uint64_t offset, uint32_t chunksize, void *data)
bool ftDataRecvDummy::recvData(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize, void *data)
{
return true;
}
/* Server Recv */
bool ftDataRecvDummy::recvDataRequest(std::string peerId, std::string hash,
bool ftDataRecvDummy::recvDataRequest(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize)
{
return true;
}
/* Send a request for a chunk map */
bool ftDataRecvDummy::recvChunkMapRequest(const std::string& peer_id,const std::string& hash,
bool is_client)
{
return true;
}
/* Send a chunk map */
bool ftDataRecvDummy::recvChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap,bool is_client)
{
return true;
}

View File

@ -81,6 +81,8 @@ class ftDataRecv
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,const CompressedChunkMap& cmap,bool is_client) = 0;
};
/**************** FOR TESTING ***********************/
/******* Pair of Send/Recv (Only need to handle Send side) ******/
class ftDataSendPair: public ftDataSend
{
@ -90,13 +92,20 @@ class ftDataSendPair: public ftDataSend
virtual ~ftDataSendPair() { return; }
/* Client Send */
virtual bool sendDataRequest(std::string peerId, std::string hash,
virtual bool sendDataRequest(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize);
/* Server Send */
virtual bool sendData(std::string peerId, std::string hash, uint64_t size,
virtual bool sendData(const std::string &peerId, const std::string &hash, uint64_t size,
uint64_t offset, uint32_t chunksize, void *data);
/* Send a request for a chunk map */
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash);
/* Send a chunk map */
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap);
ftDataRecv *mDataRecv;
};
@ -107,13 +116,20 @@ class ftDataSendDummy: public ftDataSend
virtual ~ftDataSendDummy() { return; }
/* Client Send */
virtual bool sendDataRequest(std::string peerId, std::string hash,
virtual bool sendDataRequest(const std::string &peerId, const std::string &hash,
uint64_t size, uint64_t offset, uint32_t chunksize);
/* Server Send */
virtual bool sendData(std::string peerId, std::string hash, uint64_t size,
virtual bool sendData(const std::string &peerId, const std::string &hash, uint64_t size,
uint64_t offset, uint32_t chunksize, void *data);
/* Send a request for a chunk map */
virtual bool sendChunkMapRequest(const std::string& peer_id,const std::string& hash);
/* Send a chunk map */
virtual bool sendChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap);
};
class ftDataRecvDummy: public ftDataRecv
@ -123,13 +139,20 @@ class ftDataRecvDummy: public ftDataRecv
virtual ~ftDataRecvDummy() { return; }
/* Client Recv */
virtual bool recvData(std::string peerId, std::string hash, uint64_t size,
uint64_t offset, uint32_t chunksize, void *data);
virtual bool recvData(const std::string& peerId, const std::string& hash,
uint64_t size, uint64_t offset, uint32_t chunksize, void *data);
/* Server Recv */
virtual bool recvDataRequest(std::string peerId, std::string hash,
uint64_t size, uint64_t offset, uint32_t chunksize);
virtual bool recvDataRequest(const std::string& peerId, const std::string& hash,
uint64_t size, uint64_t offset, uint32_t chunksize);
/* Send a request for a chunk map */
virtual bool recvChunkMapRequest(const std::string& peer_id,const std::string& hash,
bool is_client);
/* Send a chunk map */
virtual bool recvChunkMap(const std::string& peer_id,const std::string& hash,
const CompressedChunkMap& cmap,bool is_client);
};

View File

@ -0,0 +1,21 @@
This file documents the high-level status of the regression cases.
------------------------------------------------------------------------------------
DIRECTORY STATUS TODO
------------------------------------------------------------------------------------
services : NO TESTS write test framework for services.
turtle : NO TESTS write tests
rsserver : NO TESTS write tests
upnp : NO TESTS write tests.
util : limited manual tests complete tests, convert to automatic
dbase : limited manual tests complete tests, convert to automatic
pqi : limited manual tests complete tests, convert to automatic
ft : manual tests complete tests, convert to automatic
tcponudp : manual tests convert to automatic
dht : manual tests ignore - old code - to be replaced soon.
serialiser : automatic tests complete tests, update tests.

View File

@ -0,0 +1,53 @@
RS_TOP_DIR = ../..
##### Define any flags that are needed for this section #######
###############################################################
###############################################################
include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
TESTOBJ = fitest2.o fisavetest.o searchtest.o
#ficachetest.o
TESTS = fitest2 fisavetest searchtest
#ficachetest
ifeq ($(OS),Linux)
TESTOBJ += fimontest.o
TESTS += fimontest
endif
ifeq ($(OS),MacOSX)
TESTOBJ += fimontest.o
TESTS += fimontest
endif
all: tests
fitest2 : fitest2.o $(OBJ)
$(CC) $(CFLAGS) -o fitest2 fitest2.o $(OBJ) $(LIBS)
fisavetest : fisavetest.o $(OBJ)
$(CC) $(CFLAGS) -o fisavetest fisavetest.o $(OBJ) $(LIBS)
fimontest : fimontest.o $(OBJ)
$(CC) $(CFLAGS) -o fimontest fimontest.o $(OBJ) $(LIBS)
ficachetest : ficachetest.o $(OBJ)
$(CC) $(CFLAGS) -o ficachetest ficachetest.o $(OBJ) $(LIBS)
searchtest : searchtest.o $(OBJ)
$(CC) $(CFLAGS) -o searchtest searchtest.o $(OBJ) $(LIBS)
clobber: rmtestfiles
rmtestfiles:
$(RM) test.index
###############################################################
include $(RS_TOP_DIR)/tests/scripts/rules.mk
###############################################################

View File

@ -0,0 +1,207 @@
/*
* RetroShare FileCache Module: ficachetest.cc
*
* Copyright 2004-2007 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 "dbase/cachestrapper.h"
#include "dbase/cachetest.h"
#include <iostream>
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
#else
#include <windows.h>
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
void handleQuery(CacheStrapper *csp, RsPeerId pid,
std::map<RsPeerId, CacheStrapper *> &strappers);
/* A simple test of the CacheStrapper Code.
*
* create 3 different CacheStrappers, each with a Source/Store Pair and Transfer Class.
* pass queries and responses between the CacheStrappers,
* and ensure that the hashes in the Caches are updated.
*
*/
int main(int argc, char **argv)
{
time_t period = 11;
RsPeerId pid1("0x0101");
RsPeerId pid2("0x0102");
RsPeerId pid3("0x0103");
p3ConnectMgr *connMgr1 = NULL;
p3ConnectMgr *connMgr2 = NULL;
p3ConnectMgr *connMgr3 = NULL;
CacheStrapper sc1(connMgr1);
CacheStrapper sc2(connMgr2);
CacheStrapper sc3(connMgr3);
CacheTransfer ctt1(&sc1);
CacheTransfer ctt2(&sc2);
CacheTransfer ctt3(&sc3);
std::map<RsPeerId, CacheStrapper *> strappers;
strappers[pid1] = &sc1;
strappers[pid2] = &sc2;
strappers[pid3] = &sc3;
std::string nulldir = "";
CacheSource *csrc1 = new CacheTestSource(&sc1, nulldir);
CacheStore *cstore1 = new CacheTestStore(&ctt1, nulldir);
CacheId cid1(TESTID, 0);
CacheSource *csrc2 = new CacheTestSource(&sc2, nulldir);
CacheStore *cstore2 = new CacheTestStore(&ctt2, nulldir);
CacheId cid2(TESTID, 0);
CacheSource *csrc3 = new CacheTestSource(&sc3, nulldir);
CacheStore *cstore3 = new CacheTestStore(&ctt3, nulldir);
CacheId cid3(TESTID, 0);
CachePair cp1(csrc1, cstore1, cid1);
CachePair cp2(csrc2, cstore2, cid2);
CachePair cp3(csrc3, cstore3, cid3);
sc1.addCachePair(cp1);
sc2.addCachePair(cp2);
sc3.addCachePair(cp3);
/* add in a cache to sc2 */
CacheData cdata;
cdata.pid = pid1;
cdata.cid = cid1;
cdata.name = "Perm Cache";
cdata.path = "./";
cdata.hash = "GHJKI";
csrc1->refreshCache(cdata);
cdata.pid = pid2;
cdata.cid = cid2;
cdata.name = "Funny Cache";
cdata.path = "./";
cdata.hash = "ABCDEF";
csrc2->refreshCache(cdata);
/* now exercise it */
for(int i = 0; 1 ; i++)
{
RsPeerId src("");
CacheStrapper *csp = NULL;
if (i % 5 == 1)
{
src = pid1;
csp = &sc1;
}
else if (i % 5 == 2)
{
src = pid2;
csp = &sc2;
}
else if (i % 5 == 3)
{
src = pid3;
csp = &sc3;
}
std::cerr << std::endl;
std::cerr << "Cache Iteraton: " << time(NULL) << std::endl;
std::cerr << std::endl;
if (src != "")
{
handleQuery(csp, src, strappers);
}
if (i % 21 == 0)
{
/* print out the resources */
sc1.listCaches(std::cerr);
sc2.listCaches(std::cerr);
sc3.listCaches(std::cerr);
}
/* every once in a while change the cache on 2 */
if (i % 31 == 25)
{
cdata.hash += "X";
csrc2->refreshCache(cdata);
}
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
sleep(1);
#else
Sleep(1000);
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
/* tick the systems */
}
/* Cleanup - TODO */
return 1;
}
void handleQuery(CacheStrapper *csp, RsPeerId pid,
std::map<RsPeerId, CacheStrapper *> &strappers)
{
/* query */
std::list<RsPeerId> ids;
std::list<RsPeerId>::iterator pit;
std::cerr << "Cache Query from: " << pid << std::endl;
csp -> sendCacheQuery(ids, time(NULL));
for(pit = ids.begin(); pit != ids.end(); pit++)
{
std::cerr << "Cache Query for: " << (*pit) << std::endl;
std::map<RsPeerId, CacheStrapper *>::iterator sit;
if (strappers.end() != (sit = strappers.find(*pit)))
{
std::map<CacheId, CacheData> hashs;
std::map<CacheId, CacheData>::iterator hit;
(sit -> second) -> handleCacheQuery(pid, hashs);
for(hit = hashs.begin(); hit != hashs.end(); hit++)
{
csp -> recvCacheResponse(hit->second, time(NULL));
}
}
else
{
std::cerr << "Unknown Query Destination!" << std::endl;
}
}
}

View File

@ -0,0 +1,90 @@
/*
* RetroShare FileCache Module: fimontest.cc
*
* Copyright 2004-2007 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 "dbase/findex.h"
#include "dbase/fimonitor.h"
#include <iostream>
void usage(char *name)
{
std::cerr << "Usage: " << name << " [-p <period> ] shareDir1 [shareDir2 [shareDir3 [...]]]";
std::cerr << std::endl;
exit(1);
}
int main(int argc, char **argv)
{
/* handle commandline arguments */
int c;
int period = 60; /* recheck period in seconds */
while((c = getopt(argc, argv,"p:")) != -1)
{
switch(c)
{
case 'p':
period = atoi(optarg);
break;
default:
std::cerr << "Bad Option.";
std::cerr << std::endl;
usage(argv[0]);
break;
}
}
std::list<SharedDirInfo> rootdirs;
/* add all the rest of the commandline arguments to rootdirs list */
for(; optind < argc; optind++)
{
SharedDirInfo dir;
dir.filename = argv[optind];
dir.shareflags = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE;
rootdirs.push_back(dir);
std::cerr << "Adding shared directory: " << argv[optind] << std::endl;
}
if (rootdirs.size() < 1)
{
usage(argv[0]);
}
sleep(1);
FileIndexMonitor mon(NULL,NULL, "", "OWN ID");
/* setup monitor */
mon.setPeriod(period);
mon.setSharedDirectories(rootdirs);
/* simulate running the thread */
mon.run();
return 1;
}

View File

@ -0,0 +1,119 @@
/*
* RetroShare FileCache Module: fisavetest.cc
*
* Copyright 2004-2007 by Kefei Zhou.
*
* 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 "dbase/findex.h"
#include <iostream>
FileIndex *createBasicFileIndex(time_t age);
int main()
{
FileIndex *fi1 = createBasicFileIndex(100);
FileIndex *fi2 = new FileIndex("A SILLY ID");
fi1->printFileIndex(std::cout);
std::string fhash;
uint64_t size;
std::set<std::string> forbiddenroots;
fi1->saveIndex("test.index", fhash, size, forbiddenroots);
std::cout << " Saved Index: Size: " << size << " Hash: " << fhash << std::endl;
std::cout << " -- new file index -- " << std::endl;
fi2->loadIndex("test.index", fhash, size);
fi2->printFileIndex(std::cout);
delete fi1;
delete fi2;
return 1;
}
FileIndex *createBasicFileIndex(time_t age)
{
FileIndex *fi = new FileIndex("A SILLY ID");
FileEntry fe;
std::list<std::string> rootdirs;
rootdirs.push_back("base1");
rootdirs.push_back("base2");
rootdirs.push_back("base3");
fi -> setRootDirectories(rootdirs, age);
/* add some entries */
fe.name = "dir1";
fi -> updateDirEntry("base1",fe, age);
fe.name = "dir2";
fi -> updateDirEntry("base1",fe, age);
fe.name = "dir01";
fi -> updateDirEntry("/base1/dir1/",fe, age);
fe.name = "dir001";
fi -> updateDirEntry("/base1/dir1/dir01/",fe, age);
fe.name = "file1";
fi -> updateFileEntry("/base1/dir1/",fe, age);
fe.name = "file2";
fi -> updateFileEntry("/base1/dir1/",fe, age);
fe.name = "file3";
fi -> updateFileEntry("/base1/dir1/",fe, age);
fe.name = "file4";
fi -> updateFileEntry("/base1/dir1/",fe, age);
fe.name = "dir2";
fi -> updateDirEntry("/base1",fe, age);
fe.name = "file5";
fi -> updateFileEntry("/base1/dir2/",fe, age);
fe.name = "file6";
fi -> updateFileEntry("/base1/dir2/",fe, age);
fe.name = "file7";
fi -> updateFileEntry("/base1/dir2/",fe, age);
fe.name = "file8";
fi -> updateFileEntry("/base1/",fe, age);
fe.name = "dir3";
fi -> updateDirEntry("/base1/dir2/",fe, age);
fe.name = "file10";
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
fe.name = "file11";
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
fe.name = "file12";
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
fe.name = "dir4";
fi -> updateDirEntry("/base3/",fe, age);
fe.name = "file20";
fi -> updateFileEntry("/base3/dir4/",fe, age);
fe.name = "file21";
fi -> updateFileEntry("/base3/dir4",fe, age);
return fi;
}

View File

@ -0,0 +1,213 @@
/*
* RetroShare FileCache Module: fitest2.cc
*
* Copyright 2004-2007 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 "dbase/findex.h"
#include <iostream>
FileIndex *createBasicFileIndex(time_t age);
int test1(FileIndex *fi);
int test2(FileIndex *fi);
int main()
{
FileIndex *fi = createBasicFileIndex(100);
test1(fi);
delete fi;
return 1;
}
int test1(FileIndex *fi)
{
/* in this test we are going to get the old directories - and update them */
time_t stamp = 200;
DirEntry *olddir = NULL;
FileEntry fe;
while((olddir = fi -> findOldDirectory(stamp)))
{
/* update the directories and files here */
std::map<std::string, DirEntry *>::iterator dit;
std::map<std::string, FileEntry *>::iterator fit;
/* update this dir */
fe.name = olddir->name;
fi -> updateDirEntry(olddir->parent->path, fe, stamp);
/* update subdirs */
for(dit = olddir->subdirs.begin(); dit != olddir->subdirs.end(); dit++)
{
fe.name = (dit->second)->name;
/* set the age as out-of-date so that it gets checked */
fi -> updateDirEntry(olddir->path, fe, 0);
}
/* update files */
for(fit = olddir->files.begin(); fit != olddir->files.end(); fit++)
{
fe.name = (fit->second)->name;
fi -> updateFileEntry(olddir->path, fe, stamp);
}
/* clean up the dir (should have no effect) */
fi -> removeOldDirectory(olddir->parent->path, olddir->name, stamp);
fi -> printFileIndex(std::cout);
}
fi -> printFileIndex(std::cout);
return 1;
}
int test2(FileIndex *fi)
{
/* in this test we are going to simulate that 2 directories have disappeared */
time_t stamp = 200;
DirEntry *olddir = NULL;
FileEntry fe;
bool missingdir = false;
int i = 0;
while((olddir = fi -> findOldDirectory(stamp)))
{
missingdir = false;
if (i % 2 == 0)
{
std::cerr << " Simulating that dir doesnt exist :" << olddir->path;
std::cerr << std::endl;
missingdir = true;
}
i++;
if (!missingdir)
{
/* update the directories and files here */
std::map<std::string, DirEntry *>::iterator dit;
std::map<std::string, FileEntry *>::iterator fit;
/* update this dir */
fe.name = olddir->name;
fi -> updateDirEntry(olddir->parent->path, fe, stamp);
/* update subdirs */
for(dit = olddir->subdirs.begin(); dit != olddir->subdirs.end(); dit++)
{
fe.name = (dit->second)->name;
/* set the age as out-of-date so that it gets checked */
fi -> updateDirEntry(olddir->path, fe, 0);
}
/* update files */
for(fit = olddir->files.begin(); fit != olddir->files.end(); fit++)
{
fe.name = (fit->second)->name;
fi -> updateFileEntry(olddir->path, fe, stamp);
}
}
/* clean up the dir */
fi -> removeOldDirectory(olddir->parent->path, olddir->name, stamp);
fi -> printFileIndex(std::cout);
}
fi -> printFileIndex(std::cout);
return 1;
}
FileIndex *createBasicFileIndex(time_t age)
{
FileIndex *fi = new FileIndex("A SILLY ID");
FileEntry fe;
/* print empty FileIndex */
fi -> printFileIndex(std::cout);
std::list<std::string> rootdirs;
rootdirs.push_back("base1");
rootdirs.push_back("base2");
rootdirs.push_back("base3");
fi -> setRootDirectories(rootdirs, age);
/* add some entries */
fe.name = "dir1";
fi -> updateDirEntry("base1",fe, age);
fe.name = "file1";
fi -> updateFileEntry("/base1/dir1/",fe, age);
fe.name = "file2";
fi -> updateFileEntry("/base1/dir1/",fe, age);
fe.name = "file3";
fi -> updateFileEntry("/base1/dir1/",fe, age);
fe.name = "file4";
fi -> updateFileEntry("/base1/dir1/",fe, age);
fe.name = "dir2";
fi -> updateDirEntry("/base1",fe, age);
fe.name = "file5";
fi -> updateFileEntry("/base1/dir2/",fe, age);
fe.name = "file6";
fi -> updateFileEntry("/base1/dir2/",fe, age);
fe.name = "file7";
fi -> updateFileEntry("/base1/dir2/",fe, age);
fe.name = "file8";
fi -> updateFileEntry("/base1/",fe, age);
fe.name = "dir3";
fi -> updateDirEntry("/base1/dir2/",fe, age);
fe.name = "file10";
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
fe.name = "file11";
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
fe.name = "file12";
fi -> updateFileEntry("/base1/dir2/dir3",fe, age);
fe.name = "dir4";
fi -> updateDirEntry("/base3/",fe, age);
fe.name = "file20";
fi -> updateFileEntry("/base3/dir4/",fe, age);
fe.name = "file21";
fi -> updateFileEntry("/base3/dir4",fe, age);
// one that will fail.
fe.name = "file20";
fi -> updateFileEntry("/base3/",fe, age);
fi -> printFileIndex(std::cout);
return fi;
}

View File

@ -0,0 +1,74 @@
/*
* RetroShare FileCache Module: searchtest.cc
*
* Copyright 2004-2007 by Kefei Zhou.
*
* 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 "dbase/findex.h"
#include <iostream>
#include <fstream>
int main()
{
std::cout << std::string::npos << std::endl;
std::string testfile = "searchtest.index";
std::string fhash = "6851c28d99a6616a86942c3914476bf11997242a";
FileIndex *fi = new FileIndex("DUMB ID");
// loading fileindex
std::cout << std::endl << "Test load" << std::endl;
fi->loadIndex(testfile, fhash, 1532);
fi->printFileIndex(std::cout);
std::cout << "FileIndex Loaded" << std::endl << std::endl;
std::list<FileEntry *> hashresult;
std::list<FileEntry *> termresult;
// searchhash
std::string findhash = "82bffa6e1cdf8419397311789391238174817481";
std::cout << "Search hash : " << findhash << std::endl;
fi->searchHash(findhash, hashresult);
while(!hashresult.empty())
{
hashresult.back()->print(std::cout);
hashresult.pop_back();
}
// searchterm
std::list<std::string> terms;
terms.push_back("paper");
terms.push_back("doc");
std::cout << "Search terms" << std::endl;
fi->searchTerms(terms, termresult);
while(!termresult.empty())
{
termresult.back()->print(std::cout);
termresult.pop_back();
}
delete fi;
return 1;
}

View File

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

View File

@ -0,0 +1,411 @@
/*
* 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

@ -0,0 +1,178 @@
/*
* 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

@ -0,0 +1,166 @@
/*
* 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, 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

@ -0,0 +1,130 @@
#include "ft/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");
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;
uint32_t size_hint = 1000;
std::string peer_id = "dummyId";
bool toOld = false;
for(i = 0; i < max_timeout; i++)
{
creator->getMissingChunk(peer_id, size_hint, offset, chunk, toOld);
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(peer_id, size_hint, offset, chunk, toOld);
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;
uint32_t size_hint = 1000;
std::string peer_id = "dummyId";
bool toOld = false;
while(creator->getMissingChunk(peer_id, size_hint, offset, chunk, toOld))
{
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

@ -0,0 +1,96 @@
#include "ft/ftfileprovider.h"
#include "ft/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");
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");
ftFileProvider *provider = new ftFileProvider(filename, size, "hash");
/* create duplicate with file creator */
std::string peer_id = "dummyId";
uint32_t size_hint = 10000;
bool toOld = false;
while(creator->getMissingChunk(peer_id, size_hint, offset, chunk, toOld))
{
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

@ -0,0 +1,329 @@
/*
* 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

@ -0,0 +1,424 @@
/*
* 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

@ -0,0 +1,464 @@
/*
* 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

@ -0,0 +1,180 @@
/*
* 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 "ft/ftfileprovider.h"
#include "ft/ftfilecreator.h"
#include "ft/ftcontroller.h"
#include "ft/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);
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);
}
}

View File

@ -1,10 +1,10 @@
RS_TOP_DIR = ..
RS_TOP_DIR = ../..
##### Define any flags that are needed for this section #######
###############################################################
###############################################################
include $(RS_TOP_DIR)/scripts/config.mk
include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
TESTOBJ = netsetup_test.o
@ -16,6 +16,6 @@ netsetup_test: netsetup_test.o
$(CC) $(CFLAGS) -o netsetup_test netsetup_test.o $(LIBS)
###############################################################
include $(RS_TOP_DIR)/scripts/rules.mk
include $(RS_TOP_DIR)/tests/scripts/rules.mk
###############################################################

View File

@ -63,6 +63,7 @@ ifdef PQI_USE_XPGP
LIBS += -lssl -lcrypto -lpthread
#LIBS += -L$(UPNPC_DIR) -lminiupnpc
LIBS += $(XLIB) -ldl -lz
LIBS += -lupnp
LIBS += -lgpgme
RSLIBS = $(LIBS)