first working version

This commit is contained in:
sehraf 2015-09-07 18:46:19 +02:00
parent 0107f4e406
commit 95d6b06eb5
5 changed files with 85 additions and 61 deletions

View File

@ -40,8 +40,8 @@ class DNSResolver ;
/* order of attempts ... */ /* order of attempts ... */
const uint32_t RS_NET_CONN_TCP_ALL = 0x000f; const uint32_t RS_NET_CONN_TCP_ALL = 0x001f;
const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0; const uint32_t RS_NET_CONN_UDP_ALL = 0x00e0;
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001; 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_EXTERNAL = 0x0002;
@ -49,8 +49,8 @@ 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_TOR = 0x0008;
const uint32_t RS_NET_CONN_TCP_HIDDEN_I2P = 0x0010; const uint32_t RS_NET_CONN_TCP_HIDDEN_I2P = 0x0010;
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0010; const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0020;
const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */ const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0040; /* coming soon */
// These are set in pqipersongroup. // These are set in pqipersongroup.
const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */ const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */

View File

@ -86,7 +86,7 @@ void printConnectState(std::ostream &out, peerState &peer);
peerState::peerState() peerState::peerState()
:netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0), :netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0),
hiddenNode(false), hiddenPort(0) hiddenNode(false), hiddenPort(0), hiddenType(RS_HIDDEN_TYPE_NONE)
{ {
sockaddr_storage_clear(localaddr); sockaddr_storage_clear(localaddr);
sockaddr_storage_clear(serveraddr); sockaddr_storage_clear(serveraddr);
@ -132,11 +132,13 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
lastGroupId = 1; lastGroupId = 1;
// setup default ProxyServerAddress. // setup default ProxyServerAddress.
// Tor
sockaddr_storage_clear(mProxyServerAddressTor); sockaddr_storage_clear(mProxyServerAddressTor);
sockaddr_storage_ipv4_aton(mProxyServerAddressTor, sockaddr_storage_ipv4_aton(mProxyServerAddressTor,
kConfigDefaultProxyServerIpAddr.c_str()); kConfigDefaultProxyServerIpAddr.c_str());
sockaddr_storage_ipv4_setport(mProxyServerAddressTor, sockaddr_storage_ipv4_setport(mProxyServerAddressTor,
kConfigDefaultProxyServerPort); kConfigDefaultProxyServerPort);
// I2P
sockaddr_storage_clear(mProxyServerAddressI2P); sockaddr_storage_clear(mProxyServerAddressI2P);
sockaddr_storage_ipv4_aton(mProxyServerAddressI2P, sockaddr_storage_ipv4_aton(mProxyServerAddressI2P,
kConfigDefaultProxyServerIpAddr.c_str()); kConfigDefaultProxyServerIpAddr.c_str());
@ -144,6 +146,7 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
kConfigDefaultProxyServerPort); kConfigDefaultProxyServerPort);
mProxyServerStatusTor = RS_NET_PROXY_STATUS_UNKNOWN ; mProxyServerStatusTor = RS_NET_PROXY_STATUS_UNKNOWN ;
mProxyServerStatusI2P = RS_NET_PROXY_STATUS_UNKNOWN;
} }
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
@ -176,6 +179,7 @@ bool p3PeerMgrIMPL::setupHiddenNode(const std::string &hiddenAddress, const uint
mOwnState.hiddenNode = true; mOwnState.hiddenNode = true;
mOwnState.hiddenPort = hiddenPort; mOwnState.hiddenPort = hiddenPort;
mOwnState.hiddenDomain = hiddenAddress; mOwnState.hiddenDomain = hiddenAddress;
mOwnState.hiddenType = hiddenDomainToHiddenType(hiddenAddress);
} }
forceHiddenNode(); forceHiddenNode();
@ -375,12 +379,13 @@ bool p3PeerMgrIMPL::getGpgId(const RsPeerId &ssl_id, RsPgpId &gpgId)
bool p3PeerMgrIMPL::isHidden() bool p3PeerMgrIMPL::isHidden()
{ {
return isHidden(RS_HIDDEN_TYPE_NONE); RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
return mOwnState.hiddenNode;
} }
/** /**
* @brief checks the hidden type of the own peer. When type RS_HIDDEN_TYPE_NONE is choosen it returns the 'hiddenNode' value instead * @brief checks the hidden type of the own peer.
* @param type type to check. Use RS_HIDDEN_TYPE_NONE to check 'hiddenNode' value * @param type type to check
* @return true when the peer has the same hidden type than type * @return true when the peer has the same hidden type than type
*/ */
bool p3PeerMgrIMPL::isHidden(const uint32_t type) bool p3PeerMgrIMPL::isHidden(const uint32_t type)
@ -394,7 +399,11 @@ bool p3PeerMgrIMPL::isHidden(const uint32_t type)
return mOwnState.hiddenType == RS_HIDDEN_TYPE_I2P; return mOwnState.hiddenType == RS_HIDDEN_TYPE_I2P;
break; break;
default: default:
return mOwnState.hiddenNode; #ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::isHidden(" << type << ") unkown type -> false";
std::cerr << std::endl;
#endif
return false;
break; break;
} }
} }
@ -475,7 +484,6 @@ uint32_t p3PeerMgrIMPL::hiddenDomainToHiddenType(const std::string &domain)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return RS_HIDDEN_TYPE_NONE; return RS_HIDDEN_TYPE_NONE;
} }
bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::string &domain_addr, const uint16_t domain_port) bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::string &domain_addr, const uint16_t domain_port)
@ -1738,6 +1746,11 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
cleanup = false; cleanup = false;
bool useExtAddrFinder = mNetMgr->getIPServersEnabled(); bool useExtAddrFinder = mNetMgr->getIPServersEnabled();
/* gather these information before mPeerMtx is locked! */
struct sockaddr_storage proxy_addr_tor, proxy_addr_i2p;
getProxyServerAddress(RS_HIDDEN_TYPE_TOR, proxy_addr_tor);
getProxyServerAddress(RS_HIDDEN_TYPE_I2P, proxy_addr_i2p);
mPeerMtx.lock(); /****** MUTEX LOCKED *******/ mPeerMtx.lock(); /****** MUTEX LOCKED *******/
RsPeerNetItem *item = new RsPeerNetItem(); RsPeerNetItem *item = new RsPeerNetItem();
@ -1849,36 +1862,31 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
// Store Proxy Server. // Store Proxy Server.
// Tor // Tor
struct sockaddr_storage proxy_addr;
getProxyServerAddress(RS_HIDDEN_TYPE_TOR, proxy_addr);
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "Saving proxyServerAddress for Tor: " << sockaddr_storage_tostring(proxy_addr); std::cerr << "Saving proxyServerAddress for Tor: " << sockaddr_storage_tostring(proxy_addr_tor);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
kv.key = kConfigKeyProxyServerIpAddrTor; kv.key = kConfigKeyProxyServerIpAddrTor;
kv.value = sockaddr_storage_iptostring(proxy_addr); kv.value = sockaddr_storage_iptostring(proxy_addr_tor);
vitem->tlvkvs.pairs.push_back(kv) ; vitem->tlvkvs.pairs.push_back(kv) ;
kv.key = kConfigKeyProxyServerPortTor; kv.key = kConfigKeyProxyServerPortTor;
kv.value = sockaddr_storage_porttostring(proxy_addr); kv.value = sockaddr_storage_porttostring(proxy_addr_tor);
vitem->tlvkvs.pairs.push_back(kv) ; vitem->tlvkvs.pairs.push_back(kv) ;
// I2P // I2P
getProxyServerAddress(RS_HIDDEN_TYPE_I2P, proxy_addr);
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "Saving proxyServerAddress for I2P: " << sockaddr_storage_tostring(proxy_addr); std::cerr << "Saving proxyServerAddress for I2P: " << sockaddr_storage_tostring(proxy_addr_tor);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
kv.key = kConfigKeyProxyServerIpAddrI2P; kv.key = kConfigKeyProxyServerIpAddrI2P;
kv.value = sockaddr_storage_iptostring(proxy_addr); kv.value = sockaddr_storage_iptostring(proxy_addr_i2p);
vitem->tlvkvs.pairs.push_back(kv) ; vitem->tlvkvs.pairs.push_back(kv) ;
kv.key = kConfigKeyProxyServerPortI2P; kv.key = kConfigKeyProxyServerPortI2P;
kv.value = sockaddr_storage_porttostring(proxy_addr); kv.value = sockaddr_storage_porttostring(proxy_addr_i2p);
vitem->tlvkvs.pairs.push_back(kv) ; vitem->tlvkvs.pairs.push_back(kv) ;
saveData.push_back(vitem); saveData.push_back(vitem);
@ -2018,7 +2026,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
{ {
proxyIpAddressTor = kit->value; proxyIpAddressTor = kit->value;
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "Loaded proxyIpAddress for Tor: " << proxyIpAddress; std::cerr << "Loaded proxyIpAddress for Tor: " << proxyIpAddressTor;
std::cerr << std::endl ; std::cerr << std::endl ;
#endif #endif
@ -2027,7 +2035,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
{ {
proxyPortTor = atoi(kit->value.c_str()); proxyPortTor = atoi(kit->value.c_str());
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "Loaded proxyPort for Tor: " << proxyPort; std::cerr << "Loaded proxyPort for Tor: " << proxyPortTor;
std::cerr << std::endl ; std::cerr << std::endl ;
#endif #endif
} }
@ -2036,7 +2044,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
{ {
proxyIpAddressI2P = kit->value; proxyIpAddressI2P = kit->value;
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "Loaded proxyIpAddress for I2P: " << proxyIpAddress; std::cerr << "Loaded proxyIpAddress for I2P: " << proxyIpAddressI2P;
std::cerr << std::endl ; std::cerr << std::endl ;
#endif #endif
@ -2045,7 +2053,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
{ {
proxyPortI2P = atoi(kit->value.c_str()); proxyPortI2P = atoi(kit->value.c_str());
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "Loaded proxyPort for I2P: " << proxyPort; std::cerr << "Loaded proxyPort for I2P: " << proxyPortI2P;
std::cerr << std::endl ; std::cerr << std::endl ;
#endif #endif
} }

View File

@ -435,11 +435,11 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
} }
else if (pcs.state & RS_PEER_S_CONNECTED) else if (pcs.state & RS_PEER_S_CONNECTED)
{ {
if(isProxyAddress(RS_HIDDEN_TYPE_TOR, pcs.connectaddr) || mPeerMgr->isHidden(RS_HIDDEN_TYPE_TOR)) if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_TOR) || isProxyAddress(RS_HIDDEN_TYPE_TOR, pcs.connectaddr))
{ {
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR; d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR;
} }
else if (isProxyAddress(RS_HIDDEN_TYPE_I2P, pcs.connectaddr) || mPeerMgr->isHidden(RS_HIDDEN_TYPE_I2P)) else if (mPeerMgr->isHidden(RS_HIDDEN_TYPE_I2P) || isProxyAddress(RS_HIDDEN_TYPE_I2P, pcs.connectaddr))
{ {
d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P; d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P;
} }

View File

@ -302,7 +302,7 @@ void ServerPage::load()
for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it) for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
ui.ipAddressList->addItem(QString::fromStdString(*it)); ui.ipAddressList->addItem(QString::fromStdString(*it));
/* TOR PAGE SETTINGS - only Proxy (outgoing) */ /* HIDDEN PAGE SETTINGS - only Proxy (outgoing) */
std::string proxyaddr; std::string proxyaddr;
uint16_t proxyport; uint16_t proxyport;
uint32_t status ; uint32_t status ;
@ -315,7 +315,7 @@ void ServerPage::load()
ui.hiddenpage_proxyAddress_i2p -> setText(QString::fromStdString(proxyaddr)); ui.hiddenpage_proxyAddress_i2p -> setText(QString::fromStdString(proxyaddr));
ui.hiddenpage_proxyPort_i2p -> setValue(proxyport); ui.hiddenpage_proxyPort_i2p -> setValue(proxyport);
updateTorOutProxyIndicator(); updateOutProxyIndicator();
} }
void ServerPage::toggleAutoIncludeFriends(bool b) void ServerPage::toggleAutoIncludeFriends(bool b)
@ -702,7 +702,7 @@ void ServerPage::updateStatus()
ui.iconlabel_ext->setPixmap(QPixmap(":/images/ledoff1.png")); ui.iconlabel_ext->setPixmap(QPixmap(":/images/ledoff1.png"));
// check for Tor // check for Tor
updateTorOutProxyIndicator(); updateOutProxyIndicator();
} }
void ServerPage::toggleUPnP() void ServerPage::toggleUPnP()
@ -949,14 +949,20 @@ void ServerPage::loadHiddenNode()
ui.torpage_onionAddress->setText(QString::fromStdString(detail.hiddenNodeAddress)); ui.torpage_onionAddress->setText(QString::fromStdString(detail.hiddenNodeAddress));
ui.torpage_onionPort -> setValue(detail.hiddenNodePort); ui.torpage_onionPort -> setValue(detail.hiddenNodePort);
/* out proxy settings */
std::string proxyaddr; std::string proxyaddr;
uint16_t proxyport; uint16_t proxyport;
uint32_t proxy_state_flags; uint32_t status ;
rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, proxyaddr, proxyport, proxy_state_flags); // Tor
rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, proxyaddr, proxyport, status);
ui.hiddenpage_proxyAddress_tor -> setText(QString::fromStdString(proxyaddr)); ui.hiddenpage_proxyAddress_tor -> setText(QString::fromStdString(proxyaddr));
ui.hiddenpage_proxyPort_tor -> setValue(proxyport); ui.hiddenpage_proxyPort_tor -> setValue(proxyport);
// I2P
rsPeers->getProxyServer(RS_HIDDEN_TYPE_I2P, proxyaddr, proxyport, status);
ui.hiddenpage_proxyAddress_i2p -> setText(QString::fromStdString(proxyaddr));
ui.hiddenpage_proxyPort_i2p -> setValue(proxyport);
updateTorOutProxyIndicator(); updateOutProxyIndicator();
QString expected = "HiddenServiceDir </your/path/to/hidden/directory/service>\n"; QString expected = "HiddenServiceDir </your/path/to/hidden/directory/service>\n";
expected += "HiddenServicePort "; expected += "HiddenServicePort ";
@ -1022,7 +1028,7 @@ void ServerPage::updateStatusHiddenNode()
#endif #endif
updateTorOutProxyIndicator(); updateOutProxyIndicator();
} }
void ServerPage::saveAddressesHiddenNode() void ServerPage::saveAddressesHiddenNode()
@ -1067,27 +1073,40 @@ void ServerPage::saveAddressesHiddenNode()
} }
// HANDLE PROXY SERVER. // HANDLE PROXY SERVER.
std::string orig_proxyaddr; std::string orig_proxyaddr,new_proxyaddr;
uint16_t orig_proxyport; uint16_t orig_proxyport, new_proxyport;
uint32_t state_flags ; uint32_t status ;
rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, orig_proxyaddr, orig_proxyport,state_flags); // Tor
rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, orig_proxyaddr, orig_proxyport,status);
std::string new_proxyaddr = ui.hiddenpage_proxyAddress_tor -> text().toStdString(); new_proxyaddr = ui.hiddenpage_proxyAddress_tor -> text().toStdString();
uint16_t new_proxyport = ui.hiddenpage_proxyPort_tor -> value(); new_proxyport = ui.hiddenpage_proxyPort_tor -> value();
if ((new_proxyaddr != orig_proxyaddr) || (new_proxyport != orig_proxyport)) if ((new_proxyaddr != orig_proxyaddr) || (new_proxyport != orig_proxyport))
{ {
rsPeers->setProxyServer(RS_HIDDEN_TYPE_TOR, new_proxyaddr, new_proxyport); rsPeers->setProxyServer(RS_HIDDEN_TYPE_TOR, new_proxyaddr, new_proxyport);
} }
// I2P
rsPeers->getProxyServer(RS_HIDDEN_TYPE_I2P, orig_proxyaddr, orig_proxyport,status);
new_proxyaddr = ui.hiddenpage_proxyAddress_i2p -> text().toStdString();
new_proxyport = ui.hiddenpage_proxyPort_i2p -> value();
if ((new_proxyaddr != orig_proxyaddr) || (new_proxyport != orig_proxyport))
{
rsPeers->setProxyServer(RS_HIDDEN_TYPE_I2P, new_proxyaddr, new_proxyport);
}
rsConfig->SetMaxDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() ); rsConfig->SetMaxDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() );
load(); load();
} }
void ServerPage::updateTorOutProxyIndicator() void ServerPage::updateOutProxyIndicator()
{ {
QTcpSocket socket ; QTcpSocket socket ;
socket.connectToHost(ui.hiddenpage_proxyAddress_tor->text(),ui.hiddenpage_proxyPort_tor->text().toInt());
// Tor
socket.connectToHost(ui.hiddenpage_proxyAddress_tor->text(),ui.hiddenpage_proxyPort_tor->text().toInt());
if(socket.waitForConnected(500)) if(socket.waitForConnected(500))
{ {
socket.disconnectFromHost(); socket.disconnectFromHost();
@ -1099,24 +1118,22 @@ void ServerPage::updateTorOutProxyIndicator()
ui.iconlabel_tor_outgoing->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ; ui.iconlabel_tor_outgoing->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ;
ui.iconlabel_tor_outgoing->setToolTip(tr("Tor proxy is not enabled")) ; ui.iconlabel_tor_outgoing->setToolTip(tr("Tor proxy is not enabled")) ;
} }
}
void ServerPage::updateLocInProxyIndicator()
{
QTcpSocket socket ;
socket.connectToHost(ui.torpage_localAddress->text(),ui.torpage_localPort->text().toInt());
if(socket.waitForConnected(1000)) // I2P
socket.connectToHost(ui.hiddenpage_proxyAddress_i2p->text(),ui.hiddenpage_proxyPort_i2p->text().toInt());
if(socket.waitForConnected(500))
{ {
socket.disconnectFromHost(); socket.disconnectFromHost();
ui.iconlabel_tor_incoming->setPixmap(QPixmap(ICON_STATUS_OK)) ; ui.iconlabel_i2p_outgoing->setPixmap(QPixmap(ICON_STATUS_OK)) ;
ui.iconlabel_tor_incoming->setToolTip(tr("You are reachable through Tor.")) ; ui.iconlabel_i2p_outgoing->setToolTip(tr("Proxy seems to work.")) ;
} }
else else
{ {
ui.iconlabel_tor_incoming->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ; ui.iconlabel_i2p_outgoing->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_i2p_outgoing->setToolTip(tr("Tor proxy is not enabled")) ;
} }
} }
void ServerPage::updateTorInProxyIndicator() void ServerPage::updateTorInProxyIndicator()
{ {
// need to find a proper way to do this // need to find a proper way to do this

View File

@ -90,8 +90,7 @@ private:
void loadHiddenNode(); void loadHiddenNode();
void updateStatusHiddenNode(); void updateStatusHiddenNode();
void saveAddressesHiddenNode(); void saveAddressesHiddenNode();
void updateTorOutProxyIndicator(); void updateOutProxyIndicator();
void updateLocInProxyIndicator();
void loadFilteredIps() ; void loadFilteredIps() ;
Ui::ServerPage ui; Ui::ServerPage ui;