Share additional addresses via RsCertificate

This commit is contained in:
Gioacchino Mazzurco 2018-03-03 00:08:56 +01:00
parent 8542abd4f0
commit bed856425f
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
13 changed files with 267 additions and 149 deletions

View File

@ -727,6 +727,11 @@ void PeersHandler::handleWildcard(Request &req, Response &resp)
peerDetails.localPort );
if (!peerDetails.dyndns.empty())
mRsPeers->setDynDNS(peerDetails.id, peerDetails.dyndns);
for(auto&& ipr : peerDetails.ipAddressList)
mRsPeers->addPeerLocator(
peerDetails.id,
RsUrl(ipr.substr(0, ipr.find(' '))) );
}
}
while(false);

View File

@ -1,3 +1,23 @@
/*
* RetroShare
*
* Copyright (C) 2012-2014 Cyril Soler <csoler@users.sourceforge.net>
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <sstream>
#include <stdio.h>
@ -11,25 +31,21 @@
//#define DEBUG_RSCERTIFICATE
static const std::string PGP_CERTIFICATE_START ( "-----BEGIN PGP PUBLIC KEY BLOCK-----" );
static const std::string PGP_CERTIFICATE_END ( "-----END PGP PUBLIC KEY BLOCK-----" );
static const std::string EXTERNAL_IP_BEGIN_SECTION ( "--EXT--" );
static const std::string LOCAL_IP_BEGIN_SECTION ( "--LOCAL--" );
static const std::string SSLID_BEGIN_SECTION ( "--SSLID--" );
static const std::string LOCATION_BEGIN_SECTION ( "--LOCATION--" );
static const std::string HIDDEN_NODE_BEGIN_SECTION ( "--HIDDEN--" );
static const uint8_t CERTIFICATE_VERSION_06 = 0x06;
static const uint8_t CERTIFICATE_PTAG_PGP_SECTION = 0x01 ;
static const uint8_t CERTIFICATE_PTAG_EXTIPANDPORT_SECTION = 0x02 ;
static const uint8_t CERTIFICATE_PTAG_LOCIPANDPORT_SECTION = 0x03 ;
static const uint8_t CERTIFICATE_PTAG_DNS_SECTION = 0x04 ;
static const uint8_t CERTIFICATE_PTAG_SSLID_SECTION = 0x05 ;
static const uint8_t CERTIFICATE_PTAG_NAME_SECTION = 0x06 ;
static const uint8_t CERTIFICATE_PTAG_CHECKSUM_SECTION = 0x07 ;
static const uint8_t CERTIFICATE_PTAG_HIDDENNODE_SECTION = 0x08 ;
static const uint8_t CERTIFICATE_PTAG_VERSION_SECTION = 0x09 ;
static const uint8_t CERTIFICATE_VERSION_06 = 0x06 ;
enum CertificatePtag : uint8_t
{
CERTIFICATE_PTAG_PGP_SECTION = 0x01,
CERTIFICATE_PTAG_EXTIPANDPORT_SECTION = 0x02,
CERTIFICATE_PTAG_LOCIPANDPORT_SECTION = 0x03,
CERTIFICATE_PTAG_DNS_SECTION = 0x04,
CERTIFICATE_PTAG_SSLID_SECTION = 0x05,
CERTIFICATE_PTAG_NAME_SECTION = 0x06,
CERTIFICATE_PTAG_CHECKSUM_SECTION = 0x07,
CERTIFICATE_PTAG_HIDDENNODE_SECTION = 0x08,
CERTIFICATE_PTAG_VERSION_SECTION = 0x09,
CERTIFICATE_PTAG_EXTRA_LOCATOR = 10
};
static bool is_acceptable_radix64Char(char c)
{
@ -95,6 +111,14 @@ std::string RsCertificate::toStdString() const
addPacket( CERTIFICATE_PTAG_NAME_SECTION , (unsigned char *)location_name.c_str() ,location_name.length() , buf, p, BS ) ;
addPacket( CERTIFICATE_PTAG_SSLID_SECTION , location_id.toByteArray() ,location_id.SIZE_IN_BYTES, buf, p, BS ) ;
for (const RsUrl& locator : mLocators)
{
std::string urlStr(locator.toString());
addPacket( CERTIFICATE_PTAG_EXTRA_LOCATOR,
(unsigned char *) urlStr.c_str(), urlStr.size(),
buf, p, BS );
}
}
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(buf,p) ;
@ -195,7 +219,10 @@ RsCertificate::RsCertificate(const RsPeerDetails& Detail, const unsigned char *b
memset(ipv4_external_ip_and_port,0,6) ;
}
dns_name = Detail.dyndns ;
dns_name = Detail.dyndns;
for(auto&& ipr : Detail.ipAddressList)
mLocators.insert(RsUrl(ipr.substr(0, ipr.find(' '))));
}
}
else
@ -254,19 +281,19 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
std::vector<uint8_t> bf = Radix64::decode(str) ;
size_t size = bf.size();
bool checksum_check_passed = false ;
unsigned char *buf = bf.data() ;
size_t total_s = 0 ;
only_pgp = true ;
uint8_t certificate_version = 0x00 ;
bool checksum_check_passed = false;
unsigned char *buf = bf.data();
size_t total_s = 0;
only_pgp = true;
uint8_t certificate_version = 0x00;
while(total_s < size)
{
uint8_t ptag = buf[0];
buf = &buf[1] ;
buf = &buf[1];
unsigned char *buf2 = buf ;
uint32_t s = PGPKeyParser::read_125Size(buf) ;
unsigned char *buf2 = buf;
uint32_t s = PGPKeyParser::read_125Size(buf);
total_s += 1 + ((unsigned long)buf-(unsigned long)buf2) ;
@ -281,90 +308,80 @@ bool RsCertificate::initFromString(const std::string& instr,uint32_t& err_code)
#endif
switch(ptag)
{
case CERTIFICATE_PTAG_VERSION_SECTION: certificate_version = buf[0] ;
buf = &buf[s] ;
break ;
case CERTIFICATE_PTAG_PGP_SECTION: binary_pgp_key = new unsigned char[s] ;
memcpy(binary_pgp_key,buf,s) ;
binary_pgp_key_size = s ;
buf = &buf[s] ;
break ;
case CERTIFICATE_PTAG_NAME_SECTION: location_name = std::string((char *)buf,s) ;
buf = &buf[s] ;
break ;
case CERTIFICATE_PTAG_SSLID_SECTION:
if(s != location_id.SIZE_IN_BYTES)
{
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID ;
return false ;
}
location_id = RsPeerId(buf) ;
buf = &buf[s] ;
only_pgp = false ;
break ;
case CERTIFICATE_PTAG_DNS_SECTION: dns_name = std::string((char *)buf,s) ;
buf = &buf[s] ;
break ;
case CERTIFICATE_PTAG_HIDDENNODE_SECTION:
hidden_node_address = std::string((char *)buf,s);
hidden_node = true;
buf = &buf[s];
break ;
case CERTIFICATE_PTAG_LOCIPANDPORT_SECTION:
if(s != 6)
{
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCAL_IP;
return false ;
}
memcpy(ipv4_internal_ip_and_port,buf,s) ;
buf = &buf[s] ;
break ;
case CERTIFICATE_PTAG_EXTIPANDPORT_SECTION:
if(s != 6)
{
err_code = CERTIFICATE_PARSING_ERROR_INVALID_EXTERNAL_IP;
return false ;
}
memcpy(ipv4_external_ip_and_port,buf,s) ;
buf = &buf[s] ;
break ;
case CERTIFICATE_PTAG_CHECKSUM_SECTION:
{
if(s != 3 || total_s+3 != size)
{
err_code = CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION ;
return false ;
}
uint32_t computed_crc = PGPKeyManagement::compute24bitsCRC(bf.data(),size-5) ;
uint32_t certificate_crc = buf[0] + (buf[1] << 8) + (buf[2] << 16) ;
if(computed_crc != certificate_crc)
{
err_code = CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR ;
return false ;
}
else
checksum_check_passed = true ;
}
break ;
default:
std::cerr << "(WW) unknwown PTAG 0x" << std::hex << ptag << std::dec << " in certificate! Ignoring it." << std::endl;
buf = &buf[s] ;
break ;
case CERTIFICATE_PTAG_VERSION_SECTION:
certificate_version = buf[0];
break;
case CERTIFICATE_PTAG_PGP_SECTION:
binary_pgp_key = new unsigned char[s];
memcpy(binary_pgp_key,buf,s);
binary_pgp_key_size = s;
break;
case CERTIFICATE_PTAG_NAME_SECTION:
location_name = std::string((char *)buf,s);
break;
case CERTIFICATE_PTAG_SSLID_SECTION:
if(s != location_id.SIZE_IN_BYTES)
{
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCATION_ID;
return false;
}
location_id = RsPeerId(buf);
only_pgp = false;
break;
case CERTIFICATE_PTAG_DNS_SECTION:
dns_name = std::string((char *)buf,s);
break;
case CERTIFICATE_PTAG_HIDDENNODE_SECTION:
hidden_node_address = std::string((char *)buf,s);
hidden_node = true;
break;
case CERTIFICATE_PTAG_LOCIPANDPORT_SECTION:
if(s != 6)
{
err_code = CERTIFICATE_PARSING_ERROR_INVALID_LOCAL_IP;
return false;
}
memcpy(ipv4_internal_ip_and_port,buf,s);
break;
case CERTIFICATE_PTAG_EXTIPANDPORT_SECTION:
if(s != 6)
{
err_code = CERTIFICATE_PARSING_ERROR_INVALID_EXTERNAL_IP;
return false;
}
memcpy(ipv4_external_ip_and_port,buf,s);
break;
case CERTIFICATE_PTAG_CHECKSUM_SECTION:
{
if(s != 3 || total_s+3 != size)
{
err_code =
CERTIFICATE_PARSING_ERROR_INVALID_CHECKSUM_SECTION;
return false;
}
uint32_t computed_crc =
PGPKeyManagement::compute24bitsCRC(bf.data(),size-5);
uint32_t certificate_crc =
buf[0] + (buf[1] << 8) + (buf[2] << 16);
if(computed_crc != certificate_crc)
{
err_code = CERTIFICATE_PARSING_ERROR_CHECKSUM_ERROR;
return false;
}
else checksum_check_passed = true;
break;
}
case CERTIFICATE_PTAG_EXTRA_LOCATOR:
mLocators.insert(RsUrl(std::string((char *)buf, s)));
break;
default:
std::cerr << "(WW) unknwown PTAG 0x" << std::hex << ptag
<< std::dec << " in certificate! Ignoring it."
<< std::endl;
break;
}
buf = &buf[s];
total_s += s ;
}

View File

@ -1,7 +1,28 @@
#pragma once
/*
* RetroShare
*
* Copyright (C) 2012-2014 Cyril Soler <csoler@users.sourceforge.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "retroshare/rstypes.h"
#include "util/rsurl.h"
#include <set>
#include <string>
#include <retroshare/rstypes.h>
class RsPeerDetails ;
@ -42,6 +63,7 @@ class RsCertificate
size_t pgp_key_size() const { return binary_pgp_key_size ; }
static bool cleanCertificate(const std::string& input, std::string& output, RsCertificate::Format& format, int& error_code, bool check_content) ;
const std::set<RsUrl>& locators() const { return mLocators; }
private:
static bool cleanCertificate(const std::string& input,std::string& output,int&) ; // new radix format
@ -69,6 +91,7 @@ class RsCertificate
std::string pgp_version ;
std::string dns_name ;
std::string hidden_node_address;
std::set<RsUrl> mLocators;
bool only_pgp ; // does the cert contain only pgp info?
bool hidden_node; // IP or hidden Node Address.

View File

@ -1363,16 +1363,63 @@ bool p3PeerMgrIMPL::UpdateOwnAddress( const sockaddr_storage& pLocalAddr,
}
bool p3PeerMgrIMPL::addPeerLocator(const RsPeerId &sslId, const RsUrl& locator)
{
std::string host(locator.host());
pqiIpAddress ip;
if(!locator.hasPort() || host.empty() ||
!sockaddr_storage_inet_pton(ip.mAddr, host) ||
!sockaddr_storage_setport(ip.mAddr, locator.port())) return false;
ip.mSeenTime = time(NULL);
bool changed = false;
bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr)
if (sslId == AuthSSL::getAuthSSL()->OwnId())
{
RS_STACK_MUTEX(mPeerMtx);
changed = mOwnState.ipAddrs.updateLocalAddrs(ip);
}
else
{
RS_STACK_MUTEX(mPeerMtx);
auto it = mFriendList.find(sslId);
if (it == mFriendList.end())
{
it = mOthersList.find(sslId);
if (it == mOthersList.end())
{
#ifdef PEER_DEBUG
std::cerr << __PRETTY_FUNCTION__ << "cannot add address "
<< "info, peer id: " << sslId << " not found in list"
<< std::endl;
#endif
return false;
}
}
changed = it->second.ipAddrs.updateLocalAddrs(ip);
}
if (changed)
{
#ifdef PEER_DEBUG
std::cerr << __PRETTY_FUNCTION__ << " Added locator: "
<< locator.toString() << std::endl;
#endif
IndicateConfigChanged();
}
return changed;
}
bool p3PeerMgrIMPL::setLocalAddress( const RsPeerId &id,
const sockaddr_storage &addr )
{
bool changed = false;
if (id == AuthSSL::getAuthSSL()->OwnId())
{
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mPeerMtx);
if (!sockaddr_storage_same(mOwnState.localaddr, addr))
{
mOwnState.localaddr = addr;
@ -1390,7 +1437,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr
return changed;
}
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
RS_STACK_MUTEX(mPeerMtx);
/* check if it is a friend */
std::map<RsPeerId, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
@ -1398,7 +1445,9 @@ bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr
if (mOthersList.end() == (it = mOthersList.find(id)))
{
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres info : peer id not found in friend list id: " << id << std::endl;
std::cerr << "p3PeerMgrIMPL::setLocalAddress() cannot add addres "
<< "info : peer id not found in friend list id: "
<< id << std::endl;
#endif
return false;
}
@ -1419,10 +1468,7 @@ bool p3PeerMgrIMPL::setLocalAddress(const RsPeerId &id, const struct sockaddr
it->second.updateIpAddressList(ipAddressTimed);
#endif
if (changed) {
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
if (changed) IndicateConfigChanged();
return changed;
}

View File

@ -163,6 +163,7 @@ virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list
* 3) p3disc - reasonable
*/
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator) = 0;
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr) = 0;
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr) = 0;
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns) = 0;
@ -277,6 +278,7 @@ public:
* 3) p3disc - reasonable
*/
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator);
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);

