2009-07-23 13:11:51 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, crypton
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2009-08-19 18:15:16 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2009-07-23 13:11:51 -04:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "ServerPage.h"
|
2013-07-14 08:53:38 -04:00
|
|
|
#include <gui/FileTransfer/TurtleRouterDialog.h>
|
|
|
|
#include <gui/FileTransfer/TurtleRouterStatistics.h>
|
2009-08-17 16:19:02 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
#include "rshare.h"
|
2011-01-07 11:56:57 -05:00
|
|
|
#include "rsharesettings.h"
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2012-11-25 15:26:32 -05:00
|
|
|
#include <retroshare/rsconfig.h>
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rspeers.h>
|
2012-02-10 17:23:06 -05:00
|
|
|
#include <retroshare/rsturtle.h>
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
ServerPage::ServerPage(QWidget * parent, Qt::WFlags flags)
|
2009-08-19 18:15:16 -04:00
|
|
|
: ConfigPage(parent, flags)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
connect( ui.netModeComboBox, SIGNAL( activated ( int ) ), this, SLOT( toggleUPnP( ) ) );
|
|
|
|
connect( ui.allowIpDeterminationCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleIpDetermination(bool) ) );
|
2009-12-13 16:59:26 -05:00
|
|
|
connect( ui.allowTunnelConnectionCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleTunnelConnection(bool) ) );
|
2012-02-10 17:23:06 -05:00
|
|
|
connect( ui._max_tr_up_per_sec_SB, SIGNAL( valueChanged( int ) ), this, SLOT( updateMaxTRUpRate(int) ) );
|
2012-11-25 09:26:32 -05:00
|
|
|
connect( ui._turtle_enabled_CB, SIGNAL( toggled( bool ) ), this, SLOT( toggleTurtleRouting(bool) ) );
|
2013-02-22 16:42:27 -05:00
|
|
|
connect( ui._routing_info_PB, SIGNAL( clicked() ), this, SLOT( showRoutingInfo() ) );
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
|
|
|
timer->start(1000);
|
|
|
|
|
2013-02-22 16:42:27 -05:00
|
|
|
_routing_info_page = NULL ;
|
|
|
|
|
2009-09-15 20:03:51 -04:00
|
|
|
//load();
|
2009-07-23 13:11:51 -04:00
|
|
|
updateStatus();
|
|
|
|
|
|
|
|
bool b = rsPeers->getAllowServerIPDetermination() ;
|
|
|
|
ui.allowIpDeterminationCB->setChecked(b) ;
|
|
|
|
ui.IPServersLV->setEnabled(b) ;
|
|
|
|
|
2010-11-21 16:38:32 -05:00
|
|
|
#ifdef RS_RELEASE_VERSION
|
|
|
|
ui.allowTunnelConnectionCB->hide();
|
|
|
|
this->toggleTunnelConnection(false);
|
|
|
|
#else
|
|
|
|
b = rsPeers->getAllowTunnelConnection() ;
|
|
|
|
ui.allowTunnelConnectionCB->setChecked(b) ;
|
|
|
|
#endif
|
2009-12-13 16:59:26 -05:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
std::list<std::string> ip_servers ;
|
|
|
|
rsPeers->getIPServersList(ip_servers) ;
|
|
|
|
|
|
|
|
for(std::list<std::string>::const_iterator it(ip_servers.begin());it!=ip_servers.end();++it)
|
|
|
|
ui.IPServersLV->addItem(QString::fromStdString(*it)) ;
|
|
|
|
|
2013-02-22 16:42:27 -05:00
|
|
|
TurtleRouterStatistics *trs = new TurtleRouterStatistics ;
|
|
|
|
trs->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding)) ;
|
|
|
|
ui.tabWidget->widget(2)->layout()->addWidget(trs) ;
|
|
|
|
ui.tabWidget->widget(2)->layout()->setContentsMargins(0,5,0,0) ;
|
|
|
|
|
|
|
|
QSpacerItem *verticalSpacer = new QSpacerItem(0,0,QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
|
|
|
|
ui.tabWidget->widget(2)->layout()->addItem(verticalSpacer) ;
|
|
|
|
ui.tabWidget->widget(2)->layout()->update() ;
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-02-22 16:42:27 -05:00
|
|
|
void ServerPage::showRoutingInfo()
|
|
|
|
{
|
|
|
|
if(_routing_info_page == NULL)
|
|
|
|
_routing_info_page = new TurtleRouterDialog ;
|
|
|
|
|
|
|
|
_routing_info_page->show() ;
|
|
|
|
}
|
|
|
|
|
2012-02-10 17:23:06 -05:00
|
|
|
void ServerPage::updateMaxTRUpRate(int b)
|
|
|
|
{
|
|
|
|
rsTurtle->setMaxTRForwardRate(b) ;
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
void ServerPage::toggleIpDetermination(bool b)
|
|
|
|
{
|
|
|
|
rsPeers->allowServerIPDetermination(b) ;
|
|
|
|
ui.IPServersLV->setEnabled(b) ;
|
|
|
|
}
|
|
|
|
|
2009-12-13 16:59:26 -05:00
|
|
|
void ServerPage::toggleTunnelConnection(bool b)
|
|
|
|
{
|
|
|
|
std::cerr << "ServerPage::toggleTunnelConnection() set tunnel to : " << b << std::endl;
|
|
|
|
rsPeers->allowTunnelConnection(b) ;
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
/** Saves the changes on this page */
|
|
|
|
bool
|
2011-08-12 10:06:29 -04:00
|
|
|
ServerPage::save(QString &/*errmsg*/)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2011-01-07 11:56:57 -05:00
|
|
|
Settings->setStatusBarFlag(STATUSBAR_DISC, ui.showDiscStatusBar->isChecked());
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
/* save the server address */
|
|
|
|
/* save local address */
|
|
|
|
/* save the url for DNS access */
|
|
|
|
|
|
|
|
/* restart server */
|
|
|
|
|
|
|
|
/* save all? */
|
|
|
|
saveAddresses();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads the settings for this page */
|
|
|
|
void ServerPage::load()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* load up configuration from rsPeers */
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set net mode */
|
|
|
|
int netIndex = 0;
|
2011-07-30 13:13:08 -04:00
|
|
|
switch(detail.netMode)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
|
|
|
case RS_NETMODE_EXT:
|
|
|
|
netIndex = 2;
|
|
|
|
break;
|
|
|
|
case RS_NETMODE_UDP:
|
|
|
|
netIndex = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case RS_NETMODE_UPNP:
|
|
|
|
netIndex = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ui.netModeComboBox->setCurrentIndex(netIndex);
|
|
|
|
|
2010-10-31 10:02:33 -04:00
|
|
|
/* DHT + Discovery: (public)
|
|
|
|
* Discovery only: (private)
|
|
|
|
* DHT only: (inverted)
|
|
|
|
* None: (dark net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
netIndex = 3; // NONE.
|
|
|
|
if (detail.visState & RS_VS_DHT_ON)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2010-10-31 10:02:33 -04:00
|
|
|
if (detail.visState & RS_VS_DISC_ON)
|
|
|
|
{
|
|
|
|
netIndex = 0; // PUBLIC
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
netIndex = 2; // INVERTED
|
|
|
|
}
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
2010-10-31 10:02:33 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (detail.visState & RS_VS_DISC_ON)
|
|
|
|
{
|
|
|
|
netIndex = 1; // PRIVATE
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
netIndex = 3; // NONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
ui.discComboBox->setCurrentIndex(netIndex);
|
|
|
|
|
2012-11-25 15:26:32 -05:00
|
|
|
int dlrate = 0;
|
|
|
|
int ulrate = 0;
|
|
|
|
rsConfig->GetMaxDataRates(dlrate, ulrate);
|
|
|
|
ui.totalDownloadRate->setValue(dlrate);
|
|
|
|
ui.totalUploadRate->setValue(ulrate);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
toggleUPnP();
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
/* Addresses must be set here - otherwise can't edit it */
|
|
|
|
/* set local address */
|
|
|
|
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
|
|
|
|
ui.localPort -> setValue(detail.localPort);
|
|
|
|
/* set the server address */
|
|
|
|
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
|
|
|
|
ui.extPort -> setValue(detail.extPort);
|
2011-01-07 11:56:57 -05:00
|
|
|
/* set DynDNS */
|
|
|
|
ui.dynDNS -> setText(QString::fromStdString(detail.dyndns));
|
|
|
|
|
|
|
|
ui.showDiscStatusBar->setChecked(Settings->getStatusBarFlags() & STATUSBAR_DISC);
|
2012-02-10 17:23:06 -05:00
|
|
|
|
|
|
|
ui._max_tr_up_per_sec_SB->setValue(rsTurtle->getMaxTRForwardRate()) ;
|
2012-11-25 09:26:32 -05:00
|
|
|
ui._turtle_enabled_CB->setChecked(rsTurtle->enabled()) ;
|
2013-02-22 16:42:27 -05:00
|
|
|
|
|
|
|
ui.ipAddressList->clear();
|
|
|
|
for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
|
|
|
|
ui.ipAddressList->addItem(QString::fromStdString(*it));
|
2012-11-25 09:26:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ServerPage::toggleTurtleRouting(bool b)
|
|
|
|
{
|
2013-02-22 16:42:27 -05:00
|
|
|
ui._max_tr_up_per_sec_SB->setEnabled(b) ;
|
|
|
|
ui._routing_info_PB->setEnabled(true) ; // always enabled!
|
|
|
|
|
2012-11-25 09:26:32 -05:00
|
|
|
rsTurtle->setEnabled(b) ;
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads the settings for this page */
|
|
|
|
void ServerPage::updateStatus()
|
|
|
|
{
|
2013-07-04 15:22:02 -04:00
|
|
|
if(RsAutoUpdatePage::eventsLocked())
|
|
|
|
return ;
|
|
|
|
|
2010-04-10 10:56:34 -04:00
|
|
|
if(!isVisible())
|
|
|
|
return ;
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
/* load up configuration from rsPeers */
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* only update if can't edit */
|
|
|
|
if (!ui.localPort->isEnabled())
|
|
|
|
{
|
|
|
|
/* set local address */
|
|
|
|
ui.localPort -> setValue(detail.localPort);
|
|
|
|
ui.extPort -> setValue(detail.extPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set local address */
|
|
|
|
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
|
|
|
|
/* set the server address */
|
|
|
|
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
|
2013-02-22 16:42:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
// Now update network bits.
|
2013-08-21 17:39:40 -04:00
|
|
|
RsConfigNetStatus net_status;
|
|
|
|
rsConfig->getConfigNetStatus(net_status);
|
2013-02-22 16:42:27 -05:00
|
|
|
|
|
|
|
/******* Network Status Tab *******/
|
|
|
|
|
2013-08-21 17:39:40 -04:00
|
|
|
if(net_status.netUpnpOk)
|
2013-02-22 16:42:27 -05:00
|
|
|
ui.iconlabel_upnp->setPixmap(QPixmap(":/images/ledon1.png"));
|
|
|
|
else
|
|
|
|
ui.iconlabel_upnp->setPixmap(QPixmap(":/images/ledoff1.png"));
|
|
|
|
|
2013-08-21 17:39:40 -04:00
|
|
|
if (net_status.netLocalOk)
|
2013-02-22 16:42:27 -05:00
|
|
|
ui.iconlabel_netLimited->setPixmap(QPixmap(":/images/ledon1.png"));
|
|
|
|
else
|
|
|
|
ui.iconlabel_netLimited->setPixmap(QPixmap(":/images/ledoff1.png"));
|
|
|
|
|
2013-08-21 17:39:40 -04:00
|
|
|
if (net_status.netExtAddressOk)
|
2013-02-22 16:42:27 -05:00
|
|
|
ui.iconlabel_ext->setPixmap(QPixmap(":/images/ledon1.png"));
|
|
|
|
else
|
|
|
|
ui.iconlabel_ext->setPixmap(QPixmap(":/images/ledoff1.png"));
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ServerPage::toggleUPnP()
|
|
|
|
{
|
|
|
|
/* switch on the radioButton */
|
|
|
|
bool settingChangeable = false;
|
|
|
|
if (0 != ui.netModeComboBox->currentIndex())
|
|
|
|
{
|
|
|
|
settingChangeable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settingChangeable)
|
|
|
|
{
|
|
|
|
ui.localAddress->setEnabled(false);
|
|
|
|
ui.localPort -> setEnabled(true);
|
|
|
|
ui.extAddress -> setEnabled(false);
|
|
|
|
ui.extPort -> setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.localAddress->setEnabled(false);
|
|
|
|
ui.localPort -> setEnabled(false);
|
|
|
|
ui.extAddress -> setEnabled(false);
|
|
|
|
ui.extPort -> setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServerPage::saveAddresses()
|
|
|
|
{
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
bool saveAddr = false;
|
|
|
|
|
|
|
|
RsPeerDetails detail;
|
|
|
|
std::string ownId = rsPeers->getOwnId();
|
|
|
|
|
|
|
|
if (!rsPeers->getPeerDetails(ownId, detail))
|
|
|
|
return;
|
|
|
|
|
|
|
|
int netIndex = ui.netModeComboBox->currentIndex();
|
|
|
|
|
|
|
|
/* Check if netMode has changed */
|
2010-06-10 10:13:20 -04:00
|
|
|
uint32_t netMode = 0;
|
2009-07-23 13:11:51 -04:00
|
|
|
switch(netIndex)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
netMode = RS_NETMODE_EXT;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
netMode = RS_NETMODE_UDP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
netMode = RS_NETMODE_UPNP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-30 13:13:08 -04:00
|
|
|
if (detail.netMode != netMode)
|
2009-07-23 13:11:51 -04:00
|
|
|
rsPeers->setNetworkMode(ownId, netMode);
|
|
|
|
|
2010-06-10 10:13:20 -04:00
|
|
|
uint32_t visState = 0;
|
2009-07-23 13:11:51 -04:00
|
|
|
/* Check if vis has changed */
|
2010-10-31 10:02:33 -04:00
|
|
|
switch(ui.discComboBox->currentIndex())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
visState |= (RS_VS_DISC_ON | RS_VS_DHT_ON);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
visState |= RS_VS_DISC_ON;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
visState |= RS_VS_DHT_ON;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
if (visState != detail.visState)
|
|
|
|
rsPeers->setVisState(ownId, visState);
|
|
|
|
|
|
|
|
if (0 != netIndex)
|
|
|
|
saveAddr = true;
|
|
|
|
|
|
|
|
if (saveAddr)
|
|
|
|
{
|
2010-10-05 20:08:20 -04:00
|
|
|
rsPeers->setLocalAddress(ownId, ui.localAddress->text().toStdString(), ui.localPort->value());
|
|
|
|
rsPeers->setExtAddress(ownId, ui.extAddress->text().toStdString(), ui.extPort->value());
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
2010-10-05 20:08:20 -04:00
|
|
|
rsPeers->setDynDNS(ownId, ui.dynDNS->text().toStdString());
|
2012-11-25 15:26:32 -05:00
|
|
|
rsConfig->SetMaxDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() );
|
2010-04-22 14:49:08 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
load();
|
|
|
|
}
|
|
|
|
|