2011-05-23 17:45:25 -04:00
|
|
|
#include <QObject>
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsturtle.h>
|
2011-05-23 17:45:25 -04:00
|
|
|
#include <retroshare/rspeers.h>
|
2009-08-17 03:00:34 -04:00
|
|
|
#include "TurtleRouterDialog.h"
|
2011-05-23 17:45:25 -04:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QStylePainter>
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2011-05-30 19:06:22 -04:00
|
|
|
#include "gui/settings/rsharesettings.h"
|
|
|
|
|
2011-08-14 17:25:41 -04:00
|
|
|
static const uint MAX_TUNNEL_REQUESTS_DISPLAY = 10 ;
|
2011-03-02 09:31:03 -05:00
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
|
2009-08-17 03:00:34 -04:00
|
|
|
TurtleRouterDialog::TurtleRouterDialog(QWidget *parent)
|
2010-02-14 04:06:37 -05:00
|
|
|
: RsAutoUpdatePage(2000,parent)
|
2009-08-17 03:00:34 -04:00
|
|
|
{
|
|
|
|
setupUi(this) ;
|
2011-05-30 19:06:22 -04:00
|
|
|
|
|
|
|
m_bProcessSettings = false;
|
2010-02-14 04:06:37 -05:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
// Init the basic setup.
|
|
|
|
//
|
|
|
|
QStringList stl ;
|
|
|
|
int n=0 ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
2010-04-03 14:29:25 -04:00
|
|
|
stl.push_back(tr("Search requests")) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
top_level_s_requests = new QTreeWidgetItem(_f2f_TW,stl) ;
|
|
|
|
_f2f_TW->insertTopLevelItem(n++,top_level_s_requests) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
2010-04-03 14:29:25 -04:00
|
|
|
stl.push_back(tr("Tunnel requests")) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
top_level_t_requests = new QTreeWidgetItem(_f2f_TW,stl) ;
|
|
|
|
_f2f_TW->insertTopLevelItem(n++,top_level_t_requests) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
top_level_hashes.clear() ;
|
2011-05-23 17:45:25 -04:00
|
|
|
|
2011-05-30 19:06:22 -04:00
|
|
|
// load settings
|
|
|
|
processSettings(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TurtleRouterDialog::~TurtleRouterDialog()
|
|
|
|
{
|
|
|
|
// save settings
|
|
|
|
processSettings(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TurtleRouterDialog::processSettings(bool bLoad)
|
|
|
|
{
|
|
|
|
m_bProcessSettings = true;
|
|
|
|
|
|
|
|
Settings->beginGroup(QString("TurtleRouterDialog"));
|
|
|
|
|
|
|
|
if (bLoad) {
|
|
|
|
// load settings
|
|
|
|
|
|
|
|
// state of splitter
|
2011-05-31 17:39:44 -04:00
|
|
|
//splitter->restoreState(Settings->value("Splitter").toByteArray());
|
2011-05-30 19:06:22 -04:00
|
|
|
} else {
|
|
|
|
// save settings
|
|
|
|
|
|
|
|
// state of splitter
|
2011-05-31 17:39:44 -04:00
|
|
|
//Settings->setValue("Splitter", splitter->saveState());
|
2011-05-30 19:06:22 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings->endGroup();
|
|
|
|
|
|
|
|
m_bProcessSettings = false;
|
|
|
|
|
2009-08-17 03:00:34 -04:00
|
|
|
}
|
|
|
|
|
2011-05-30 19:06:22 -04:00
|
|
|
|
2010-02-14 04:06:37 -05:00
|
|
|
void TurtleRouterDialog::updateDisplay()
|
2009-08-17 03:00:34 -04:00
|
|
|
{
|
2010-02-14 04:06:37 -05:00
|
|
|
std::vector<std::vector<std::string> > hashes_info ;
|
|
|
|
std::vector<std::vector<std::string> > tunnels_info ;
|
2011-05-23 17:45:25 -04:00
|
|
|
std::vector<TurtleRequestDisplayInfo > search_reqs_info ;
|
|
|
|
std::vector<TurtleRequestDisplayInfo > tunnel_reqs_info ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-14 04:06:37 -05:00
|
|
|
rsTurtle->getInfo(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
updateTunnelRequests(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
2011-05-31 17:51:15 -04:00
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString TurtleRouterDialog::getPeerName(const std::string& peer_id)
|
|
|
|
{
|
|
|
|
static std::map<std::string, QString> names ;
|
|
|
|
|
|
|
|
std::map<std::string,QString>::const_iterator it = names.find(peer_id) ;
|
|
|
|
|
|
|
|
if( it != names.end())
|
|
|
|
return it->second ;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RsPeerDetails detail ;
|
|
|
|
if(!rsPeers->getPeerDetails(peer_id,detail))
|
|
|
|
return "unknown peer";
|
|
|
|
|
2011-07-17 19:07:29 -04:00
|
|
|
return (names[peer_id] = QString::fromUtf8(detail.name.c_str())) ;
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TurtleRouterDialog::updateTunnelRequests( const std::vector<std::vector<std::string> >& hashes_info,
|
|
|
|
const std::vector<std::vector<std::string> >& tunnels_info,
|
|
|
|
const std::vector<TurtleRequestDisplayInfo >& search_reqs_info,
|
|
|
|
const std::vector<TurtleRequestDisplayInfo >& tunnel_reqs_info)
|
|
|
|
{
|
2010-02-14 04:06:37 -05:00
|
|
|
// now display this in the QTableWidgets
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
QStringList stl ;
|
2010-02-14 05:53:57 -05:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
// remove all children of top level objects
|
|
|
|
for(int i=0;i<_f2f_TW->topLevelItemCount();++i)
|
2011-03-02 09:31:03 -05:00
|
|
|
{
|
|
|
|
QTreeWidgetItem *taken ;
|
|
|
|
while( (taken = _f2f_TW->topLevelItem(i)->takeChild(0)) != NULL)
|
|
|
|
delete taken ;
|
|
|
|
}
|
2010-02-14 05:53:57 -05:00
|
|
|
|
2010-02-23 04:14:35 -05:00
|
|
|
for(uint i=0;i<hashes_info.size();++i)
|
|
|
|
findParentHashItem(hashes_info[i][0]) ;
|
|
|
|
|
2010-02-26 09:34:46 -05:00
|
|
|
bool unknown_hash_found = false ;
|
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
// check that an entry exist for all hashes
|
|
|
|
for(uint i=0;i<tunnels_info.size();++i)
|
2010-02-14 05:53:57 -05:00
|
|
|
{
|
2010-02-20 17:51:24 -05:00
|
|
|
const std::string& hash(tunnels_info[i][3]) ;
|
|
|
|
|
|
|
|
QTreeWidgetItem *parent = findParentHashItem(hash) ;
|
|
|
|
|
2012-02-05 16:05:11 -05:00
|
|
|
if(parent->text(0).left(14) == tr("Unknown hashes"))
|
2010-02-26 09:34:46 -05:00
|
|
|
unknown_hash_found = true ;
|
|
|
|
|
2012-02-05 16:05:11 -05:00
|
|
|
QString str = tr("Tunnel id") + ": " + QString::fromUtf8(tunnels_info[i][0].c_str()) + "\t [" + QString::fromUtf8(tunnels_info[i][2].c_str()) + "] --> [" + QString::fromUtf8(tunnels_info[i][1].c_str()) + "]\t\t " + tr("last transfer") + ": " + QString::fromStdString(tunnels_info[i][4]) + "\t " + tr("Speed") + ": " + QString::fromStdString(tunnels_info[i][5]) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
parent->addChild(new QTreeWidgetItem(stl)) ;
|
2010-02-14 05:53:57 -05:00
|
|
|
}
|
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
for(uint i=0;i<search_reqs_info.size();++i)
|
|
|
|
{
|
2012-02-05 16:05:11 -05:00
|
|
|
QString str = tr("Request id: %1\t from [%2]\t %3 secs ago").arg(search_reqs_info[i].request_id,0,16).arg(getPeerName(search_reqs_info[i].source_peer_id)).arg(search_reqs_info[i].age);
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
top_level_s_requests->addChild(new QTreeWidgetItem(stl)) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
}
|
2010-04-03 14:29:25 -04:00
|
|
|
top_level_s_requests->setText(0, tr("Search requests") + "(" + QString::number(search_reqs_info.size()) + ")" ) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
for(uint i=0;i<tunnel_reqs_info.size();++i)
|
|
|
|
if(i+MAX_TUNNEL_REQUESTS_DISPLAY >= tunnel_reqs_info.size() || i < MAX_TUNNEL_REQUESTS_DISPLAY)
|
2011-03-02 09:31:03 -05:00
|
|
|
{
|
2012-02-05 16:05:11 -05:00
|
|
|
QString str = tr("Request id: %1\t from [%2]\t %3 secs ago").arg(tunnel_reqs_info[i].request_id,0,16).arg(getPeerName(tunnel_reqs_info[i].source_peer_id)).arg(tunnel_reqs_info[i].age);
|
2011-03-02 09:31:03 -05:00
|
|
|
|
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
|
|
|
|
|
|
|
top_level_t_requests->addChild(new QTreeWidgetItem(stl)) ;
|
|
|
|
}
|
|
|
|
else if(i == MAX_TUNNEL_REQUESTS_DISPLAY)
|
|
|
|
{
|
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(QString("...")) ;
|
|
|
|
top_level_t_requests->addChild(new QTreeWidgetItem(stl)) ;
|
|
|
|
|
|
|
|
}
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-04-03 14:29:25 -04:00
|
|
|
top_level_t_requests->setText(0, tr("Tunnel requests") + "("+QString::number(tunnel_reqs_info.size()) + ")") ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
QTreeWidgetItem *unknown_hashs_item = findParentHashItem("") ;
|
2012-02-05 16:05:11 -05:00
|
|
|
unknown_hashs_item->setText(0,tr("Unknown hashes") + " (" + QString::number(unknown_hashs_item->childCount())+QString(")")) ;
|
2011-03-02 09:31:03 -05:00
|
|
|
|
2010-02-23 04:14:35 -05:00
|
|
|
// Ok, this is a N2 search, but there are very few elements in the list.
|
2010-02-20 17:51:24 -05:00
|
|
|
for(int i=2;i<_f2f_TW->topLevelItemCount();)
|
2010-02-23 04:14:35 -05:00
|
|
|
{
|
|
|
|
bool found = false ;
|
2010-02-26 09:34:46 -05:00
|
|
|
|
2012-02-05 16:05:11 -05:00
|
|
|
if(_f2f_TW->topLevelItem(i)->text(0).left(14) == tr("Unknown hashes") && unknown_hash_found)
|
2010-02-26 09:34:46 -05:00
|
|
|
found = true ;
|
|
|
|
|
2010-02-27 15:19:31 -05:00
|
|
|
if(_f2f_TW->topLevelItem(i)->childCount() > 0) // this saves uploading hashes
|
|
|
|
found = true ;
|
|
|
|
|
2010-02-26 09:34:46 -05:00
|
|
|
for(uint j=0;j<hashes_info.size() && !found;++j)
|
2010-02-23 04:14:35 -05:00
|
|
|
if(_f2f_TW->topLevelItem(i)->text(0).toStdString() == hashes_info[j][0])
|
|
|
|
found=true ;
|
|
|
|
|
|
|
|
if(!found)
|
2011-03-02 09:31:03 -05:00
|
|
|
delete _f2f_TW->takeTopLevelItem(i) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
else
|
|
|
|
++i ;
|
2010-02-23 04:14:35 -05:00
|
|
|
}
|
2010-02-20 17:51:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem *TurtleRouterDialog::findParentHashItem(const std::string& hash)
|
|
|
|
{
|
|
|
|
// look for the hash, and insert a new element if necessary.
|
|
|
|
//
|
2012-02-05 16:05:11 -05:00
|
|
|
QList<QTreeWidgetItem*> items = _f2f_TW->findItems((hash=="")?tr("Unknown hashes"):QString::fromStdString(hash),Qt::MatchStartsWith) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
|
|
|
|
if(items.empty())
|
|
|
|
{
|
|
|
|
QStringList stl ;
|
2012-02-05 16:05:11 -05:00
|
|
|
stl.push_back((hash=="")?tr("Unknown hashes"):QString::fromStdString(hash)) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(_f2f_TW,stl) ;
|
|
|
|
_f2f_TW->insertTopLevelItem(0,item) ;
|
|
|
|
|
|
|
|
return item ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return items.front() ;
|
2009-08-17 03:00:34 -04:00
|
|
|
}
|