From e77064eaf19d26ae01c1d319017c35bf49ac5364 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 14 Nov 2009 20:20:33 +0000 Subject: [PATCH] removed deadlock by replacing lock() by trylock(). As a result sometimes, authGPG::getDetails() may return false. As soon as it is used by the GUI only, it shoul dbe ok. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1823 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/authgpg.cc | 64 ++++++++++++++++---------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index cc559ea0f..a05fb2d74 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -1331,20 +1331,15 @@ void GPGAuthMgr::addTrustingPeer(std::string) } /**** These Two are common */ -std::string GPGAuthMgr::getName(std::string id) +std::string GPGAuthMgr::getPGPName(std::string id) { - std::string name = AuthSSL::getName(id); - if (name != "") - { - RsStackMutex stack(pgpMtx); /******* LOCKED ******/ + RsStackMutex stack(pgpMtx); /******* LOCKED ******/ - certmap::iterator it; - if (mKeyList.end() != (it = mKeyList.find(id))) - { - return it->second.user.name; - } - } - return name; + certmap::iterator it; + if (mKeyList.end() != (it = mKeyList.find(id))) + return it->second.user.name; + + return std::string(); } bool GPGAuthMgr::getDetails(std::string id, pqiAuthDetails &details) @@ -1360,35 +1355,42 @@ bool GPGAuthMgr::getDetails(std::string id, pqiAuthDetails &details) if (AuthSSL::getDetails(id, details)) { - RsStackMutex stack(pgpMtx); /******* LOCKED ******/ - - certmap::iterator it; - if (mKeyList.end() != (it = mKeyList.find(details.issuer))) + //RsStackMutex stack(pgpMtx); /******* LOCKED ******/ + if(pgpMtx.trylock()) { - /* what do we want from the gpg mgr */ - details.location = details.location; - details.name = it->second.user.name; - details.email = it->second.user.email; + certmap::iterator it; + if (mKeyList.end() != (it = mKeyList.find(details.issuer))) + { + /* what do we want from the gpg mgr */ + details.location = details.location; + details.name = it->second.user.name; + details.email = it->second.user.email; - //details = it->second.user; + //details = it->second.user; + } + pgpMtx.unlock() ; return true; } - return true; + return false ; } else { - RsStackMutex stack(pgpMtx); /******* LOCKED ******/ - - /* if we cannot find a ssl cert - might be a pgp cert */ - certmap::iterator it; - if (mKeyList.end() != (it = mKeyList.find(id))) + //RsStackMutex stack(pgpMtx); /******* LOCKED ******/ + if(pgpMtx.trylock()) { - /* what do we want from the gpg mgr */ - details = it->second.user; - return true; + /* if we cannot find a ssl cert - might be a pgp cert */ + certmap::iterator it; + if (mKeyList.end() != (it = mKeyList.find(id))) + { + /* what do we want from the gpg mgr */ + details = it->second.user; + pgpMtx.unlock() ; + return true; + } + pgpMtx.unlock() ; } + return false; } - return false; }