From 871ca11aff142ea958097f745806a0e29b0a1726 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Dec 2012 20:55:44 +0000 Subject: [PATCH] fixed ftserver1test git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6038 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/tests/common/testutils.h | 51 +++++++++++++ libretroshare/src/tests/ft/Makefile | 4 +- .../src/tests/ft/ftcontrollertest.cc | 54 +------------- libretroshare/src/tests/ft/ftserver1test.cc | 72 ++++++++++++------- libretroshare/src/tests/ft/ftserver1test.sh | 3 + 5 files changed, 106 insertions(+), 78 deletions(-) create mode 100755 libretroshare/src/tests/ft/ftserver1test.sh diff --git a/libretroshare/src/tests/common/testutils.h b/libretroshare/src/tests/common/testutils.h index 9d1abf6e6..b2cda54a0 100644 --- a/libretroshare/src/tests/common/testutils.h +++ b/libretroshare/src/tests/common/testutils.h @@ -2,6 +2,10 @@ #include #include #include +#include +#include +#include +#include class TestUtils { @@ -42,4 +46,51 @@ class TestUtils { return t_RsGenericIdType<8>::random().toStdString(true); } + + class DummyAuthGPG: public AuthGPG + { + public: + DummyAuthGPG(const std::string& ownId) + :AuthGPG("pgp_pubring.pgp","pgp_secring.pgp","pgp_trustdb.pgp","lock"), mOwnId(ownId) + { + } + + virtual std::string getGPGOwnId() + { + return mOwnId ; + } + + virtual bool isGPGAccepted(const std::string& pgp_id) { return true ; } + + private: + std::string mOwnId ; + }; + + class DummyAuthSSL: public AuthSSLimpl + { + public: + DummyAuthSSL(const std::string& ownId) + : mOwnId(ownId) + { + } + + virtual std::string OwnId() + { + return mOwnId ; + } + + private: + std::string mOwnId ; + }; + + class DummyRsPeers: public p3Peers + { + public: + DummyRsPeers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm) : p3Peers(lm,pm,nm) {} + + //virtual bool getFriendList(std::list& fl) { ; return true ;} + + private: + std::list mFriends ; + }; }; diff --git a/libretroshare/src/tests/ft/Makefile b/libretroshare/src/tests/ft/Makefile index d45631a32..8ac19ff3d 100644 --- a/libretroshare/src/tests/ft/Makefile +++ b/libretroshare/src/tests/ft/Makefile @@ -41,8 +41,8 @@ ftextralisttest : ftextralisttest.o ftdataplextest : ftdataplextest.o ftsearch_dummy.o ftdata_dummy.o $(CC) $(CFLAGS) -o ftdataplextest ftdata_dummy.o ftdataplextest.o ftsearch_dummy.o $(LIBS) -ftserver1test : ftserver1test.o - $(CC) $(CFLAGS) -o ftserver1test ftserver1test.o $(LIBS) +ftserver1test : ftserver1test.o pqitestor.o + $(CC) $(CFLAGS) -o ftserver1test ftserver1test.o pqitestor.o $(LIBS) ftserver2test : ftserver2test.o $(CC) $(CFLAGS) -o ftserver2test ftserver2test.o $(LIBS) diff --git a/libretroshare/src/tests/ft/ftcontrollertest.cc b/libretroshare/src/tests/ft/ftcontrollertest.cc index 9568a7ac6..086cbb0a0 100644 --- a/libretroshare/src/tests/ft/ftcontrollertest.cc +++ b/libretroshare/src/tests/ft/ftcontrollertest.cc @@ -56,53 +56,6 @@ #include -class FakeGPG: public AuthGPG -{ - public: - FakeGPG(const std::string& ownId) - :AuthGPG("pgp_pubring.pgp","pgp_secring.pgp","pgp_trustdb.pgp","lock"), mOwnId(ownId) - { - } - - virtual std::string getGPGOwnId() - { - return mOwnId ; - } - - virtual bool isGPGAccepted(const std::string& pgp_id) { return true ; } - - private: - std::string mOwnId ; -}; - -class FakeSSL: public AuthSSLimpl -{ - public: - FakeSSL(const std::string& ownId) - : mOwnId(ownId) - { - } - - virtual std::string OwnId() - { - return mOwnId ; - } - - private: - std::string mOwnId ; -}; - -class FakeRsPeers: public p3Peers -{ - public: - FakeRsPeers(p3LinkMgr *lm, p3PeerMgr *pm, p3NetMgr *nm) : p3Peers(lm,pm,nm) {} - - virtual bool getFriendList(std::list& fl) { fl = mFriends ; return true ;} - - private: - std::list mFriends ; -}; - class TestData { public: @@ -176,10 +129,10 @@ int main(int argc, char **argv) std::string ssl_own_id = TestUtils::createRandomSSLId() ; std::string gpg_own_id = TestUtils::createRandomPGPId() ; - FakeGPG fakeGPG(gpg_own_id) ; + TestUtils::DummyAuthGPG fakeGPG(gpg_own_id) ; AuthGPG::setAuthGPG_debug(&fakeGPG) ; - FakeSSL fakeSSL(ssl_own_id) ; + TestUtils::DummyAuthSSL fakeSSL(ssl_own_id) ; AuthSSL::setAuthSSL_debug(&fakeSSL) ; /* do logging */ @@ -263,8 +216,7 @@ int main(int argc, char **argv) p3LinkMgrIMPL *linkMgr = new p3LinkMgrIMPL(peerMgr,netMgr); mLinkMgrs[*it] = linkMgr; - rsPeers = new FakeRsPeers(linkMgr,peerMgr,netMgr) ; - + rsPeers = new TestUtils::DummyRsPeers(linkMgr,peerMgr,netMgr) ; for(fit = friendList.begin(); fit != friendList.end(); fit++) { diff --git a/libretroshare/src/tests/ft/ftserver1test.cc b/libretroshare/src/tests/ft/ftserver1test.cc index bfc21c362..d8722eb9c 100644 --- a/libretroshare/src/tests/ft/ftserver1test.cc +++ b/libretroshare/src/tests/ft/ftserver1test.cc @@ -41,8 +41,12 @@ #include "pqi/p3linkmgr.h" #include "pqi/p3peermgr.h" +#include "pqi/p3netmgr.h" #include "util/rsdebug.h" +#include "util/utest.h" +#include "common/testutils.h" +#include "retroshare/rsiface.h" #include "pqitestor.h" #include "util/rsdir.h" @@ -50,6 +54,7 @@ #include +INITTEST(); void do_random_server_test(ftDataMultiplex *mplex, ftExtraList *eList, std::list &files); @@ -67,10 +72,10 @@ int main(int argc, char **argv) uint32_t debugLevel = 5; bool debugStderr = true; - std::list fileList; + std::list fileList; std::list peerIds; std::map mFtServers; - std::map mConnMgrs; + std::map mLinkMgrs; #ifdef PTW32_STATIC_LIB pthread_win32_process_attach_np(); @@ -127,10 +132,26 @@ int main(int argc, char **argv) for(; optind < argc; optind++) { std::cerr << "Adding: " << argv[optind] << std::endl; - fileList.push_back(std::string(argv[optind])); + + SharedDirInfo info ; + info.filename = std::string(argv[optind]) ; + info.virtualname = info.filename ; + info.shareflags = DIR_FLAGS_PERMISSIONS_MASK ; + info.parent_groups.clear() ; + + fileList.push_back(info); } std::cerr << "Point 2" << std::endl; + std::string ssl_own_id = TestUtils::createRandomSSLId() ; + std::string gpg_own_id = TestUtils::createRandomPGPId() ; + + TestUtils::DummyAuthGPG fakeGPG(gpg_own_id) ; + AuthGPG::setAuthGPG_debug(&fakeGPG) ; + + TestUtils::DummyAuthSSL fakeSSL(ssl_own_id) ; + AuthSSL::setAuthSSL_debug(&fakeSSL) ; + /* We need to setup a series 2 - 4 different ftServers.... * * Each one needs: @@ -141,30 +162,27 @@ int main(int argc, char **argv) std::list::const_iterator it, jit; - std::list baseFriendList, friendList; - std::list::iterator fit; + std::list baseFriendList, friendList; + std::list::iterator fit; - std::cerr << "Point 3" << std::endl; - P3Hub *testHub = new P3Hub(0, NULL); + 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; + RsPeerDetails pad; pad.id = *it; + pad.gpg_id = TestUtils::createRandomPGPId() ; pad.name = *it; pad.trustLvl = 5; pad.ownsign = true; - pad.trusted = false; + //pad.trusted = false; baseFriendList.push_back(pad); - std::cerr << "ftserver1test::setup peer: " << *it; - std::cerr << std::endl; + std::cerr << "ftserver1test::setup peer: " << *it << std::endl; } - std::cerr << "Point 5" << std::endl; std::ostringstream pname; pname << "/tmp/rstst-" << time(NULL); @@ -172,7 +190,6 @@ int main(int argc, char **argv) std::string basepath = pname.str(); RsDirUtil::checkCreateDirectory(basepath); - std::cerr << "Point 6" << std::endl; for(it = peerIds.begin(); it != peerIds.end(); it++) @@ -188,22 +205,26 @@ int main(int argc, char **argv) } } - p3AuthMgr *authMgr = new p3DummyAuthMgr(*it, friendList); - p3ConnectMgr *connMgr = new p3ConnectMgr(authMgr); - mConnMgrs[*it] = connMgr; + //p3AuthMgr *authMgr = new p3DummyAuthMgr(*it, friendList); + p3PeerMgrIMPL *peerMgr = new p3PeerMgrIMPL(ssl_own_id,gpg_own_id,"My GPG name","My SSL location"); + p3NetMgrIMPL *netMgr = new p3NetMgrIMPL ; + p3LinkMgrIMPL *linkMgr = new p3LinkMgrIMPL(peerMgr,netMgr); + mLinkMgrs[*it] = linkMgr; + + rsPeers = new TestUtils::DummyRsPeers(linkMgr,peerMgr,netMgr) ; for(fit = friendList.begin(); fit != friendList.end(); fit++) { /* add as peer to authMgr */ - connMgr->addFriend(fit->id); + peerMgr->addFriend(fit->id,fit->gpg_id); } P3Pipe *pipe = new P3Pipe(); //(*it); /* add server */ ftServer *server; - server = new ftServer(authMgr, connMgr); + server = new ftServer(peerMgr,linkMgr); mFtServers[*it] = server; server->setP3Interface(pipe); @@ -230,24 +251,23 @@ int main(int argc, char **argv) //sleep(60); - NotifyBase *base = NULL; + NotifyBase *base = new NotifyBase; server->SetupFtServer(base); - testHub->addP3Pipe(*it, pipe, connMgr); + testHub->addP3Pipe(*it, pipe, linkMgr); 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; + std::map::iterator cit; - while(1) + for(int i=0;i < 20;++i) { std::cerr << "ftserver1test::sleep()"; std::cerr << std::endl; @@ -260,12 +280,14 @@ int main(int argc, char **argv) (sit->second)->tick(); } - for(cit = mConnMgrs.begin(); cit != mConnMgrs.end(); cit++) + for(cit = mLinkMgrs.begin(); cit != mLinkMgrs.end(); cit++) { /* update */ (cit->second)->tick(); } } + + FINALREPORT("FtServer running.") ; } diff --git a/libretroshare/src/tests/ft/ftserver1test.sh b/libretroshare/src/tests/ft/ftserver1test.sh new file mode 100755 index 000000000..379ecc7fa --- /dev/null +++ b/libretroshare/src/tests/ft/ftserver1test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +./ftserver1test -p 8cb3a1677872c9e8248fd5ddeac84000 -p 8cb3a1677872c9e8248fd5ddeac84001 -p 8cb3a1677872c9e8248fd5ddeac84002 .