Ported branch commits:

3148: 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

	  libretroshare/src/pqi/authssl.cc
	  libretroshare/src/pqi/p3connmgr.cc
	  libretroshare/src/pqi/p3connmgr.h
	  libretroshare/src/services/p3disc.cc

3149: removed uninitialized memory read
      
	  libretroshare/src/pqi/authgpg.cc

3151: corrected missed update of peer info when connected. Disabled setting
	  peer connexion IP from p3disc info (does not make sense, and leads to
	  errors)

      libretroshare/src/services/p3disc.cc



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3152 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-06-16 20:18:46 +00:00
parent e9fabc34e9
commit 347c80fb1e
5 changed files with 54 additions and 31 deletions

View File

@ -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++)
{

View File

@ -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 {

View File

@ -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<IpAddressTimed>& IpAddressTimedList)
bool p3ConnectMgr::updateAddressList(const std::string& id, const std::list<IpAddressTimed>& 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::list<IpAd
/* check if it is our own ip */
if (id == getOwnId())
{
ownState.updateIpAddressList(IpAddressTimedList);
ownState.updateIpAddressList(IpAddressTimedList,merge);
//if we have no ext address from upnp or extAdrFinder, we will use this list for ext ip detection
//useless, already done in network consistency check
@ -2852,7 +2853,7 @@ bool p3ConnectMgr::setAddressList(const std::string& id, const std::list<IpAd
}
/* "it" points to peer */
it->second.updateIpAddressList(IpAddressTimedList);
it->second.updateIpAddressList(IpAddressTimedList,merge);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
@ -3229,7 +3230,7 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> 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<IpAddressTimed> peerConnectState::getIpAddressList()
return ipAddressList;
}
void peerConnectState::updateIpAddressList(const std::list<IpAddressTimed>& ipTimedList) //purge old addresses to keep a small list
void peerConnectState::updateIpAddressList(const std::list<IpAddressTimed>& ipTimedList,bool merge) //purge old addresses to keep a small list
{
std::list<IpAddressTimed>::const_iterator ipListIt;
if(!merge)
ipAddressList.clear() ;
for (ipListIt = ipTimedList.begin(); ipListIt!=(ipTimedList.end()); ++ipListIt)
updateIpAddressList(*ipListIt);
std::list<IpAddressTimed>::const_iterator ipListIt;
for (ipListIt = ipTimedList.begin(); ipListIt!=(ipTimedList.end()); ++ipListIt)
updateIpAddressList(*ipListIt);
}
void peerConnectState::updateIpAddressList(const IpAddressTimed& ipTimed)

View File

@ -144,8 +144,13 @@ class peerConnectState
//used to store friends ip lists
void sortIpAddressListBySeenTime(); //Sort the ip list ordering by seen time
std::list<IpAddressTimed> 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<IpAddressTimed>& ipTimedList,bool merge=true);
void updateIpAddressList(const IpAddressTimed& ipTimed);
void updateIpAddressList(const std::list<IpAddressTimed>& 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<IpAddressTimed>& IpAddressTimedList);
bool updateAddressList(const std::string& id, const std::list<IpAddressTimed>& IpAddressTimedList,bool merge = true);
bool setNetworkMode(std::string id, uint32_t netMode);
bool setVisState(std::string id, uint32_t visState);

View File

@ -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