diff --git a/libretroshare/src/dbase/Makefile b/libretroshare/src/dbase/Makefile deleted file mode 100644 index 2464b9495..000000000 --- a/libretroshare/src/dbase/Makefile +++ /dev/null @@ -1,51 +0,0 @@ - -RS_TOP_DIR = .. -##### Define any flags that are needed for this section ####### -############################################################### - -############################################################### -include $(RS_TOP_DIR)/scripts/config.mk -############################################################### - -RSOBJ = findex.o fimonitor.o cachestrapper.o fistore.o \ - rsexpr.o - -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: librs 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) - -############################################################### -include $(RS_TOP_DIR)/scripts/rules.mk -############################################################### - diff --git a/libretroshare/src/dbase/ficachetest.cc b/libretroshare/src/dbase/ficachetest.cc deleted file mode 100644 index 547776cfa..000000000 --- a/libretroshare/src/dbase/ficachetest.cc +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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 "cachestrapper.h" -#include "cachetest.h" - -#include -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ -#ifndef WINDOWS_SYS -#else - #include -#endif -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ - - -void handleQuery(CacheStrapper *csp, RsPeerId pid, - std::map &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 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 &strappers) -{ - /* query */ - std::list ids; - std::list::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::iterator sit; - if (strappers.end() != (sit = strappers.find(*pit))) - { - std::map hashs; - std::map::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; - } - } -} - diff --git a/libretroshare/src/dbase/fimontest.cc b/libretroshare/src/dbase/fimontest.cc deleted file mode 100644 index f3945c870..000000000 --- a/libretroshare/src/dbase/fimontest.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 "findex.h" -#include "fimonitor.h" - -#include - -void usage(char *name) -{ - std::cerr << "Usage: " << name << " [-p ] 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 rootdirs; - - /* add all the rest of the commandline arguments to rootdirs list */ - for(; optind < argc; optind++) - { - rootdirs.push_back(argv[optind]); - 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; -} - - diff --git a/libretroshare/src/dbase/fisavetest.cc b/libretroshare/src/dbase/fisavetest.cc deleted file mode 100644 index f1a6d2bec..000000000 --- a/libretroshare/src/dbase/fisavetest.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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 - -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; - fi1->saveIndex("test.index", fhash, size); - - 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 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; -} - diff --git a/libretroshare/src/dbase/fitest2.cc b/libretroshare/src/dbase/fitest2.cc deleted file mode 100644 index 7d1fc4c9a..000000000 --- a/libretroshare/src/dbase/fitest2.cc +++ /dev/null @@ -1,213 +0,0 @@ -/* - * 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 - -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::iterator dit; - std::map::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::iterator dit; - std::map::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 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; -} - diff --git a/libretroshare/src/dbase/searchtest.cc b/libretroshare/src/dbase/searchtest.cc deleted file mode 100644 index 2bd4bffa0..000000000 --- a/libretroshare/src/dbase/searchtest.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 -#include - -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 hashresult; - std::list 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 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; -} diff --git a/libretroshare/src/ft/Makefile b/libretroshare/src/ft/Makefile deleted file mode 100644 index a252472b5..000000000 --- a/libretroshare/src/ft/Makefile +++ /dev/null @@ -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 -############################################################### - - diff --git a/libretroshare/src/ft/ftcontrollertest.cc b/libretroshare/src/ft/ftcontrollertest.cc deleted file mode 100755 index 66b0ddbec..000000000 --- a/libretroshare/src/ft/ftcontrollertest.cc +++ /dev/null @@ -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 - - -class TestData -{ - public: - - ftServer *loadServer; - std::list otherServers; - std::list extraList; -}; - - -extern "C" void *do_server_test_thread(void *p); - - -void usage(char *name) -{ - std::cerr << "Usage: " << name << " [-sa] [-p ] [-d ] [-e ] [ [ ... ]] "; - 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 fileList; - std::list extraList; - std::list peerIds; - std::map mFtServers; - std::map mConnMgrs; - - ftServer *mLoadServer = NULL; - std::list mOtherServers; - std::list::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::const_iterator it, jit; - - std::list baseFriendList, friendList; - std::list::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::iterator sit; - std::map::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::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 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 srcIds; - srcIds.push_back(details.id); - server->FileRequest(details.name, details.hash, - details.count, "", 0, srcIds); - } - - exit(1); -} - - - - diff --git a/libretroshare/src/ft/ftdataplextest.cc b/libretroshare/src/ft/ftdataplextest.cc deleted file mode 100644 index 4736e5b57..000000000 --- a/libretroshare/src/ft/ftdataplextest.cc +++ /dev/null @@ -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 &files); - - -void usage(char *name) -{ - std::cerr << "Usage: " << name << " [-p ] [-d ] [ ... ] "; - 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 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::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 &files) -{ - std::cerr << "do_random_server_iteration()"; - std::cerr << std::endl; - - std::list::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 &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); - } -} - - diff --git a/libretroshare/src/ft/ftextralisttest.cc b/libretroshare/src/ft/ftextralisttest.cc deleted file mode 100644 index dd9e266e9..000000000 --- a/libretroshare/src/ft/ftextralisttest.cc +++ /dev/null @@ -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 toHash, std::list hashed); - - -void usage(char *name) -{ - std::cerr << "Usage: " << name << " -h -p -d "; - 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 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 toHash; - std::list hashed; - std::list::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 toHash, std::list hashed) -{ - std::cerr << "displayExtraListDetails()"; - std::cerr << std::endl; - - std::list::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; - } - } -} - - - diff --git a/libretroshare/src/ft/ftfilecreatortest.cc b/libretroshare/src/ft/ftfilecreatortest.cc deleted file mode 100644 index 907cf406f..000000000 --- a/libretroshare/src/ft/ftfilecreatortest.cc +++ /dev/null @@ -1,122 +0,0 @@ -#include "ftfilecreator.h" - -#include "util/utest.h" -#include - -#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; -} - diff --git a/libretroshare/src/ft/ftfileprovidertest.cc b/libretroshare/src/ft/ftfileprovidertest.cc deleted file mode 100644 index 26808e7d1..000000000 --- a/libretroshare/src/ft/ftfileprovidertest.cc +++ /dev/null @@ -1,93 +0,0 @@ -#include "ftfileprovider.h" -#include "ftfilecreator.h" - -#include "util/utest.h" -#include - -#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; -} diff --git a/libretroshare/src/ft/ftserver1test.cc b/libretroshare/src/ft/ftserver1test.cc deleted file mode 100644 index 406105e52..000000000 --- a/libretroshare/src/ft/ftserver1test.cc +++ /dev/null @@ -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 - - - -void do_random_server_test(ftDataMultiplex *mplex, ftExtraList *eList, std::list &files); - - -void usage(char *name) -{ - std::cerr << "Usage: " << name << " [-p ] [-d ] [ ... ] "; - 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 fileList; - std::list peerIds; - std::map mFtServers; - std::map 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::const_iterator it, jit; - - std::list baseFriendList, friendList; - std::list::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::iterator sit; - std::map::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 &files) -{ - std::cerr << "do_random_server_iteration()"; - std::cerr << std::endl; - - std::list::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 &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 - diff --git a/libretroshare/src/ft/ftserver2test.cc b/libretroshare/src/ft/ftserver2test.cc deleted file mode 100644 index db58aab9a..000000000 --- a/libretroshare/src/ft/ftserver2test.cc +++ /dev/null @@ -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 - - -class TestData -{ - public: - - ftServer *loadServer; - std::list otherServers; - std::list extraList; -}; - - -extern "C" void *do_server_test_thread(void *p); - - -void usage(char *name) -{ - std::cerr << "Usage: " << name << " [-sa] [-p ] [-d ] [-e ] [ [ ... ]] "; - 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 fileList; - std::list extraList; - std::list peerIds; - std::map mFtServers; - std::map mConnMgrs; - - ftServer *mLoadServer = NULL; - std::list mOtherServers; - std::list::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::const_iterator it, jit; - - std::list baseFriendList, friendList; - std::list::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::iterator sit; - std::map::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::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); -} - - - - diff --git a/libretroshare/src/ft/ftserver3test.cc b/libretroshare/src/ft/ftserver3test.cc deleted file mode 100644 index 045da5976..000000000 --- a/libretroshare/src/ft/ftserver3test.cc +++ /dev/null @@ -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 - - -class TestData -{ - public: - - ftServer *loadServer; - std::list otherServers; - std::list extraList; -}; - - -extern "C" void *do_server_test_thread(void *p); - - -void usage(char *name) -{ - std::cerr << "Usage: " << name << " [-soa] [-p ] [-d ] [-e ] [ [ ... ]] "; - 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 fileList; - std::list extraList; - std::list peerIds; - std::map mFtServers; - std::map mConnMgrs; - - ftServer *mLoadServer = NULL; - std::list mOtherServers; - std::list::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::const_iterator it, jit; - - std::list baseFriendList, friendList; - std::list::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::iterator sit; - std::map::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 results; - std::list::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 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); -} - - - - diff --git a/libretroshare/src/ft/fttransfermoduletest.cc b/libretroshare/src/ft/fttransfermoduletest.cc deleted file mode 100644 index 0370a841e..000000000 --- a/libretroshare/src/ft/fttransfermoduletest.cc +++ /dev/null @@ -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 &files); - - -void usage(char *name) -{ - std::cerr << "Usage: " << name << " [-p ] [-d ] [ ... ] "; - 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 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::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 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); - } -} - diff --git a/libretroshare/src/serialiser/Makefile b/libretroshare/src/serialiser/Makefile deleted file mode 100644 index 98bf62bf4..000000000 --- a/libretroshare/src/serialiser/Makefile +++ /dev/null @@ -1,75 +0,0 @@ - -RS_TOP_DIR = .. -##### Define any flags that are needed for this section ####### -############################################################### - -############################################################### -include $(RS_TOP_DIR)/scripts/config.mk -############################################################### - -RSOBJ = rsserial.o rsbaseserial.o rstlvbase.o rstlvtypes.o -RSOBJ += rstlvfileitem.o # TLV Objs -RSOBJ += rstlvkeys.o # TLV Objs -RSOBJ += rstlvimage.o # TLV Objs -RSOBJ += rstlvutil.o # TLV Objs -RSOBJ += rstlvkvwide.o # TLV Objs -RSOBJ += rsbaseitems.o rsconfigitems.o rsdiscitems.o # RsItems -RSOBJ += rsmsgitems.o rsrankitems.o # RsItems -RSOBJ += rsphotoitems.o # RsItems -RSOBJ += rsgameitems.o # RsItems -RSOBJ += rsdistribitems.o # RsItems -RSOBJ += rsforumitems.o # RsItems -RSOBJ += rschannelitems.o # RsItems -RSOBJ += rsqblogitems.o # RsItems -RSOBJ += rsstatusitems.o # RsItems - -TESTOBJ = tlvbase_test.o tlvbase_test2.o tlvfileitem_test.o -TESTOBJ += tlvitems_test.o tlvstack_test.o tlvconfig_test.o -TESTOBJ += rsserial_test.o rstlvwidetest.o tlvrandom_test.o - -#rsbaseitem_test.o - -TESTS = tlvbase_test tlvbase_test2 tlvfileitem_test -TESTS += tlvitems_test tlvstack_test tlvconfig_test -TESTS += rstlvwidetest tlvrandom_test -#rsserial_test - -#rsbaseitem_test - -all: librs tests - -tlvbase_test : tlvbase_test.o - $(CC) $(CFLAGS) -o tlvbase_test tlvbase_test.o $(OBJ) $(LIBS) - -tlvbase_test2 : tlvbase_test2.o - $(CC) $(CFLAGS) -o tlvbase_test2 tlvbase_test2.o $(OBJ) $(LIBS) - -tlvfileitem_test : tlvfileitem_test.o - $(CC) $(CFLAGS) -o tlvfileitem_test tlvfileitem_test.o $(OBJ) $(LIBS) - -tlvitems_test : tlvitems_test.o - $(CC) $(CFLAGS) -o tlvitems_test tlvitems_test.o $(OBJ) $(LIBS) - -tlvstack_test : tlvstack_test.o - $(CC) $(CFLAGS) -o tlvstack_test tlvstack_test.o $(OBJ) $(LIBS) - -tlvconfig_test : tlvconfig_test.o - $(CC) $(CFLAGS) -o tlvconfig_test tlvconfig_test.o $(OBJ) $(LIBS) - -rsserial_test : rsserial_test.o - $(CC) $(CFLAGS) -o rsserial_test rsserial_test.o $(OBJ) $(LIBS) - -rsbaseitem_test : rsbaseitem_test.o - $(CC) $(CFLAGS) -o rsbaseitem_test rsbaseitem_test.o $(OBJ) $(LIBS) - -rstlvwidetest : rstlvwidetest.o - $(CC) $(CFLAGS) -o rstlvwidetest rstlvwidetest.o $(OBJ) $(LIBS) - -tlvrandom_test : tlvrandom_test.o - $(CC) $(CFLAGS) -o tlvrandom_test tlvrandom_test.o $(OBJ) $(LIBS) - - -############################################################### -include $(RS_TOP_DIR)/scripts/rules.mk -############################################################### - diff --git a/libretroshare/src/serialiser/rsbaseitem_test.cc b/libretroshare/src/serialiser/rsbaseitem_test.cc deleted file mode 100644 index 4743e5248..000000000 --- a/libretroshare/src/serialiser/rsbaseitem_test.cc +++ /dev/null @@ -1,191 +0,0 @@ - -/* - * libretroshare/src/serialiser: rsbaseitem_test.cc - * - * RetroShare Serialiser. - * - * Copyright 2007-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". - * - */ - -/****************************************************************** - * tlvfileitem test. - * - * - */ - -#include -#include -#include "serialiser/rstlvtypes.h" -#include "serialiser/rstlvutil.h" -#include "util/utest.h" - -INITTEST(); - -static int test_RsFileItem(); -static int test_RsFileData(); - -int main() -{ - std::cerr << "RsFile[Item/Data/...] Tests" << std::endl; - - test_RsFileItem(); - test_RsFileData(); - - FINALREPORT("RsTlvFile[Item/Data/...] Tests"); - - return TESTRESULT(); -} - -int test_RsTlvFileItem() -{ - - - - - RsTlvFileItem i1; - RsTlvFileItem i2; - - /* initialise */ - i1.filesize = 101010; - i1.hash = "ABCDEFEGHE"; - i1.name = "TestFile.txt"; - i1.pop = 12; - i1.age = 456; - - CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2)); - - /* check the data is the same */ - CHECK(i1.filesize == i2.filesize); - CHECK(i1.hash == i2.hash); - CHECK(i1.name == i2.name); - CHECK(i1.path == i2.path); - CHECK(i1.pop == i2.pop); - CHECK(i1.age == i2.age); - - /* do it again without optional data */ - i1.filesize = 123; - i1.name = ""; - i1.pop = 0; - i1.age = 0; - - CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2)); - - /* check the data is the same */ - CHECK(i1.filesize == i2.filesize); - CHECK(i1.hash == i2.hash); - CHECK(i1.name == i2.name); - CHECK(i1.path == i2.path); - CHECK(i1.pop == i2.pop); - CHECK(i1.age == i2.age); - - /* one more time - long file name, some optional data */ - i1.filesize = 123; - i1.name = "A Very Long File name that should fit in easily ??? with som $&%&^%* strange char (**$^%#&^$#*^%(&^ in there too!!!! ~~~!!$#(^$)$)(&%^)&\" oiyu thend"; - i1.pop = 666; - i1.age = 0; - - CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2)); - - /* check the data is the same */ - CHECK(i1.filesize == i2.filesize); - CHECK(i1.hash == i2.hash); - CHECK(i1.name == i2.name); - CHECK(i1.path == i2.path); - CHECK(i1.pop == i2.pop); - CHECK(i1.age == i2.age); - - REPORT("Serialise/Deserialise RsTlvFileItem"); - - return 1; -} - -int test_RsTlvFileSet() -{ - RsTlvFileSet s1; - RsTlvFileSet s2; - - int i = 0; - for(i = 0; i < 15; i++) - { - RsTlvFileItem fi; - fi.filesize = 16 + i * i; - fi.hash = "ABCDEF"; - std::ostringstream out; - out << "File" << i << "_inSet.txt"; - fi.name = out.str(); - if (i % 2 == 0) - { - fi.age = 10 * i; - } - else - { - fi.age = 0; - } - fi.pop = 0; - - s1.items.push_back(fi); - } - - CHECK(test_SerialiseTlvItem(std::cerr, &s1, &s2)); - - /* check the data is the same - TODO */ - - REPORT("Serialise/Deserialise RsTlvFileSet"); - - return 1; -} - - -int test_RsTlvFileData() -{ - RsTlvFileData d1; - RsTlvFileData d2; - - /* initialise */ - d1.file.filesize = 101010; - d1.file.hash = "ABCDEFEGHE"; - d1.file.name = ""; - d1.file.age = 0; - d1.file.pop = 0; - - char data[15]; - d1.binData.setBinData(data, 15); - - d1.file_offset = 222; - - CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2)); - - /* check the data is the same */ - CHECK(d1.file.filesize == d2.file.filesize); - CHECK(d1.file.hash == d2.file.hash); - CHECK(d1.file.name == d2.file.name); - CHECK(d1.file.path == d2.file.path); - CHECK(d1.file.pop == d2.file.pop); - CHECK(d1.file.age == d2.file.age); - - CHECK(d1.file_offset == d2.file_offset); - CHECK(d1.binData.bin_len == d2.binData.bin_len); - - REPORT("Serialise/Deserialise RsTlvFileData"); - - return 1; -} - - diff --git a/libretroshare/src/serialiser/rstlvwidetest.cc b/libretroshare/src/serialiser/rstlvwidetest.cc deleted file mode 100644 index 91f663387..000000000 --- a/libretroshare/src/serialiser/rstlvwidetest.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * libretroshare/src/serialiser: rstlvkvwidetest.cc - * - * RetroShare Serialiser. - * - * Copyright 2007-2008 by Chris Parker - * - * 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 -#include -#include -#include "serialiser/rstlvkvwide.h" -#include "serialiser/rstlvutil.h" -#include "util/utest.h" - - -INITTEST(); - - /* define utility functions to test out with */ - - //static int testRstlvWide(); -static int testRsTlvWideSet(); - -int main() -{ - std::cerr << "RsTlvWideTest[Item/Data/...] Tests" << std::endl; - - testRsTlvWideSet(); - - FINALREPORT("RsTlvWideTest[Item/Data/...] Tests"); - - return TESTRESULT(); -} - -int testRsTlvWideSet() -{ - RsTlvKeyValueWideSet i1, i2; // one to set and other to get - RsTlvKeyValueWide i_pair; // input pair - RsTlvFileItem hello; - - std::string randString("it should work now."); - int j, k; - - std::cerr << "entering loop now" << std::endl; - /* store a 15 random pairs */ - - for(int i = 0; i < 15 ; i++) - { - j = rand() % 4; - k = rand() % 4; - std::cerr << "j: " << j << " k: " << k << std::endl; - i_pair.wKey.assign(randString.begin(), randString.end()); - std::cerr << "loop count:" << i << std::endl; - i_pair.wValue.assign(randString.begin(), randString.end()); - std::cerr << "loop count:" << i << std::endl; - i1.wPairs.push_back(i_pair); - - i_pair.TlvClear(); - } - - std::cerr << "out of loop now" << std::endl; - - CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2)); - - /*check that the data is the same*/ - - REPORT("Serialize/Deserialize RsTlvKeyValueWideSet"); - - return 1; -} diff --git a/libretroshare/src/serialiser/tlvbase_test.cc b/libretroshare/src/serialiser/tlvbase_test.cc deleted file mode 100644 index f6d15423e..000000000 --- a/libretroshare/src/serialiser/tlvbase_test.cc +++ /dev/null @@ -1,185 +0,0 @@ - -/* - * libretroshare/src/serialiser: tlvbase_test.cc - * - * RetroShare Serialiser. - * - * Copyright 2007-2008 by Horatio. - * - * 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 -#include -#include - -#include "serialiser/rstlvbase.h" -#include "util/utest.h" -#include "util/rsnet.h" - -INITTEST(); - -static int test_RsTlvBase(); -int main() -{ - std::cerr << " RsTlvBase Tests" < -#include "serialiser/rstlvtypes.h" -#include "serialiser/rstlvbase.h" -#include "serialiser/rstlvutil.h" -#include "util/utest.h" -#include "util/rsnet.h" - -INITTEST(); - -static int test_RsTlvString(); -static int test_RsTlvUInt32(); -static int test_RsTlvIPAddr(); - -int main() -{ - std::cerr << "RsTlvBase Tests" << std::endl; - - test_RsTlvString(); - test_RsTlvUInt32(); - test_RsTlvIPAddr(); - - FINALREPORT("RsTlvBase Tests"); - - return TESTRESULT(); -} - -int test_RsTlvUInt32() -{ - return 1; -} - -int test_OneString(std::string input, uint16_t type); - -int test_RsTlvString() -{ - std::string nullString; - std::string oneString = "1"; - std::string shortString = "ab cd"; - std::string longString = "abcd efgh ijkl mnop qrst uvw"; - - std::cerr << "test_RsTlvString() Testing" << std::endl; - test_OneString(nullString, 1234); - test_OneString(oneString, 12); - test_OneString(shortString, 79); - test_OneString(longString, 7654); - - REPORT("Serialise RsTlvFileItem"); - - return 1; -} - - -int test_OneString(std::string input, uint16_t type) -{ - /* an array to work from */ - char tlvdata[2048]; - std::string OutString; - - std::cerr << "test_OneString() Testing ... Print/Serialise/Deserialise"; - std::cerr << std::endl; - /* start with SetTlvString() */ - - uint16_t initsize = GetTlvStringSize(input); - uint32_t outOffset = 0; - uint32_t inOffset = 0; - - std::cerr << "Serialising: " << input << std::endl; - CHECK(SetTlvString((void*)tlvdata, 2048, &outOffset, type, input)); - std::cerr << "Init Size: " << initsize << std::endl; - std::cerr << "Serialised Size: " << outOffset << std::endl; - displayRawPacket(std::cerr, tlvdata, outOffset); - - CHECK(outOffset == initsize); /* check that the offset matches the size */ - - std::cerr << "DeSerialising" << std::endl; - - /* fails if type is wrong! */ - CHECK(0 == GetTlvString((void*)tlvdata, outOffset, &inOffset, type-1, OutString)); - CHECK(GetTlvString((void*)tlvdata, outOffset, &inOffset, type, OutString)); - - CHECK(initsize == inOffset); /* check that the offset matches the size */ - CHECK(input == OutString); /* check that strings match */ - std::cerr << "Deserialised: Size: " << inOffset << std::endl; - std::cerr << "Deserialised: String: " << OutString << std::endl; - - REPORT("Serialise OneString"); - - return 1; -} - -int test_IpAddr(struct sockaddr_in *addr, uint16_t type); - -static int test_RsTlvIPAddr() -{ - struct sockaddr_in addr; - - inet_aton("10.0.0.111", &(addr.sin_addr)); - addr.sin_port = htons(1111); - - test_IpAddr(&addr, 1234); - - inet_aton("255.255.255.1", &(addr.sin_addr)); - addr.sin_port = htons(9999); - - test_IpAddr(&addr, 1234); - - inet_aton("128.255.255.1", &(addr.sin_addr)); - addr.sin_port = htons(0); - - test_IpAddr(&addr, 1234); - - return 1; -} - -int test_IpAddr(struct sockaddr_in *addr, uint16_t type) -{ - /* an array to work from */ - char tlvdata[2048]; - struct sockaddr_in outaddr; - - std::cerr << "test_IpAddr() Testing ... Print/Serialise/Deserialise"; - std::cerr << std::endl; - /* start with SetTlvString() */ - - uint16_t initsize = GetTlvIpAddrPortV4Size(); - uint32_t outOffset = 0; - uint32_t inOffset = 0; - - std::cerr << "Serialising IPAddr: " << inet_ntoa(addr->sin_addr) << std::endl; - std::cerr << " Port : " << ntohs(addr->sin_port) << std::endl; - - CHECK(SetTlvIpAddrPortV4((void*)tlvdata, 2048, &outOffset, type, addr)); - std::cerr << "Init Size: " << initsize << std::endl; - std::cerr << "Serialised Size: " << outOffset << std::endl; - displayRawPacket(std::cerr, tlvdata, outOffset); - - CHECK(outOffset == initsize); /* check that the offset matches the size */ - - std::cerr << "DeSerialising" << std::endl; - - /* fails if type is wrong! */ - CHECK(0 == GetTlvIpAddrPortV4((void*)tlvdata, outOffset, &inOffset, type-1, &outaddr)); - CHECK(GetTlvIpAddrPortV4((void*)tlvdata, outOffset, &inOffset, type, &outaddr)); - - CHECK(initsize == inOffset); /* check that the offset matches the size */ - CHECK(addr->sin_addr.s_addr == outaddr.sin_addr.s_addr); /* check that IP match */ - CHECK(addr->sin_port == outaddr.sin_port); /* check that Port match */ - std::cerr << "Deserialised: Size: " << inOffset << std::endl; - std::cerr << "Deserialised IPAddr: " << inet_ntoa(outaddr.sin_addr) << std::endl; - std::cerr << " Port : " << ntohs(outaddr.sin_port) << std::endl; - - REPORT("Serialise OneIP/Port"); - - return 1; -} - - - diff --git a/libretroshare/src/serialiser/tlvconfig_test.cc b/libretroshare/src/serialiser/tlvconfig_test.cc deleted file mode 100755 index 72a44b40b..000000000 --- a/libretroshare/src/serialiser/tlvconfig_test.cc +++ /dev/null @@ -1,192 +0,0 @@ - -/* - * libretroshare/src/serialiser: tlvconfig_test.cc - * - * RetroShare Serialiser. - * - * Copyright 2007-2008 by Chris Parker. - * - * 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". - * - */ - - -/****************************************************************** - * tlvfileitem test. - * - * - */ - -#include -#include -#include -#include "serialiser/rstlvtypes.h" -#include "serialiser/rstlvkvwide.h" -#include "serialiser/rstlvutil.h" -#include "util/utest.h" - -INITTEST(); - -static int testRsTlvPeerIdSet(); -static int testRsTlvServiceIdSet(); -static int testRsTlvKeyValue(); -static int testRsTlvKeyValueSet(); -static int testRsTlvWideSet(); - - -int main() -{ - std::cerr << "RsTlvConfig[Item/Data/...] Tests" << std::endl; - - testRsTlvPeerIdSet(); - testRsTlvServiceIdSet();//tbd - testRsTlvKeyValue();//tbd - testRsTlvKeyValueSet();//tbd - testRsTlvWideSet(); - - - FINALREPORT("RsTlvConfig[Item/Data/...] Tests"); - - return TESTRESULT(); -} - -int testRsTlvPeerIdSet() -{ - - RsTlvPeerIdSet i1, i2; // one to set and other to get - - std::string testString; - - std::string randString[5]; - randString[0] = "e$424!�!�"; - randString[1] = "e~:@L{L{KHKG"; - randString[2] = "e{@O**/*/*"; - randString[3] = "e?<HG�!�%$"; - randString[4] = "e>HG�!�%$"; - randString[4] = "e>HG�!�%$"; - randString[4] = "e> -#include -#include "serialiser/rstlvtypes.h" -#include "serialiser/rstlvutil.h" -#include "util/utest.h" - -INITTEST(); - -static int test_RsTlvFileItem(); -static int test_RsTlvFileSet(); -static int test_RsTlvFileData(); -static int test_RsTlvFileStack(); - -int main() -{ - std::cerr << "RsTlvFile[Item/Data/...] Tests" << std::endl; - - test_RsTlvFileItem(); - test_RsTlvFileData(); - test_RsTlvFileSet(); - - FINALREPORT("RsTlvFile[Item/Data/...] Tests"); - - return TESTRESULT(); -} - -int test_RsTlvFileItem() -{ - RsTlvFileItem i1; - RsTlvFileItem i2; - - /* initialise */ - i1.filesize = 101010; - i1.hash = "ABCDEFEGHE"; - i1.name = "TestFile.txt"; - i1.pop = 12; - i1.age = 456; - - CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2)); - - /* check the data is the same */ - CHECK(i1.filesize == i2.filesize); - CHECK(i1.hash == i2.hash); - CHECK(i1.name == i2.name); - CHECK(i1.path == i2.path); - CHECK(i1.pop == i2.pop); - CHECK(i1.age == i2.age); - - /* do it again without optional data */ - i1.filesize = 123; - i1.name = ""; - i1.pop = 0; - i1.age = 0; - - CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2)); - - /* check the data is the same */ - CHECK(i1.filesize == i2.filesize); - CHECK(i1.hash == i2.hash); - CHECK(i1.name == i2.name); - CHECK(i1.path == i2.path); - CHECK(i1.pop == i2.pop); - CHECK(i1.age == i2.age); - - /* one more time - long file name, some optional data */ - i1.filesize = 123; - i1.name = "A Very Long File name that should fit in easily ??? with som $&%&^%* strange char (**$^%#&^$#*^%(&^ in there too!!!! ~~~!!$#(^$)$)(&%^)&\" oiyu thend"; - i1.pop = 666; - i1.age = 0; - - CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2)); - - /* check the data is the same */ - CHECK(i1.filesize == i2.filesize); - CHECK(i1.hash == i2.hash); - CHECK(i1.name == i2.name); - CHECK(i1.path == i2.path); - CHECK(i1.pop == i2.pop); - CHECK(i1.age == i2.age); - - REPORT("Serialise/Deserialise RsTlvFileItem"); - - return 1; -} - -int test_RsTlvFileSet() -{ - RsTlvFileSet s1; - RsTlvFileSet s2; - - int i = 0; - for(i = 0; i < 15; i++) - { - RsTlvFileItem fi; - fi.filesize = 16 + i * i; - fi.hash = "ABCDEF"; - std::ostringstream out; - out << "File" << i << "_inSet.txt"; - fi.name = out.str(); - if (i % 2 == 0) - { - fi.age = 10 * i; - } - else - { - fi.age = 0; - } - fi.pop = 0; - - s1.items.push_back(fi); - } - - CHECK(test_SerialiseTlvItem(std::cerr, &s1, &s2)); - - /* check the data is the same - TODO */ - - REPORT("Serialise/Deserialise RsTlvFileSet"); - - return 1; -} - - -int test_RsTlvFileData() -{ - RsTlvFileData d1; - RsTlvFileData d2; - - /* initialise */ - d1.file.filesize = 101010; - d1.file.hash = "ABCDEFEGHE"; - d1.file.name = ""; - d1.file.age = 0; - d1.file.pop = 0; - - char data[15]; - d1.binData.setBinData(data, 15); - - d1.file_offset = 222; - - CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2)); - - /* check the data is the same */ - CHECK(d1.file.filesize == d2.file.filesize); - CHECK(d1.file.hash == d2.file.hash); - CHECK(d1.file.name == d2.file.name); - CHECK(d1.file.path == d2.file.path); - CHECK(d1.file.pop == d2.file.pop); - CHECK(d1.file.age == d2.file.age); - - CHECK(d1.file_offset == d2.file_offset); - CHECK(d1.binData.bin_len == d2.binData.bin_len); - - REPORT("Serialise/Deserialise RsTlvFileData"); - - return 1; -} - - diff --git a/libretroshare/src/serialiser/tlvitems_test.cc b/libretroshare/src/serialiser/tlvitems_test.cc deleted file mode 100644 index 0ad436155..000000000 --- a/libretroshare/src/serialiser/tlvitems_test.cc +++ /dev/null @@ -1,89 +0,0 @@ - -/* - * libretroshare/src/serialiser: tlvitems_test.cc - * - * RetroShare Serialiser. - * - * Copyright 2007-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". - * - */ - -/****************************************************************** - * tlvfileitem test. - * - * - */ - -#include -#include -#include "serialiser/rstlvtypes.h" -#include "serialiser/rstlvutil.h" -#include "util/utest.h" - -INITTEST(); - -static int test_RsTlvBinData(); -static int test_RsTlvStepping(); - -int main() -{ - std::cerr << "RsTlvItems Tests" << std::endl; - - test_RsTlvBinData(); - - FINALREPORT("RsTlvItems Tests"); - - return TESTRESULT(); -} - -#define BIN_LEN 523456 /* bigger than 64k */ - -int test_RsTlvBinData() -{ - RsTlvBinaryData d1(1023); - RsTlvBinaryData d2(1023); - - char data[BIN_LEN] = {0}; - int i, j; - for(i = 0; i < BIN_LEN; i++) - { - data[i] = i%13; - } - - for(j = 1; j < BIN_LEN; j *= 2) - { - d1.setBinData(data, j); - CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2)); - - CHECK(d1.bin_len == d2.bin_len); - CHECK(0 == memcmp(d1.bin_data, d2.bin_data, d1.bin_len)); - } - - REPORT("Serialise/Deserialise RsTlvBinData"); - - return 1; -} - -int test_RsTlvStepping() -{ - - - return 1; -} - diff --git a/libretroshare/src/serialiser/tlvrandom_test.cc b/libretroshare/src/serialiser/tlvrandom_test.cc deleted file mode 100644 index 9b0a87d40..000000000 --- a/libretroshare/src/serialiser/tlvrandom_test.cc +++ /dev/null @@ -1,194 +0,0 @@ - -/* - * libretroshare/src/serialiser: tlvrandom_test.cc - * - * RetroShare Serialiser. - * - * Copyright 2009 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". - * - */ - -/****************************************************************** - * tlvrandom_test. - * - * This test is designed to attempt to break the TLV serialiser. - * - * To do this we throw random data at the serialisers and try to decode it. - * As the serialiser will only attempt to deserialise if the tlvtype matches - * we cheat a little, and make this match - to increase to actual deserialise - * attempts. - * - * This test runs for 30 seconds and attempts to do as - * many deserialisation as possible. - */ - -#include -#include -#include "serialiser/rstlvbase.h" -#include "serialiser/rstlvtypes.h" -#include "serialiser/rstlvkeys.h" -#include "serialiser/rstlvkvwide.h" -#include "serialiser/rstlvutil.h" - -#include "util/utest.h" - -INITTEST(); - -#define TEST_LENGTH 30 - -static int test_TlvRandom(void *data, uint32_t len, uint32_t offset); - -int main() -{ - std::cerr << "TlvRandom Tests" << std::endl; - - /* random data array to work through */ - uint32_t dsize = 10000000; - uint32_t i; - uint8_t *data = (uint8_t *) malloc(dsize); - - if (!data) - { - std::cerr << "Failed to allocate array"; - std::cerr << std::endl; - exit(1); - } - - time_t startTs = time(NULL); - time_t endTs = startTs + TEST_LENGTH; - - srandom(startTs); - for(i = 0; i < dsize; i++) - { - data[i] = random() % 256; - } - - std::cerr << "TlvRandom Tests: setup data." << std::endl; - - int count = 0; - for(i = 0; endTs > time(NULL); i += 2) - { - uint32_t len = dsize - i; - count += test_TlvRandom(&(data[i]), len, i); - - std::cerr << "Run: " << count << " tests"; - std::cerr << std::endl; - } - - FINALREPORT("RsTlvItems Tests"); - - return TESTRESULT(); -} - -#define BIN_LEN 523456 /* bigger than 64k */ - -int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset); -int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset); - - -int test_TlvRandom(void *data, uint32_t len, uint32_t offset) -{ - uint32_t tmpoffset = 0; - - /* List of all the TLV types it could be! */ - RsTlvSecurityKey skey; - RsTlvSecurityKeySet skeyset; - RsTlvKeySignature keysign; - - RsTlvBinaryData bindata(TLV_TYPE_IMAGE); - - RsTlvFileItem fileitem; - RsTlvFileSet fileset; - RsTlvFileData filedata; - - RsTlvPeerIdSet peerset; - RsTlvServiceIdSet servset; - - RsTlvKeyValue kv; - RsTlvKeyValueSet kvset; - RsTlvKeyValueWide kvwide; - RsTlvKeyValueWideSet kvwideset; - - RsTlvImage image; - - /* try to decode - with all types first */ - std::cerr << "test_TlvRandom:: Testing Files " << std::endl; - test_TlvItem(&bindata, data, len, offset); - test_TlvItem(&fileitem, data, len, offset); - test_TlvItem(&fileset, data, len, offset); - test_TlvItem(&filedata, data, len, offset); - std::cerr << "test_TlvRandom:: Testing Sets " << std::endl; - test_TlvItem(&peerset, data, len, offset); - test_TlvItem(&servset, data, len, offset); - test_TlvItem(&kv, data, len, offset); - test_TlvItem(&kvset, data, len, offset); - test_TlvItem(&kvwide, data, len, offset); - test_TlvItem(&kvwideset, data, len, offset); - std::cerr << "test_TlvRandom:: Testing Keys " << std::endl; - test_TlvItem(&skey, data, len, offset); - test_TlvItem(&skeyset, data, len, offset); - test_TlvItem(&keysign, data, len, offset); - - /* now set the type correctly before decoding */ - std::cerr << "test_TlvRandom:: Testing Files (TYPESET)" << std::endl; - test_SetTlvItem(&bindata, TLV_TYPE_IMAGE, data, len, offset); - test_SetTlvItem(&fileitem,TLV_TYPE_FILEITEM, data, len, offset); - test_SetTlvItem(&fileset, TLV_TYPE_FILESET, data, len, offset); - test_SetTlvItem(&filedata, TLV_TYPE_FILEDATA, data, len, offset); - std::cerr << "test_TlvRandom:: Testing Sets (TYPESET)" << std::endl; - test_SetTlvItem(&peerset, TLV_TYPE_PEERSET, data, len, offset); - test_SetTlvItem(&servset, TLV_TYPE_SERVICESET, data, len, offset); - test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset); - test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset); - test_SetTlvItem(&kvwide, TLV_TYPE_WKEYVALUE, data, len, offset); - test_SetTlvItem(&kvwideset, TLV_TYPE_WKEYVALUESET, data, len, offset); - std::cerr << "test_TlvRandom:: Testing Keys (TYPESET)" << std::endl; - test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset); - test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset); - test_SetTlvItem(&keysign, TLV_TYPE_KEYSIGNATURE, data, len, offset); - - return 26; /* number of tests */ -} - -int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset) -{ - uint32_t tmp_offset = offset; - if (item->GetTlv(data, size, &tmp_offset)) - { - std::cerr << "TLV decoded Random!"; - std::cerr << std::endl; - item->print(std::cerr, 20); - } - else - { - std::cerr << "TLV failed to decode"; - std::cerr << std::endl; - } -} - -int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset) -{ - /* set TLV type first! */ - void *typedata = (((uint8_t *) data) + offset); - SetTlvType(typedata, size - offset, type); - - return test_TlvItem(item, data, size, offset); -} - - diff --git a/libretroshare/src/serialiser/tlvstack_test.cc b/libretroshare/src/serialiser/tlvstack_test.cc deleted file mode 100644 index fe174f37e..000000000 --- a/libretroshare/src/serialiser/tlvstack_test.cc +++ /dev/null @@ -1,104 +0,0 @@ - -/* - * libretroshare/src/serialiser: tlvstack_test.cc - * - * RetroShare Serialiser. - * - * Copyright 2007-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". - * - */ - -/****************************************************************** - * tlvfileitem test. - * - * - */ - -#include -#include "serialiser/rstlvtypes.h" -#include "serialiser/rstlvutil.h" -#include "util/utest.h" - -INITTEST(); - -static int test_RsTlvStack(); - -int main() -{ - std::cerr << "RsTlvItem Stack Tests" << std::endl; - - test_RsTlvStack(); - - FINALREPORT("RsTlvItem Stack Tests"); - - return TESTRESULT(); -} - - -#define BIN_LEN 53 - -int test_RsTlvStack() -{ - - /* now create a set of TLV items for the random generator */ - - RsTlvBinaryData *bd1 = new RsTlvBinaryData(123); - RsTlvBinaryData *bd2 = new RsTlvBinaryData(125); - - char data[BIN_LEN] = {0}; - int i; - for(i = 0; i < BIN_LEN; i++) - { - data[i] = i%13; - } - - bd1->setBinData(data, 5); - bd2->setBinData(data, 21); - - RsTlvFileItem *fi1 = new RsTlvFileItem(); - RsTlvFileItem *fi2 = new RsTlvFileItem(); - - /* initialise */ - fi1->filesize = 101010; - fi1->hash = "ABCDEFEGHE"; - fi1->name = "TestFile.txt"; - fi1->pop = 12; - fi1->age = 456; - - fi2->filesize = 101010; - fi2->hash = "ABCDEFEGHE"; - fi2->name = "TestFile.txt"; - fi2->pop = 0; - fi2->age = 0;; - - std::vector items; - items.resize(4); - items[0] = bd1; - items[1] = bd2; - items[2] = fi1; - items[3] = fi2; - - test_TlvSet(items, 1024); - - REPORT("Serialise/Deserialise RsTlvBinData"); - - return 1; -} - - diff --git a/libretroshare/src/ft/TestNotes.txt b/libretroshare/src/tests/ft/TestNotes.txt similarity index 100% rename from libretroshare/src/ft/TestNotes.txt rename to libretroshare/src/tests/ft/TestNotes.txt diff --git a/libretroshare/src/tests/serialiser/Makefile b/libretroshare/src/tests/serialiser/Makefile index 5fbf4a30b..e90358f10 100644 --- a/libretroshare/src/tests/serialiser/Makefile +++ b/libretroshare/src/tests/serialiser/Makefile @@ -13,9 +13,7 @@ TESTOBJ += rsserial_test.o rstlvwidetest.o tlvrandom_test.o TESTS = tlvbase_test tlvbase_test2 tlvfileitem_test TESTS += tlvitems_test tlvstack_test tlvconfig_test -TESTS += rstlvwidetest tlvrandom_test -#rsserial_test - +TESTS += rstlvwidetest tlvrandom_test rsserial_test #rsbaseitem_test all: tests diff --git a/libretroshare/src/serialiser/rsserial_test.cc b/libretroshare/src/tests/serialiser/rsserial_test.cc similarity index 100% rename from libretroshare/src/serialiser/rsserial_test.cc rename to libretroshare/src/tests/serialiser/rsserial_test.cc