mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 00:49:41 -05:00
Changed some mutex around p3ConnectMgr::mOwnState. Please review.
Made getIPAddressFromString thread safe, just in case. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3374 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
30e4509043
commit
fa9ea81ad7
@ -1801,6 +1801,7 @@ void p3ConnectMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
|||||||
|
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
bool isFriend = true;
|
bool isFriend = true;
|
||||||
|
bool newAddrs;
|
||||||
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
@ -2007,6 +2008,8 @@ void p3ConnectMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newAddrs = it->second.ipAddrs.updateAddrs(addrs);
|
||||||
} /****** STACK UNLOCK MUTEX *******/
|
} /****** STACK UNLOCK MUTEX *******/
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
@ -2019,7 +2022,6 @@ void p3ConnectMgr::peerStatus(std::string id, const pqiIpAddrSet &addrs,
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool newAddrs = it->second.ipAddrs.updateAddrs(addrs);
|
|
||||||
#ifndef P3CONNMGR_NO_AUTO_CONNECTION
|
#ifndef P3CONNMGR_NO_AUTO_CONNECTION
|
||||||
|
|
||||||
#ifndef P3CONNMGR_NO_TCP_CONNECTIONS
|
#ifndef P3CONNMGR_NO_TCP_CONNECTIONS
|
||||||
@ -2071,6 +2073,8 @@ 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 p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMode, uint32_t visState, time_t lastContact)
|
||||||
{
|
{
|
||||||
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
//set a new retry period, so the more frinds we have the less we launch conection attempts
|
//set a new retry period, so the more frinds we have the less we launch conection attempts
|
||||||
mRetryPeriod = MIN_RETRY_PERIOD + (mFriendList.size() * 2);
|
mRetryPeriod = MIN_RETRY_PERIOD + (mFriendList.size() * 2);
|
||||||
|
|
||||||
@ -2091,10 +2095,7 @@ bool p3ConnectMgr::addFriend(std::string id, std::string gpg_id, uint32_t netMod
|
|||||||
std::cerr << "p3ConnectMgr::addFriend() " << id << "; gpg_id : " << gpg_id << std::endl;
|
std::cerr << "p3ConnectMgr::addFriend() " << id << "; gpg_id : " << gpg_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
|
||||||
if (mFriendList.end() != mFriendList.find(id))
|
if (mFriendList.end() != mFriendList.find(id))
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
@ -2547,35 +2548,34 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
|
|||||||
|
|
||||||
bool p3ConnectMgr::setLocalAddress(std::string id, struct sockaddr_in addr)
|
bool p3ConnectMgr::setLocalAddress(std::string id, struct sockaddr_in addr)
|
||||||
{
|
{
|
||||||
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
if (mOwnState.currentlocaladdr.sin_addr.s_addr != addr.sin_addr.s_addr ||
|
|
||||||
mOwnState.currentlocaladdr.sin_port != addr.sin_port)
|
|
||||||
{
|
{
|
||||||
changed = true;
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
}
|
if (mOwnState.currentlocaladdr.sin_addr.s_addr != addr.sin_addr.s_addr ||
|
||||||
|
mOwnState.currentlocaladdr.sin_port != addr.sin_port)
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
mOwnState.currentlocaladdr = addr;
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
}
|
||||||
mOwnState.currentlocaladdr = addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
netReset();
|
netReset();
|
||||||
#ifdef CONN_DEBUG_RESET
|
#ifdef CONN_DEBUG_RESET
|
||||||
std::cerr << "p3ConnectMgr::setLocalAddress() Calling NetReset" << std::endl;
|
std::cerr << "p3ConnectMgr::setLocalAddress() Calling NetReset" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
/* check if it is a friend */
|
/* check if it is a friend */
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||||
{
|
{
|
||||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||||
@ -2607,10 +2607,8 @@ bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
|
|||||||
{
|
{
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
{
|
{
|
||||||
{
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
mOwnState.currentserveraddr = addr;
|
||||||
mOwnState.currentserveraddr = addr;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2649,11 +2647,11 @@ bool p3ConnectMgr::setDynDNS(std::string id, std::string dyndns)
|
|||||||
{
|
{
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
{
|
{
|
||||||
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
mOwnState.dyndns = dyndns;
|
mOwnState.dyndns = dyndns;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
/* check if it is a friend */
|
/* check if it is a friend */
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
@ -2720,22 +2718,30 @@ bool p3ConnectMgr::updateAddressList(const std::string& id, const pqiIpAddrSe
|
|||||||
|
|
||||||
bool p3ConnectMgr::setNetworkMode(std::string id, uint32_t netMode)
|
bool p3ConnectMgr::setNetworkMode(std::string id, uint32_t netMode)
|
||||||
{
|
{
|
||||||
if (id == AuthSSL::getAuthSSL()->OwnId())
|
if (id == AuthSSL::getAuthSSL()->OwnId())
|
||||||
{
|
{
|
||||||
uint32_t visState = mOwnState.visState;
|
uint32_t visState;
|
||||||
|
uint32_t oldNetMode;
|
||||||
|
{
|
||||||
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
visState = mOwnState.visState;
|
||||||
|
oldNetMode = mOwnState.netMode;
|
||||||
|
}
|
||||||
|
|
||||||
setOwnNetConfig(netMode, visState);
|
setOwnNetConfig(netMode, visState);
|
||||||
if ((netMode & RS_NET_MODE_ACTUAL) != (mOwnState.netMode & RS_NET_MODE_ACTUAL)) {
|
|
||||||
#ifdef CONN_DEBUG_RESET
|
if ((netMode & RS_NET_MODE_ACTUAL) != (oldNetMode & RS_NET_MODE_ACTUAL)) {
|
||||||
std::cerr << "p3ConnectMgr::setNetworkMode() Calling NetReset" << std::endl;
|
#ifdef CONN_DEBUG_RESET
|
||||||
#endif
|
std::cerr << "p3ConnectMgr::setNetworkMode() Calling NetReset" << std::endl;
|
||||||
netReset();
|
#endif
|
||||||
}
|
netReset();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
/* check if it is a friend */
|
/* check if it is a friend */
|
||||||
std::map<std::string, peerConnectState>::iterator it;
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||||
{
|
{
|
||||||
if (mOthersList.end() == (it = mOthersList.find(id)))
|
if (mOthersList.end() == (it = mOthersList.find(id)))
|
||||||
|
@ -132,6 +132,9 @@ bool isExternalNet(const struct in_addr *addr)
|
|||||||
bool getIPAddressFromString (const char *addr_str, struct in_addr *addr)
|
bool getIPAddressFromString (const char *addr_str, struct in_addr *addr)
|
||||||
{
|
{
|
||||||
if (addr_str && addr) {
|
if (addr_str && addr) {
|
||||||
|
static RsMutex mtx;
|
||||||
|
RsStackMutex stack(mtx);
|
||||||
|
|
||||||
hostent *pHost = gethostbyname (addr_str);
|
hostent *pHost = gethostbyname (addr_str);
|
||||||
if (pHost) {
|
if (pHost) {
|
||||||
addr->s_addr = *(unsigned long*) (pHost->h_addr);
|
addr->s_addr = *(unsigned long*) (pHost->h_addr);
|
||||||
|
Loading…
Reference in New Issue
Block a user