diff --git a/libretroshare/src/pqi/p3linkmgr.cc b/libretroshare/src/pqi/p3linkmgr.cc index 016e47d5c..17f07fa69 100644 --- a/libretroshare/src/pqi/p3linkmgr.cc +++ b/libretroshare/src/pqi/p3linkmgr.cc @@ -964,24 +964,25 @@ bool p3LinkMgrIMPL::connectResult(const RsPeerId &id, bool success, bool isIncom if (flags == RS_NET_CONN_UDP_ALL) { #ifdef LINKMGR_DEBUG -#endif std::cerr << "p3LinkMgrIMPL::connectResult() Sending Feedback for UDP connection"; std::cerr << std::endl; +#endif if (success) { #ifdef LINKMGR_DEBUG -#endif std::cerr << "p3LinkMgrIMPL::connectResult() UDP Update CONNECTED to: " << id; std::cerr << std::endl; +#endif mNetMgr->netAssistStatusUpdate(id, NETMGR_DHT_FEEDBACK_CONNECTED); } else { #ifdef LINKMGR_DEBUG -#endif + std::cerr << "p3LinkMgrIMPL::connectResult() UDP Update FAILED to: " << id; std::cerr << std::endl; +#endif /* have no differentiation between failure and closed? */ mNetMgr->netAssistStatusUpdate(id, NETMGR_DHT_FEEDBACK_CONN_FAILED); @@ -1624,6 +1625,17 @@ bool p3LinkMgrIMPL::retryConnectTCP(const RsPeerId &id) /* first possibility - is it a hidden peer */ if (mPeerMgr->isHiddenPeer(id)) { + /* check for valid hidden type */ + uint32_t type = mPeerMgr->getHiddenType(id); + if (type & (~RS_HIDDEN_TYPE_MASK)) + { +#ifdef LINKMGR_DEBUG + std::cerr << "p3LinkMgrIMPL::retryConnectTCP() invalid hidden type (" << type << ") -> return false"; + std::cerr << std::endl; +#endif + return false; + } + struct sockaddr_storage proxy_addr; std::string domain_addr; uint16_t domain_port; @@ -1636,7 +1648,7 @@ bool p3LinkMgrIMPL::retryConnectTCP(const RsPeerId &id) std::map::iterator it; if (mFriendList.end() != (it = mFriendList.find(id))) { - locked_ConnectAttempt_ProxyAddress(&(it->second), proxy_addr, domain_addr, domain_port); + locked_ConnectAttempt_ProxyAddress(&(it->second), type, proxy_addr, domain_addr, domain_port); return locked_ConnectAttempt_Complete(&(it->second)); } } @@ -2018,7 +2030,7 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std } -void p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, const struct sockaddr_storage &proxy_addr, const std::string &domain_addr, uint16_t domain_port) +void p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, const uint32_t type, const struct sockaddr_storage &proxy_addr, const std::string &domain_addr, uint16_t domain_port) { #ifdef LINKMGR_DEBUG std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress() trying address: " << domain_addr << ":" << domain_port << std::endl; @@ -2026,7 +2038,22 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, peerConnectAddress pca; pca.addr = proxy_addr; - pca.type = RS_NET_CONN_TCP_HIDDEN; + switch (type) { + case RS_HIDDEN_TYPE_TOR: + pca.type = RS_NET_CONN_TCP_HIDDEN_TOR; + break; + case RS_HIDDEN_TYPE_I2P: + pca.type = RS_NET_CONN_TCP_HIDDEN_I2P; + break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: + /**** THIS CASE SHOULD NOT BE TRIGGERED - since this function is called with a valid hidden type only ****/ + std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_ProxyAddress() hidden type of addr: " << domain_addr << " is unkown -> THIS SHOULD NEVER HAPPEN!" << std::endl; + std::cerr << " - peer : " << peer->id << "(" << peer->name << ")" << std::endl; + std::cerr << " - proxy: " << sockaddr_storage_tostring(proxy_addr) << std::endl; + std::cerr << " - addr : " << domain_addr << ":" << domain_port << std::endl; + pca.type = RS_NET_CONN_TCP_UNKNOW_TOPOLOGY; + } //for the delay, we add a random time and some more time when the friend list is big pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY; diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h index a35bf508c..0565cd740 100644 --- a/libretroshare/src/pqi/p3linkmgr.h +++ b/libretroshare/src/pqi/p3linkmgr.h @@ -40,16 +40,17 @@ class DNSResolver ; /* order of attempts ... */ -const uint32_t RS_NET_CONN_TCP_ALL = 0x000f; -const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0; +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 = 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_UDP_DHT_SYNC = 0x0010; -const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* 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! */ @@ -302,7 +303,7 @@ void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, const struc void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs); void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t dynPort); void locked_ConnectAttempt_AddTunnel(peerConnectState *peer); -void locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, const struct sockaddr_storage &proxy_addr, const std::string &domain_addr, uint16_t domain_port); +void locked_ConnectAttempt_ProxyAddress(peerConnectState *peer, const uint32_t type, const struct sockaddr_storage &proxy_addr, const std::string &domain_addr, uint16_t domain_port); bool locked_ConnectAttempt_Complete(peerConnectState *peer); diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index dde9d3569..3cdc29e5a 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -74,17 +74,20 @@ const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 4; #define MIN_RETRY_PERIOD 140 static const std::string kConfigDefaultProxyServerIpAddr = "127.0.0.1"; -static const uint16_t kConfigDefaultProxyServerPort = 9050; // standard port. +static const uint16_t kConfigDefaultProxyServerPortTor = 9050; // standard port. +static const uint16_t kConfigDefaultProxyServerPortI2P = 10; // there is no standard port though static const std::string kConfigKeyExtIpFinder = "USE_EXTR_IP_FINDER"; -static const std::string kConfigKeyProxyServerIpAddr = "PROXY_SERVER_IPADDR"; -static const std::string kConfigKeyProxyServerPort = "PROXY_SERVER_PORT"; +static const std::string kConfigKeyProxyServerIpAddrTor = "PROXY_SERVER_IPADDR"; +static const std::string kConfigKeyProxyServerPortTor = "PROXY_SERVER_PORT"; +static const std::string kConfigKeyProxyServerIpAddrI2P = "PROXY_SERVER_IPADDR_I2P"; +static const std::string kConfigKeyProxyServerPortI2P = "PROXY_SERVER_PORT_I2P"; void printConnectState(std::ostream &out, peerState &peer); peerState::peerState() :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(serveraddr); @@ -130,13 +133,21 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_ lastGroupId = 1; // setup default ProxyServerAddress. - sockaddr_storage_clear(mProxyServerAddress); - sockaddr_storage_ipv4_aton(mProxyServerAddress, + // Tor + sockaddr_storage_clear(mProxyServerAddressTor); + sockaddr_storage_ipv4_aton(mProxyServerAddressTor, kConfigDefaultProxyServerIpAddr.c_str()); - sockaddr_storage_ipv4_setport(mProxyServerAddress, - kConfigDefaultProxyServerPort); + sockaddr_storage_ipv4_setport(mProxyServerAddressTor, + kConfigDefaultProxyServerPortTor); + // I2P + sockaddr_storage_clear(mProxyServerAddressI2P); + sockaddr_storage_ipv4_aton(mProxyServerAddressI2P, + kConfigDefaultProxyServerIpAddr.c_str()); + sockaddr_storage_ipv4_setport(mProxyServerAddressI2P, + kConfigDefaultProxyServerPortI2P); - mProxyServerStatus = RS_NET_PROXY_STATUS_UNKNOWN ; + mProxyServerStatusTor = RS_NET_PROXY_STATUS_UNKNOWN ; + mProxyServerStatusI2P = RS_NET_PROXY_STATUS_UNKNOWN; } #ifdef PEER_DEBUG @@ -169,6 +180,7 @@ bool p3PeerMgrIMPL::setupHiddenNode(const std::string &hiddenAddress, const uint mOwnState.hiddenNode = true; mOwnState.hiddenPort = hiddenPort; mOwnState.hiddenDomain = hiddenAddress; + mOwnState.hiddenType = hiddenDomainToHiddenType(hiddenAddress); } forceHiddenNode(); @@ -188,6 +200,7 @@ bool p3PeerMgrIMPL::forceHiddenNode() #endif } mOwnState.hiddenNode = true; + mOwnState.hiddenType = hiddenDomainToHiddenType(mOwnState.hiddenDomain); // force external address - otherwise its invalid. sockaddr_storage_clear(mOwnState.serveraddr); @@ -372,8 +385,43 @@ bool p3PeerMgrIMPL::isHidden() return mOwnState.hiddenNode; } +/** + * @brief checks the hidden type of the own peer. + * @param type type to check + * @return true when the peer has the same hidden type than type + */ +bool p3PeerMgrIMPL::isHidden(const uint32_t type) +{ + RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + switch (type) { + case RS_HIDDEN_TYPE_TOR: + return mOwnState.hiddenType == RS_HIDDEN_TYPE_TOR; + break; + case RS_HIDDEN_TYPE_I2P: + return mOwnState.hiddenType == RS_HIDDEN_TYPE_I2P; + break; + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::isHidden(" << type << ") unkown type -> false"; + std::cerr << std::endl; +#endif + return false; + break; + } +} bool p3PeerMgrIMPL::isHiddenPeer(const RsPeerId &ssl_id) +{ + return isHiddenPeer(ssl_id, RS_HIDDEN_TYPE_NONE); +} + +/** + * @brief checks the hidden type of a given ssl id. When type RS_HIDDEN_TYPE_NONE is choosen it returns the 'hiddenNode' value instead + * @param ssl_id to check + * @param type type to check. Use RS_HIDDEN_TYPE_NONE to check 'hiddenNode' value + * @return true when the peer has the same hidden type than type + */ +bool p3PeerMgrIMPL::isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ @@ -394,9 +442,91 @@ bool p3PeerMgrIMPL::isHiddenPeer(const RsPeerId &ssl_id) std::cerr << "p3PeerMgrIMPL::isHiddenPeer(" << ssl_id << ") = " << (it->second).hiddenNode; std::cerr << std::endl; #endif - return (it->second).hiddenNode; + switch (type) { + case RS_HIDDEN_TYPE_TOR: + return (it->second).hiddenType == RS_HIDDEN_TYPE_TOR; + break; + case RS_HIDDEN_TYPE_I2P: + return (it->second).hiddenType == RS_HIDDEN_TYPE_I2P; + break; + default: + return (it->second).hiddenNode; + break; + } } +bool hasEnding (std::string const &fullString, std::string const &ending) { + if (fullString.length() < ending.length()) + return false; + + return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending)); +} + +/** + * @brief resolves the hidden type (tor or i2p) from a domain + * @param domain to check + * @return RS_HIDDEN_TYPE_TOR, RS_HIDDEN_TYPE_I2P or RS_HIDDEN_TYPE_NONE + * + * Tor: ^[a-z2-7]{16}\.onion$ + * + * I2P: There is more than one address: + * - pub. key in base64 + * - hash in base32 ( ^[a-z2-7]{52}\.b32\.i2p$ ) + * - "normal" .i2p domains + */ +uint32_t p3PeerMgrIMPL::hiddenDomainToHiddenType(const std::string &domain) +{ + if(hasEnding(domain, ".onion")) + return RS_HIDDEN_TYPE_TOR; + if(hasEnding(domain, ".i2p")) + return RS_HIDDEN_TYPE_I2P; + +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::hiddenDomainToHiddenType() unknown hidden type: " << domain; + std::cerr << std::endl; +#endif + return RS_HIDDEN_TYPE_UNKNOWN; +} + +/** + * @brief returns the hidden type of a peer + * @param ssl_id peer id + * @return hidden type + */ +uint32_t p3PeerMgrIMPL::getHiddenType(const RsPeerId &ssl_id) +{ + RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + + if (ssl_id == AuthSSL::getAuthSSL()->OwnId()) + return mOwnState.hiddenType; + + /* check for existing */ + std::map::iterator it; + it = mFriendList.find(ssl_id); + if (it == mFriendList.end()) + { +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::getHiddenType(" << ssl_id << ") Missing Peer => false"; + std::cerr << std::endl; +#endif + + return false; + } + +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::getHiddenType(" << ssl_id << ") = " << (it->second).hiddenType; + std::cerr << std::endl; +#endif + return (it->second).hiddenType; +} + +/** + * @brief sets hidden domain and port for a given ssl ID + * @param ssl_id peer to set domain and port for + * @param domain_addr + * @param domain_port + * @return true on success + */ bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::string &domain_addr, const uint16_t domain_port) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ @@ -426,6 +556,7 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::strin mOwnState.hiddenNode = true; mOwnState.hiddenDomain = domain; mOwnState.hiddenPort = domain_port; + mOwnState.hiddenType = hiddenDomainToHiddenType(domain); #ifdef PEER_DEBUG std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set own State"; std::cerr << std::endl; @@ -448,6 +579,7 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::strin it->second.hiddenDomain = domain; it->second.hiddenPort = domain_port; it->second.hiddenNode = true; + it->second.hiddenType = hiddenDomainToHiddenType(domain); #ifdef PEER_DEBUG std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set Peers State"; std::cerr << std::endl; @@ -456,15 +588,40 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::strin return true; } -bool p3PeerMgrIMPL::setProxyServerAddress(const struct sockaddr_storage &proxy_addr) +/** + * @brief sets the proxy server address for a hidden service + * @param type hidden service type + * @param proxy_addr proxy address + * @return true on success + */ +bool p3PeerMgrIMPL::setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - if (!sockaddr_storage_same(mProxyServerAddress,proxy_addr)) - { - IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ - mProxyServerAddress = proxy_addr; + switch (type) { + case RS_HIDDEN_TYPE_I2P: + if (!sockaddr_storage_same(mProxyServerAddressI2P, proxy_addr)) + { + IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ + mProxyServerAddressI2P = proxy_addr; + } + break; + case RS_HIDDEN_TYPE_TOR: + if (!sockaddr_storage_same(mProxyServerAddressTor, proxy_addr)) + { + IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ + mProxyServerAddressTor = proxy_addr; + } + break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::setProxyServerAddress() unknown hidden type " << type << " -> false"; + std::cerr << std::endl; +#endif + return false; } + return true; } @@ -480,21 +637,71 @@ bool p3PeerMgrIMPL::resetOwnExternalAddressList() return true ; } -bool p3PeerMgrIMPL::getProxyServerStatus(uint32_t& proxy_status) -{ - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - - proxy_status = mProxyServerStatus; - return true; -} -bool p3PeerMgrIMPL::getProxyServerAddress(struct sockaddr_storage &proxy_addr) +/** + * @brief returs proxy server status for a hidden service proxy + * @param type hidden service type + * @param proxy_status + * @return true on success + */ +bool p3PeerMgrIMPL::getProxyServerStatus(const uint32_t type, uint32_t& proxy_status) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - proxy_addr = mProxyServerAddress; + switch (type) { + case RS_HIDDEN_TYPE_I2P: + proxy_status = mProxyServerStatusI2P; + break; + case RS_HIDDEN_TYPE_TOR: + proxy_status = mProxyServerStatusTor; + break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::getProxyServerStatus() unknown hidden type " << type << " -> false"; + std::cerr << std::endl; +#endif + return false; + } + return true; } - + +/** + * @brief returs proxy server address for a hidden service proxy + * @param type hidden service type + * @param proxy_addr + * @return true on success + */ +bool p3PeerMgrIMPL::getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr) +{ + RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + + switch (type) { + case RS_HIDDEN_TYPE_I2P: + proxy_addr = mProxyServerAddressI2P; + break; + case RS_HIDDEN_TYPE_TOR: + proxy_addr = mProxyServerAddressTor; + break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::getProxyServerAddress() unknown hidden type " << type << " -> false"; + std::cerr << std::endl; +#endif + return false; + } + return true; +} + +/** + * @brief looks up the proxy address and domain/port that have to be used when connecting to a peer + * @param ssl_id peer to connect to + * @param proxy_addr proxy address to be used + * @param domain_addr domain to connect to + * @param domain_port port to connect to + * @return true on success + */ bool p3PeerMgrIMPL::getProxyAddress(const RsPeerId &ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port) { RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ @@ -515,7 +722,21 @@ bool p3PeerMgrIMPL::getProxyAddress(const RsPeerId &ssl_id, struct sockaddr_stor domain_addr = it->second.hiddenDomain; domain_port = it->second.hiddenPort; - proxy_addr = mProxyServerAddress; + switch (it->second.hiddenType) { + case RS_HIDDEN_TYPE_I2P: + proxy_addr = mProxyServerAddressI2P; + break; + case RS_HIDDEN_TYPE_TOR: + proxy_addr = mProxyServerAddressTor; + break; + case RS_HIDDEN_TYPE_UNKNOWN: + default: +#ifdef PEER_DEBUG + std::cerr << "p3PeerMgrIMPL::getProxyAddress() no valid hidden type (" << it->second.hiddenType << ") for peer id " << ssl_id << " -> false"; + std::cerr << std::endl; +#endif + return false; + } return true; } @@ -1620,9 +1841,10 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) cleanup = false; bool useExtAddrFinder = mNetMgr->getIPServersEnabled(); - // Store Proxy Server. - struct sockaddr_storage proxy_addr; - getProxyServerAddress(proxy_addr); + /* 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 *******/ @@ -1733,17 +1955,33 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) vitem->tlvkvs.pairs.push_back(kv) ; + // Store Proxy Server. + // Tor #ifdef PEER_DEBUG - std::cerr << "Saving proxyServerAddress: " << sockaddr_storage_tostring(proxy_addr); + std::cerr << "Saving proxyServerAddress for Tor: " << sockaddr_storage_tostring(proxy_addr_tor); std::cerr << std::endl; #endif - kv.key = kConfigKeyProxyServerIpAddr; - kv.value = sockaddr_storage_iptostring(proxy_addr); + kv.key = kConfigKeyProxyServerIpAddrTor; + kv.value = sockaddr_storage_iptostring(proxy_addr_tor); vitem->tlvkvs.pairs.push_back(kv) ; - kv.key = kConfigKeyProxyServerPort; - kv.value = sockaddr_storage_porttostring(proxy_addr); + kv.key = kConfigKeyProxyServerPortTor; + kv.value = sockaddr_storage_porttostring(proxy_addr_tor); + vitem->tlvkvs.pairs.push_back(kv) ; + + // I2P +#ifdef PEER_DEBUG + std::cerr << "Saving proxyServerAddress for I2P: " << sockaddr_storage_tostring(proxy_addr_i2p); + std::cerr << std::endl; +#endif + + kv.key = kConfigKeyProxyServerIpAddrI2P; + kv.value = sockaddr_storage_iptostring(proxy_addr_i2p); + vitem->tlvkvs.pairs.push_back(kv) ; + + kv.key = kConfigKeyProxyServerPortI2P; + kv.value = sockaddr_storage_porttostring(proxy_addr_i2p); vitem->tlvkvs.pairs.push_back(kv) ; saveData.push_back(vitem); @@ -1779,8 +2017,10 @@ bool p3PeerMgrIMPL::loadList(std::list& load) // DEFAULTS. bool useExtAddrFinder = true; - std::string proxyIpAddress = kConfigDefaultProxyServerIpAddr; - uint16_t proxyPort = kConfigDefaultProxyServerPort; + std::string proxyIpAddressTor = kConfigDefaultProxyServerIpAddr; + uint16_t proxyPortTor = kConfigDefaultProxyServerPortTor; + std::string proxyIpAddressI2P = kConfigDefaultProxyServerIpAddr; + uint16_t proxyPortI2P = kConfigDefaultProxyServerPortI2P; if (load.empty()) { std::cerr << "p3PeerMgrIMPL::loadList() list is empty, it may be a configuration problem." << std::endl; @@ -1876,20 +2116,38 @@ bool p3PeerMgrIMPL::loadList(std::list& load) std::cerr << "setting use_extr_addr_finder to " << useExtAddrFinder << std::endl ; #endif } - else if (kit->key == kConfigKeyProxyServerIpAddr) + // Tor + else if (kit->key == kConfigKeyProxyServerIpAddrTor) { - proxyIpAddress = kit->value; + proxyIpAddressTor = kit->value; #ifdef PEER_DEBUG - std::cerr << "Loaded proxyIpAddress: " << proxyIpAddress; + std::cerr << "Loaded proxyIpAddress for Tor: " << proxyIpAddressTor; std::cerr << std::endl ; #endif } - else if (kit->key == kConfigKeyProxyServerPort) + else if (kit->key == kConfigKeyProxyServerPortTor) { - proxyPort = atoi(kit->value.c_str()); + proxyPortTor = atoi(kit->value.c_str()); #ifdef PEER_DEBUG - std::cerr << "Loaded proxyPort: " << proxyPort; + std::cerr << "Loaded proxyPort for Tor: " << proxyPortTor; + std::cerr << std::endl ; +#endif + } + // I2p + else if (kit->key == kConfigKeyProxyServerIpAddrI2P) + { + proxyIpAddressI2P = kit->value; +#ifdef PEER_DEBUG + std::cerr << "Loaded proxyIpAddress for I2P: " << proxyIpAddressI2P; + std::cerr << std::endl ; +#endif + } + else if (kit->key == kConfigKeyProxyServerPortI2P) + { + proxyPortI2P = atoi(kit->value.c_str()); +#ifdef PEER_DEBUG + std::cerr << "Loaded proxyPort for I2P: " << proxyPortI2P; std::cerr << std::endl ; #endif } @@ -2005,13 +2263,24 @@ bool p3PeerMgrIMPL::loadList(std::list& load) // Configure Proxy Server. struct sockaddr_storage proxy_addr; + // Tor sockaddr_storage_clear(proxy_addr); - sockaddr_storage_ipv4_aton(proxy_addr, proxyIpAddress.c_str()); - sockaddr_storage_ipv4_setport(proxy_addr, proxyPort); + sockaddr_storage_ipv4_aton(proxy_addr, proxyIpAddressTor.c_str()); + sockaddr_storage_ipv4_setport(proxy_addr, proxyPortTor); if (sockaddr_storage_isValidNet(proxy_addr)) { - setProxyServerAddress(proxy_addr); + setProxyServerAddress(RS_HIDDEN_TYPE_TOR, proxy_addr); + } + + // I2P + sockaddr_storage_clear(proxy_addr); + sockaddr_storage_ipv4_aton(proxy_addr, proxyIpAddressI2P.c_str()); + sockaddr_storage_ipv4_setport(proxy_addr, proxyPortI2P); + + if (sockaddr_storage_isValidNet(proxy_addr)) + { + setProxyServerAddress(RS_HIDDEN_TYPE_I2P, proxy_addr); } return true; diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 2af81855a..51789d296 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -90,6 +90,7 @@ class peerState bool hiddenNode; /* all IP addresses / dyndns must be blank */ std::string hiddenDomain; uint16_t hiddenPort; + uint32_t hiddenType; std::string location; std::string name; @@ -185,12 +186,16 @@ virtual bool getPeerName(const RsPeerId &ssl_id, std::string &name) = 0; virtual bool getGpgId(const RsPeerId &sslId, RsPgpId &gpgId) = 0; virtual uint32_t getConnectionType(const RsPeerId &sslId) = 0; -virtual bool setProxyServerAddress(const struct sockaddr_storage &proxy_addr) = 0; -virtual bool getProxyServerAddress(struct sockaddr_storage &proxy_addr) = 0; -virtual bool getProxyServerStatus(uint32_t& status) = 0; +virtual bool setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr) = 0; +virtual bool getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr) = 0; +virtual bool getProxyServerStatus(const uint32_t type, uint32_t& status) = 0; virtual bool isHidden() = 0; +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 uint32_t getHiddenType(const RsPeerId &ssl_id) = 0; virtual int getFriendCount(bool ssl, bool online) = 0; @@ -288,12 +293,16 @@ virtual bool getPeerName(const RsPeerId& ssl_id, std::string& name); virtual bool getGpgId(const RsPeerId& sslId, RsPgpId& gpgId); virtual uint32_t getConnectionType(const RsPeerId& sslId); -virtual bool setProxyServerAddress(const struct sockaddr_storage &proxy_addr); -virtual bool getProxyServerAddress(struct sockaddr_storage &proxy_addr); -virtual bool getProxyServerStatus(uint32_t &proxy_status); +virtual bool setProxyServerAddress(const uint32_t type, const struct sockaddr_storage &proxy_addr); +virtual bool getProxyServerAddress(const uint32_t type, struct sockaddr_storage &proxy_addr); +virtual bool getProxyServerStatus(const uint32_t type, uint32_t &proxy_status); virtual bool isHidden(); -virtual bool isHiddenPeer(const RsPeerId& ssl_id); +virtual bool isHidden(const uint32_t type); +virtual bool isHiddenPeer(const RsPeerId &ssl_id); +virtual bool isHiddenPeer(const RsPeerId &ssl_id, const uint32_t type); virtual bool getProxyAddress(const RsPeerId& ssl_id, struct sockaddr_storage &proxy_addr, std::string &domain_addr, uint16_t &domain_port); +virtual uint32_t hiddenDomainToHiddenType(const std::string &domain); +virtual uint32_t getHiddenType(const RsPeerId &ssl_id); virtual int getFriendCount(bool ssl, bool online); @@ -369,8 +378,10 @@ private: std::map mFriendsPermissionFlags ; // permission flags for each gpg key - struct sockaddr_storage mProxyServerAddress; - uint32_t mProxyServerStatus ; + struct sockaddr_storage mProxyServerAddressTor; + struct sockaddr_storage mProxyServerAddressI2P; + uint32_t mProxyServerStatusTor ; + uint32_t mProxyServerStatusI2P ; }; diff --git a/libretroshare/src/pqi/pqi_base.h b/libretroshare/src/pqi/pqi_base.h index 2f2446315..d6128b579 100644 --- a/libretroshare/src/pqi/pqi_base.h +++ b/libretroshare/src/pqi/pqi_base.h @@ -249,7 +249,8 @@ class PQInterface: public RateInterface const uint32_t PQI_CONNECT_TCP = 0x0001; const uint32_t PQI_CONNECT_UDP = 0x0002; -const uint32_t PQI_CONNECT_HIDDEN_TCP = 0x0004; +const uint32_t PQI_CONNECT_HIDDEN_TOR_TCP = 0x0004; +const uint32_t PQI_CONNECT_HIDDEN_I2P_TCP = 0x0008; #define BIN_FLAGS_NO_CLOSE 0x0001 diff --git a/libretroshare/src/pqi/pqibin.cc b/libretroshare/src/pqi/pqibin.cc index 3c9ed7731..3ff000ec0 100644 --- a/libretroshare/src/pqi/pqibin.cc +++ b/libretroshare/src/pqi/pqibin.cc @@ -500,7 +500,7 @@ void printNetBinID(std::ostream &out, const RsPeerId& id, uint32_t t) { out << "TCP)"; } - else if (t == PQI_CONNECT_HIDDEN_TCP) + else if (t & (PQI_CONNECT_HIDDEN_TOR_TCP | PQI_CONNECT_HIDDEN_I2P_TCP)) { out << "HTCP"; } diff --git a/libretroshare/src/pqi/pqipersongrp.cc b/libretroshare/src/pqi/pqipersongrp.cc index 9336736b4..e6a44d5cd 100644 --- a/libretroshare/src/pqi/pqipersongrp.cc +++ b/libretroshare/src/pqi/pqipersongrp.cc @@ -617,15 +617,19 @@ int pqipersongrp::connectPeer(const RsPeerId& id uint32_t ptype; if (type & RS_NET_CONN_TCP_ALL) { - if (type == RS_NET_CONN_TCP_HIDDEN) - { - ptype = PQI_CONNECT_HIDDEN_TCP; - timeout = RS_TCP_HIDDEN_TIMEOUT_PERIOD; - } - else - { + switch (type) { + case RS_NET_CONN_TCP_HIDDEN_TOR: + ptype = PQI_CONNECT_HIDDEN_TOR_TCP; + timeout = RS_TCP_HIDDEN_TIMEOUT_PERIOD; + break; + case RS_NET_CONN_TCP_HIDDEN_I2P: + ptype = PQI_CONNECT_HIDDEN_I2P_TCP; + timeout = RS_TCP_HIDDEN_TIMEOUT_PERIOD; + break; + default: ptype = PQI_CONNECT_TCP; - timeout = RS_TCP_STD_TIMEOUT_PERIOD; + timeout = RS_TCP_STD_TIMEOUT_PERIOD; + break; } #ifdef PGRP_DEBUG std::cerr << " pqipersongrp::connectPeer() connecting with TCP: Timeout :" << timeout; diff --git a/libretroshare/src/pqi/pqisslpersongrp.cc b/libretroshare/src/pqi/pqisslpersongrp.cc index 8988d8872..898b28bb5 100644 --- a/libretroshare/src/pqi/pqisslpersongrp.cc +++ b/libretroshare/src/pqi/pqisslpersongrp.cc @@ -91,7 +91,36 @@ pqiperson * pqisslpersongrp::locked_createPerson(const RsPeerId& id, pqilistener pqiconnect *pqisc = new pqiconnect(pqip, rss, pqis); - pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TCP, pqisc); + /* first select type based on peer */ + uint32_t typePeer = mPeerMgr->getHiddenType(id); + switch (typePeer) { + case RS_HIDDEN_TYPE_TOR: + pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TOR_TCP, pqisc); + break; + case RS_HIDDEN_TYPE_I2P: + pqip -> addChildInterface(PQI_CONNECT_HIDDEN_I2P_TCP, pqisc); + break; + default: + /* peer is not a hidden one but we are */ + /* select type based on ourselves */ + uint32_t typeOwn = mPeerMgr->getHiddenType(AuthSSL::getAuthSSL()->OwnId()); + switch (typeOwn) { + case RS_HIDDEN_TYPE_I2P: + pqip -> addChildInterface(PQI_CONNECT_HIDDEN_I2P_TCP, pqisc); + break; + default: + /* this case shouldn't happen! */ + std::cerr << "pqisslpersongrp::locked_createPerson WARNING INVALID HIDDEN TYPES - THIS SHOULD NOT HAPPEN!" << std::endl; + std::cerr << " - ID: " << id << std::endl; + std::cerr << " - mPeerMgr->isHidden(): " << mPeerMgr->isHidden() << std::endl; + std::cerr << " - mPeerMgr->isHiddenPeer(id): " << mPeerMgr->isHiddenPeer(id) << std::endl; + std::cerr << " - hidden types: peer=" << typePeer << " own=" << typeOwn << std::endl; + std::cerr << " --> falling back to Tor" << std::endl; + case RS_HIDDEN_TYPE_TOR: + pqip -> addChildInterface(PQI_CONNECT_HIDDEN_TOR_TCP, pqisc); + break; + } + } } else { diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index afb3f1a81..b10c85983 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -63,6 +63,14 @@ const uint32_t RS_NETMODE_EXT = 0x0003; const uint32_t RS_NETMODE_HIDDEN = 0x0004; const uint32_t RS_NETMODE_UNREACHABLE = 0x0005; +/* Hidden Type */ +const uint32_t RS_HIDDEN_TYPE_NONE = 0x0000; +const uint32_t RS_HIDDEN_TYPE_UNKNOWN = 0x0001; +const uint32_t RS_HIDDEN_TYPE_TOR = 0x0002; +const uint32_t RS_HIDDEN_TYPE_I2P = 0x0004; +/* mask to match all valid hidden types */ +const uint32_t RS_HIDDEN_TYPE_MASK = RS_HIDDEN_TYPE_I2P | RS_HIDDEN_TYPE_TOR; + /* Visibility */ const uint32_t RS_VS_DISC_OFF = 0x0000; const uint32_t RS_VS_DISC_MINIMAL = 0x0001; @@ -96,7 +104,8 @@ const uint32_t RS_PEER_CONNECTSTATE_TRYING_UDP = 3; const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_TCP = 4; const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_UDP = 5; const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_TOR = 6; -const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN = 7; +const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_I2P = 7; +const uint32_t RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN = 8; /* Error codes for certificate cleaning and cert parsing. Numbers should not overlap. */ @@ -232,6 +241,7 @@ class RsPeerDetails bool isHiddenNode; std::string hiddenNodeAddress; uint16_t hiddenNodePort; + uint32_t hiddenType; // Filled in for Standard Node. std::string localAddr; @@ -350,8 +360,8 @@ class RsPeers virtual bool setNetworkMode(const RsPeerId &ssl_id, uint32_t netMode) = 0; virtual bool setVisState(const RsPeerId &ssl_id, uint16_t vs_disc, uint16_t vs_dht) = 0; - virtual bool getProxyServer(std::string &addr, uint16_t &port,uint32_t& status_flags) = 0; - virtual bool setProxyServer(const std::string &addr, const uint16_t port) = 0; + virtual bool getProxyServer(const uint32_t type, std::string &addr, uint16_t &port,uint32_t& status_flags) = 0; + virtual bool setProxyServer(const uint32_t type, const std::string &addr, const uint16_t port) = 0; virtual void getIPServersList(std::list& ip_servers) = 0; virtual void allowServerIPDetermination(bool) = 0; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 54819d40a..3bbb8de3f 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); @@ -435,20 +437,79 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) } else if (pcs.state & RS_PEER_S_CONNECTED) { - if(isProxyAddress(pcs.connectaddr) || mPeerMgr->isHidden()) - d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR; - else if (pcs.connecttype == RS_NET_CONN_TCP_ALL) - { - d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TCP; - } - else if (pcs.connecttype == RS_NET_CONN_UDP_ALL) - { - d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UDP; - } - else - { - d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN; - } + /* peer is connected - determine how and set proper connectState */ + if(mPeerMgr->isHidden()) + { + uint32_t type; + /* hidden location */ + /* use connection direction to determine connection type */ + if(pcs.actAsServer) + { + /* incoming connection */ + /* use own type to set connectState */ + type = mPeerMgr->getHiddenType(AuthSSL::getAuthSSL()->OwnId()); + switch (type) { + case RS_HIDDEN_TYPE_TOR: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR; + break; + case RS_HIDDEN_TYPE_I2P: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P; + break; + default: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN; + break; + } + } + else + { + /* outgoing connection */ + /* use peer hidden type to set connectState */ + switch (ps.hiddenType) { + case RS_HIDDEN_TYPE_TOR: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR; + break; + case RS_HIDDEN_TYPE_I2P: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P; + break; + default: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN; + break; + } + } + } + else if (ps.hiddenType & RS_HIDDEN_TYPE_MASK) + { + /* hidden peer */ + /* use hidden type to set connectState */ + switch (ps.hiddenType) { + case RS_HIDDEN_TYPE_TOR: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TOR; + break; + case RS_HIDDEN_TYPE_I2P: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_I2P; + break; + default: + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN; + break; + } + } + else + { + /* peer and we are normal nodes */ + /* use normal detection to set connectState */ + if (pcs.connecttype == RS_NET_CONN_TCP_ALL) + { + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_TCP; + } + else if (pcs.connecttype == RS_NET_CONN_UDP_ALL) + { + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UDP; + } + else + { + d.connectState = RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN; + } + } } d.wasDeniedConnection = pcs.wasDeniedConnection; @@ -457,13 +518,13 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d) return true; } -bool p3Peers::isProxyAddress(const sockaddr_storage& addr) +bool p3Peers::isProxyAddress(const uint32_t type, const sockaddr_storage& addr) { uint16_t port ; std::string string_addr; - uint32_t status ; + uint32_t status ; - if(!getProxyServer(string_addr, port, status)) + if(!getProxyServer(type, string_addr, port, status)) return false ; return sockaddr_storage_iptostring(addr)==string_addr && sockaddr_storage_port(addr)==port ; @@ -923,21 +984,21 @@ bool p3Peers::setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht) return mPeerMgr->setVisState(id, vs_disc, vs_dht); } -bool p3Peers::getProxyServer(std::string &addr, uint16_t &port, uint32_t &status) +bool p3Peers::getProxyServer(const uint32_t type, std::string &addr, uint16_t &port, uint32_t &status) { #ifdef P3PEERS_DEBUG std::cerr << "p3Peers::getProxyServer()" << std::endl; #endif struct sockaddr_storage proxy_addr; - mPeerMgr->getProxyServerAddress(proxy_addr); + mPeerMgr->getProxyServerAddress(type, proxy_addr); addr = sockaddr_storage_iptostring(proxy_addr); port = sockaddr_storage_port(proxy_addr); - mPeerMgr->getProxyServerStatus(status); + mPeerMgr->getProxyServerStatus(type, status); return true; } -bool p3Peers::setProxyServer(const std::string &addr_str, const uint16_t port) +bool p3Peers::setProxyServer(const uint32_t type, const std::string &addr_str, const uint16_t port) { #ifdef P3PEERS_DEBUG std::cerr << "p3Peers::setProxyServer() " << std::endl; @@ -958,7 +1019,7 @@ bool p3Peers::setProxyServer(const std::string &addr_str, const uint16_t port) #endif /********************************** WINDOWS/UNIX SPECIFIC PART *******************/ { - return mPeerMgr->setProxyServerAddress(addr); + return mPeerMgr->setProxyServerAddress(type, addr); } else { @@ -1107,6 +1168,7 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai { pd.hiddenNodeAddress = domain; pd.hiddenNodePort = port; + pd.hiddenType = mPeerMgr->hiddenDomainToHiddenType(domain); } } else @@ -1311,7 +1373,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/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 66540003e..3f4fb8763 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -94,9 +94,9 @@ virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns); virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode); virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht); -virtual bool getProxyServer(std::string &addr, uint16_t &port,uint32_t& status); -virtual bool setProxyServer(const std::string &addr, const uint16_t port); -virtual bool isProxyAddress(const sockaddr_storage&); +virtual bool getProxyServer(const uint32_t type, std::string &addr, uint16_t &port,uint32_t& status); +virtual bool setProxyServer(const uint32_t type,const std::string &addr, const uint16_t port); +virtual bool isProxyAddress(const uint32_t type,const sockaddr_storage&); virtual void getIPServersList(std::list& ip_servers) ; virtual void allowServerIPDetermination(bool) ; diff --git a/retroshare-gui/src/gui/GenCertDialog.cpp b/retroshare-gui/src/gui/GenCertDialog.cpp index 9bebf4b2f..ba6282dc4 100644 --- a/retroshare-gui/src/gui/GenCertDialog.cpp +++ b/retroshare-gui/src/gui/GenCertDialog.cpp @@ -165,7 +165,7 @@ GenCertDialog::GenCertDialog(bool onlyGenerateIdentity, QWidget *parent) #if QT_VERSION >= 0x040700 ui.email_input->setPlaceholderText(tr("[Optional] Visible to your friends, and friends of friends.")) ; ui.node_input->setPlaceholderText(tr("[Required] Examples: Home, Laptop,...")) ; - ui.hiddenaddr_input->setPlaceholderText(tr("[Required] Examples: xa76giaf6ifda7ri63i263.onion (obtained by you from Tor)")) ; + ui.hiddenaddr_input->setPlaceholderText(tr("[Required] Tor/I2P address - Examples: xa76giaf6ifda7ri63i263.onion (obtained by you from Tor)")) ; ui.name_input->setPlaceholderText(tr("[Required] Visible to your friends, and friends of friends.")); ui.password_input->setPlaceholderText(tr("[Required] This password protects your private PGP key.")); ui.password_input_2->setPlaceholderText(tr("[Required] Type the same password again here.")); @@ -458,7 +458,7 @@ void GenCertDialog::genPerson() /* Message Dialog */ QMessageBox::warning(this, tr("Invalid hidden node"), - tr("Please enter a valid address of the form: 31769173498.onion:7800"), + tr("Please enter a valid address of the form: 31769173498.onion:7800 or [52 characters].b32.i2p"), QMessageBox::Ok); return; } diff --git a/retroshare-gui/src/gui/GenCertDialog.ui b/retroshare-gui/src/gui/GenCertDialog.ui index 4fe4f46ac..3dfd19786 100644 --- a/retroshare-gui/src/gui/GenCertDialog.ui +++ b/retroshare-gui/src/gui/GenCertDialog.ui @@ -7,7 +7,7 @@ 0 0 853 - 592 + 711 @@ -111,7 +111,7 @@ You can create a new profile with this form. -Alternatively you can use an existing profile. Just uncheck "Create a new profile" +Alternatively you can use an existing profile. Just uncheck "Create a new profile" true @@ -431,7 +431,7 @@ Alternatively you can use an existing profile. Just uncheck "Create a new profil - Tor address + hidden address @@ -593,7 +593,7 @@ anonymous, you can use a fake email. - <html><head/><body><p>This is a Tor Onion address of the form: xa76giaf6ifda7ri63i263.onion </p><p>In order to get one, you must configure Tor to create a new hidden service. If you do not yet have one, you can still go on, and make it right later in Retroshare's Options-&gt;Server-&gt;Tor configuration panel.</p></body></html> + <html><head/><body><p>This can be a Tor Onion address of the form: xa76giaf6ifda7ri63i263.onion <br/>or an I2P address in the form: [52 characters].b32.i2p </p><p>In order to get one, you must configure either Tor or I2P to create a new hidden service / server tunnel. If you do not yet have one, you can still go on, and make it right later in Retroshare's Options-&gt;Server-&gt;Hidden Service configuration panel.</p></body></html> true @@ -761,6 +761,7 @@ anonymous, you can use a fake email. + no_node_label genButton2 header_label genprofileinfo_label @@ -772,17 +773,17 @@ anonymous, you can use a fake email. label_hiddenaddr2 + + StyledLabel + QLabel +
gui/common/StyledLabel.h
+
HeaderFrame QFrame
gui/common/HeaderFrame.h
1
- - StyledLabel - QLabel -
gui/common/StyledLabel.h
-
diff --git a/retroshare-gui/src/gui/common/StatusDefs.cpp b/retroshare-gui/src/gui/common/StatusDefs.cpp index b0756c88f..486312c61 100644 --- a/retroshare-gui/src/gui/common/StatusDefs.cpp +++ b/retroshare-gui/src/gui/common/StatusDefs.cpp @@ -182,6 +182,10 @@ QString StatusDefs::connectStateString(RsPeerDetails &details) stateString = qApp->translate("StatusDefs", "Connected: Tor"); isConnected = true; break; + case RS_PEER_CONNECTSTATE_CONNECTED_I2P: + stateString = qApp->translate("StatusDefs", "Connected: I2P"); + isConnected = true; + break; case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN: stateString = qApp->translate("StatusDefs", "Connected: Unknown"); isConnected = true; @@ -231,6 +235,7 @@ QString StatusDefs::connectStateWithoutTransportTypeString(RsPeerDetails &detail case RS_PEER_CONNECTSTATE_CONNECTED_TCP: case RS_PEER_CONNECTSTATE_CONNECTED_UDP: case RS_PEER_CONNECTSTATE_CONNECTED_TOR: + case RS_PEER_CONNECTSTATE_CONNECTED_I2P: case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN: stateString = qApp->translate("StatusDefs", "Connected"); break; @@ -258,6 +263,9 @@ QString StatusDefs::connectStateIpString(RsPeerDetails &details) case RS_PEER_CONNECTSTATE_CONNECTED_TOR: stateString += QString(details.actAsServer ? qApp->translate("StatusDefs", "Tor-in") : qApp->translate("StatusDefs", "Tor-out")); break; + case RS_PEER_CONNECTSTATE_CONNECTED_I2P: + stateString += QString(details.actAsServer ? qApp->translate("StatusDefs", "I2P-in") : qApp->translate("StatusDefs", "I2P-out")); + break; case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN: stateString += qApp->translate("StatusDefs", "unkown"); break; diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 80aaf7698..73523637b 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -488,6 +488,7 @@ void ConnectFriendWizard::initializePage(int id) } ui->nodeEdit->setText(loc); + ui->ipEdit->setText(QString::fromStdString(peerDetails.isHiddenNode ? peerDetails.hiddenNodeAddress : peerDetails.extAddr)); ui->signersEdit->setPlainText(ts); fillGroups(this, ui->groupComboBox, groupId); diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui index df4209e44..0d27f1bc5 100644 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.ui @@ -31,7 +31,7 @@ - &Enter the certificate manually + Enter the certificate manually @@ -52,7 +52,7 @@ - &Enter RetroShare ID manually + Enter RetroShare ID manually @@ -1039,21 +1039,21 @@ resources.
- + Signers - + true - + This peer is already on your friend list. Adding it might just set it's ip address. @@ -1063,6 +1063,20 @@ resources. + + + + IP-Addr: + + + + + + + IP-Address + + + diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index e44e275cc..16f9a4533 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; @@ -302,15 +303,20 @@ void ServerPage::load() for(std::list::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it) ui.ipAddressList->addItem(QString::fromStdString(*it)); - /* TOR PAGE SETTINGS - only Proxy (outgoing) */ + /* HIDDEN PAGE SETTINGS - only Proxy (outgoing) */ std::string proxyaddr; uint16_t proxyport; uint32_t status ; - rsPeers->getProxyServer(proxyaddr, proxyport, status); - ui.torpage_proxyAddress -> setText(QString::fromStdString(proxyaddr)); - ui.torpage_proxyPort -> setValue(proxyport); + // Tor + rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, proxyaddr, proxyport, status); + ui.hiddenpage_proxyAddress_tor -> setText(QString::fromStdString(proxyaddr)); + 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(); } void ServerPage::toggleAutoIncludeFriends(bool b) @@ -697,7 +703,7 @@ void ServerPage::updateStatus() ui.iconlabel_ext->setPixmap(QPixmap(":/images/ledoff1.png")); // check for Tor - updateTorOutProxyIndicator(); + updateOutProxyIndicator(); } void ServerPage::toggleUPnP() @@ -807,17 +813,29 @@ void ServerPage::saveAddresses() rsConfig->SetMaxDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() ); // HANDLE PROXY SERVER. - std::string orig_proxyaddr; - uint16_t orig_proxyport; - uint32_t status ; - rsPeers->getProxyServer(orig_proxyaddr, orig_proxyport,status); + std::string orig_proxyaddr, new_proxyaddr; + uint16_t orig_proxyport, new_proxyport; + uint32_t status ; + // Tor + rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, orig_proxyaddr, orig_proxyport,status); - std::string new_proxyaddr = ui.torpage_proxyAddress -> text().toStdString(); - uint16_t new_proxyport = ui.torpage_proxyPort -> value(); + new_proxyaddr = ui.hiddenpage_proxyAddress_tor -> text().toStdString(); + new_proxyport = ui.hiddenpage_proxyPort_tor -> value(); if ((new_proxyaddr != orig_proxyaddr) || (new_proxyport != orig_proxyport)) { - rsPeers->setProxyServer(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); } load(); @@ -893,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 */ @@ -901,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. @@ -924,32 +942,64 @@ 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; - uint16_t proxyport; - uint32_t proxy_state_flags; - rsPeers->getProxyServer(proxyaddr, proxyport, proxy_state_flags); - ui.torpage_proxyAddress -> setText(QString::fromStdString(proxyaddr)); - ui.torpage_proxyPort -> setValue(proxyport); + uint16_t proxyport; + uint32_t status ; + // Tor + rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, proxyaddr, proxyport, status); + ui.hiddenpage_proxyAddress_tor -> setText(QString::fromStdString(proxyaddr)); + 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 \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 += "http://127.0.0.1:7657/i2ptunnelmgr - I2P Hidden Services\n"; + expected += tr("Points at: "); + expected += QString::fromStdString(detail.localAddr); + expected += ":"; + expected += QString::number(detail.localPort); + break; + case RS_HIDDEN_TYPE_TOR: + 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; + default: + ui.l_serviceAddress->setText(tr("Service Address")); + ui.l_incomingTestResult->setText(tr("incoming ok")); + + expected += "Please fill in a service address"; + + break; + } + ui.hiddenpage_configuration->setPlainText(expected); } /** Loads the settings for this page */ @@ -1005,7 +1055,7 @@ void ServerPage::updateStatusHiddenNode() #endif - updateTorOutProxyIndicator(); + updateOutProxyIndicator(); } void ServerPage::saveAddressesHiddenNode() @@ -1036,41 +1086,54 @@ 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); } // HANDLE PROXY SERVER. - std::string orig_proxyaddr; - uint16_t orig_proxyport; - uint32_t state_flags ; - rsPeers->getProxyServer(orig_proxyaddr, orig_proxyport,state_flags); + std::string orig_proxyaddr,new_proxyaddr; + uint16_t orig_proxyport, new_proxyport; + uint32_t status ; + // Tor + rsPeers->getProxyServer(RS_HIDDEN_TYPE_TOR, orig_proxyaddr, orig_proxyport,status); - std::string new_proxyaddr = ui.torpage_proxyAddress -> text().toStdString(); - uint16_t new_proxyport = ui.torpage_proxyPort -> value(); + new_proxyaddr = ui.hiddenpage_proxyAddress_tor -> text().toStdString(); + new_proxyport = ui.hiddenpage_proxyPort_tor -> value(); if ((new_proxyaddr != orig_proxyaddr) || (new_proxyport != orig_proxyport)) { - rsPeers->setProxyServer(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() ); load(); } -void ServerPage::updateTorOutProxyIndicator() +void ServerPage::updateOutProxyIndicator() { QTcpSocket socket ; - socket.connectToHost(ui.torpage_proxyAddress->text(),ui.torpage_proxyPort->text().toInt()); + // Tor + socket.connectToHost(ui.hiddenpage_proxyAddress_tor->text(),ui.hiddenpage_proxyPort_tor->text().toInt()); if(socket.waitForConnected(500)) { socket.disconnectFromHost(); @@ -1082,25 +1145,23 @@ void ServerPage::updateTorOutProxyIndicator() ui.iconlabel_tor_outgoing->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ; 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)) - { - socket.disconnectFromHost(); - ui.iconlabel_tor_incoming->setPixmap(QPixmap(ICON_STATUS_OK)) ; - ui.iconlabel_tor_incoming->setToolTip(tr("You are reachable through Tor.")) ; - } - else - { - 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!")) ; - } + // I2P + socket.connectToHost(ui.hiddenpage_proxyAddress_i2p->text(),ui.hiddenpage_proxyPort_i2p->text().toInt()); + if(socket.waitForConnected(500)) + { + socket.disconnectFromHost(); + ui.iconlabel_i2p_outgoing->setPixmap(QPixmap(ICON_STATUS_OK)) ; + ui.iconlabel_i2p_outgoing->setToolTip(tr("Proxy seems to work.")) ; + } + else + { + ui.iconlabel_i2p_outgoing->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)) ; + ui.iconlabel_i2p_outgoing->setToolTip(tr("I2P proxy is not enabled")) ; + } } -void ServerPage::updateTorInProxyIndicator() + +void ServerPage::updateInProxyIndicator() { // need to find a proper way to do this @@ -1113,21 +1174,31 @@ void ServerPage::updateTorInProxyIndicator() QNetworkProxy proxy ; proxy.setType(QNetworkProxy::Socks5Proxy); - proxy.setHostName(ui.torpage_proxyAddress->text()); - proxy.setPort(ui.torpage_proxyPort->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: + proxy.setHostName(ui.hiddenpage_proxyAddress_tor->text()); + proxy.setPort(ui.hiddenpage_proxyPort_tor->text().toInt()); + break; + default: + return; + } 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); - movie->start() ; + //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_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.torpage_proxyAddress->text().toStdString() << ":" << ui.torpage_proxyPort->text().toInt() << std::endl; + 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; connect(manager, SIGNAL(finished(QNetworkReply*)),this,SLOT(handleNetworkReply(QNetworkReply*))) ; @@ -1143,8 +1214,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 @@ -1152,8 +1223,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.\nAre 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 1c84e10b5..521487ac7 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.h +++ b/retroshare-gui/src/gui/settings/ServerPage.h @@ -52,6 +52,7 @@ public slots: void updateStatus(); private slots: + // ban list void updateSelectedBlackListIP(int row, int, int, int); void updateSelectedWhiteListIP(int row,int,int,int); void addIpRangeToBlackList(); @@ -69,25 +70,27 @@ private slots: void ipFilterContextMenu(const QPoint &); void ipWhiteListContextMenu(const QPoint &point); void removeBannedIp(); + + // server void saveAddresses(); void toggleUPnP(); void toggleIpDetermination(bool) ; void toggleTunnelConnection(bool) ; void clearKnownAddressList() ; void handleNetworkReply(QNetworkReply *reply); - void updateTorInProxyIndicator(); + void updateInProxyIndicator(); private: - - // Alternative Versions for HiddenNode Mode. + // ban list void addPeerToIPTable(QTableWidget *table, int row, const BanListPeer &blp); bool removeCurrentRowFromBlackList(sockaddr_storage& collected_addr,int& masked_bytes); bool removeCurrentRowFromWhiteList(sockaddr_storage &collected_addr, int &masked_bytes); + + // Alternative Versions for HiddenNode Mode. void loadHiddenNode(); void updateStatusHiddenNode(); void saveAddressesHiddenNode(); - void updateTorOutProxyIndicator(); - void updateLocInProxyIndicator(); + void updateOutProxyIndicator(); void loadFilteredIps() ; Ui::ServerPage ui; @@ -95,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 5a481d8b5..a8c12b5ad 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.ui +++ b/retroshare-gui/src/gui/settings/ServerPage.ui @@ -11,7 +11,16 @@ - + + 6 + + + 6 + + + 6 + + 6 @@ -515,7 +524,7 @@ behind a firewall or a VPN. 0 - + IP blacklist @@ -756,15 +765,15 @@ behind a firewall or a VPN. - + - Tor Configuration + Hidden Service Configuration - Outgoing Tor Connections + Outgoing Connections @@ -779,10 +788,10 @@ behind a firewall or a VPN. - + - + 10 @@ -822,16 +831,71 @@ behind a firewall or a VPN. + + + + 0 + + + 0 + + + + + + + I2P Socks Proxy + + + + + + + + + + 10 + + + 65535 + + + + + + + + + + + + + + :/images/ledoff1.png + + + + + + + I2P outgoing Okay + + + + + + + 16777215 - 100 + 145 - Qt::ScrollBarAlwaysOff + Qt::ScrollBarAsNeeded true @@ -839,8 +903,11 @@ behind a firewall or a VPN. Tor Socks Proxy default: 127.0.0.1:9050. Set in torrc config and update here. -You can connect to Hidden Nodes, even if you -are running a standard Node, so why not setup Tor? +I2P Socks Proxy: see http://127.0.0.1:7657/i2ptunnelmgr for setting up a client tunnel: +Tunnel Wizard -> Client Tunnel -> SOCKS 4/4a/5 -> enter a name -> leave 'Outproxies' empty -> enter port (memorize!) [you may also want to set the reachability to 127.0.0.1] -> check 'Auto Start' -> finish! +Now enter the address (e.g. 127.0.0.1) and the port you've picked before for the I2P Proxy. + +You can connect to Hidden Nodes, even if you are running a standard Node, so why not setup Tor and/or I2P? @@ -848,7 +915,7 @@ are running a standard Node, so why not setup Tor? - + 0 @@ -856,13 +923,13 @@ are running a standard Node, so why not setup Tor? - Incoming Tor Connections + Incoming Service Connections - + 10 @@ -874,9 +941,9 @@ are running a standard Node, so why not setup Tor? - + - <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> + <html><head/><body><p>This button simulates a SSL connection to your hidden address using the corresponding proxy. If your hidden 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,</p></body></html> Test @@ -886,7 +953,7 @@ are running a standard Node, so why not setup Tor? - + 10 @@ -896,9 +963,9 @@ are running a standard Node, so why not setup Tor? - + - Onion Address + Service Address @@ -910,23 +977,23 @@ are running a standard Node, so why not setup Tor? - + - <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 your hidden address. It should look like <span style=" font-weight:600;">[something].onion</span> or <span style=" font-weight:600;">[something].b32.i2p. </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>. For I2P: Setup a server tunnel ( http://127.0.0.1:7657/i2ptunnelmgr ) and copy it's base32 address when it is started (should end with .b32.i2p)</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> + <html><head/><body><p>This is the local address to which the 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> - + 16 @@ -942,9 +1009,9 @@ are running a standard Node, so why not setup Tor? - + - Tor incoming ok + incoming ok @@ -957,12 +1024,12 @@ are running a standard Node, so why not setup Tor? - Expected torrc Port Configuration: + Expected Configuration: - + 0 @@ -988,8 +1055,7 @@ are running a standard Node, so why not setup Tor? true - HiddenServiceDir </your/path/to/hidden/directory/service> -HiddenServicePort 9191 127.0.0.1:9191 + Please fill in a service address @@ -1013,12 +1079,14 @@ HiddenServicePort 9191 127.0.0.1:9191 true - To Receive Connections, you must first setup a Tor Hidden Service. -See Tor documentation for HOWTO details. + To Receive Connections, you must first setup a Tor/I2P Hidden Service. +For Tor: See torrc and documentation for HOWTO details. +For I2P: See http://127.0.0.1:7657/i2ptunnelmgr for setting up a server tunnel: +Tunnel Wizard -> Server Tunnel -> Standard -> enter a name -> enter the address and port your RS is using (see Local Address above) -> check 'Auto Start' -> finish! -Once this is done, paste the Onion Address in the box above. -This is your external address on the Tor network. -Finally make sure that the Ports match the Tor configuration. +Once this is done, paste the Onion/I2P (Base32) Address in the box above. +This is your external address on the Tor/I2P network. +Finally make sure that the Ports match the configuration. If you have issues connecting over Tor check the Tor logs too.