diff --git a/libretroshare/src/tests/network_simulator/MonitoredRsPeers.cpp b/libretroshare/src/tests/network_simulator/MonitoredRsPeers.cpp new file mode 100644 index 000000000..aa952ea68 --- /dev/null +++ b/libretroshare/src/tests/network_simulator/MonitoredRsPeers.cpp @@ -0,0 +1,12 @@ +#include +#include "MonitoredRsPeers.h" + +MonitoredRsPeers::MonitoredRsPeers(const Network& net) + : p3Peers(NULL,NULL,NULL),_network(net) +{ +} + +bool MonitoredRsPeers::getPeerDetails(const std::string& str,RsPeerDetails& details) +{ + std::cerr << __PRETTY_FUNCTION__ << " called" << std::endl; +} diff --git a/libretroshare/src/tests/network_simulator/MonitoredRsPeers.h b/libretroshare/src/tests/network_simulator/MonitoredRsPeers.h new file mode 100644 index 000000000..4706cc316 --- /dev/null +++ b/libretroshare/src/tests/network_simulator/MonitoredRsPeers.h @@ -0,0 +1,14 @@ +#include + +class Network ; + +class MonitoredRsPeers: public p3Peers +{ + public: + MonitoredRsPeers(const Network& net) ; + + virtual bool getPeerDetails(const std::string& peer_id,RsPeerDetails& details) ; + + private: + const Network& _network ; +}; diff --git a/libretroshare/src/tests/network_simulator/MonitoredTurtle.cpp b/libretroshare/src/tests/network_simulator/MonitoredTurtle.cpp new file mode 100644 index 000000000..4013f837a --- /dev/null +++ b/libretroshare/src/tests/network_simulator/MonitoredTurtle.cpp @@ -0,0 +1,14 @@ +#include "MonitoredTurtle.h" + +bool MonitoredTurtleRouter::performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info) +{ + std::map::const_iterator it( _local_files.find(hash) ) ; + + if(it != _local_files.end() ) + { + info = it->second ; + return true ; + } + else + return false ; +} diff --git a/libretroshare/src/tests/network_simulator/MonitoredTurtle.h b/libretroshare/src/tests/network_simulator/MonitoredTurtle.h index 07e5b5310..397313e17 100644 --- a/libretroshare/src/tests/network_simulator/MonitoredTurtle.h +++ b/libretroshare/src/tests/network_simulator/MonitoredTurtle.h @@ -12,4 +12,8 @@ class MonitoredTurtleRouter: public p3turtle virtual bool loadConfiguration(std::string& loadHash) { return true ;} virtual bool saveConfiguration() { return true ;} + virtual bool performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info) ; + + private: + std::map _local_files ; }; diff --git a/libretroshare/src/tests/network_simulator/Network.cpp b/libretroshare/src/tests/network_simulator/Network.cpp index 034dd95e5..b27abd68b 100644 --- a/libretroshare/src/tests/network_simulator/Network.cpp +++ b/libretroshare/src/tests/network_simulator/Network.cpp @@ -83,12 +83,12 @@ void Network::tick() while( (item = node(i).outgoing()) != NULL) { + std::cerr << "Tick: send item from " << item->PeerId() << " to " << Network::node(i).id() << std::endl; + PeerNode& node = node_by_id(item->PeerId()) ; item->PeerId(Network::node(i).id()) ; node.incoming(item) ; - - std::cerr << "Tick: send item from " << item->PeerId() << " to " << Network::node(i).id() << std::endl; } } } @@ -111,9 +111,9 @@ class FakeLinkMgr: public p3LinkMgrIMPL { } - virtual std::string getOwnId() const { return _own_id ; } - virtual void getOnlineList(std::list& lst) const { lst = _friends ; } - virtual uint32_t getLinkType(const std::string&) const { return RS_NET_CONN_TCP_ALL | RS_NET_CONN_SPEED_NORMAL; } + virtual const std::string getOwnId() { return _own_id ; } + virtual void getOnlineList(std::list& lst) { lst = _friends ; } + virtual uint32_t getLinkType(const std::string&) { return RS_NET_CONN_TCP_ALL | RS_NET_CONN_SPEED_NORMAL; } private: std::string _own_id ; @@ -148,6 +148,7 @@ PeerNode::~PeerNode() void PeerNode::tick() { + std::cerr << " ticking peer node " << _id << std::endl; _service_server->tick() ; } @@ -159,3 +160,9 @@ RsRawItem *PeerNode::outgoing() { return _service_server->outgoing() ; } + +void PeerNode::manageFileHash(const std::string& hash) +{ + _turtle->monitorFileTunnels("file 1",hash,10000) ; +} + diff --git a/libretroshare/src/tests/network_simulator/Network.h b/libretroshare/src/tests/network_simulator/Network.h index 14d10d650..4650c2216 100644 --- a/libretroshare/src/tests/network_simulator/Network.h +++ b/libretroshare/src/tests/network_simulator/Network.h @@ -26,6 +26,10 @@ class PeerNode void tick() ; const RsTurtle *turtle_service() const ; + + // turtle methods + void manageFileHash(const std::string& hash) ; + private: p3ServiceServer *_service_server ; MonitoredTurtleRouter *_turtle ; diff --git a/libretroshare/src/tests/network_simulator/NetworkViewer.cpp b/libretroshare/src/tests/network_simulator/NetworkViewer.cpp index 78ccfadc9..409fb61b7 100644 --- a/libretroshare/src/tests/network_simulator/NetworkViewer.cpp +++ b/libretroshare/src/tests/network_simulator/NetworkViewer.cpp @@ -1,4 +1,8 @@ #include +#include +#include + +#include #include "Network.h" #include "NetworkViewer.h" @@ -21,6 +25,11 @@ NetworkViewer::NetworkViewer(QWidget *parent,Network&net) } timerId = startTimer(1000/25) ; + + connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(contextMenu(QPoint))); + + action_ManageHash = new QAction(QString("Manage hash"),this) ; + QObject::connect(action_ManageHash,SIGNAL(triggered()),this,SLOT(actionManageHash())) ; } void NetworkViewer::draw() @@ -258,9 +267,9 @@ void NetworkViewer::timerEvent(QTimerEvent *event) if (!itemsMoved) { killTimer(timerId); -#ifdef DEBUG_ELASTIC +//#ifdef DEBUG_ELASTIC std::cerr << "Killing timr" << std::endl ; -#endif +//#endif timerId = 0; } else @@ -305,6 +314,10 @@ void NetworkViewer::mousePressEvent(QMouseEvent *e) updateGL() ; emit nodeSelected(i) ; + + if(e->button() == Qt::RightButton) + emit customContextMenuRequested(QPoint(e->x(),e->y())) ; + return ; } @@ -408,3 +421,35 @@ void NetworkViewer::calculateForces(const Network::NodeId& node_id,const double new_y = std::min(std::max(new_y, 10.0f), height() - 10.0f); } +void NetworkViewer::contextMenu(QPoint p) +{ + std::cerr << "Context menu request at point " << p.x() << " " << p.y() << std::endl; + + QMenu contextMnu ;//= ui.msgText->createStandardContextMenu(matrix.map(point)); + + contextMnu.addAction(action_ManageHash); + contextMnu.exec(mapToGlobal(p)); +} + +void NetworkViewer::actionManageHash() +{ + if(_current_selected_node < 0) + return ; + + std::cerr << "Managing hash..." << std::endl; + + unsigned char hash_bytes[20] ; + for(int i=0;i<20;++i) + hash_bytes[i] = lrand48() & 0xff ; + + std::string hash = t_RsGenericIdType<20>(hash_bytes).toStdString(false) ;; + + std::cerr << " current node = " << _current_selected_node << std::endl ; + std::cerr << " adding random hash = " << hash << std::endl; + + _network.node(_current_selected_node).manageFileHash(hash) ; + + updateGL() ; +} + + diff --git a/libretroshare/src/tests/network_simulator/NetworkViewer.h b/libretroshare/src/tests/network_simulator/NetworkViewer.h index 98beb8f9a..4585bb2f9 100644 --- a/libretroshare/src/tests/network_simulator/NetworkViewer.h +++ b/libretroshare/src/tests/network_simulator/NetworkViewer.h @@ -1,3 +1,4 @@ +#include #include // The network simulator GUI has the following functionalities: @@ -41,6 +42,8 @@ class NetworkViewer: public QGLViewer public slots: void timerEvent(QTimerEvent *) ; + void contextMenu(QPoint) ; + void actionManageHash() ; private: void calculateForces(const Network::NodeId& node_id,const double *map,int W,int H,float x,float y,float /*speedf*/,float& new_x, float& new_y) ; @@ -65,4 +68,6 @@ class NetworkViewer: public QGLViewer int _current_selected_node ; bool _dragging ; + + QAction *action_ManageHash ; }; diff --git a/libretroshare/src/tests/network_simulator/README.txt b/libretroshare/src/tests/network_simulator/README.txt index 7aaad52e6..630ea6815 100644 --- a/libretroshare/src/tests/network_simulator/README.txt +++ b/libretroshare/src/tests/network_simulator/README.txt @@ -34,5 +34,6 @@ Implementation constraints Complilation ============ - * needs QGLViewer-dev library (standard on ubuntu, package name is libqglviewer-qt4-dev) + * needs the QGLViewer-dev library (standard on ubuntu, package name is libqglviewer-qt4-dev) + * should compile on windows and MacOS as well. Use http://www.libqglviewer.com diff --git a/libretroshare/src/tests/network_simulator/main.cpp b/libretroshare/src/tests/network_simulator/main.cpp index 0d8d97816..de5881b5e 100644 --- a/libretroshare/src/tests/network_simulator/main.cpp +++ b/libretroshare/src/tests/network_simulator/main.cpp @@ -2,6 +2,7 @@ #include "Network.h" #include "NetworkSimulatorGUI.h" +#include "MonitoredRsPeers.h" #include #include @@ -28,6 +29,8 @@ int main(int argc, char *argv[]) network.initRandom(20,0.2) ; + rsPeers = new MonitoredRsPeers(network) ; + if(show_gui) { QApplication app(argc,argv) ; diff --git a/libretroshare/src/tests/network_simulator/network.pro b/libretroshare/src/tests/network_simulator/network.pro index 693d880cb..8f795b0cc 100644 --- a/libretroshare/src/tests/network_simulator/network.pro +++ b/libretroshare/src/tests/network_simulator/network.pro @@ -7,8 +7,13 @@ INCLUDEPATH *= ../.. TARGET = NetworkSim -SOURCES = Network.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp -HEADERS = Network.h MonitoredTurtle.h NetworkViewer.h NetworkSimulatorGUI.h TurtleRouterStatistics.h RsAutoUpdatePage.h +SOURCES = Network.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \ + TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp MonitoredRsPeers.cpp \ + MonitoredTurtle.cpp + +HEADERS = Network.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 ../../../../openpgpsdk/src/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2