diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 9c30aef2f..a297069da 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -391,12 +391,25 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::st std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort()"; std::cerr << std::endl; + std::string domain = domain_addr; + // trim whitespace! + size_t pos = domain.find_last_not_of(" \t\n"); + if (std::string::npos != pos) + { + domain = domain.substr(0, pos + 1); + } + pos = domain.find_first_not_of(" \t\n"); + if (std::string::npos != pos) + { + domain = domain.substr(pos); + } + IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ if (ssl_id == AuthSSL::getAuthSSL()->OwnId()) { mOwnState.hiddenNode = true; - mOwnState.hiddenDomain = domain_addr; + mOwnState.hiddenDomain = domain; mOwnState.hiddenPort = domain_port; std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set own State"; std::cerr << std::endl; @@ -413,7 +426,7 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::st return false; } - it->second.hiddenDomain = domain_addr; + it->second.hiddenDomain = domain; it->second.hiddenPort = domain_port; it->second.hiddenNode = true; std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set Peers State"; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 330ef1e6e..97bbcf3fd 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -735,41 +735,58 @@ bool p3Peers::setLocation(const std::string &ssl_id, const std::string &locatio } +bool splitAddressString(const std::string &addr, std::string &domain, uint16_t &port) +{ + std::cerr << "splitAddressString() Input: " << addr << std::endl; + + size_t cpos = addr.rfind(':'); + if (cpos == std::string::npos) + { + std::cerr << "splitAddressString Failed to parse (:)"; + std::cerr << std::endl; + return false; + } + + int lenport = addr.length() - (cpos + 1); // +1 to skip over : char. + if (lenport <= 0) + { + std::cerr << "splitAddressString() Missing Port "; + std::cerr << std::endl; + return false; + } + + domain = addr.substr(0, cpos); + std::string portstr = addr.substr(cpos + 1, std::string::npos); + int portint = atoi(portstr.c_str()); + + if ((portint < 0) || (portint > 65535)) + { + std::cerr << "splitAddressString() Invalid Port"; + std::cerr << std::endl; + return false; + } + port = portint; + + std::cerr << "splitAddressString() Domain: " << domain << " Port: " << port; + std::cerr << std::endl; + return true; +} + + bool p3Peers::setHiddenNode(const std::string &id, const std::string &hidden_node_address) { #ifdef P3PEERS_DEBUG std::cerr << "p3Peers::setHiddenNode() " << id << std::endl; #endif - size_t cpos = hidden_node_address.rfind(':'); - if (cpos == std::string::npos) + std::string domain; + uint16_t port; + if (!splitAddressString(hidden_node_address, domain, port)) { - std::cerr << "p3Peers::setHiddenNode() Failed to parse (:) " << hidden_node_address << std::endl; return false; } - - int lenport = hidden_node_address.length() - (cpos + 1); // +1 to skip over : char. - if (lenport <= 0) - { - std::cerr << "p3Peers::setHiddenNode() Missing Port: " << hidden_node_address << std::endl; - return false; - } - - std::string domain = hidden_node_address.substr(0, cpos); - std::string port = hidden_node_address.substr(cpos + 1, std::string::npos); - int portint = atoi(port.c_str()); - - if ((portint < 0) || (portint > 65535)) - { - std::cerr << "p3Peers::setHiddenNode() Invalid Port: " << hidden_node_address << std::endl; - return false; - } - - std::cerr << "p3Peers::setHiddenNode() Domain: " << domain << " Port: " << portint; - std::cerr << std::endl; - mPeerMgr->setNetworkMode(id, RS_NET_MODE_HIDDEN); - mPeerMgr->setHiddenDomainPort(id, domain, (uint16_t) portint); + mPeerMgr->setHiddenDomainPort(id, domain, port); return true; } @@ -1049,8 +1066,14 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai if (!cert.hidden_node_string().empty()) { pd.isHiddenNode = true; - pd.hiddenNodeAddress = cert.hidden_node_string(); - //pd.hiddenNodePort = cert.hidden_node_port(); + + std::string domain; + uint16_t port; + if (splitAddressString(cert.hidden_node_string(), domain, port)) + { + pd.hiddenNodeAddress = domain; + pd.hiddenNodePort = port; + } } else { diff --git a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp index 6219950eb..0f5cd379f 100755 --- a/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp +++ b/retroshare-gui/src/gui/connect/ConnectFriendWizard.cpp @@ -631,7 +631,7 @@ void ConnectFriendWizard::accept() if (peerDetails.isHiddenNode) { std::cerr << "ConnectFriendWizard::accept() : setting hidden node." << std::endl; - rsPeers->setHiddenNode(peerDetails.id, peerDetails.hiddenNodeAddress); + rsPeers->setHiddenNode(peerDetails.id, peerDetails.hiddenNodeAddress, peerDetails.hiddenNodePort); } else {