made server settings more generic and added i2p support

This commit is contained in:
sehraf 2015-09-07 22:57:54 +02:00
parent 95d6b06eb5
commit fed43450ae
7 changed files with 82 additions and 50 deletions

View File

@ -40,17 +40,17 @@ class DNSResolver ;
/* order of attempts ... */
const uint32_t RS_NET_CONN_TCP_ALL = 0x001f;
const uint32_t RS_NET_CONN_UDP_ALL = 0x00e0;
const uint32_t RS_NET_CONN_TCP_ALL = 0x00ff;
const uint32_t RS_NET_CONN_UDP_ALL = 0x0f00;
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001;
const uint32_t RS_NET_CONN_TCP_EXTERNAL = 0x0002;
const uint32_t RS_NET_CONN_TCP_UNKNOW_TOPOLOGY = 0x0004;
const uint32_t RS_NET_CONN_TCP_HIDDEN_TOR = 0x0008;
const uint32_t RS_NET_CONN_TCP_HIDDEN_I2P = 0x0010;
const uint32_t RS_NET_CONN_TCP_HIDDEN_TOR = 0x0008;
const uint32_t RS_NET_CONN_TCP_HIDDEN_I2P = 0x0010;
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0020;
const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0040; /* coming soon */
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0100;
const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0200; /* coming soon */
// These are set in pqipersongroup.
const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */

View File

@ -194,6 +194,7 @@ virtual bool isHidden(const uint32_t type) = 0;
virtual bool isHiddenPeer(const RsPeerId &ssl_id) = 0;
virtual bool isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type) = 0;
virtual bool getProxyAddress(const RsPeerId &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port) = 0;
virtual uint32_t hiddenDomainToHiddenType(const std::string &domain) = 0;
virtual int getFriendCount(bool ssl, bool online) = 0;

View File

@ -238,6 +238,7 @@ class RsPeerDetails
bool isHiddenNode;
std::string hiddenNodeAddress;
uint16_t hiddenNodePort;
uint32_t hiddenType;
// Filled in for Standard Node.
std::string localAddr;

View File

@ -313,6 +313,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
d.isHiddenNode = true;
d.hiddenNodeAddress = ps.hiddenDomain;
d.hiddenNodePort = ps.hiddenPort;
d.hiddenType = ps.hiddenType;
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
d.localPort = sockaddr_storage_port(ps.localaddr);
d.extAddr = "hidden";
@ -324,6 +325,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
d.isHiddenNode = false;
d.hiddenNodeAddress = "";
d.hiddenNodePort = 0;
d.hiddenType = RS_HIDDEN_TYPE_NONE;
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
d.localPort = sockaddr_storage_port(ps.localaddr);
@ -1113,6 +1115,7 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai
{
pd.hiddenNodeAddress = domain;
pd.hiddenNodePort = port;
pd.hiddenType = mPeerMgr->hiddenDomainToHiddenType(domain);
}
}
else
@ -1317,7 +1320,7 @@ RsPeerDetails::RsPeerDetails()
hasSignedMe(false),accept_connection(false),
state(0),localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),vs_disc(0), vs_dht(0),
lastConnect(0),connectState(0),connectStateString(""),connectPeriod(0),foundDHT(false),
wasDeniedConnection(false), deniedTS(0)
wasDeniedConnection(false), deniedTS(0), hiddenType(RS_HIDDEN_TYPE_NONE)
{
}

View File

