From fed43450ae71091bd085462fbbcdd30e3e9633bf Mon Sep 17 00:00:00 2001 From: sehraf Date: Mon, 7 Sep 2015 22:57:54 +0200 Subject: [PATCH] made server settings more generic and added i2p support --- libretroshare/src/pqi/p3linkmgr.h | 12 +-- libretroshare/src/pqi/p3peermgr.h | 1 + libretroshare/src/retroshare/rspeers.h | 1 + libretroshare/src/rsserver/p3peers.cc | 5 +- .../src/gui/settings/ServerPage.cpp | 88 ++++++++++++------- retroshare-gui/src/gui/settings/ServerPage.h | 3 +- retroshare-gui/src/gui/settings/ServerPage.ui | 22 ++--- 7 files changed, 82 insertions(+), 50 deletions(-) diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h index 5be0b2707..8208546be 100644 --- a/libretroshare/src/pqi/p3linkmgr.h +++ b/libretroshare/src/pqi/p3linkmgr.h @@ -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! */ diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 2941ba182..a6150863c 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -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; diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 6d8adf050..aa7423ae9 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -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; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index d31a4639a..0b95b2ec6 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -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) { } diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index 69825d04d..18715d823 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -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::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 \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 \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(); diff --git a/retroshare-gui/src/gui/settings/ServerPage.h b/retroshare-gui/src/gui/settings/ServerPage.h index c660c2188..521487ac7 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.h +++ b/retroshare-gui/src/gui/settings/ServerPage.h @@ -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 diff --git a/retroshare-gui/src/gui/settings/ServerPage.ui b/retroshare-gui/src/gui/settings/ServerPage.ui index 4e3119ce1..c15596b49 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.ui +++ b/retroshare-gui/src/gui/settings/ServerPage.ui @@ -914,7 +914,7 @@ are running a standard Node, so why not setup Tor and/or I2P? - + 0 @@ -922,13 +922,13 @@ are running a standard Node, so why not setup Tor and/or I2P? - Incoming Tor Connections + Incoming Service Connections - + 10 @@ -940,7 +940,7 @@ are running a standard Node, so why not setup Tor and/or I2P? - + <html><head/><body><p>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 "security warning" about connections from your local host IP (127.0.0.1) in the News Feed if you enabled it,</p></body></html> @@ -952,7 +952,7 @@ are running a standard Node, so why not setup Tor and/or I2P? - + 10 @@ -962,7 +962,7 @@ are running a standard Node, so why not setup Tor and/or I2P? - + Onion Address @@ -976,14 +976,14 @@ are running a standard Node, so why not setup Tor and/or I2P? - + <html><head/><body><p>This is your onion address. It should look like <span style=" font-weight:600;">[something].onion. </span>If you configured a hidden service with Tor, the onion address is generated automatically by Tor. You can get it in e.g. <span style=" font-weight:600;">/var/lib/tor/[service name]/hostname</span></p></body></html> - + <html><head/><body><p>This is the local address to which the Tor hidden service points at your localhost. Most of the time, <span style=" font-weight:600;">127.0.0.1</span> is the right answer.</p></body></html> @@ -992,7 +992,7 @@ are running a standard Node, so why not setup Tor and/or I2P? - + 16 @@ -1008,7 +1008,7 @@ are running a standard Node, so why not setup Tor and/or I2P? - + Tor incoming ok @@ -1028,7 +1028,7 @@ are running a standard Node, so why not setup Tor and/or I2P? - + 0