From 44a1f6f6f39ca41c31e30e05d8712aaad288a9a4 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 6 Apr 2014 07:56:20 +0000 Subject: [PATCH] a bit of code splitting git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7243 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/tests/network_simulator/Network.cpp | 166 +----------------- .../src/tests/network_simulator/Network.h | 50 +----- .../src/tests/network_simulator/network.pro | 4 +- 3 files changed, 4 insertions(+), 216 deletions(-) diff --git a/libretroshare/src/tests/network_simulator/Network.cpp b/libretroshare/src/tests/network_simulator/Network.cpp index 17478f245..7164d3f47 100644 --- a/libretroshare/src/tests/network_simulator/Network.cpp +++ b/libretroshare/src/tests/network_simulator/Network.cpp @@ -16,6 +16,7 @@ #include #include "Network.h" #include "MonitoredTurtle.h" +#include "FakeComponents.h" bool Network::initRandom(uint32_t nb_nodes,float connexion_probability) { @@ -100,168 +101,3 @@ PeerNode& Network::node_by_id(const RsPeerId& id) return node(it->second) ; } -class FakeLinkMgr: public p3LinkMgrIMPL -{ - public: - FakeLinkMgr(const RsPeerId& own_id,const std::list& friends) - : p3LinkMgrIMPL(NULL,NULL),_own_id(own_id),_friends(friends) - { - } - - virtual const RsPeerId& getOwnId() { return _own_id ; } - virtual void getOnlineList(std::list& lst) { lst = _friends ; } - virtual uint32_t getLinkType(const RsPeerId&) { return RS_NET_CONN_TCP_ALL | RS_NET_CONN_SPEED_NORMAL; } - - virtual bool getPeerName(const RsPeerId &ssl_id, std::string &name) { name = ssl_id.toStdString() ; return true ;} - - private: - RsPeerId _own_id ; - std::list _friends ; -}; - -class FakePublisher: public pqiPublisher -{ - public: - virtual bool sendItem(RsRawItem *item) - { - _item_queue.push_back(item) ; - } - - RsRawItem *outgoing() - { - if(_item_queue.empty()) - return NULL ; - - RsRawItem *item = _item_queue.front() ; - _item_queue.pop_front() ; - return item ; - } - - private: - std::list _item_queue ; -}; - -class FakePeerMgr: public p3PeerMgrIMPL -{ - public: - FakePeerMgr(const RsPeerId& own,const std::list& ids) - : p3PeerMgrIMPL(own,RsPgpId(),"no name","location name") - { - for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) - _ids.insert(*it) ; - } - - virtual bool idFriend(const RsPeerId& ssl_id) { return _ids.find(ssl_id) != _ids.end() ; } - - virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) - { - return ~ServicePermissionFlags(0) ; - } - std::set _ids ; -}; -const RsTurtle *PeerNode::turtle_service() const -{ - return _turtle ; -} - -class FakeServiceControl: public p3ServiceControl -{ - public: - FakeServiceControl(p3LinkMgr *lm) - : p3ServiceControl(lm),mLink(lm) - { - } - - virtual void getPeersConnected(const uint32_t serviceId, std::set &peerSet) - { - std::list ids ; - mLink->getOnlineList(ids) ; - - for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) - peerSet.insert(*it) ; - } - - virtual bool checkFilter(uint32_t,const RsPeerId& id) - { - return true ; - } - p3LinkMgr *mLink; -}; - -PeerNode::PeerNode(const RsPeerId& id,const std::list& friends) - : _id(id) -{ - // add a service server. - - p3LinkMgr *link_mgr = new FakeLinkMgr(id, friends) ; - p3PeerMgr *peer_mgr = new FakePeerMgr(id, friends) ; - - _publisher = new FakePublisher ; - p3ServiceControl *ctrl = new FakeServiceControl(link_mgr) ; - - _service_server = new p3ServiceServer(_publisher,ctrl); - - ftServer *ft_server = new ftServer(peer_mgr,ctrl) ; - - _service_server->addService(_turtle = new p3turtle(ctrl,link_mgr),true) ; - - _ftserver = new MonitoredTurtleClient ; - _ftserver->connectToTurtleRouter(_turtle) ; - - RsServicePermissions perms; - perms.mDefaultAllowed = true ; - perms.mServiceId = RS_SERVICE_TYPE_TURTLE ; - - ctrl->updateServicePermissions(RS_SERVICE_TYPE_TURTLE,perms) ; - // add a turtle router. - // -} - -PeerNode::~PeerNode() -{ - delete _service_server ; -} - -void PeerNode::tick() -{ - std::cerr << " ticking peer node " << _id << std::endl; - _service_server->tick() ; -} - -void PeerNode::incoming(RsRawItem *item) -{ - _service_server->recvItem(item) ; -} -RsRawItem *PeerNode::outgoing() -{ - return dynamic_cast(_publisher)->outgoing() ; -} - -void PeerNode::provideFileHash(const RsFileHash& hash) -{ - _provided_hashes.insert(hash) ; - _ftserver->provideFileHash(hash) ; -} - -void PeerNode::manageFileHash(const RsFileHash& hash) -{ - _managed_hashes.insert(hash) ; - _turtle->monitorTunnels(hash,_ftserver) ; -} - -void PeerNode::getTrafficInfo(NodeTrafficInfo& info) -{ - std::vector > hashes_info ; - std::vector > tunnels_info ; - std::vector search_reqs_info ; - std::vector tunnel_reqs_info ; - - _turtle->getInfo(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ; - - for(uint32_t i=0;i #include #include -#include - -class MonitoredTurtleRouter ; -class MonitoredTurtleClient ; -class RsTurtle ; -class RsRawItem ; -class p3ServiceServer ; - -class PeerNode -{ - public: - struct NodeTrafficInfo - { - std::map local_src ; // peer id., tunnel id - std::map local_dst ; - }; - - PeerNode(const RsPeerId& id,const std::list& friends) ; - ~PeerNode() ; - - RsRawItem *outgoing() ; - void incoming(RsRawItem *) ; - - const RsPeerId& id() const { return _id ;} - - void tick() ; - - const RsTurtle *turtle_service() const ; - - // Turtle-related methods - // - void manageFileHash(const RsFileHash& hash) ; - void provideFileHash(const RsFileHash& hash) ; - - const std::set& providedHashes() const { return _provided_hashes; } - const std::set& managedHashes() const { return _managed_hashes; } - - void getTrafficInfo(NodeTrafficInfo& trinfo) ; // - - private: - p3ServiceServer *_service_server ; - p3turtle *_turtle ; - MonitoredTurtleClient *_ftserver ; - pqiPublisher *_publisher ; - RsPeerId _id ; - - std::set _provided_hashes ; - std::set _managed_hashes ; -}; +#include "PeerNode.h" template class Graph { diff --git a/libretroshare/src/tests/network_simulator/network.pro b/libretroshare/src/tests/network_simulator/network.pro index b294968ec..2a43b1822 100644 --- a/libretroshare/src/tests/network_simulator/network.pro +++ b/libretroshare/src/tests/network_simulator/network.pro @@ -7,11 +7,11 @@ INCLUDEPATH *= ../.. .. TARGET = NetworkSim -SOURCES = Network.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \ +SOURCES = Network.cpp PeerNode.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \ TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp MonitoredRsPeers.cpp \ MonitoredTurtle.cpp -HEADERS = Network.h MonitoredTurtle.h NetworkViewer.h NetworkSimulatorGUI.h \ +HEADERS = Network.h PeerNode.h MonitoredTurtle.h NetworkViewer.h NetworkSimulatorGUI.h \ TurtleRouterStatistics.h RsAutoUpdatePage.h MonitoredRsPeers.h FORMS = NetworkSimulatorGUI.ui TurtleRouterStatistics.ui