added tunnel display

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5637 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-10-04 21:06:01 +00:00
parent fbf8a76cee
commit 729464d60e
6 changed files with 103 additions and 3 deletions

View File

@ -12,3 +12,13 @@ bool MonitoredTurtleRouter::performLocalHashSearch(const TurtleFileHash& hash,Fi
else
return false ;
}
void MonitoredTurtleRouter::provideFileHash(const std::string& hash)
{
FileInfo& info( _local_files[hash] ) ;
info.fname = "File 1" ;
info.size = 100000 ;
info.hash = hash ;
}

View File

@ -14,6 +14,10 @@ class MonitoredTurtleRouter: public p3turtle
virtual bool saveConfiguration() { return true ;}
virtual bool performLocalHashSearch(const TurtleFileHash& hash,FileInfo& info) ;
// new functions to replace somme internal functionalities
void provideFileHash(const std::string& hash) ;
private:
std::map<std::string,FileInfo> _local_files ;
};

View File

@ -115,6 +115,8 @@ class FakeLinkMgr: public p3LinkMgrIMPL
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; }
virtual bool getPeerName(const std::string &ssl_id, std::string &name) { name = ssl_id ; return true ;}
private:
std::string _own_id ;
std::list<std::string> _friends ;
@ -161,8 +163,31 @@ RsRawItem *PeerNode::outgoing()
return _service_server->outgoing() ;
}
void PeerNode::provideFileHash(const std::string& hash)
{
_provided_hashes.insert(hash) ;
_turtle->provideFileHash(hash) ;
}
void PeerNode::manageFileHash(const std::string& hash)
{
_managed_hashes.insert(hash) ;
_turtle->monitorFileTunnels("file 1",hash,10000) ;
}
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,6 +6,7 @@
#include <list>
#include <vector>
#include <stdint.h>
#include <turtle/p3turtle.h>
class MonitoredTurtleRouter ;
class RsTurtle ;
@ -15,6 +16,12 @@ 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 std::string& id,const std::list<std::string>& friends) ;
~PeerNode() ;
@ -27,13 +34,23 @@ class PeerNode
const RsTurtle *turtle_service() const ;
// turtle methods
// Turtle-related methods
//
void manageFileHash(const std::string& hash) ;
void provideFileHash(const std::string& 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 ;
MonitoredTurtleRouter *_turtle ;
std::string _id ;
std::set<TurtleFileHash> _provided_hashes ;
std::set<TurtleFileHash> _managed_hashes ;
};
template<class NODE_TYPE> class Graph

View File

@ -28,7 +28,7 @@ NetworkViewer::NetworkViewer(QWidget *parent,Network&net)
connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(contextMenu(QPoint)));
action_ManageHash = new QAction(QString("Manage hash"),this) ;
action_ManageHash = new QAction(QString("Manage new random hash"),this) ;
QObject::connect(action_ManageHash,SIGNAL(triggered()),this,SLOT(actionManageHash())) ;
}
@ -53,19 +53,28 @@ void NetworkViewer::draw()
// Now, draw all edges
glEnable(GL_LINE_SMOOTH) ;
glColor3f(0.4f,0.4f,0.4f) ;
glBegin(GL_LINES) ;
for(uint32_t i=0;i<_network.n_nodes();++i)
{
PeerNode::NodeTrafficInfo traffic_info ;
_network.node(i).getTrafficInfo(traffic_info) ;
const std::set<uint32_t>& neighs( _network.neighbors(i) ) ;
for(std::set<uint32_t>::const_iterator it(neighs.begin());it!=neighs.end();++it)
{
if(traffic_info.local_src.find(_network.node(*it).id())!=traffic_info.local_src.end() || traffic_info.local_dst.find(_network.node(*it).id())!=traffic_info.local_dst.end())
glColor3f(0.9f,0.4f,0.2f) ;
else
glColor3f(0.4f,0.4f,0.4f) ;
if( i < *it )
{
glVertex2f(_node_coords[ i].x, _node_coords[ i].y) ;
glVertex2f(_node_coords[*it].x, _node_coords[*it].y) ;
}
}
}
glEnd() ;
@ -428,6 +437,26 @@ void NetworkViewer::contextMenu(QPoint p)
QMenu contextMnu ;//= ui.msgText->createStandardContextMenu(matrix.map(point));
contextMnu.addAction(action_ManageHash);
// make a list of hashes provided by all nodes except this one
std::set<TurtleFileHash> hashes ;
for(uint32_t i=0;i<_network.n_nodes();++i)
if(i != _current_selected_node)
hashes.insert( _network.node(i).managedHashes().begin(), _network.node(i).managedHashes().end()) ;
if(!hashes.empty())
{
QMenu *Mnu2 = contextMnu.addMenu("Provide hash") ;
for(std::set<TurtleFileHash>::const_iterator it(hashes.begin());it!=hashes.end();++it)
{
QAction* provide_hash_action = new QAction(QString::fromStdString(*it), Mnu2);
connect(provide_hash_action, SIGNAL(triggered()), this, SLOT(actionProvideHash()));
Mnu2->addAction(provide_hash_action);
}
}
contextMnu.exec(mapToGlobal(p));
}
@ -452,4 +481,17 @@ void NetworkViewer::actionManageHash()
updateGL() ;
}
void NetworkViewer::actionProvideHash()
{
QString hash = qobject_cast<QAction*>(sender())->text() ;//data().toString().toStdString();
if(_current_selected_node < 0)
return ;
std::cerr << "Providing hash " << hash.toStdString() << std::endl;
_network.node(_current_selected_node).provideFileHash(hash.toStdString()) ;
updateGL() ;
}

View File

@ -44,6 +44,7 @@ class NetworkViewer: public QGLViewer
void timerEvent(QTimerEvent *) ;
void contextMenu(QPoint) ;
void actionManageHash() ;
void actionProvideHash() ;
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) ;
@ -70,4 +71,5 @@ class NetworkViewer: public QGLViewer
bool _dragging ;
QAction *action_ManageHash ;
QAction *action_ProvideHash ;
};