Added Dht Query GUI display

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-peernet@4322 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-06-22 22:48:02 +00:00
parent 8e1118faf2
commit 4c7beaa5c7
8 changed files with 641 additions and 11 deletions

View File

@ -18,16 +18,19 @@ QT += network xml script
SOURCES += main.cpp\
mainwindow.cpp \
dhtwindow.cpp \
dhtquery.cpp \
peernet.cc \
netstatebox.cc
HEADERS += mainwindow.h \
dhtwindow.h \
dhtquery.h \
peernet.h \
netstatebox.h
FORMS += mainwindow.ui \
dhtwindow.ui
dhtwindow.ui \
dhtquery.ui
librs {

321
PeerNetQt/src/dhtquery.cpp Normal file
View File

@ -0,0 +1,321 @@
#include "dhtquery.h"
#include "ui_dhtquery.h"
#include <QTimer>
#include <QDateTime>
#include <sstream>
#include <algorithm>
#include <iostream>
#include <iomanip>
DhtQuery::DhtQuery(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::DhtQuery)
{
ui->setupUi(this);
// tick for gui update.
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
// connect add Peer button.
//connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addPeer()));
//connect(ui->chatLineEdit, SIGNAL(returnPressed()), this, SLOT(sendChat()));
}
DhtQuery::~DhtQuery()
{
delete ui;
}
void DhtQuery::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void DhtQuery::setPeerNet(PeerNet *pnet)
{
mPeerNet = pnet;
}
void DhtQuery::setQueryId(std::string id)
{
mQueryId = id;
}
void DhtQuery::update()
{
//std::cerr << "DhtQuery::update()" << std::endl;
updateDhtQuery();
}
#define QTW_COL_BUCKET 0
#define QTW_COL_PEERID 1
#define QTW_COL_IPADDR 2
#define QTW_COL_FLAGS 3
#define QTW_COL_FOUND 4
#define QTW_COL_SEND 5
#define QTW_COL_RECV 6
void DhtQuery::updateDhtQuery()
{
/* Hackish display of all Dht peers, should be split into buckets (as children) */
time_t now = time(NULL);
bdQuerySummary query;
if (!mPeerNet->get_query_status(mQueryId, query))
{
return;
}
ui->queryLine->setText(QString::fromStdString(mQueryId));
std::ostringstream statestr;
switch(query.mState)
{
default:
statestr << "Unknown";
break;
case BITDHT_QUERY_READY:
statestr << "Ready";
break;
case BITDHT_QUERY_QUERYING:
statestr << "Querying";
break;
case BITDHT_QUERY_FAILURE:
statestr << "Failure";
break;
case BITDHT_QUERY_FOUND_CLOSEST:
statestr << "Found Closest";
break;
case BITDHT_QUERY_PEER_UNREACHABLE:
statestr << "Unreachable";
break;
case BITDHT_QUERY_SUCCESS:
statestr << "Success";
break;
}
ui->queryStatusLabel->setText(QString::fromStdString(statestr.str()));
std::ostringstream extrastr;
extrastr << "QueryLimit: ";
bdStdPrintNodeId(extrastr, &(query.mLimit));
extrastr << " QueryFlags: " << query.mQueryFlags;
extrastr << " QueryAge: " << now - query.mQueryTS;
extrastr << " SearchTime: " << query.mSearchTime;
extrastr << " IdleRetryPeriod: " << query.mQueryIdlePeerRetryPeriod;
ui->queryExtraLabel->setText(QString::fromStdString(extrastr.str()));
std::multimap<bdMetric, bdPeer>::iterator cit;
std::list<bdPeer>::iterator lit;
//std::multimap<bdMetric, bdPeer> mClosest;
//std::multimap<bdMetric, bdPeer> mPotentialClosest;
//std::list<bdPeer> mPotentialProxies;
QTreeWidget *qcTreeWidget = ui->closestTreeWidget;
qcTreeWidget->clear();
for(cit = query.mClosest.begin(); cit != query.mClosest.end(); cit++)
{
/* find the entry */
QTreeWidgetItem *item = NULL;
bdPeer *bdp = &(cit->second);
/* insert */
item = new QTreeWidgetItem();
int dist = bdStdBucketDistance(&(cit->first));
std::ostringstream buckstr;
buckstr << "(" << std::setw(3) << std::setfill('0') << dist << ") ";
bdStdPrintNodeId(buckstr, &(cit->first));
std::ostringstream ipstr;
ipstr << inet_ntoa(bdp->mPeerId.addr.sin_addr);
ipstr << ":" << ntohs(bdp->mPeerId.addr.sin_port);
std::ostringstream idstr;
bdStdPrintNodeId(idstr, &(bdp->mPeerId.id));
std::ostringstream flagsstr;
flagsstr << "0x" << std::hex << std::setfill('0') << bdp->mPeerFlags;
std::ostringstream foundstr;
foundstr << now - bdp->mFoundTime << " secs ago";
std::ostringstream lastsendstr;
if (bdp->mLastSendTime == 0)
{
lastsendstr << "never";
}
else
{
lastsendstr << now - bdp->mLastSendTime << " secs ago";
}
std::ostringstream lastrecvstr;
if (bdp->mLastRecvTime == 0)
{
lastrecvstr << "never";
}
else
{
lastrecvstr << now - bdp->mLastRecvTime << " secs ago";
}
item -> setData(QTW_COL_BUCKET, Qt::DisplayRole, QString::fromStdString(buckstr.str()));
item -> setData(QTW_COL_IPADDR, Qt::DisplayRole, QString::fromStdString(ipstr.str()));
item -> setData(QTW_COL_PEERID, Qt::DisplayRole, QString::fromStdString(idstr.str()));
item -> setData(QTW_COL_FLAGS, Qt::DisplayRole, QString::fromStdString(flagsstr.str()));
item -> setData(QTW_COL_FOUND, Qt::DisplayRole, QString::fromStdString(foundstr.str()));
item -> setData(QTW_COL_SEND, Qt::DisplayRole, QString::fromStdString(lastsendstr.str()));
item -> setData(QTW_COL_RECV, Qt::DisplayRole, QString::fromStdString(lastrecvstr.str()));
qcTreeWidget->addTopLevelItem(item);
}
QTreeWidget *qpcTreeWidget = ui->potTreeWidget;
qpcTreeWidget->clear();
for(cit = query.mPotentialClosest.begin(); cit != query.mPotentialClosest.end(); cit++)
{
/* find the entry */
QTreeWidgetItem *item = NULL;
bdPeer *bdp = &(cit->second);
/* insert */
item = new QTreeWidgetItem();
int dist = bdStdBucketDistance(&(cit->first));
std::ostringstream buckstr;
buckstr << "(" << std::setw(3) << std::setfill('0') << dist << ") ";
bdStdPrintNodeId(buckstr, &(cit->first));
std::ostringstream ipstr;
ipstr << inet_ntoa(bdp->mPeerId.addr.sin_addr);
ipstr << ":" << ntohs(bdp->mPeerId.addr.sin_port);
std::ostringstream idstr;
bdStdPrintNodeId(idstr, &(bdp->mPeerId.id));
std::ostringstream flagsstr;
flagsstr << "0x" << std::hex << std::setfill('0') << bdp->mPeerFlags;
std::ostringstream foundstr;
foundstr << now - bdp->mFoundTime << " secs ago";
std::ostringstream lastsendstr;
if (bdp->mLastSendTime == 0)
{
lastsendstr << "never";
}
else
{
lastsendstr << now - bdp->mLastSendTime << " secs ago";
}
std::ostringstream lastrecvstr;
if (bdp->mLastRecvTime == 0)
{
lastrecvstr << "never";
}
else
{
lastrecvstr << now - bdp->mLastRecvTime << " secs ago";
}
item -> setData(QTW_COL_BUCKET, Qt::DisplayRole, QString::fromStdString(buckstr.str()));
item -> setData(QTW_COL_IPADDR, Qt::DisplayRole, QString::fromStdString(ipstr.str()));
item -> setData(QTW_COL_PEERID, Qt::DisplayRole, QString::fromStdString(idstr.str()));
item -> setData(QTW_COL_FLAGS, Qt::DisplayRole, QString::fromStdString(flagsstr.str()));
item -> setData(QTW_COL_FOUND, Qt::DisplayRole, QString::fromStdString(foundstr.str()));
item -> setData(QTW_COL_SEND, Qt::DisplayRole, QString::fromStdString(lastsendstr.str()));
item -> setData(QTW_COL_RECV, Qt::DisplayRole, QString::fromStdString(lastrecvstr.str()));
qpcTreeWidget->addTopLevelItem(item);
}
QTreeWidget *qpTreeWidget = ui->proxyTreeWidget;
qpTreeWidget->clear();
for(lit = query.mPotentialProxies.begin(); lit != query.mPotentialProxies.end(); lit++)
{
/* find the entry */
QTreeWidgetItem *item = NULL;
bdPeer *bdp = &(*lit);
/* insert */
item = new QTreeWidgetItem();
std::ostringstream buckstr;
buckstr << "n/a";
//bdStdPrintNodeId(buckstr, &(lit->first));
std::ostringstream ipstr;
ipstr << inet_ntoa(bdp->mPeerId.addr.sin_addr);
ipstr << ":" << ntohs(bdp->mPeerId.addr.sin_port);
std::ostringstream idstr;
bdStdPrintNodeId(idstr, &(bdp->mPeerId.id));
std::ostringstream flagsstr;
flagsstr << "0x" << std::hex << std::setfill('0') << bdp->mPeerFlags;
std::ostringstream foundstr;
foundstr << now - bdp->mFoundTime << " secs ago";
std::ostringstream lastsendstr;
if (bdp->mLastSendTime == 0)
{
lastsendstr << "never";
}
else
{
lastsendstr << now - bdp->mLastSendTime << " secs ago";
}
std::ostringstream lastrecvstr;
if (bdp->mLastRecvTime == 0)
{
lastrecvstr << "never";
}
else
{
lastrecvstr << now - bdp->mLastRecvTime << " secs ago";
}
item -> setData(QTW_COL_BUCKET, Qt::DisplayRole, QString::fromStdString(buckstr.str()));
item -> setData(QTW_COL_IPADDR, Qt::DisplayRole, QString::fromStdString(ipstr.str()));
item -> setData(QTW_COL_PEERID, Qt::DisplayRole, QString::fromStdString(idstr.str()));
item -> setData(QTW_COL_FLAGS, Qt::DisplayRole, QString::fromStdString(flagsstr.str()));
item -> setData(QTW_COL_FOUND, Qt::DisplayRole, QString::fromStdString(foundstr.str()));
item -> setData(QTW_COL_SEND, Qt::DisplayRole, QString::fromStdString(lastsendstr.str()));
item -> setData(QTW_COL_RECV, Qt::DisplayRole, QString::fromStdString(lastrecvstr.str()));
qpTreeWidget->addTopLevelItem(item);
}
}

34
PeerNetQt/src/dhtquery.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef DHTQUERYWINDOW_H
#define DHTQUERYWINDOW_H
#include <QMainWindow>
#include "peernet.h"
namespace Ui {
class DhtQuery;
}
class DhtQuery : public QMainWindow {
Q_OBJECT
public:
DhtQuery(QWidget *parent = 0);
~DhtQuery();
void setPeerNet(PeerNet *pnet);
void setQueryId(std::string id);
void updateDhtQuery();
public slots:
void update();
protected:
void changeEvent(QEvent *e);
private:
Ui::DhtQuery *ui;
PeerNet *mPeerNet;
std::string mQueryId;
};
#endif // DHTQUERYWINDOW_H

195
PeerNetQt/src/dhtquery.ui Normal file
View File

@ -0,0 +1,195 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DhtQuery</class>
<widget class="QMainWindow" name="DhtQuery">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>644</width>
<height>590</height>
</rect>
</property>
<property name="windowTitle">
<string>DhtQueryWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLineEdit" name="queryLine">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Query Peer Id</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="queryStatusLabel">
<property name="text">
<string>Query Status</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="queryExtraLabel">
<property name="text">
<string>Query Extra</string>
</property>
</widget>
</item>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTreeWidget" name="closestTreeWidget">
<column>
<property name="text">
<string>Metrix</string>
</property>
</column>
<column>
<property name="text">
<string>Closest Id</string>
</property>
</column>
<column>
<property name="text">
<string>Ip Address</string>
</property>
</column>
<column>
<property name="text">
<string>Flags</string>
</property>
</column>
<column>
<property name="text">
<string>Found</string>
</property>
</column>
<column>
<property name="text">
<string>Last Sent</string>
</property>
</column>
<column>
<property name="text">
<string>Last Recv</string>
</property>
</column>
</widget>
<widget class="QTreeWidget" name="potTreeWidget">
<column>
<property name="text">
<string>Metrix</string>
</property>
</column>
<column>
<property name="text">
<string>Potential Peer Id</string>
</property>
</column>
<column>
<property name="text">
<string>IP Address</string>
</property>
</column>
<column>
<property name="text">
<string>Flags</string>
</property>
</column>
<column>
<property name="text">
<string>Found</string>
</property>
</column>
<column>
<property name="text">
<string>Last Sent</string>
</property>
</column>
<column>
<property name="text">
<string>Last Recv</string>
</property>
</column>
</widget>
<widget class="QTreeWidget" name="proxyTreeWidget">
<column>
<property name="text">
<string>Metrix</string>
</property>
</column>
<column>
<property name="text">
<string>Ip Address</string>
</property>
</column>
<column>
<property name="text">
<string>Potential Proxy Id</string>
</property>
</column>
<column>
<property name="text">
<string>Flags</string>
</property>
</column>
<column>
<property name="text">
<string>Found</string>
</property>
</column>
<column>
<property name="text">
<string>Last Sent</string>
</property>
</column>
<column>
<property name="text">
<string>Last Recv</string>
</property>
</column>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>644</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -1,4 +1,5 @@
#include "dhtwindow.h"
#include "dhtquery.h"
#include "ui_dhtwindow.h"
#include <QTimer>
#include <QDateTime>
@ -8,6 +9,13 @@
#include <iostream>
#include <iomanip>
#define QTW_COL_PEERID 0
#define QTW_COL_STATUS 1
#define QTW_COL_FLAGS 2
#define QTW_COL_RESULTS 3
DhtWindow::DhtWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::DhtWindow)
@ -20,8 +28,8 @@ DhtWindow::DhtWindow(QWidget *parent) :
timer->start(1000);
// connect add Peer button.
//connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addPeer()));
//connect(ui->chatLineEdit, SIGNAL(returnPressed()), this, SLOT(sendChat()));
connect(ui->queryTreeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(setQueryId()));
connect(ui->queryButton, SIGNAL(clicked()), this, SLOT(showQuery()));
}
DhtWindow::~DhtWindow()
@ -47,6 +55,36 @@ void DhtWindow::setPeerNet(PeerNet *pnet)
}
void DhtWindow::setDhtQuery(DhtQuery *qw)
{
mQueryWindow = qw;
}
void DhtWindow::showQuery()
{
mQueryWindow->show();
}
void DhtWindow::setQueryId()
{
std::cerr << "DhtWindow::setQueryId()";
std::cerr << std::endl;
/* get the item that is selected in the queryWindow */
QTreeWidget *queryTreeWidget = ui->queryTreeWidget;
QTreeWidgetItem *item = queryTreeWidget->currentItem();
if (item)
{
std::string id = item->data(QTW_COL_PEERID, Qt::DisplayRole).toString().toStdString();
mQueryWindow->setQueryId(id);
std::cerr << "Setting Query Id to: " << id;
std::cerr << std::endl;
}
}
void DhtWindow::update()
{
//std::cerr << "DhtWindow::update()" << std::endl;
@ -146,10 +184,7 @@ void DhtWindow::updateDhtPeers()
}
#define QTW_COL_PEERID 0
#define QTW_COL_STATUS 1
#define QTW_COL_FLAGS 2
#define QTW_COL_RESULTS 3
void DhtWindow::updateDhtQueries()
{

View File

@ -4,6 +4,8 @@
#include <QMainWindow>
#include "peernet.h"
#include "dhtquery.h"
namespace Ui {
class DhtWindow;
}
@ -15,12 +17,16 @@ public:
~DhtWindow();
void setPeerNet(PeerNet *pnet);
void setDhtQuery(DhtQuery *qw);
void updateDhtPeers();
void updateDhtQueries();
public slots:
void update();
void setQueryId();
void showQuery();
protected:
void changeEvent(QEvent *e);
@ -28,6 +34,7 @@ protected:
private:
Ui::DhtWindow *ui;
PeerNet *mPeerNet;
DhtQuery *mQueryWindow;
};
#endif // DHTWINDOW_H

View File

@ -18,12 +18,41 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="dhtLabel">
<property name="text">
<string>DHT Details:</string>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>-1</number>
</property>
</widget>
<item>
<widget class="QLabel" name="dhtLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>DHT Details:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="queryButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show Query Details</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSplitter" name="splitter">

View File

@ -5,6 +5,7 @@
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "dhtwindow.h"
#include "dhtquery.h"
/* for static PThreads under windows... we need to init the library...
* Not sure if this is needed?
@ -145,10 +146,15 @@ int main(int argc, char *argv[])
w.show();
DhtWindow dw;
dw.hide();
DhtQuery qw;
qw.hide();
w.setPeerNet(pnet);
w.setDhtWindow(&dw);
dw.setPeerNet(pnet);
dw.setDhtQuery(&qw);
qw.setPeerNet(pnet);
qw.setQueryId("");
return a.exec();
}