@ -53,7 +53,7 @@
//#define SERVER_DEBUG 1
ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
: ConfigPage(parent, flags), mIsHiddenNode(false)
: ConfigPage(parent, flags), mIsHiddenNode(false), mHiddenType(RS_HIDDEN_TYPE_NONE)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
@ -61,7 +61,7 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
connect( ui.netModeComboBox, SIGNAL( activated ( int ) ), this, SLOT( toggleUPnP( ) ) );
connect( ui.allowIpDeterminationCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleIpDetermination(bool) ) );
connect( ui.cleanKnownIPs_PB, SIGNAL( clicked( ) ), this, SLOT( clearKnownAddressList() ) );
connect( ui.testIncomingTor_PB, SIGNAL( clicked( ) ), this, SLOT( updateTorInProxyIndicator() ) );
connect( ui.testIncoming_PB, SIGNAL( clicked( ) ), this, SLOT( updateInProxyIndicator() ) );
manager = NULL ;
@ -105,7 +105,7 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
for(std::list<std::string>::const_iterator it(ip_servers.begin());it!=ip_servers.end();++it)
ui.IPServersLV->addItem(QString::fromStdString(*it)) ;
ui.torpage_incoming->setVisible(false);
ui.hiddenpage_incoming->setVisible(false);
#ifdef SERVER_DEBUG
std::cerr << "ServerPage::ServerPage() called";
@ -218,6 +218,7 @@ void ServerPage::load()
if (mIsHiddenNode)
{
mHiddenType = detail.hiddenType;
ui.tabWidget->setTabEnabled(1,false) ;
loadHiddenNode();
return;
@ -910,7 +911,7 @@ void ServerPage::loadHiddenNode()
ui.label_dynDNS->setVisible(false);
ui.dynDNS ->setVisible(false);
ui.torpage_incoming->setVisible(true);
ui.hiddenpage_incoming->setVisible(true);
/* Addresses must be set here - otherwise can't edit it */
/* set local address */
@ -918,7 +919,7 @@ void ServerPage::loadHiddenNode()
ui.localPort -> setValue(detail.localPort);
/* set the server address */
ui.extAddress->setText(tr("Hidden - See Tor Config"));
ui.extAddress->setText(tr("Hidden - See Config"));
ui.showDiscStatusBar->setChecked(Settings->getStatusBarFlags() & STATUSBAR_DISC);
ui.showDiscStatusBar->hide() ; // hidden because not functional at the moment.
@ -941,13 +942,15 @@ void ServerPage::loadHiddenNode()
/* TOR PAGE SETTINGS */
/* set local address */
ui.torpage_localAddress->setEnabled(false);
ui.torpage_localAddress->setText(QString::fromStdString(detail.localAddr));
ui.torpage_localPort -> setValue(detail.localPort);
ui.hiddenpage_localAddress->setEnabled(false);
ui.hiddenpage_localAddress->setText(QString::fromStdString(detail.localAddr));
ui.hiddenpage_localPort -> setValue(detail.localPort);
/* set the server address */
ui.torpage_onionAddress->setText(QString::fromStdString(detail.hiddenNodeAddress));
ui.torpage_onionPort -> setValue(detail.hiddenNodePort);
ui.hiddenpage_serviceAddress->setText(QString::fromStdString(detail.hiddenNodeAddress));
ui.hiddenpage_servicePort -> setValue(detail.hiddenNodePort);
/* in I2P there is no port - there is only the address */
ui.hiddenpage_servicePort->setEnabled(detail.hiddenType != RS_HIDDEN_TYPE_I2P);
/* out proxy settings */
std::string proxyaddr;
@ -964,15 +967,29 @@ void ServerPage::loadHiddenNode()
updateOutProxyIndicator();
QString expected = "HiddenServiceDir </your/path/to/hidden/directory/service>\n";
expected += "HiddenServicePort ";
expected += QString::number(detail.hiddenNodePort);
expected += " ";
expected += QString::fromStdString(detail.localAddr);
expected += ":";
expected += QString::number(detail.localPort);
QString expected;
switch (mHiddenType) {
case RS_HIDDEN_TYPE_I2P:
ui.l_serviceAddress->setText(tr("I2P Address"));
ui.l_incomingTestResult->setText(tr("I2P incoming ok"));
ui.torpage_configuration->setPlainText(expected);
expected = "--TODO-- see http://127.0.0.1:7657/i2ptunnelmgr";
break;
case RS_HIDDEN_TYPE_TOR:
default:
ui.l_serviceAddress->setText(tr("Onion Address"));
ui.l_incomingTestResult->setText(tr("Tor incoming ok"));
expected = "HiddenServiceDir </your/path/to/hidden/directory/service>\n";
expected += "HiddenServicePort ";
expected += QString::number(detail.hiddenNodePort);
expected += " ";
expected += QString::fromStdString(detail.localAddr);
expected += ":";
expected += QString::number(detail.localPort);
break;
}
ui.hiddenpage_configuration->setPlainText(expected);
}
/** Loads the settings for this page */
@ -1059,14 +1076,14 @@ void ServerPage::saveAddressesHiddenNode()
if ((vs_disc != detail.vs_disc) || (vs_dht != detail.vs_dht))
rsPeers->setVisState(ownId, vs_disc, vs_dht);
if (detail.localPort != ui.torpage_localPort->value())
if (detail.localPort != ui.hiddenpage_localPort->value())
{
// Set Local Address - force to 127.0.0.1
rsPeers->setLocalAddress(ownId, "127.0.0.1", ui.torpage_localPort->value());
rsPeers->setLocalAddress(ownId, "127.0.0.1", ui.hiddenpage_localPort->value());
}
std::string hiddenAddr = ui.torpage_onionAddress->text().toStdString();
uint16_t hiddenPort = ui.torpage_onionPort->value();
std::string hiddenAddr = ui.hiddenpage_serviceAddress->text().toStdString();
uint16_t hiddenPort = ui.hiddenpage_servicePort->value();
if ((hiddenAddr != detail.hiddenNodeAddress) || (hiddenPort != detail.hiddenNodePort))
{
rsPeers->setHiddenNode(ownId, hiddenAddr, hiddenPort);
@ -1134,7 +1151,7 @@ void ServerPage::updateOutProxyIndicator()
}
}
void ServerPage::updateTorInProxyIndicator()
void ServerPage::updateInProxyIndicator()
{
// need to find a proper way to do this
@ -1147,19 +1164,28 @@ void ServerPage::updateTorInProxyIndicator()
QNetworkProxy proxy ;
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName(ui.hiddenpage_proxyAddress_tor->text());
proxy.setPort(ui.hiddenpage_proxyPort_tor->text().toInt());
switch (mHiddenType) {
case RS_HIDDEN_TYPE_I2P:
proxy.setHostName(ui.hiddenpage_proxyAddress_i2p->text());
proxy.setPort(ui.hiddenpage_proxyPort_i2p->text().toInt());
break;
case RS_HIDDEN_TYPE_TOR:
default:
proxy.setHostName(ui.hiddenpage_proxyAddress_tor->text());
proxy.setPort(ui.hiddenpage_proxyPort_tor->text().toInt());
break;
}
proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability | proxy.capabilities()) ;
//ui.iconlabel_tor_incoming->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ;
//ui.testIncomingTor_PB->setIcon(QIcon(":/loader/circleball-16.gif")) ;
QMovie *movie = new QMovie(":/images/loader/circleball-16.gif");
ui.iconlabel_tor_incoming->setMovie(movie);
ui.iconlabel_service_incoming->setMovie(movie);
movie->start() ;
QNetworkProxy::setApplicationProxy(proxy) ;
QUrl url("https://"+ui.torpage_onionAddress->text() + ":" + ui.torpage_onionPort->text()) ;
QUrl url("https://"+ui.hiddenpage_serviceAddress->text() + ":" + ui.hiddenpage_servicePort->text()) ;
std::cerr << "Setting proxy hostname+port to " << std::dec << ui.hiddenpage_proxyAddress_tor->text().toStdString() << ":" << ui.hiddenpage_proxyPort_tor->text().toInt() << std::endl;
std::cerr << "Connecting to " << url.toString().toStdString() << std::endl;
@ -1177,8 +1203,8 @@ void ServerPage::handleNetworkReply(QNetworkReply *reply)
if(reply->isOpen() && error == QNetworkReply::SslHandshakeFailedError)
{
std::cerr <<"Connected!" << std::endl;
ui.iconlabel_tor_incoming->setPixmap(QPixmap(ICON_STATUS_OK)) ;
ui.iconlabel_tor_incoming->setToolTip(tr("You are reachable through Tor.")) ;
ui.iconlabel_service_incoming->setPixmap(QPixmap(ICON_STATUS_OK)) ;
ui.iconlabel_service_incoming->setToolTip(tr("You are reachable through the hidden service.")) ;
//ui.testIncomingTor_PB->setIcon(QIcon(ICON_STATUS_OK)) ;
}
else
@ -1186,8 +1212,8 @@ void ServerPage::handleNetworkReply(QNetworkReply *reply)
std::cerr <<"Failed!" << std::endl;
//ui.testIncomingTor_PB->setIcon(QIcon(ICON_STATUS_UNKNOWN)) ;
ui.iconlabel_tor_incoming->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ;
ui.iconlabel_tor_incoming->setToolTip(tr("Tor proxy is not enabled or broken.\nAre you running a Tor hidden service?\nCheck your ports!")) ;
ui.iconlabel_service_incoming->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ;
ui.iconlabel_service_incoming->setToolTip(tr("The proxy is not enabled or broken.\Are all services up and running fine??\nAlso check your ports!")) ;
}
reply->close();

