a bit of code splitting

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7243 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-04-06 07:56:20 +00:00
parent 7403a5c6d9
commit 44a1f6f6f3
3 changed files with 4 additions and 216 deletions

View File

@ -16,6 +16,7 @@
#include <services/p3service.h> #include <services/p3service.h>
#include "Network.h" #include "Network.h"
#include "MonitoredTurtle.h" #include "MonitoredTurtle.h"
#include "FakeComponents.h"
bool Network::initRandom(uint32_t nb_nodes,float connexion_probability) bool Network::initRandom(uint32_t nb_nodes,float connexion_probability)
{ {
@ -100,168 +101,3 @@ PeerNode& Network::node_by_id(const RsPeerId& id)
return node(it->second) ; return node(it->second) ;
} }
class FakeLinkMgr: public p3LinkMgrIMPL
{
public:
FakeLinkMgr(const RsPeerId& own_id,const std::list<RsPeerId>& friends)
: p3LinkMgrIMPL(NULL,NULL),_own_id(own_id),_friends(friends)
{
}
virtual const RsPeerId& getOwnId() { return _own_id ; }
virtual void getOnlineList(std::list<RsPeerId>& 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<RsPeerId> _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<RsRawItem*> _item_queue ;
};
class FakePeerMgr: public p3PeerMgrIMPL
{
public:
FakePeerMgr(const RsPeerId& own,const std::list<RsPeerId>& ids)
: p3PeerMgrIMPL(own,RsPgpId(),"no name","location name")
{
for(std::list<RsPeerId>::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<RsPeerId> _ids ;
};
const RsTurtle *PeerNode::turtle_service() const
{
return _turtle ;
}
class FakeServiceControl: public p3ServiceControl
{
public:
FakeServiceControl(p3LinkMgr *lm)
: p3ServiceControl(lm),mLink(lm)
{
}
virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet)
{
std::list<RsPeerId> ids ;
mLink->getOnlineList(ids) ;
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
peerSet.insert(*it) ;
}
virtual bool checkFilter(uint32_t,const RsPeerId& id)
{
return true ;
}
p3LinkMgr *mLink;
};
PeerNode::PeerNode(const RsPeerId& id,const std::list<RsPeerId>& 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<FakePublisher*>(_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<std::vector<std::string> > hashes_info ;
std::vector<std::vector<std::string> > tunnels_info ;
std::vector<TurtleRequestDisplayInfo > search_reqs_info ;
std::vector<TurtleRequestDisplayInfo > tunnel_reqs_info ;
_turtle->getInfo(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
for(uint32_t i=0;i<tunnels_info.size();++i)
{
info.local_src[tunnels_info[i][1]] = tunnels_info[i][0] ;
info.local_src[tunnels_info[i][2]] = tunnels_info[i][0] ;
}
}

View File

@ -6,55 +6,7 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <stdint.h> #include <stdint.h>
#include <turtle/p3turtle.h> #include "PeerNode.h"
class MonitoredTurtleRouter ;
class MonitoredTurtleClient ;
class RsTurtle ;
class RsRawItem ;
class p3ServiceServer ;
class PeerNode
{
public:
struct NodeTrafficInfo
{
std::map<std::string,std::string> local_src ; // peer id., tunnel id
std::map<std::string,std::string> local_dst ;
};
PeerNode(const RsPeerId& id,const std::list<RsPeerId>& friends) ;
~PeerNode() ;
RsRawItem *outgoing() ;
void incoming(RsRawItem *) ;
const RsPeerId& id() const { return _id ;}
void tick() ;
const RsTurtle *turtle_service() const ;
// Turtle-related methods
//
void manageFileHash(const RsFileHash& hash) ;
void provideFileHash(const RsFileHash& hash) ;
const std::set<TurtleFileHash>& providedHashes() const { return _provided_hashes; }
const std::set<TurtleFileHash>& managedHashes() const { return _managed_hashes; }
void getTrafficInfo(NodeTrafficInfo& trinfo) ; //
private:
p3ServiceServer *_service_server ;
p3turtle *_turtle ;
MonitoredTurtleClient *_ftserver ;
pqiPublisher *_publisher ;
RsPeerId _id ;
std::set<TurtleFileHash> _provided_hashes ;
std::set<TurtleFileHash> _managed_hashes ;
};
template<class NODE_TYPE> class Graph template<class NODE_TYPE> class Graph
{ {

View File

@ -7,11 +7,11 @@ INCLUDEPATH *= ../.. ..
TARGET = NetworkSim TARGET = NetworkSim
SOURCES = Network.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \ SOURCES = Network.cpp PeerNode.cpp main.cpp NetworkViewer.cpp NetworkSimulatorGUI.cpp \
TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp MonitoredRsPeers.cpp \ TurtleRouterStatistics.cpp RsAutoUpdatePage.cpp MonitoredRsPeers.cpp \
MonitoredTurtle.cpp MonitoredTurtle.cpp
HEADERS = Network.h MonitoredTurtle.h NetworkViewer.h NetworkSimulatorGUI.h \ HEADERS = Network.h PeerNode.h MonitoredTurtle.h NetworkViewer.h NetworkSimulatorGUI.h \
TurtleRouterStatistics.h RsAutoUpdatePage.h MonitoredRsPeers.h TurtleRouterStatistics.h RsAutoUpdatePage.h MonitoredRsPeers.h
FORMS = NetworkSimulatorGUI.ui TurtleRouterStatistics.ui FORMS = NetworkSimulatorGUI.ui TurtleRouterStatistics.ui