From eb7a52a2a762ae7f516fa7f7509957c3a871f19e Mon Sep 17 00:00:00 2001 From: electron128 Date: Thu, 4 Jun 2015 13:25:19 +0000 Subject: [PATCH] fixed bug reporting wrong IP for connection (patch from Cyril) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8367 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/serialiser/rsdiscovery2items.cc | 8 +++++++- libretroshare/src/serialiser/rsdiscovery2items.h | 11 +++++++---- libretroshare/src/services/p3discovery2.cc | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/libretroshare/src/serialiser/rsdiscovery2items.cc b/libretroshare/src/serialiser/rsdiscovery2items.cc index 92c159ff2..611a7e80a 100644 --- a/libretroshare/src/serialiser/rsdiscovery2items.cc +++ b/libretroshare/src/serialiser/rsdiscovery2items.cc @@ -682,6 +682,8 @@ uint32_t RsDiscSerialiser::sizeContact(RsDiscContactItem *item) s += item->localAddrV4.TlvSize(); /* localaddr */ s += item->extAddrV4.TlvSize(); /* remoteaddr */ + s += item->currentConnectAddress.TlvSize() ; + s += item->localAddrV6.TlvSize(); /* localaddr */ s += item->extAddrV6.TlvSize(); /* remoteaddr */ @@ -758,7 +760,9 @@ bool RsDiscSerialiser::serialiseContact(RsDiscContactItem *item, void *data, ok &= item->localAddrV6.SetTlv(data, tlvsize, &offset); ok &= item->extAddrV6.SetTlv(data, tlvsize, &offset); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); + ok &= item->currentConnectAddress.SetTlv(data, tlvsize, &offset); + + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); ok &= item->localAddrList.SetTlv(data, tlvsize, &offset); ok &= item->extAddrList.SetTlv(data, tlvsize, &offset); @@ -860,6 +864,8 @@ RsDiscContactItem *RsDiscSerialiser::deserialiseContact(void *data, uint32_t *pk ok &= item->localAddrV6.GetTlv(data, rssize, &offset); ok &= item->extAddrV6.GetTlv(data, rssize, &offset); + ok &= item->currentConnectAddress.GetTlv(data, rssize, &offset); + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DYNDNS, item->dyndns); ok &= item->localAddrList.GetTlv(data, rssize, &offset); ok &= item->extAddrList.GetTlv(data, rssize, &offset); diff --git a/libretroshare/src/serialiser/rsdiscovery2items.h b/libretroshare/src/serialiser/rsdiscovery2items.h index f20928551..dad0d0fb5 100644 --- a/libretroshare/src/serialiser/rsdiscovery2items.h +++ b/libretroshare/src/serialiser/rsdiscovery2items.h @@ -33,10 +33,11 @@ #include "serialiser/rstlvaddrs.h" #include "serialiser/rsserviceids.h" -const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01; -const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02; -const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT = 0x03; -const uint8_t RS_PKT_SUBTYPE_DISC_SERVICES = 0x04; +const uint8_t RS_PKT_SUBTYPE_DISC_PGP_LIST = 0x01; +const uint8_t RS_PKT_SUBTYPE_DISC_PGP_CERT = 0x02; +const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT_deprecated = 0x03; +const uint8_t RS_PKT_SUBTYPE_DISC_SERVICES = 0x04; +const uint8_t RS_PKT_SUBTYPE_DISC_CONTACT = 0x05; class RsDiscItem: public RsItem { @@ -125,6 +126,8 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent = 0); // STANDARD. + RsTlvIpAddress currentConnectAddress ; // used to check! + RsTlvIpAddress localAddrV4; /* Mandatory */ RsTlvIpAddress extAddrV4; /* Mandatory */ diff --git a/libretroshare/src/services/p3discovery2.cc b/libretroshare/src/services/p3discovery2.cc index e949527e8..72de5a6e3 100644 --- a/libretroshare/src/services/p3discovery2.cc +++ b/libretroshare/src/services/p3discovery2.cc @@ -811,12 +811,21 @@ void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toI if (sit->second.mDiscStatus != RS_VS_DISC_OFF) { peerState detail; - if (mPeerMgr->getFriendNetStatus(sit->first, detail)) + peerConnectState detail2; + + if (mPeerMgr->getFriendNetStatus(sit->first, detail)) { RsDiscContactItem *pkt = new RsDiscContactItem(); populateContactInfo(detail, pkt); pkt->PeerId(toId); + // send to each peer its own connection address. + + if(sit->first == toId && mLinkMgr->getFriendNetStatus(sit->first,detail2)) + pkt->currentConnectAddress.addr = detail2.connectaddr; + else + sockaddr_storage_clear(pkt->currentConnectAddress.addr) ; + #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::sendContactInfo_locked() Sending"; std::cerr << std::endl; @@ -850,8 +859,8 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt if (item->sslId == rsPeers->getOwnId()) { - if(sockaddr_storage_isExternalNet(item->extAddrV4.addr)) - mPeerMgr->addCandidateForOwnExternalAddress(item->PeerId(), item->extAddrV4.addr) ; + if(sockaddr_storage_isExternalNet(item->currentConnectAddress.addr)) + mPeerMgr->addCandidateForOwnExternalAddress(item->PeerId(), item->currentConnectAddress.addr) ; #ifdef P3DISC_DEBUG std::cerr << "p3discovery2::processContactInfo(" << fromId << ") PGPID: "; std::cerr << item->pgpId << " Ignoring Info on self";