corrected a cross lock between p3ConnectMgr::connectResult() ->...-> UdpBitDht::removeFindNode() and bdNodeManager::iteration() ->...-> p3ConnectMgr::retryConnectUDP(), by making calls to netAssisFriend() off-mutex.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3874 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-11-27 20:00:26 +00:00
parent 78dea3c630
commit 4f80b2557e

View File

@ -73,6 +73,9 @@ const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 4;
* #define CONN_DEBUG_TICK 1
***/
#define CONN_DEBUG 1
#define CONN_DEBUG_RESET 1
#define CONN_DEBUG_TICK 1
#define CONN_DEBUG_RESET 1
/****
@ -1736,6 +1739,9 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
*/
bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address)
{
bool should_netAssistFriend_false = false ;
bool should_netAssistFriend_true = false ;
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
@ -1820,11 +1826,12 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, s
/* remove other attempts */
it->second.inConnAttempt = false;
it->second.connAddrs.clear();
netAssistFriend(id, false);
should_netAssistFriend_false = true ;
mStatusChanged = true;
return true;
}
else
{
it->second.inConnAttempt = false;
#ifdef CONN_DEBUG
@ -1841,16 +1848,20 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags, s
it->second.lastcontact = time(NULL); /* time of disconnect */
netAssistFriend(id, true);
should_netAssistFriend_true = true ;
}
if (it->second.connAddrs.size() < 1)
if (it->second.connAddrs.size() >= 1)
{
return true;
}
it->second.actions |= RS_PEER_CONNECT_REQ;
mStatusChanged = true;
}
}
}
if(should_netAssistFriend_true)
netAssistFriend(id,true) ;
if(should_netAssistFriend_false)
netAssistFriend(id,false) ;
return true;
}
@ -2151,6 +2162,9 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
/*******************************************************************/
bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMode, uint32_t visState, time_t lastContact)
{
bool should_netAssistFriend_true = false ;
bool should_netAssistFriend_false = false ;
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
@ -2224,18 +2238,17 @@ bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMod
if (it->second.visState & RS_VIS_STATE_NODHT)
{
/* hidden from DHT world */
netAssistFriend(id, false);
should_netAssistFriend_false = true ;
}
else
{
netAssistFriend(id, true);
should_netAssistFriend_true = true ;
}
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
else
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::addFriend() Creating New Entry" << std::endl;
#endif
@ -2260,9 +2273,15 @@ bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMod
mStatusChanged = true;
/* expect it to be a standard DHT */
netAssistFriend(id, true);
should_netAssistFriend_true = true ;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
}
if(should_netAssistFriend_true)
netAssistFriend(id,true) ;
if(should_netAssistFriend_false)
netAssistFriend(id,false) ;
return true;
}
@ -3122,7 +3141,6 @@ bool p3ConnectMgr::setLocation(std::string id, std::string location)
bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
{
if (id == AuthSSL::getAuthSSL()->OwnId())
{
uint32_t netMode;
@ -3134,11 +3152,13 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
return true;
}
bool dht_state ;
bool isFriend = false;
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */
std::map<std::string, peerConnectState>::iterator it;
bool isFriend = false;
if (mFriendList.end() == (it = mFriendList.find(id)))
{
if (mOthersList.end() == (it = mOthersList.find(id)))
@ -3153,10 +3173,12 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
/* "it" points to peer */
it->second.visState = visState;
dht_state = it->second.visState & RS_VIS_STATE_NODHT ;
}
if(isFriend)
{
/* toggle DHT state */
if (it->second.visState & RS_VIS_STATE_NODHT)
if(dht_state)
{
/* hidden from DHT world */
netAssistFriend(id, false);
@ -3859,17 +3881,25 @@ bool p3ConnectMgr::netAssistConnectShutdown()
bool p3ConnectMgr::netAssistFriend(std::string id, bool on)
{
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
std::list<pqiNetAssistConnect*> toFind ;
std::list<pqiNetAssistConnect*> toDrop ;
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
for(it = mDhts.begin(); it != mDhts.end(); it++)
{
if (on)
{
(it->second)->findPeer(id);
}
toFind.push_back(it->second) ;
else
{
(it->second)->dropPeer(id);
toDrop.push_back(it->second) ;
}
}
for(std::list<pqiNetAssistConnect*>::const_iterator it(toFind.begin());it!=toFind.end();++it)
(*it)->findPeer(id) ;
for(std::list<pqiNetAssistConnect*>::const_iterator it(toDrop.begin());it!=toDrop.end();++it)
(*it)->dropPeer(id) ;
return true;
}