added global router to network simulator

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7248 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-04-06 09:21:36 +00:00
parent e93cd21a2e
commit cc8b1e8cb0
10 changed files with 89 additions and 21 deletions

View File

@ -8,6 +8,8 @@ INCLUDEPATH *= ../../.. ..
TARGET = NetworkSim
DESTDIR = bin
PRE_TARGETDEPS = ../nscore/nscore.pro
SOURCES = main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \
TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp

View File

@ -29,6 +29,7 @@ class FakePublisher: public pqiPublisher
virtual bool sendItem(RsRawItem *item)
{
_item_queue.push_back(item) ;
return true ;
}
RsRawItem *outgoing()

View File

@ -0,0 +1,24 @@
#include "MonitoredGRouterClient.h"
const uint32_t MonitoredGRouterClient::GROUTER_CLIENT_SERVICE_ID_00 = 0x0111 ;
void MonitoredGRouterClient::receiveGRouterData(const GRouterKeyId& destination_key,const RsGRouterGenericDataItem *item)
{
std::cerr << "received one global grouter item for key " << destination_key << std::endl;
}
void MonitoredGRouterClient::provideKey(const GRouterKeyId& key_id)
{
_grouter->registerKey(key_id,GROUTER_CLIENT_SERVICE_ID_00,"test grouter address") ;
std::cerr << "Registered new key " << key_id << " for service " << std::hex << GROUTER_CLIENT_SERVICE_ID_00 << std::dec << std::endl;
}
void MonitoredGRouterClient::sendMessage(const GRouterKeyId& destination_key_id) const
{
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ;
item->data_size = 1000 + (RSRandom::random_u32()%1000) ;
item->data_bytes = (unsigned char *)malloc(item->data_size) ;
_grouter->sendData(destination_key_id,item) ;
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <grouter/grouterclientservice.h>
class MonitoredGRouterClient: public GRouterClientService
{
public:
static const uint32_t GROUTER_CLIENT_SERVICE_ID_00 ;
// Derived from grouterclientservice.h
//
virtual void connectToGlobalRouter(p3GRouter *p) { _grouter = p ; p->registerClientService(GROUTER_CLIENT_SERVICE_ID_00,this) ; }
virtual void receiveGRouterData(const GRouterKeyId& destination_key,const RsGRouterGenericDataItem *item);
// Own functionality
//
void sendMessage(const GRouterKeyId& destination_key) const ;
void provideKey(const GRouterKeyId& key) ;
private:
p3GRouter *_grouter ;
};

View File

@ -1,4 +1,4 @@
#include "MonitoredTurtle.h"
#include "MonitoredTurtleClient.h"
bool MonitoredTurtleClient::handleTunnelRequest(const TurtleFileHash& hash,const RsPeerId& peer_id)
{

View File

@ -15,7 +15,7 @@
#include <ft/ftcontroller.h>
#include <services/p3service.h>
#include "Network.h"
#include "MonitoredTurtle.h"
#include "MonitoredTurtleClient.h"
#include "FakeComponents.h"
bool Network::initRandom(uint32_t nb_nodes,float connexion_probability)

View File

@ -1,6 +1,7 @@
#include "PeerNode.h"
#include "FakeComponents.h"
#include "MonitoredTurtle.h"
#include "MonitoredTurtleClient.h"
#include "MonitoredGRouterClient.h"
PeerNode::PeerNode(const RsPeerId& id,const std::list<RsPeerId>& friends)
: _id(id)
@ -15,20 +16,24 @@ PeerNode::PeerNode(const RsPeerId& id,const std::list<RsPeerId>& friends)
_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.
// Turtle business
_service_server->addService(_turtle = new p3turtle(ctrl,link_mgr),true) ;
_turtle_client = new MonitoredTurtleClient ;
_turtle_client->connectToTurtleRouter(_turtle) ;
// global router business.
//
_service_server->addService(_grouter = new p3GRouter(ctrl,link_mgr),true) ;
_grouter_client = new MonitoredGRouterClient ;
_grouter_client->connectToGlobalRouter(_grouter) ;
}
PeerNode::~PeerNode()
@ -54,13 +59,13 @@ RsRawItem *PeerNode::outgoing()
void PeerNode::provideFileHash(const RsFileHash& hash)
{
_provided_hashes.insert(hash) ;
_ftserver->provideFileHash(hash) ;
_turtle_client->provideFileHash(hash) ;
}
void PeerNode::manageFileHash(const RsFileHash& hash)
{
_managed_hashes.insert(hash) ;
_turtle->monitorTunnels(hash,_ftserver) ;
_turtle->monitorTunnels(hash,_turtle_client) ;
}
void PeerNode::getTrafficInfo(NodeTrafficInfo& info)

View File

@ -3,10 +3,11 @@
#include <retroshare/rstypes.h>
#include <turtle/p3turtle.h>
class MonitoredTurtleRouter ;
class MonitoredTurtleClient ;
class MonitoredGRouterClient ;
class RsTurtle ;
class p3turtle ;
class p3GRouter ;
class pqiPublisher ;
class RsRawItem ;
class p3ServiceServer ;
@ -30,10 +31,10 @@ class PeerNode
void tick() ;
const RsTurtle *turtle_service() const { return _turtle ; }
// Turtle-related methods
//
const RsTurtle *turtle_service() const { return _turtle ; }
void manageFileHash(const RsFileHash& hash) ;
void provideFileHash(const RsFileHash& hash) ;
@ -42,13 +43,23 @@ class PeerNode
void getTrafficInfo(NodeTrafficInfo& trinfo) ; //
// GRouter-related methods
//
private:
p3ServiceServer *_service_server ;
p3turtle *_turtle ;
MonitoredTurtleClient *_ftserver ;
pqiPublisher *_publisher ;
RsPeerId _id ;
// turtle stuff
//
p3turtle *_turtle ;
MonitoredTurtleClient *_turtle_client ;
// grouter stuff
//
p3GRouter *_grouter ;
MonitoredGRouterClient *_grouter_client ;
std::set<RsFileHash> _provided_hashes ;
std::set<RsFileHash> _managed_hashes ;
};

View File

@ -8,11 +8,13 @@ TARGET = nscore
SOURCES = Network.cpp \
PeerNode.cpp \
MonitoredRsPeers.cpp \
MonitoredTurtle.cpp
MonitoredTurtleClient.cpp \
MonitoredGRouterClient.cpp
HEADERS = Network.h \
PeerNode.h \
MonitoredTurtle.h \
MonitoredRsPeers.h
MonitoredRsPeers.h \
MonitoredTurtleClient.h \
MonitoredGRouterClient.h
DESTDIR = ../lib