mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
ee8aac48a5
commit
f283bede4b
@ -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;
|
||||
}
|
14
libretroshare/src/tests/network_simulator/MonitoredRsPeers.h
Normal file
14
libretroshare/src/tests/network_simulator/MonitoredRsPeers.h
Normal 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 ;
|
||||
};
|
@ -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 ;
|
||||
}
|
@ -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<std::string,FileInfo> _local_files ;
|
||||
};
|
||||
|
@ -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<std::string>& 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<std::string>& 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) ;
|
||||
}
|
||||
|
||||
|
@ -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 ;
|
||||
|
@ -1,4 +1,8 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
#include <util/rsid.h>
|
||||
|
||||
#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() ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <QPoint>
|
||||
#include <QGLViewer/qglviewer.h>
|
||||
|
||||
// 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 ;
|
||||
};
|
||||
|
@ -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
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "Network.h"
|
||||
#include "NetworkSimulatorGUI.h"
|
||||
#include "MonitoredRsPeers.h"
|
||||
#include <QApplication>
|
||||
#include <argstream.h>
|
||||
|
||||
@ -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) ;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user