View File

@ -33,6 +33,7 @@
#include <retroshare/rstypes.h>
#include <retroshare/rsfiles.h>
#include <retroshare/rsids.h>
#include "util/rsurl.h"
/* The Main Interface Class - for information about your Peers
* A peer is another RS instance, means associated with an SSL certificate
@ -370,6 +371,7 @@ public:
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port) = 0;
virtual bool isHiddenNode(const RsPeerId &id) = 0;
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator) = 0;
virtual bool setLocalAddress(const RsPeerId &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setExtAddress( const RsPeerId &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setDynDNS(const RsPeerId &id, const std::string &addr) = 0;

View File

@ -904,6 +904,9 @@ bool p3Peers::setHiddenNode(const RsPeerId &id, const std::string &address, uin
return true;
}
bool p3Peers::addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator)
{ return mPeerMgr->addPeerLocator(ssl_id, locator); }
bool p3Peers::setLocalAddress(const RsPeerId &id,
const std::string &addr_str, uint16_t port)
{
@ -1148,11 +1151,12 @@ bool p3Peers::loadCertificateFromString(const std::string& cert, RsPeerId& ssl_
return res ;
}
bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetails &pd,uint32_t& error_code)
bool p3Peers::loadDetailsFromStringCert( const std::string &certstr,
RsPeerDetails &pd,
uint32_t& error_code )
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::LoadCertificateFromString() ";
std::cerr << std::endl;
std::cerr << "p3Peers::LoadCertificateFromString() " << std::endl;
#endif
//parse the text to get ip address
try
@ -1192,9 +1196,11 @@ bool p3Peers::loadDetailsFromStringCert(const std::string &certstr, RsPeerDetai
pd.localPort = cert.loc_port_us();
pd.extAddr = cert.ext_ip_string();
pd.extPort = cert.ext_port_us();
pd.dyndns = cert.dns_string() ;
pd.dyndns = cert.dns_string();
for(const RsUrl& locator : cert.locators())
pd.ipAddressList.push_back(locator.toString());
}
}
}
catch(uint32_t e)
{
std::cerr << "ConnectFriendWizard : Parse ip address error :" << e << std::endl;

View File

@ -36,6 +36,7 @@
#endif
#include "retroshare/rspeers.h"
#include "util/rsurl.h"
class p3LinkMgr;
class p3PeerMgr;
@ -96,7 +97,8 @@ public:
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port);
virtual bool isHiddenNode(const RsPeerId &id);
virtual bool setLocalAddress(const RsPeerId &id, const std::string &addr, uint16_t port);
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator);
virtual bool setLocalAddress(const RsPeerId &id, const std::string &addr, uint16_t port);
virtual bool setExtAddress(const RsPeerId &id, const std::string &addr, uint16_t port);
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode);

View File

@ -192,8 +192,7 @@ bool sockaddr_storage_copyip(struct sockaddr_storage &dst, const struct sockaddr
uint16_t sockaddr_storage_port(const struct sockaddr_storage &addr)
{
#ifdef SS_DEBUG
std::cerr << "sockaddr_storage_port()";
std::cerr << std::endl;
std::cerr << "sockaddr_storage_port()" << std::endl;
#endif
switch(addr.ss_family)
{
@ -203,8 +202,10 @@ uint16_t sockaddr_storage_port(const struct sockaddr_storage &addr)
return sockaddr_storage_ipv6_port(addr);
default:
std::cerr << "sockaddr_storage_port() invalid addr.ss_family" << std::endl;
#ifdef SS_DEBUG
sockaddr_storage_dump(addr);
print_stacktrace();
#endif
break;
}
return 0;
@ -504,7 +505,7 @@ std::string sockaddr_storage_tostring(const struct sockaddr_storage &addr)
url.setScheme("ipv6");
break;
default:
return "INVALID_IP";
return "AF_INVALID";
}
url.setHost(sockaddr_storage_iptostring(addr))
@ -613,9 +614,11 @@ std::string sockaddr_storage_iptostring(const struct sockaddr_storage &addr)
break;
default:
output = "INVALID_IP";
std::cerr << __PRETTY_FUNCTION__ << " Got invalid IP:" << std::endl;
std::cerr << __PRETTY_FUNCTION__ << " Got invalid IP!" << std::endl;
#ifdef SS_DEBUG
sockaddr_storage_dump(addr);
print_stacktrace();
#endif
break;
}
return output;

View File

@ -34,10 +34,10 @@ RsUrl::RsUrl(const std::string& urlStr) : mPort(0), mHasPort(false)
RsUrl& RsUrl::fromString(const std::string& urlStr)
{
size_t urlSize = urlStr.size();
size_t endI = urlStr.size()-1;
size_t schemeEndI = urlStr.find(schemeSeparator);
if(schemeEndI == string::npos)
if(schemeEndI >= endI)
{
mScheme = urlStr;
return *this;
@ -46,15 +46,16 @@ RsUrl& RsUrl::fromString(const std::string& urlStr)
mScheme = urlStr.substr(0, schemeEndI);
size_t hostBeginI = schemeEndI + 3;
if(hostBeginI >= urlSize) return *this;
if(hostBeginI >= endI) return *this;
bool hasSquareBr = (urlStr[hostBeginI] == ipv6WrapOpen[0]);
size_t hostEndI;
if(hasSquareBr)
{
if(++hostBeginI >= urlSize) return *this;
if(++hostBeginI >= endI) return *this;
hostEndI = urlStr.find(ipv6WrapClose, hostBeginI);
mHost = urlStr.substr(hostBeginI, hostEndI - hostBeginI - 1);
++hostEndI;
}
else
{
@ -64,24 +65,25 @@ RsUrl& RsUrl::fromString(const std::string& urlStr)
hostEndI = min(hostEndI, urlStr.find(fragmentSeparator, hostBeginI));
mHost = urlStr.substr(hostBeginI, hostEndI - hostBeginI);
if(hostEndI == string::npos) return *this;
}
if( hostEndI >= endI ) return *this;
mHasPort = (sscanf(&urlStr[hostEndI], ":%hu", &mPort) == 1);
size_t pathBeginI = urlStr.find(pathSeparator, hostEndI);
size_t pathBeginI = urlStr.find(pathSeparator, hostBeginI);
size_t pathEndI = string::npos;
if(pathBeginI != string::npos)
if(pathBeginI < endI)
{
pathEndI = urlStr.find(querySeparator, pathBeginI);
pathEndI = min(pathEndI, urlStr.find(fragmentSeparator, pathBeginI));
mPath = UrlDecode(urlStr.substr(pathBeginI, pathEndI - pathBeginI));
if(pathEndI == string::npos) return *this;
if(pathEndI >= endI) return *this;
}
size_t queryBeginI = urlStr.find(querySeparator, schemeEndI);
size_t queryEndI = urlStr.find(fragmentSeparator, schemeEndI);
if(queryBeginI != string::npos)
size_t queryBeginI = urlStr.find(querySeparator, hostBeginI);
size_t queryEndI = urlStr.find(fragmentSeparator, hostBeginI);
if(queryBeginI < endI)
{
string qStr = urlStr.substr(queryBeginI+1, queryEndI-queryBeginI-1);
@ -96,14 +98,16 @@ RsUrl& RsUrl::fromString(const std::string& urlStr)
kPos = vEndPos+1;
assPos = qStr.find(queryAssign, vEndPos);
}
while(assPos != string::npos);
while(assPos < endI);
if(queryEndI == string::npos) return *this;
if(queryEndI >= endI) return *this;
}
size_t fragmentBeginI = urlStr.find(fragmentSeparator, schemeEndI);
if(fragmentBeginI != string::npos)
size_t fragmentBeginI = urlStr.find(fragmentSeparator, hostBeginI);
if(fragmentBeginI < endI)
mFragment = UrlDecode(urlStr.substr(++fragmentBeginI));
return *this;
}
std::string RsUrl::toString() const

View File

@ -65,17 +65,17 @@ struct RsUrl
const std::string& ignoreChars = "");
static std::string UrlDecode(const std::string& str);
inline bool operator<(const RsUrl& rhs)
inline bool operator<(const RsUrl& rhs) const
{ return toString() < rhs.toString(); }
inline bool operator>(const RsUrl& rhs)
inline bool operator>(const RsUrl& rhs) const
{ return toString() > rhs.toString(); }
inline bool operator<=(const RsUrl& rhs)
inline bool operator<=(const RsUrl& rhs) const
{ return toString() <= rhs.toString(); }
inline bool operator>=(const RsUrl& rhs)
inline bool operator>=(const RsUrl& rhs) const
{ return toString() >= rhs.toString(); }
inline bool operator==(const RsUrl& rhs)
inline bool operator==(const RsUrl& rhs) const
{ return toString() == rhs.toString(); }
inline bool operator!=(const RsUrl& rhs)
inline bool operator!=(const RsUrl& rhs) const
{ return toString() != rhs.toString(); }
static const std::string schemeSeparator;

View File

@ -2067,6 +2067,10 @@ bool FriendList::importFriendlist(QString &fileName, bool &errorPeers, bool &err
rsPeers->setDynDNS(rsPeerDetails.id, rsPeerDetails.dyndns);
if (!rsPeerDetails.location.empty())
rsPeers->setLocation(rsPeerDetails.id, rsPeerDetails.location);
for(auto&& ipr : rsPeerDetails.ipAddressList)
rsPeers->addPeerLocator(
rsPeerDetails.id,
RsUrl(ipr.substr(0, ipr.find(' '))) );
}
} else if (!rsPeerDetails.gpg_id.isNull()) {
// only pgp id is avaiable

View File

@ -974,6 +974,10 @@ void ConnectFriendWizard::accept()
std::cerr << "ConnectFriendWizard::accept() : setting DynDNS." << std::endl;
rsPeers->setDynDNS(peerDetails.id, peerDetails.dyndns);
}
for(auto&& ipr : peerDetails.ipAddressList)
rsPeers->addPeerLocator(
peerDetails.id,
RsUrl(ipr.substr(0, ipr.find(' '))) );
}
}