diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index b00918569..a3a8695f6 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -1277,6 +1277,7 @@ bool AuthGPG::LoadCertificateFromString(std::string str, std::string &gpg_id) } //retrieve the id of the key certmap::iterator it; + gpg_id = "" ; RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::READ_LOCK); /******* LOCKED ******/ for(it = mKeyList.begin(); it != mKeyList.end(); it++) { diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index ac6ab94d3..85142522f 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -2075,7 +2075,7 @@ int AuthSSL::VerifyX509Callback(int preverify_ok, X509_STORE_CTX *ctx) if (mConnMgr->getFriendNetStatus(peer_id_in_context, detail)) { //transfer ips only if the two peers got the same gpg key if (detail.gpg_id == getX509CNString(X509_STORE_CTX_get_current_cert(ctx)->cert_info->issuer)) { - mConnMgr->setAddressList(certId, detail.getIpAddressList()); + mConnMgr->updateAddressList(certId, detail.getIpAddressList()); } } } else { diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index f61040f6a..08b700537 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -317,7 +317,7 @@ void p3ConnectMgr::netReset() #ifdef CONN_DEBUG_RESET std::cerr << "p3ConnectMgr time since last reset : " << delta << std::endl; #endif - if (delta < MIN_TIME_BETWEEN_NET_RESET) { + if (delta < (time_t)MIN_TIME_BETWEEN_NET_RESET) { { RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/ mNetStatus = RS_NET_NEED_RESET; @@ -594,7 +594,7 @@ void p3ConnectMgr::netTick() connMtx.unlock(); /* UNLOCK MUTEX */ /* start tcp network - if necessary */ //TODO : implement stop listeners in net reset - if (!mListenerActive && netStatus != RS_NET_NEED_RESET && (time(NULL) - mNetInitTS) > (MIN_TIME_BETWEEN_NET_RESET + 2)) {//start connection 2 second after the possible next one net reset + if (!mListenerActive && netStatus != RS_NET_NEED_RESET && (time(NULL) - mNetInitTS) > (time_t)(MIN_TIME_BETWEEN_NET_RESET + 2)) {//start connection 2 second after the possible next one net reset startListeners(); } @@ -678,7 +678,7 @@ void p3ConnectMgr::netDhtInit() #endif connMtx.lock(); /* LOCK MUTEX */ - uint32_t vs = ownState.visState; + //uint32_t vs = ownState.visState; connMtx.unlock(); /* UNLOCK MUTEX */ @@ -727,7 +727,7 @@ void p3ConnectMgr::netUpnpCheck() struct sockaddr_in extAddr; int upnpState = netAssistFirewallActive(); - if ((upnpState == 0) && (delta > MAX_UPNP_INIT)) + if ((upnpState == 0) && (delta > (time_t)MAX_UPNP_INIT)) { #ifdef CONN_DEBUG_TICK std::cerr << "p3ConnectMgr::netUpnpCheck() "; @@ -2152,21 +2152,22 @@ bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMod return true; } - //Authentication is now tested at connection time, we don't store the ssl cert anymore - if (!AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getAuthGPG()->getGPGOwnId()) - { + //Authentication is now tested at connection time, we don't store the ssl cert anymore + // + if (!AuthGPG::getAuthGPG()->isGPGAccepted(gpg_id) && gpg_id != AuthGPG::getAuthGPG()->getGPGOwnId()) + { #ifdef CONN_DEBUG - std::cerr << "p3ConnectMgr::addFriend() gpg is not accepted" << std::endl; + std::cerr << "p3ConnectMgr::addFriend() gpg is not accepted" << std::endl; #endif - /* no auth */ - return false; - } + /* no auth */ + return false; + } /* check if it is in others */ // if (mOthersList.end() != (it = mOthersList.find(id))) - if (false) - { + if (false) + { /* (2) in mOthersList -> move over */ #ifdef CONN_DEBUG std::cerr << "p3ConnectMgr::addFriend() Move from Others" << std::endl; @@ -2202,7 +2203,7 @@ bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMod IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ return true; - } + } #ifdef CONN_DEBUG std::cerr << "p3ConnectMgr::addFriend() Creating New Entry" << std::endl; @@ -2807,7 +2808,7 @@ bool p3ConnectMgr::setDynDNS(std::string id, std::string dyndns) return true; } -bool p3ConnectMgr::setAddressList(const std::string& id, const std::list& IpAddressTimedList) +bool p3ConnectMgr::updateAddressList(const std::string& id, const std::list& IpAddressTimedList,bool merge) { #ifdef CONN_DEBUG std::cerr << "p3ConnectMgr::setAddressList() called for id : " << id << std::endl; @@ -2818,7 +2819,7 @@ bool p3ConnectMgr::setAddressList(const std::string& id, const std::listsecond.updateIpAddressList(IpAddressTimedList); + it->second.updateIpAddressList(IpAddressTimedList,merge); IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ return true; @@ -3229,7 +3230,7 @@ bool p3ConnectMgr::loadList(std::list load) setLocalAddress(pitem->pid, pitem->currentlocaladdr); setExtAddress(pitem->pid, pitem->currentremoteaddr); setDynDNS (pitem->pid, pitem->dyndns); - setAddressList(pitem->pid, pitem->ipAddressList); + updateAddressList(pitem->pid, pitem->ipAddressList,false); } else if (sitem) { @@ -3607,12 +3608,15 @@ std::list peerConnectState::getIpAddressList() return ipAddressList; } -void peerConnectState::updateIpAddressList(const std::list& ipTimedList) //purge old addresses to keep a small list +void peerConnectState::updateIpAddressList(const std::list& ipTimedList,bool merge) //purge old addresses to keep a small list { - std::list::const_iterator ipListIt; + if(!merge) + ipAddressList.clear() ; - for (ipListIt = ipTimedList.begin(); ipListIt!=(ipTimedList.end()); ++ipListIt) - updateIpAddressList(*ipListIt); + std::list::const_iterator ipListIt; + + for (ipListIt = ipTimedList.begin(); ipListIt!=(ipTimedList.end()); ++ipListIt) + updateIpAddressList(*ipListIt); } void peerConnectState::updateIpAddressList(const IpAddressTimed& ipTimed) diff --git a/libretroshare/src/pqi/p3connmgr.h b/libretroshare/src/pqi/p3connmgr.h index 76c4ba074..e22beff9f 100644 --- a/libretroshare/src/pqi/p3connmgr.h +++ b/libretroshare/src/pqi/p3connmgr.h @@ -144,8 +144,13 @@ class peerConnectState //used to store friends ip lists void sortIpAddressListBySeenTime(); //Sort the ip list ordering by seen time std::list getIpAddressList(); //return the sorted ant purged list. + + // The function that takes a list, can either merge the list into the + // existing list (default behavior), or only set the list to the new data, + // which might be used if the info is from an authoritative source. + // + void updateIpAddressList(const std::list& ipTimedList,bool merge=true); void updateIpAddressList(const IpAddressTimed& ipTimed); - void updateIpAddressList(const std::list& ipTimedList); void printIpAddressList(); static bool is_same_address (const IpAddressTimed& first, const IpAddressTimed& second); @@ -227,7 +232,7 @@ void setOwnNetConfig(uint32_t netMode, uint32_t visState); bool setLocalAddress(std::string id, struct sockaddr_in addr); bool setExtAddress(std::string id, struct sockaddr_in addr); bool setDynDNS(std::string id, std::string dyndns); -bool setAddressList(const std::string& id, const std::list& IpAddressTimedList); +bool updateAddressList(const std::string& id, const std::list& IpAddressTimedList,bool merge = true); bool setNetworkMode(std::string id, uint32_t netMode); bool setVisState(std::string id, uint32_t visState); diff --git a/libretroshare/src/services/p3disc.cc b/libretroshare/src/services/p3disc.cc index 6f85c48b0..72d875de9 100644 --- a/libretroshare/src/services/p3disc.cc +++ b/libretroshare/src/services/p3disc.cc @@ -556,6 +556,8 @@ void p3disc::recvPeerDetails(RsDiscReply *item) // if(AuthGPG::getAuthGPG()->isGPGAccepted(pitem->gpg_id) || pitem->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId()) { + bool merge = true ; + // Add with no disc by default. If friend already exists, it will do nothing // #ifdef P3DISC_DEBUG @@ -566,7 +568,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item) // Update if know this peer, and if it's not already connected. // - if(rsPeers->getPeerDetails(pitem->pid, storedDetails) && !(storedDetails.state & RS_PEER_CONNECTED)) + if(rsPeers->getPeerDetails(pitem->pid, storedDetails)) { #ifdef P3DISC_DEBUG std::cerr << "Friend is not connected -> updating info" << std::endl; @@ -576,12 +578,18 @@ void p3disc::recvPeerDetails(RsDiscReply *item) // Update if it's fresh info or if it's from the peer itself // their info is fresher than ours, update ours // - mConnMgr->setNetworkMode(pitem->pid, pitem->netMode); - mConnMgr->setLocation(pitem->pid, pitem->location); + if(!(storedDetails.state & RS_PEER_CONNECTED)) + { + mConnMgr->setNetworkMode(pitem->pid, pitem->netMode); + mConnMgr->setLocation(pitem->pid, pitem->location); + } // The info from the peer itself is ultimately trustable, so we can override some info, // such as: // - local and global addresses + // - address list + // + // If we enter here, we're necessarily connected to this peer. // if (item->PeerId() == pitem->pid) { @@ -591,10 +599,15 @@ void p3disc::recvPeerDetails(RsDiscReply *item) std::cerr << " -> current remote addr = " << pitem->currentremoteaddr << std::endl; std::cerr << " -> clearing NODISC flag " << std::endl; #endif - mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr); - mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr); + //mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr); + //mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr); pitem->visState &= ~RS_VIS_STATE_NODISC ; mConnMgr->setVisState(pitem->pid, pitem->visState); + + // When the peer sends his own list of IPs, the info replaces the existing info, because the + // peer is the primary source of his own IPs. + // + merge = false ; } } #ifdef P3DISC_DEBUG @@ -608,7 +621,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item) if (pitem->dyndns != "") mConnMgr->setDynDNS(pitem->pid, pitem->dyndns); - mConnMgr->setAddressList(pitem->pid, pitem->ipAddressList); + mConnMgr->updateAddressList(pitem->pid, pitem->ipAddressList,merge); } #ifdef P3DISC_DEBUG else