From df4cf6030ebce146279993e978a5d108f19f7872 Mon Sep 17 00:00:00 2001 From: drbob Date: Sat, 12 Apr 2014 07:22:57 +0000 Subject: [PATCH] Added NxsNetMgr to simulator git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7266 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- tests/librssimulator/peer/FakeNxsNetMgr.h | 36 +++++++++++++++++++ tests/librssimulator/peer/PeerNode.cc | 13 +++++++ tests/librssimulator/peer/PeerNode.h | 4 +++ .../testing/IsolatedServiceTester.cc | 14 +++++++- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/librssimulator/peer/FakeNxsNetMgr.h diff --git a/tests/librssimulator/peer/FakeNxsNetMgr.h b/tests/librssimulator/peer/FakeNxsNetMgr.h new file mode 100644 index 000000000..39a35796f --- /dev/null +++ b/tests/librssimulator/peer/FakeNxsNetMgr.h @@ -0,0 +1,36 @@ +#pragma once + +#include "gxs/rsgxsnetservice.h" +#include "FakeLinkMgr.h" + +class FakeNxsNetMgr : public RsNxsNetMgr +{ + +public: + + FakeNxsNetMgr(FakeLinkMgr *linkMgr) + :mLinkMgr(linkMgr) { return; } + + const RsPeerId& getOwnId() + { + return mLinkMgr->getOwnId(); + } + + void getOnlineList(uint32_t serviceId, std::set& ssl_peers) + { + (void) serviceId; + + std::list peerList; + mLinkMgr->getOnlineList(peerList); + + std::list::const_iterator it; + for(it = peerList.begin(); it != peerList.end(); it++) + { + ssl_peers.insert(*it); + } + } +private: + + FakeLinkMgr *mLinkMgr; +}; + diff --git a/tests/librssimulator/peer/PeerNode.cc b/tests/librssimulator/peer/PeerNode.cc index 8adfb90c5..30c320759 100644 --- a/tests/librssimulator/peer/PeerNode.cc +++ b/tests/librssimulator/peer/PeerNode.cc @@ -22,6 +22,7 @@ #include "FakeNetMgr.h" #include "FakePublisher.h" #include "FakeServiceControl.h" +#include "FakeNxsNetMgr.h" PeerNode::PeerNode(const RsPeerId& id,const std::list& friends, bool online) @@ -31,6 +32,7 @@ PeerNode::PeerNode(const RsPeerId& id,const std::list& friends, bool o mLinkMgr = new FakeLinkMgr(id, friends, online) ; mPeerMgr = new FakePeerMgr(id, friends) ; mPublisher = new FakePublisher() ; + mNxsNetMgr = new FakeNxsNetMgr(mLinkMgr); _service_control = new FakeServiceControl(mLinkMgr) ; _service_server = new p3ServiceServer(mPublisher,_service_control); @@ -75,6 +77,12 @@ p3PeerMgr *PeerNode::getPeerMgr() return mPeerMgr; } + +RsNxsNetMgr *PeerNode::getNxsNetMgr() +{ + return mNxsNetMgr; +} + void PeerNode::notifyOfFriends() { std::list friendList; @@ -172,12 +180,17 @@ void PeerNode::takeOffline(std::list &offlineList) void PeerNode::tick() { +#ifdef DEBUG std::cerr << " ticking peer node " << _id << std::endl; +#endif _service_server->tick() ; } void PeerNode::incoming(RsRawItem *item) { +#ifdef DEBUG + std::cerr << "PeerNode::incoming()" << std::endl; +#endif _service_server->recvItem(item) ; } diff --git a/tests/librssimulator/peer/PeerNode.h b/tests/librssimulator/peer/PeerNode.h index 23fc131e5..cf7ac428d 100644 --- a/tests/librssimulator/peer/PeerNode.h +++ b/tests/librssimulator/peer/PeerNode.h @@ -11,6 +11,8 @@ class p3ServiceControl; class FakeLinkMgr; class FakePeerMgr; class FakeNetMgr; +class RsNxsNetMgr; +class FakeNxsNetMgr; class pqiMonitor; class pqiServiceMonitor; class pqiService; @@ -33,6 +35,7 @@ class PeerNode p3LinkMgr *getLinkMgr(); p3PeerMgr *getPeerMgr(); p3NetMgr *getNetMgr(); + RsNxsNetMgr *getNxsNetMgr(); void AddService(pqiService *service); void AddPqiMonitor(pqiMonitor *service); @@ -52,6 +55,7 @@ class PeerNode FakeLinkMgr *mLinkMgr; FakePeerMgr *mPeerMgr; FakeNetMgr *mNetMgr; + FakeNxsNetMgr *mNxsNetMgr; /* for monitors */ std::list mPqiMonitors; diff --git a/tests/librssimulator/testing/IsolatedServiceTester.cc b/tests/librssimulator/testing/IsolatedServiceTester.cc index e881620c0..c8ae3854b 100644 --- a/tests/librssimulator/testing/IsolatedServiceTester.cc +++ b/tests/librssimulator/testing/IsolatedServiceTester.cc @@ -34,7 +34,7 @@ bool IsolatedServiceTester::startup() bool IsolatedServiceTester::tick() { - + mNode->tick(); return true; } @@ -57,9 +57,11 @@ RsItem *IsolatedServiceTester::getPacket() RsRawItem *rawitem = mNode->outgoing(); if (rawitem) { +#ifdef DEBUG /* convert back to standard item for convenience */ std::cerr << "IsolatedServiceTester::getPacket() have RsRawItem"; std::cerr << std::endl; +#endif /* convert to RsServiceItem */ uint32_t size = rawitem->getRawLength(); @@ -96,8 +98,10 @@ RsItem *IsolatedServiceTester::getPacket() bool IsolatedServiceTester::sendPacket(RsItem *si) { +#ifdef DEBUG std::cerr << "IsolatedServiceTester::sendPacket()"; std::cerr << std::endl; +#endif /* try to convert */ uint32_t size = mRsSerialiser->size(si); @@ -132,6 +136,14 @@ bool IsolatedServiceTester::sendPacket(RsItem *si) if (raw) { +#ifdef DEBUG + std::cerr << "IsolatedServiceTester::sendPacket()"; + std::cerr << std::endl; + si->print(std::cerr); + std::cerr << "IsolatedServiceTester::sendPacket() passing to Node: "; + std::cerr << std::endl; +#endif + raw->PeerId(si->PeerId()); mNode->incoming(raw); }