mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Add configuration age to listnetworks results and GUI.
This commit is contained in:
parent
31d718c4a4
commit
4296db2358
9 changed files with 130 additions and 57 deletions
|
@ -1,11 +1,17 @@
|
||||||
#include "aboutwindow.h"
|
#include "aboutwindow.h"
|
||||||
#include "ui_aboutwindow.h"
|
#include "ui_aboutwindow.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include "../node/Defaults.hpp"
|
||||||
|
|
||||||
AboutWindow::AboutWindow(QWidget *parent) :
|
AboutWindow::AboutWindow(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::AboutWindow)
|
ui(new Ui::AboutWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
#ifndef __APPLE__
|
||||||
|
ui->uninstallButton->hide();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
AboutWindow::~AboutWindow()
|
AboutWindow::~AboutWindow()
|
||||||
|
@ -15,4 +21,11 @@ AboutWindow::~AboutWindow()
|
||||||
|
|
||||||
void AboutWindow::on_uninstallButton_clicked()
|
void AboutWindow::on_uninstallButton_clicked()
|
||||||
{
|
{
|
||||||
|
// Apple only... other OSes have more intrinsic mechanisms for uninstalling.
|
||||||
|
QMessageBox::information(
|
||||||
|
this,
|
||||||
|
"Uninstalling ZeroTier One",
|
||||||
|
QString("Uninstalling ZeroTier One is easy!\n\nJust remove ZeroTier One from your Applications folder and the service will automatically shut down within a few seconds. Then, on your next reboot, all other support files will be automatically deleted.\n\nIf you wish to uninstall the service and support files now, you can run the 'uninstall.sh' script found in ") + ZeroTier::ZT_DEFAULTS.defaultHomePath.c_str() + " using the 'sudo' command in a terminal.",
|
||||||
|
QMessageBox::Ok,
|
||||||
|
QMessageBox::NoButton);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>About ZeroTier One</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowIcon">
|
<property name="windowIcon">
|
||||||
<iconset resource="resources.qrc">
|
<iconset resource="resources.qrc">
|
||||||
|
|
|
@ -52,9 +52,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->startTimer(1000);
|
this->startTimer(1000); // poll service every second
|
||||||
this->setEnabled(false); // gets enabled when updates are received
|
this->setEnabled(false); // gets enabled when updates are received
|
||||||
mainWindow = this;
|
mainWindow = this;
|
||||||
|
this->cyclesSinceResponseFromService = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -101,6 +102,11 @@ void MainWindow::timerEvent(QTimerEvent *event)
|
||||||
zeroTierClient = new ZeroTier::Node::LocalClient(authToken.c_str(),0,&handleZTMessage,this);
|
zeroTierClient = new ZeroTier::Node::LocalClient(authToken.c_str(),0,&handleZTMessage,this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: do something more user-friendly here... or maybe try to restart
|
||||||
|
// the service?
|
||||||
|
if (++this->cyclesSinceResponseFromService == 3)
|
||||||
|
QMessageBox::critical(this,"No Response from Service","The ZeroTier One service does not appear to be running.",QMessageBox::Ok,QMessageBox::NoButton);
|
||||||
|
|
||||||
zeroTierClient->send("info");
|
zeroTierClient->send("info");
|
||||||
zeroTierClient->send("listnetworks");
|
zeroTierClient->send("listnetworks");
|
||||||
zeroTierClient->send("listpeers");
|
zeroTierClient->send("listpeers");
|
||||||
|
@ -119,9 +125,7 @@ void MainWindow::customEvent(QEvent *event)
|
||||||
if (hdr[0] != "200")
|
if (hdr[0] != "200")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Enable main window on valid communication with service
|
this->cyclesSinceResponseFromService = 0;
|
||||||
if (!this->isEnabled())
|
|
||||||
this->setEnabled(true);
|
|
||||||
|
|
||||||
if (hdr[1] == "info") {
|
if (hdr[1] == "info") {
|
||||||
if (hdr.size() >= 3)
|
if (hdr.size() >= 3)
|
||||||
|
@ -134,8 +138,8 @@ void MainWindow::customEvent(QEvent *event)
|
||||||
std::map< std::string,std::vector<std::string> > byNwid;
|
std::map< std::string,std::vector<std::string> > byNwid;
|
||||||
for(unsigned long i=1;i<m->ztMessage.size();++i) {
|
for(unsigned long i=1;i<m->ztMessage.size();++i) {
|
||||||
std::vector<std::string> l(ZeroTier::Node::LocalClient::splitLine(m->ztMessage[i]));
|
std::vector<std::string> l(ZeroTier::Node::LocalClient::splitLine(m->ztMessage[i]));
|
||||||
// 200 listnetworks <nwid> <name> <status> <type> <dev> <ips>
|
// 200 listnetworks <nwid> <name> <status> <config age> <type> <dev> <ips>
|
||||||
if ((l.size() == 8)&&(l[2].length() == 16))
|
if ((l.size() == 9)&&(l[2].length() == 16))
|
||||||
byNwid[l[2]] = l;
|
byNwid[l[2]] = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,10 +153,10 @@ void MainWindow::customEvent(QEvent *event)
|
||||||
if (byNwid.count(i->first)) {
|
if (byNwid.count(i->first)) {
|
||||||
std::vector<std::string> &l = byNwid[i->first];
|
std::vector<std::string> &l = byNwid[i->first];
|
||||||
i->second.second->setNetworkName(l[3]);
|
i->second.second->setNetworkName(l[3]);
|
||||||
i->second.second->setStatus(l[4]);
|
i->second.second->setStatus(l[4],l[5]);
|
||||||
i->second.second->setNetworkType(l[5]);
|
i->second.second->setNetworkType(l[6]);
|
||||||
i->second.second->setNetworkDeviceName(l[6]);
|
i->second.second->setNetworkDeviceName(l[7]);
|
||||||
i->second.second->setIps(l[7]);
|
i->second.second->setIps(l[8]);
|
||||||
} else {
|
} else {
|
||||||
delete ui->networkListWidget->takeItem(i->second.first);
|
delete ui->networkListWidget->takeItem(i->second.first);
|
||||||
}
|
}
|
||||||
|
@ -163,10 +167,10 @@ void MainWindow::customEvent(QEvent *event)
|
||||||
std::vector<std::string> &l = i->second;
|
std::vector<std::string> &l = i->second;
|
||||||
Network *nw = new Network((QWidget *)0,i->first);
|
Network *nw = new Network((QWidget *)0,i->first);
|
||||||
nw->setNetworkName(l[3]);
|
nw->setNetworkName(l[3]);
|
||||||
nw->setStatus(l[4]);
|
nw->setStatus(l[4],l[5]);
|
||||||
nw->setNetworkType(l[5]);
|
nw->setNetworkType(l[6]);
|
||||||
nw->setNetworkDeviceName(l[6]);
|
nw->setNetworkDeviceName(l[7]);
|
||||||
nw->setIps(l[7]);
|
nw->setIps(l[8]);
|
||||||
QListWidgetItem *item = new QListWidgetItem();
|
QListWidgetItem *item = new QListWidgetItem();
|
||||||
item->setSizeHint(nw->sizeHint());
|
item->setSizeHint(nw->sizeHint());
|
||||||
ui->networkListWidget->addItem(item);
|
ui->networkListWidget->addItem(item);
|
||||||
|
@ -186,13 +190,23 @@ void MainWindow::customEvent(QEvent *event)
|
||||||
QString st(this->myAddress);
|
QString st(this->myAddress);
|
||||||
st += " (";
|
st += " (";
|
||||||
st += this->myStatus;
|
st += this->myStatus;
|
||||||
|
st += ", v";
|
||||||
|
st += this->myVersion;
|
||||||
st += ", ";
|
st += ", ";
|
||||||
st += QString::number(this->numPeers);
|
st += QString::number(this->numPeers);
|
||||||
st += " peers)";
|
st += " peers)";
|
||||||
while (st.size() < 38)
|
while (st.size() < 45)
|
||||||
st += QChar::Space;
|
st += QChar::Space;
|
||||||
ui->statusAndAddressButton->setText(st);
|
ui->statusAndAddressButton->setText(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->myStatus == "ONLINE") {
|
||||||
|
if (!this->isEnabled())
|
||||||
|
this->setEnabled(true);
|
||||||
|
} else {
|
||||||
|
if (this->isEnabled())
|
||||||
|
this->setEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_joinNetworkButton_clicked()
|
void MainWindow::on_joinNetworkButton_clicked()
|
||||||
|
@ -217,12 +231,6 @@ void MainWindow::on_actionAbout_triggered()
|
||||||
about->show();
|
about->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionJoin_Network_triggered()
|
|
||||||
{
|
|
||||||
// Does the same thing as clicking join button on main UI
|
|
||||||
on_joinNetworkButton_clicked();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_networkIdLineEdit_textChanged(const QString &text)
|
void MainWindow::on_networkIdLineEdit_textChanged(const QString &text)
|
||||||
{
|
{
|
||||||
QString newText;
|
QString newText;
|
||||||
|
|
|
@ -45,8 +45,7 @@ protected:
|
||||||
private slots:
|
private slots:
|
||||||
void on_joinNetworkButton_clicked();
|
void on_joinNetworkButton_clicked();
|
||||||
void on_actionAbout_triggered();
|
void on_actionAbout_triggered();
|
||||||
void on_actionJoin_Network_triggered();
|
void on_networkIdLineEdit_textChanged(const QString &text);
|
||||||
void on_networkIdLineEdit_textChanged(const QString &arg1);
|
|
||||||
void on_statusAndAddressButton_clicked();
|
void on_statusAndAddressButton_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -56,6 +55,7 @@ private:
|
||||||
QString myStatus;
|
QString myStatus;
|
||||||
QString myVersion;
|
QString myVersion;
|
||||||
unsigned int numPeers;
|
unsigned int numPeers;
|
||||||
|
unsigned int cyclesSinceResponseFromService;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
<string notr="true">border: 0;</string>
|
<string notr="true">border: 0;</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>0000000000 (OFFLINE, 0 peers) </string>
|
<string>0000000000 (OFFLINE, v0.0.0, 0 peers) </string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolButtonStyle">
|
<property name="toolButtonStyle">
|
||||||
<enum>Qt::ToolButtonTextOnly</enum>
|
<enum>Qt::ToolButtonTextOnly</enum>
|
||||||
|
@ -203,7 +203,6 @@
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>File</string>
|
<string>File</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionJoin_Network"/>
|
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionExit"/>
|
<addaction name="actionExit"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -215,11 +214,6 @@
|
||||||
<string>About</string>
|
<string>About</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionJoin_Network">
|
|
||||||
<property name="text">
|
|
||||||
<string>Join Network</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="actionExit">
|
<action name="actionExit">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Exit</string>
|
<string>Exit</string>
|
||||||
|
|
|
@ -28,9 +28,12 @@ Network::~Network()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::setStatus(const std::string &status)
|
void Network::setStatus(const std::string &status,const std::string &age)
|
||||||
{
|
{
|
||||||
ui->statusLabel->setText(QString(status.c_str()));
|
ui->statusLabel->setText(QString(status.c_str()));
|
||||||
|
if (status == "OK")
|
||||||
|
ui->ageLabel->setText(QString("(configuration is ") + age.c_str() + " seconds old)");
|
||||||
|
else ui->ageLabel->setText(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::setNetworkName(const std::string &name)
|
void Network::setNetworkName(const std::string &name)
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
explicit Network(QWidget *parent = 0,const std::string &nwid = std::string());
|
explicit Network(QWidget *parent = 0,const std::string &nwid = std::string());
|
||||||
virtual ~Network();
|
virtual ~Network();
|
||||||
|
|
||||||
void setStatus(const std::string &status);
|
void setStatus(const std::string &status,const std::string &age);
|
||||||
void setNetworkName(const std::string &name);
|
void setNetworkName(const std::string &name);
|
||||||
void setNetworkType(const std::string &type);
|
void setNetworkType(const std::string &type);
|
||||||
void setNetworkDeviceName(const std::string &dev);
|
void setNetworkDeviceName(const std::string &dev);
|
||||||
|
|
|
@ -174,28 +174,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
|
||||||
<widget class="QLabel" name="statusLabel">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<weight>75</weight>
|
|
||||||
<bold>true</bold>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>?</string>
|
|
||||||
</property>
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::PlainText</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0">
|
<item row="6" column="0">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -222,6 +200,76 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>12</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="statusLabel">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>?</string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::PlainText</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="ageLabel">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>(configuration is 0 seconds old)</string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::PlainText</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -200,7 +200,7 @@ std::vector<std::string> NodeConfig::execute(const char *command)
|
||||||
_r->topology->eachPeer(_DumpPeerStatistics(r));
|
_r->topology->eachPeer(_DumpPeerStatistics(r));
|
||||||
} else if (cmd[0] == "listnetworks") {
|
} else if (cmd[0] == "listnetworks") {
|
||||||
Mutex::Lock _l(_networks_m);
|
Mutex::Lock _l(_networks_m);
|
||||||
_P("200 listnetworks <nwid> <name> <status> <type> <dev> <ips>");
|
_P("200 listnetworks <nwid> <name> <status> <config age> <type> <dev> <ips>");
|
||||||
for(std::map< uint64_t,SharedPtr<Network> >::const_iterator nw(_networks.begin());nw!=_networks.end();++nw) {
|
for(std::map< uint64_t,SharedPtr<Network> >::const_iterator nw(_networks.begin());nw!=_networks.end();++nw) {
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
std::set<InetAddress> ips(nw->second->tap().ips());
|
std::set<InetAddress> ips(nw->second->tap().ips());
|
||||||
|
@ -211,10 +211,17 @@ std::vector<std::string> NodeConfig::execute(const char *command)
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<NetworkConfig> nconf(nw->second->config2());
|
SharedPtr<NetworkConfig> nconf(nw->second->config2());
|
||||||
_P("200 listnetworks %.16llx %s %s %s %s %s",
|
|
||||||
|
long long age = (nconf) ? ((long long)Utils::now() - (long long)nconf->timestamp()) : (long long)0;
|
||||||
|
if (age < 0)
|
||||||
|
age = 0;
|
||||||
|
age /= 1000;
|
||||||
|
|
||||||
|
_P("200 listnetworks %.16llx %s %s %lld %s %s %s",
|
||||||
(unsigned long long)nw->first,
|
(unsigned long long)nw->first,
|
||||||
((nconf) ? nconf->name().c_str() : "?"),
|
((nconf) ? nconf->name().c_str() : "?"),
|
||||||
Network::statusString(nw->second->status()),
|
Network::statusString(nw->second->status()),
|
||||||
|
age,
|
||||||
((nconf) ? (nconf->isOpen() ? "public" : "private") : "?"),
|
((nconf) ? (nconf->isOpen() ? "public" : "private") : "?"),
|
||||||
nw->second->tap().deviceName().c_str(),
|
nw->second->tap().deviceName().c_str(),
|
||||||
((tmp.length() > 0) ? tmp.c_str() : "-"));
|
((tmp.length() > 0) ? tmp.c_str() : "-"));
|
||||||
|
|
Loading…
Add table
Reference in a new issue