diff --git a/libretroshare/src/tests/network_simulator/NetworkSimulatorGUI.cpp b/libretroshare/src/tests/network_simulator/gui/NetworkSimulatorGUI.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/NetworkSimulatorGUI.cpp rename to libretroshare/src/tests/network_simulator/gui/NetworkSimulatorGUI.cpp diff --git a/libretroshare/src/tests/network_simulator/NetworkSimulatorGUI.h b/libretroshare/src/tests/network_simulator/gui/NetworkSimulatorGUI.h similarity index 100% rename from libretroshare/src/tests/network_simulator/NetworkSimulatorGUI.h rename to libretroshare/src/tests/network_simulator/gui/NetworkSimulatorGUI.h diff --git a/libretroshare/src/tests/network_simulator/NetworkSimulatorGUI.ui b/libretroshare/src/tests/network_simulator/gui/NetworkSimulatorGUI.ui similarity index 100% rename from libretroshare/src/tests/network_simulator/NetworkSimulatorGUI.ui rename to libretroshare/src/tests/network_simulator/gui/NetworkSimulatorGUI.ui diff --git a/libretroshare/src/tests/network_simulator/NetworkViewer.cpp b/libretroshare/src/tests/network_simulator/gui/NetworkViewer.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/NetworkViewer.cpp rename to libretroshare/src/tests/network_simulator/gui/NetworkViewer.cpp diff --git a/libretroshare/src/tests/network_simulator/NetworkViewer.h b/libretroshare/src/tests/network_simulator/gui/NetworkViewer.h similarity index 100% rename from libretroshare/src/tests/network_simulator/NetworkViewer.h rename to libretroshare/src/tests/network_simulator/gui/NetworkViewer.h diff --git a/libretroshare/src/tests/network_simulator/RsAutoUpdatePage.cpp b/libretroshare/src/tests/network_simulator/gui/RsAutoUpdatePage.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/RsAutoUpdatePage.cpp rename to libretroshare/src/tests/network_simulator/gui/RsAutoUpdatePage.cpp diff --git a/libretroshare/src/tests/network_simulator/RsAutoUpdatePage.h b/libretroshare/src/tests/network_simulator/gui/RsAutoUpdatePage.h similarity index 100% rename from libretroshare/src/tests/network_simulator/RsAutoUpdatePage.h rename to libretroshare/src/tests/network_simulator/gui/RsAutoUpdatePage.h diff --git a/libretroshare/src/tests/network_simulator/TurtleRouterStatistics.cpp b/libretroshare/src/tests/network_simulator/gui/TurtleRouterStatistics.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/TurtleRouterStatistics.cpp rename to libretroshare/src/tests/network_simulator/gui/TurtleRouterStatistics.cpp diff --git a/libretroshare/src/tests/network_simulator/TurtleRouterStatistics.h b/libretroshare/src/tests/network_simulator/gui/TurtleRouterStatistics.h similarity index 100% rename from libretroshare/src/tests/network_simulator/TurtleRouterStatistics.h rename to libretroshare/src/tests/network_simulator/gui/TurtleRouterStatistics.h diff --git a/libretroshare/src/tests/network_simulator/TurtleRouterStatistics.ui b/libretroshare/src/tests/network_simulator/gui/TurtleRouterStatistics.ui similarity index 100% rename from libretroshare/src/tests/network_simulator/TurtleRouterStatistics.ui rename to libretroshare/src/tests/network_simulator/gui/TurtleRouterStatistics.ui diff --git a/libretroshare/src/tests/network_simulator/gui/gui.pro b/libretroshare/src/tests/network_simulator/gui/gui.pro new file mode 100644 index 000000000..b647a8ea5 --- /dev/null +++ b/libretroshare/src/tests/network_simulator/gui/gui.pro @@ -0,0 +1,19 @@ +TEMPLATE = app + +CONFIG *= qt qglviewer +QT *= xml opengl + +INCLUDEPATH *= ../.. .. + +TARGET = NetworkSim +DESTDIR = bin + +SOURCES = main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \ + TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp + +HEADERS = NetworkViewer.h NetworkSimulatorGUI.h \ + TurtleRouterStatistics.h RsAutoUpdatePage.h + +FORMS = NetworkSimulatorGUI.ui TurtleRouterStatistics.ui + +LIBS *= ../../../lib/libretroshare.a ../../../../../libbitdht/src/lib/libbitdht.a ../../../../../../lib/sqlcipher/.libs/libsqlcipher.a ../../../../../openpgpsdk/src/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2 -lixml diff --git a/libretroshare/src/tests/network_simulator/main.cpp b/libretroshare/src/tests/network_simulator/gui/main.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/main.cpp rename to libretroshare/src/tests/network_simulator/gui/main.cpp diff --git a/libretroshare/src/tests/network_simulator/network.pro b/libretroshare/src/tests/network_simulator/network.pro deleted file mode 100644 index 2a43b1822..000000000 --- a/libretroshare/src/tests/network_simulator/network.pro +++ /dev/null @@ -1,19 +0,0 @@ -TEMPLATE = app - -CONFIG *= qt qglviewer -QT *= xml opengl - -INCLUDEPATH *= ../.. .. - -TARGET = NetworkSim - -SOURCES = Network.cpp PeerNode.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \ - TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp MonitoredRsPeers.cpp \ - MonitoredTurtle.cpp - -HEADERS = Network.h PeerNode.h MonitoredTurtle.h NetworkViewer.h NetworkSimulatorGUI.h \ - TurtleRouterStatistics.h RsAutoUpdatePage.h MonitoredRsPeers.h - -FORMS = NetworkSimulatorGUI.ui TurtleRouterStatistics.ui - -LIBS *= ../../lib/libretroshare.a ../../../../libbitdht/src/lib/libbitdht.a ../../../../../lib/sqlcipher/.libs/libsqlcipher.a ../../../../openpgpsdk/src/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2 -lixml diff --git a/libretroshare/src/tests/network_simulator/nscore/FakeComponents.h b/libretroshare/src/tests/network_simulator/nscore/FakeComponents.h new file mode 100644 index 000000000..1fea8c479 --- /dev/null +++ b/libretroshare/src/tests/network_simulator/nscore/FakeComponents.h @@ -0,0 +1,90 @@ +#pragma once + +#include +#include +#include + +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 ; +}; + +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; +}; + diff --git a/libretroshare/src/tests/network_simulator/MainLoop.cpp b/libretroshare/src/tests/network_simulator/nscore/MainLoop.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/MainLoop.cpp rename to libretroshare/src/tests/network_simulator/nscore/MainLoop.cpp diff --git a/libretroshare/src/tests/network_simulator/MonitoredRsPeers.cpp b/libretroshare/src/tests/network_simulator/nscore/MonitoredRsPeers.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/MonitoredRsPeers.cpp rename to libretroshare/src/tests/network_simulator/nscore/MonitoredRsPeers.cpp diff --git a/libretroshare/src/tests/network_simulator/MonitoredRsPeers.h b/libretroshare/src/tests/network_simulator/nscore/MonitoredRsPeers.h similarity index 100% rename from libretroshare/src/tests/network_simulator/MonitoredRsPeers.h rename to libretroshare/src/tests/network_simulator/nscore/MonitoredRsPeers.h diff --git a/libretroshare/src/tests/network_simulator/MonitoredTurtle.cpp b/libretroshare/src/tests/network_simulator/nscore/MonitoredTurtle.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/MonitoredTurtle.cpp rename to libretroshare/src/tests/network_simulator/nscore/MonitoredTurtle.cpp diff --git a/libretroshare/src/tests/network_simulator/MonitoredTurtle.h b/libretroshare/src/tests/network_simulator/nscore/MonitoredTurtle.h similarity index 100% rename from libretroshare/src/tests/network_simulator/MonitoredTurtle.h rename to libretroshare/src/tests/network_simulator/nscore/MonitoredTurtle.h diff --git a/libretroshare/src/tests/network_simulator/Network.cpp b/libretroshare/src/tests/network_simulator/nscore/Network.cpp similarity index 100% rename from libretroshare/src/tests/network_simulator/Network.cpp rename to libretroshare/src/tests/network_simulator/nscore/Network.cpp diff --git a/libretroshare/src/tests/network_simulator/Network.h b/libretroshare/src/tests/network_simulator/nscore/Network.h similarity index 100% rename from libretroshare/src/tests/network_simulator/Network.h rename to libretroshare/src/tests/network_simulator/nscore/Network.h diff --git a/libretroshare/src/tests/network_simulator/nscore/PeerNode.cpp b/libretroshare/src/tests/network_simulator/nscore/PeerNode.cpp new file mode 100644 index 000000000..9a944565d --- /dev/null +++ b/libretroshare/src/tests/network_simulator/nscore/PeerNode.cpp @@ -0,0 +1,81 @@ +#include "PeerNode.h" +#include "FakeComponents.h" +#include "MonitoredTurtle.h" + +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 + +class MonitoredTurtleRouter ; +class MonitoredTurtleClient ; +class RsTurtle ; +class p3turtle ; +class pqiPublisher ; +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 { return _turtle ; } + + // 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 ; +}; + diff --git a/libretroshare/src/tests/network_simulator/nscore/core.pro b/libretroshare/src/tests/network_simulator/nscore/core.pro new file mode 100644 index 000000000..7c2b39623 --- /dev/null +++ b/libretroshare/src/tests/network_simulator/nscore/core.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG *= staticlib + +INCLUDEPATH *= ../../.. .. + +TARGET = nscore + +SOURCES = Network.cpp \ + PeerNode.cpp \ + MonitoredRsPeers.cpp \ + MonitoredTurtle.cpp + +HEADERS = Network.h \ + PeerNode.h \ + MonitoredTurtle.h \ + MonitoredRsPeers.h + +DESTDIR = ../lib