View File

@ -78,7 +78,7 @@ private slots:
void toggleTunnelConnection(bool) ;
void clearKnownAddressList() ;
void handleNetworkReply(QNetworkReply *reply);
void updateTorInProxyIndicator();
void updateInProxyIndicator();
private:
// ban list
@ -98,6 +98,7 @@ private:
QNetworkAccessManager *manager ;
bool mIsHiddenNode;
u_int32_t mHiddenType;
};
#endif // !SERVERPAGE_H

View File

@ -914,7 +914,7 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
</widget>
</item>
<item>
<widget class="QGroupBox" name="torpage_incoming">
<widget class="QGroupBox" name="hiddenpage_incoming">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -922,13 +922,13 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
</sizepolicy>
</property>
<property name="title">
<string>Incoming Tor Connections</string>
<string>Incoming Service Connections</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QSpinBox" name="torpage_localPort">
<widget class="QSpinBox" name="hiddenpage_localPort">
<property name="minimum">
<number>10</number>
</property>
@ -940,7 +940,7 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
<item row="0" column="3">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QPushButton" name="testIncomingTor_PB">
<widget class="QPushButton" name="testIncoming_PB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This button simulates a SSL connection to your Tor address using the Tor proxy. If your Tor node is reachable, it should cause a SSL handshake error, which RS will interpret as a valid connection state. This operation might also cause several &quot;security warning&quot; about connections from your local host IP (127.0.0.1) in the News Feed if you enabled it,&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -952,7 +952,7 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
</layout>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="torpage_onionPort">
<widget class="QSpinBox" name="hiddenpage_servicePort">
<property name="minimum">
<number>10</number>
</property>
@ -962,7 +962,7 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<widget class="QLabel" name="l_serviceAddress">
<property name="text">
<string>Onion Address</string>
</property>
@ -976,14 +976,14 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="torpage_onionAddress">
<widget class="QLineEdit" name="hiddenpage_serviceAddress">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is your onion address. It should look like &lt;span style=&quot; font-weight:600;&quot;&gt;[something].onion. &lt;/span&gt;If you configured a hidden service with Tor, the onion address is generated automatically by Tor. You can get it in e.g. &lt;span style=&quot; font-weight:600;&quot;&gt;/var/lib/tor/[service name]/hostname&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="torpage_localAddress">
<widget class="QLineEdit" name="hiddenpage_localAddress">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is the local address to which the Tor hidden service points at your localhost. Most of the time, &lt;span style=&quot; font-weight:600;&quot;&gt;127.0.0.1&lt;/span&gt; is the right answer.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@ -992,7 +992,7 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
<item row="1" column="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="iconlabel_tor_incoming">
<widget class="QLabel" name="iconlabel_service_incoming">
<property name="maximumSize">
<size>
<width>16</width>
@ -1008,7 +1008,7 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<widget class="QLabel" name="l_incomingTestResult">
<property name="text">
<string>Tor incoming ok</string>
</property>
@ -1028,7 +1028,7 @@ are running a standard Node, so why not setup Tor and/or I2P? </string>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="torpage_configuration">
<widget class="QPlainTextEdit" name="hiddenpage_configuration">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>