* modified code to add PeerId to stunner->exclusiveMode.

* fixed missing releaseExclusiveMode.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4490 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-27 13:56:35 +00:00
parent 461378a3de
commit f67da9f8ce

View File

@ -559,7 +559,12 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
} }
/* if we get here, we are an endpoint (peer specified in peerId) */ /* if we get here, we are an endpoint (peer specified in peerId) */
/* translate id into string for exclusive mode */
std::ostringstream idstr;
bdStdPrintNodeId(idstr, &(peerId.id));
std::string pid = idstr.str();
switch(cbtype) switch(cbtype)
{ {
case BITDHT_CONNECT_CB_AUTH: case BITDHT_CONNECT_CB_AUTH:
@ -701,7 +706,8 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << "dhtConnectionCallback: Attempting to Grab ExclusiveLock of UdpStunner"; std::cerr << "dhtConnectionCallback: Attempting to Grab ExclusiveLock of UdpStunner";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
int stun_age = mProxyStunner->grabExclusiveMode();
int stun_age = mProxyStunner->grabExclusiveMode(pid);
if (stun_age > 0) if (stun_age > 0)
{ {
int delay = 0; int delay = 0;
@ -735,7 +741,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << "PeerAction: Connect Proxy: ERROR Cannot find PeerStatus"; std::cerr << "PeerAction: Connect Proxy: ERROR Cannot find PeerStatus";
std::cerr << std::endl; std::cerr << std::endl;
connectionAllowed = BITDHT_CONNECT_ERROR_TEMPUNAVAIL; connectionAllowed = BITDHT_CONNECT_ERROR_TEMPUNAVAIL;
mProxyStunner->releaseExclusiveMode(false); mProxyStunner->releaseExclusiveMode(pid,false);
} }
} }
else else
@ -1075,6 +1081,12 @@ int p3BitDht::doActions()
bool connectionReqFailed = false; bool connectionReqFailed = false;
bool grabbedExclusivePort = false; bool grabbedExclusivePort = false;
/* translate id into string for exclusive mode */
std::ostringstream idstr;
bdStdPrintNodeId(idstr, &(action.mDestId.id));
std::string pid = idstr.str();
// Parameters that will be used for the Connect Request. // Parameters that will be used for the Connect Request.
struct sockaddr_in connAddr; // We zero this address. (DHT Layer handles most cases) struct sockaddr_in connAddr; // We zero this address. (DHT Layer handles most cases)
sockaddr_clear(&connAddr); sockaddr_clear(&connAddr);
@ -1143,6 +1155,8 @@ int p3BitDht::doActions()
stunner = mDhtStunner; stunner = mDhtStunner;
} }
if ((connectOk) && (stunner) && (stunner->externalAddr(extaddr, extStable))) if ((connectOk) && (stunner) && (stunner->externalAddr(extaddr, extStable)))
{ {
if (extStable) if (extStable)
@ -1157,7 +1171,7 @@ int p3BitDht::doActions()
/* check if we require exclusive use of the proxy port */ /* check if we require exclusive use of the proxy port */
if (exclusivePort) if (exclusivePort)
{ {
int stun_age = mProxyStunner->grabExclusiveMode(); int stun_age = mProxyStunner->grabExclusiveMode(pid);
if (stun_age > 0) if (stun_age > 0)
{ {
int delay = 0; int delay = 0;
@ -1285,10 +1299,10 @@ int p3BitDht::doActions()
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
if (grabbedExclusivePort) //if (grabbedExclusivePort)
{ //{
mProxyStunner->releaseExclusiveMode(false); // mProxyStunner->releaseExclusiveMode(pid,false);
} //}
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND);
@ -1300,6 +1314,25 @@ int p3BitDht::doActions()
dpd->mPeerReqState = RSDHT_PEERREQ_STOPPED; dpd->mPeerReqState = RSDHT_PEERREQ_STOPPED;
dpd->mPeerReqMode = action.mMode; dpd->mPeerReqMode = action.mMode;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
if (grabbedExclusivePort)
{
ReleaseProxyExclusiveMode_locked(dpd, false);
}
}
else
{
std::cerr << "PeerAction: ERROR Connection Attempt to: ";
bdStdPrintId(std::cerr, &(action.mDestId));
std::cerr << " has no Internal Dht Peer!";
std::cerr << std::endl;
if (grabbedExclusivePort)
{
std::cerr << "PeerAction: ERROR ERROR, we grabd Exclusive Port to do this, trying emergency release";
std::cerr << std::endl;
mProxyStunner->releaseExclusiveMode(pid,false);
}
} }
} }
@ -2176,7 +2209,8 @@ void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::monitorConnections() Request Active (Paused)... Killing for next Attempt"; std::cerr << "p3BitDht::UdpConnectionFailed_locked() ";
std::cerr << "Request Active (Paused)... Killing for next Attempt";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -2195,7 +2229,8 @@ void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
// only an error if we initiated the connection. // only an error if we initiated the connection.
else if (dpd->mPeerConnectPoint == BD_PROXY_CONNECTION_START_POINT) else if (dpd->mPeerConnectPoint == BD_PROXY_CONNECTION_START_POINT)
{ {
std::cerr << "p3BitDht::monitorConnections() ERROR Request not active, can't stop"; std::cerr << "p3BitDht::UdpConnectionFailed_locked() ";
std::cerr << "ERROR Request not active, can't stop";
std::cerr << std::endl; std::cerr << std::endl;
} }
@ -2207,22 +2242,28 @@ void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrChgLikely) void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrChgLikely)
{ {
#ifdef DEBUG_BITDHT_COMMON #ifdef DEBUG_BITDHT_COMMON
#endif
std::cerr << "p3BitDht::ReleaseProxyExclusiveMode_locked()"; std::cerr << "p3BitDht::ReleaseProxyExclusiveMode_locked()";
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id)); bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
std::cerr << std::endl; std::cerr << std::endl;
#endif
/* translate id into string for exclusive mode */
std::ostringstream idstr;
bdStdPrintNodeId(idstr, &(dpd->mDhtId.id));
std::string pid = idstr.str();
if (dpd->mExclusiveProxyLock) if (dpd->mExclusiveProxyLock)
{ {
if (mProxyStunner->releaseExclusiveMode(addrChgLikely)) if (mProxyStunner->releaseExclusiveMode(pid, addrChgLikely))
{ {
dpd->mExclusiveProxyLock = false; dpd->mExclusiveProxyLock = false;
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
#endif
std::cerr << "p3BitDht::ReleaseProxyExclusiveMode_locked() Lock released by Connection to peer: "; std::cerr << "p3BitDht::ReleaseProxyExclusiveMode_locked() Lock released by Connection to peer: ";
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id)); bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
std::cerr << std::endl; std::cerr << std::endl;
#endif
} }
else else
{ {
@ -2237,9 +2278,9 @@ void p3BitDht::ReleaseProxyExclusiveMode_locked(DhtPeerDetails *dpd, bool addrCh
else else
{ {
#ifdef DEBUG_BITDHT_COMMON #ifdef DEBUG_BITDHT_COMMON
#endif
std::cerr << "p3BitDht::ReleaseProxyExclusiveMode_locked() Don't Have a Lock"; std::cerr << "p3BitDht::ReleaseProxyExclusiveMode_locked() Don't Have a Lock";
std::cerr << std::endl; std::cerr << std::endl;
#endif
} }
} }