From aa15f95907f4b6e5518bd90f368a5c62e0515e7d Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 16 Jun 2010 18:58:45 +0000 Subject: [PATCH] modified the update system for address lists, so that the list is totally replaced (and not merged) when it comes from the peer itself. This helps cleaning wrong addresses git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@3148 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/authssl.cc | 2 +- libretroshare/src/pqi/p3connmgr.cc | 48 +++++++++++++++------------- libretroshare/src/pqi/p3connmgr.h | 9 ++++-- libretroshare/src/services/p3disc.cc | 10 +++++- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 87cf41f0d..afdb96cde 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 3624afda9..264b2e27b 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -308,7 +308,7 @@ void p3ConnectMgr::netReset() #ifdef CONN_DEBUG 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; @@ -577,7 +577,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(); } @@ -658,7 +658,7 @@ void p3ConnectMgr::netDhtInit() #endif connMtx.lock(); /* LOCK MUTEX */ - uint32_t vs = ownState.visState; + //uint32_t vs = ownState.visState; connMtx.unlock(); /* UNLOCK MUTEX */ @@ -707,7 +707,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() "; @@ -2096,21 +2096,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; @@ -2146,7 +2147,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; @@ -2656,7 +2657,7 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr) 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; @@ -2667,7 +2668,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; @@ -3069,7 +3070,7 @@ bool p3ConnectMgr::loadList(std::list load) } setLocalAddress(pitem->pid, pitem->currentlocaladdr); setExtAddress(pitem->pid, pitem->currentremoteaddr); - setAddressList(pitem->pid, pitem->ipAddressList); + updateAddressList(pitem->pid, pitem->ipAddressList,false); } else if (sitem) { @@ -3447,12 +3448,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 c38a78c6e..cbd8953aa 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); @@ -225,7 +230,7 @@ bool getNetStatusExtraAddressCheckOk(); 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 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 79546df31..7405adf25 100644 --- a/libretroshare/src/services/p3disc.cc +++ b/libretroshare/src/services/p3disc.cc @@ -552,6 +552,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 @@ -578,6 +580,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item) // The info from the peer itself is ultimately trustable, so we can override some info, // such as: // - local and global addresses + // - address list // if (item->PeerId() == pitem->pid) { @@ -591,6 +594,11 @@ void p3disc::recvPeerDetails(RsDiscReply *item) 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 @@ -602,7 +610,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item) #endif // allways update address list, except if it's ours - mConnMgr->setAddressList(pitem->pid, pitem->ipAddressList); + mConnMgr->updateAddressList(pitem->pid, pitem->ipAddressList,merge); } #ifdef P3DISC_DEBUG else