added TR simulation

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5627 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-09-30 19:14:10 +00:00
parent ee8aac48a5
commit f283bede4b
11 changed files with 124 additions and 10 deletions

View File

@ -0,0 +1,12 @@
#include <iostream>
#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;
}

View File

@ -0,0 +1,14 @@
#include <rsserver/p3peers.h>
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 ;
};

View File

@ -0,0 +1,14 @@
#include "MonitoredTurtle.h"
bool MonitoredTurtleRouter::performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info)
{
std::map<std::string,FileInfo>::const_iterator it( _local_files.find(hash) ) ;
if(it != _local_files.end() )
{
info = it->second ;
return true ;
}
else
return false ;
}

View File

@ -12,4 +12,8 @@ class MonitoredTurtleRouter: public p3turtle
virtual bool loadConfiguration(std::string& loadHash) { return true ;} virtual bool loadConfiguration(std::string& loadHash) { return true ;}
virtual bool saveConfiguration() { return true ;} virtual bool saveConfiguration() { return true ;}
virtual bool performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info) ;
private:
std::map<std::string,FileInfo> _local_files ;
}; };

View File

@ -83,12 +83,12 @@ void Network::tick()
while( (item = node(i).outgoing()) != NULL) 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()) ; PeerNode& node = node_by_id(item->PeerId()) ;
item->PeerId(Network::node(i).id()) ; item->PeerId(Network::node(i).id()) ;
node.incoming(item) ; 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 const std::string getOwnId() { return _own_id ; }
virtual void getOnlineList(std::list<std::string>& lst) const { lst = _friends ; } virtual void getOnlineList(std::list<std::string>& lst) { lst = _friends ; }
virtual uint32_t getLinkType(const std::string&) const { return RS_NET_CONN_TCP_ALL | RS_NET_CONN_SPEED_NORMAL; } virtual uint32_t getLinkType(const std::string&) { return RS_NET_CONN_TCP_ALL | RS_NET_CONN_SPEED_NORMAL; }
private: private:
std::string _own_id ; std::string _own_id ;
@ -148,6 +148,7 @@ PeerNode::~PeerNode()
void PeerNode::tick() void PeerNode::tick()
{ {
std::cerr << " ticking peer node " << _id << std::endl;
_service_server->tick() ; _service_server->tick() ;
} }
@ -159,3 +160,9 @@ RsRawItem *PeerNode::outgoing()
{ {
return _service_server->outgoing() ; return _service_server->outgoing() ;
} }
void PeerNode::manageFileHash(const std::string& hash)
{
_turtle->monitorFileTunnels("file 1",hash,10000) ;
}

View File

@ -26,6 +26,10 @@ class PeerNode
void tick() ; void tick() ;
const RsTurtle *turtle_service() const ; const RsTurtle *turtle_service() const ;
// turtle methods
void manageFileHash(const std::string& hash) ;
private: private:
p3ServiceServer *_service_server ; p3ServiceServer *_service_server ;
MonitoredTurtleRouter *_turtle ; MonitoredTurtleRouter *_turtle ;

View File

@ -1,4 +1,8 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QMenu>
#include <QAction>
#include <util/rsid.h>
#include "Network.h" #include "Network.h"
#include "NetworkViewer.h" #include "NetworkViewer.h"
@ -21,6 +25,11 @@ NetworkViewer::NetworkViewer(QWidget *parent,Network&net)
} }
timerId = startTimer(1000/25) ; 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() void NetworkViewer::draw()
@ -258,9 +267,9 @@ void NetworkViewer::timerEvent(QTimerEvent *event)
if (!itemsMoved) { if (!itemsMoved) {
killTimer(timerId); killTimer(timerId);
#ifdef DEBUG_ELASTIC //#ifdef DEBUG_ELASTIC
std::cerr << "Killing timr" << std::endl ; std::cerr << "Killing timr" << std::endl ;
#endif //#endif
timerId = 0; timerId = 0;
} }
else else
@ -305,6 +314,10 @@ void NetworkViewer::mousePressEvent(QMouseEvent *e)
updateGL() ; updateGL() ;
emit nodeSelected(i) ; emit nodeSelected(i) ;
if(e->button() == Qt::RightButton)
emit customContextMenuRequested(QPoint(e->x(),e->y())) ;
return ; 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); 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() ;
}

View File

@ -1,3 +1,4 @@
#include <QPoint>
#include <QGLViewer/qglviewer.h> #include <QGLViewer/qglviewer.h>
// The network simulator GUI has the following functionalities: // The network simulator GUI has the following functionalities:
@ -41,6 +42,8 @@ class NetworkViewer: public QGLViewer
public slots: public slots:
void timerEvent(QTimerEvent *) ; void timerEvent(QTimerEvent *) ;
void contextMenu(QPoint) ;
void actionManageHash() ;
private: 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) ; 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 ; int _current_selected_node ;
bool _dragging ; bool _dragging ;
QAction *action_ManageHash ;
}; };

View File

@ -34,5 +34,6 @@ Implementation constraints
Complilation 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

View File

@ -2,6 +2,7 @@
#include "Network.h" #include "Network.h"
#include "NetworkSimulatorGUI.h" #include "NetworkSimulatorGUI.h"
#include "MonitoredRsPeers.h"
#include <QApplication> #include <QApplication>
#include <argstream.h> #include <argstream.h>
@ -28,6 +29,8 @@ int main(int argc, char *argv[])
network.initRandom(20,0.2) ; network.initRandom(20,0.2) ;
rsPeers = new MonitoredRsPeers(network) ;
if(show_gui) if(show_gui)
{ {
QApplication app(argc,argv) ; QApplication app(argc,argv) ;

View File

@ -7,8 +7,13 @@ INCLUDEPATH *= ../..
TARGET = NetworkSim TARGET = NetworkSim
SOURCES = Network.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp SOURCES = Network.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \
HEADERS = Network.h MonitoredTurtle.h NetworkViewer.h NetworkSimulatorGUI.h TurtleRouterStatistics.h RsAutoUpdatePage.h 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 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 LIBS *= ../../lib/libretroshare.a ../../../../libbitdht/src/lib/libbitdht.a ../../../../openpgpsdk/src/lib/libops.a -lgnome-keyring -lupnp -lssl -lcrypto -lbz2