fixed up hidden addresses and removed whitespace from onion address.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@7036 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2014-01-18 23:29:22 +00:00
parent affdd49001
commit d39c5c028a
3 changed files with 66 additions and 30 deletions

View File

@ -391,12 +391,25 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::st
std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort()"; std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort()";
std::cerr << std::endl; 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! *****/ IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
if (ssl_id == AuthSSL::getAuthSSL()->OwnId()) if (ssl_id == AuthSSL::getAuthSSL()->OwnId())
{ {
mOwnState.hiddenNode = true; mOwnState.hiddenNode = true;
mOwnState.hiddenDomain = domain_addr; mOwnState.hiddenDomain = domain;
mOwnState.hiddenPort = domain_port; mOwnState.hiddenPort = domain_port;
std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set own State"; std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set own State";
std::cerr << std::endl; std::cerr << std::endl;
@ -413,7 +426,7 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const std::string &ssl_id, const std::st
return false; return false;
} }
it->second.hiddenDomain = domain_addr; it->second.hiddenDomain = domain;
it->second.hiddenPort = domain_port; it->second.hiddenPort = domain_port;
it->second.hiddenNode = true; it->second.hiddenNode = true;
std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set Peers State"; std::cerr << "p3PeerMgrIMPL::setHiddenDomainPort() Set Peers State";

View File

@ -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) bool p3Peers::setHiddenNode(const std::string &id, const std::string &hidden_node_address)
{ {
#ifdef P3PEERS_DEBUG #ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::setHiddenNode() " << id << std::endl; std::cerr << "p3Peers::setHiddenNode() " << id << std::endl;
#endif #endif
size_t cpos = hidden_node_address.rfind(':'); std::string domain;
if (cpos == std::string::npos) uint16_t port;
if (!splitAddressString(hidden_node_address, domain, port))
{ {
std::cerr << "p3Peers::setHiddenNode() Failed to parse (:) " << hidden_node_address << std::endl;
return false; 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->setNetworkMode(id, RS_NET_MODE_HIDDEN);
mPeerMgr->setHiddenDomainPort(id, domain, (uint16_t) portint); mPeerMgr->setHiddenDomainPort(id, domain, port);
return true; return true;
} }
@ -1049,8 +1066,14 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai
if (!cert.hidden_node_string().empty()) if (!cert.hidden_node_string().empty())
{ {
pd.isHiddenNode = true; 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 else
{ {

View File

@ -631,7 +631,7 @@ void ConnectFriendWizard::accept()
if (peerDetails.isHiddenNode) if (peerDetails.isHiddenNode)
{ {
std::cerr << "ConnectFriendWizard::accept() : setting hidden node." << std::endl; std::cerr << "ConnectFriendWizard::accept() : setting hidden node." << std::endl;
rsPeers->setHiddenNode(peerDetails.id, peerDetails.hiddenNodeAddress); rsPeers->setHiddenNode(peerDetails.id, peerDetails.hiddenNodeAddress, peerDetails.hiddenNodePort);
} }
else else
{ {