More Udp Connection Bugfixes:

* connected Dht ConnectCallback()
 * added missing break statement in peernet logic (directattempt).
 * added state update if ConnectionRequest is rejected by DHT (normally because MODE UNAVAILABLE).
 * switched off UdpStunner.
 * added Debug Modes to rsUdpStack & rsFixedUdpStack.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4448 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-15 11:13:20 +00:00
parent 0229ef1fe8
commit bffaf6e5ef
5 changed files with 59 additions and 14 deletions

View file

@ -375,7 +375,7 @@ uint32_t PeerConnectStateBox::connectCb_direct()
} }
else if (mNoAttempts >= MAX_DIRECT_ATTEMPTS) /* if too many attempts */ else if (mNoAttempts >= MAX_DIRECT_ATTEMPTS) /* if too many attempts */
{ {
/* switch to RELAY attempt */ /* no RELAY attempt => FAILED_WAIT */
mState = CSB_FAILED_WAIT; mState = CSB_FAILED_WAIT;
retval = CSB_ACTION_WAIT; retval = CSB_ACTION_WAIT;
mStateTS = now; mStateTS = now;

View file

@ -67,7 +67,7 @@ virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t statu
virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId, virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
uint32_t mode, uint32_t point, uint32_t cbtype, uint32_t errcode) uint32_t mode, uint32_t point, uint32_t cbtype, uint32_t errcode)
{ {
return 0; return mParent->ConnectCallback(srcId, proxyId, destId, mode, point, cbtype, errcode);
} }
private: private:

View file

@ -329,6 +329,7 @@ int p3BitDht::OnlinePeerCallback_locked(const bdId *id, uint32_t status, DhtPeer
connectOk = false; connectOk = false;
doTCPCallback = true; doTCPCallback = true;
} }
break;
case CSB_ACTION_DIRECT_CONN: case CSB_ACTION_DIRECT_CONN:
{ {
@ -421,6 +422,9 @@ int p3BitDht::UnreachablePeerCallback_locked(const bdId *id, uint32_t status, Dh
default: default:
case CSB_ACTION_WAIT: case CSB_ACTION_WAIT:
{ {
std::cerr << "dhtPeerCallback. Request to Wait ... so no Connection Attempt for ";
bdStdPrintId(std::cerr, id);
std::cerr << std::endl;
connectOk = false; connectOk = false;
} }
break; break;
@ -1023,6 +1027,7 @@ int p3BitDht::doActions()
std::cerr << std::endl; std::cerr << std::endl;
bool connectionRequested = false; bool connectionRequested = false;
bool connectionReqFailed = false;
if ((action.mMode == BITDHT_CONNECT_MODE_DIRECT) || if ((action.mMode == BITDHT_CONNECT_MODE_DIRECT) ||
(action.mMode == BITDHT_CONNECT_MODE_RELAY)) (action.mMode == BITDHT_CONNECT_MODE_RELAY))
@ -1030,9 +1035,15 @@ int p3BitDht::doActions()
struct sockaddr_in laddr; // We zero this address. The DHT layer should be able to handle this! struct sockaddr_in laddr; // We zero this address. The DHT layer should be able to handle this!
sockaddr_clear(&laddr); sockaddr_clear(&laddr);
uint32_t start = 1; uint32_t start = 1;
mUdpBitDht->ConnectionRequest(&laddr, &(action.mDestId.id), action.mMode, start); if (mUdpBitDht->ConnectionRequest(&laddr, &(action.mDestId.id), action.mMode, start))
{
connectionRequested = true; connectionRequested = true;
} }
else
{
connectionReqFailed = true;
}
}
else if (action.mMode == BITDHT_CONNECT_MODE_PROXY) else if (action.mMode == BITDHT_CONNECT_MODE_PROXY)
{ {
struct sockaddr_in extaddr; struct sockaddr_in extaddr;
@ -1076,22 +1087,23 @@ int p3BitDht::doActions()
std::cerr << std::endl; std::cerr << std::endl;
int start = 1; int start = 1;
mUdpBitDht->ConnectionRequest(&extaddr, &(action.mDestId.id), action.mMode, start); if (mUdpBitDht->ConnectionRequest(&extaddr, &(action.mDestId.id), action.mMode, start))
{
connectionRequested = true; connectionRequested = true;
} }
else else
{
connectionReqFailed = true;
}
}
else
{ {
std::cerr << "PeerAction: ERROR Proxy Connection Attempt to: "; std::cerr << "PeerAction: ERROR Proxy Connection Attempt to: ";
bdStdPrintId(std::cerr, &(action.mDestId)); bdStdPrintId(std::cerr, &(action.mDestId));
std::cerr << " is Discarded, as Own External Proxy Address is Not Stable!"; std::cerr << " is Discarded, as Own External Proxy Address is Not Stable!";
std::cerr << std::endl; std::cerr << std::endl;
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ connectionReqFailed = true;
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND);
if (dpd)
{
dpd->mConnectLogic.updateCb(CSB_UPDATE_MODE_UNAVAILABLE);
}
} }
} }
else else
@ -1115,6 +1127,12 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
std::cerr << "PeerAction: Connection Attempt to: ";
bdStdPrintId(std::cerr, &(action.mDestId));
std::cerr << " has gone ahead";
std::cerr << std::endl;
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND);
if (dpd) if (dpd)
{ {
@ -1130,6 +1148,26 @@ int p3BitDht::doActions()
} }
} }
if (connectionReqFailed)
{
std::cerr << "PeerAction: Connection Attempt to: ";
bdStdPrintId(std::cerr, &(action.mDestId));
std::cerr << " is Discarded, as Mode is Unavailable";
std::cerr << std::endl;
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND);
if (dpd)
{
dpd->mConnectLogic.updateCb(CSB_UPDATE_MODE_UNAVAILABLE);
dpd->mPeerReqStatusMsg = "Req Mode Unavailable";
dpd->mPeerReqState = RSDHT_PEERREQ_STOPPED;
dpd->mPeerReqMode = action.mMode;
dpd->mPeerReqTS = now;
}
}
} }
break; break;

View file

@ -38,6 +38,7 @@
class UdpStack class UdpStack
{ {
public: public:
rsUdpStack(int testmode, struct sockaddr_in &local) { return; }
UdpStack(struct sockaddr_in &local) { return; } UdpStack(struct sockaddr_in &local) { return; }
/* from pqiNetListener */ /* from pqiNetListener */
@ -57,6 +58,9 @@ class rsUdpStack: public UdpStack, public pqiNetListener
rsUdpStack(struct sockaddr_in &local) rsUdpStack(struct sockaddr_in &local)
:UdpStack(local) { return; } :UdpStack(local) { return; }
rsUdpStack(int testmode, struct sockaddr_in &local)
:UdpStack(testmode, local) { return; }
/* from pqiNetListener */ /* from pqiNetListener */
virtual bool resetListener(struct sockaddr_in &local) virtual bool resetListener(struct sockaddr_in &local)
{ {
@ -75,6 +79,9 @@ class rsFixedUdpStack: public UdpStack, public pqiNetListener
rsFixedUdpStack(struct sockaddr_in &local) rsFixedUdpStack(struct sockaddr_in &local)
:UdpStack(local) { return; } :UdpStack(local) { return; }
rsFixedUdpStack(int testmode, struct sockaddr_in &local)
:UdpStack(testmode, local) { return; }
/* from pqiNetListener */ /* from pqiNetListener */
virtual bool resetListener(struct sockaddr_in &local) virtual bool resetListener(struct sockaddr_in &local)
{ {

View file

@ -38,7 +38,7 @@ static const int STUN_TTL = 64;
* #define DEBUG_UDP_STUNNER_FILTER 1 * #define DEBUG_UDP_STUNNER_FILTER 1
*/ */
#define DEBUG_UDP_STUNNER 1 //#define DEBUG_UDP_STUNNER 1
const int32_t TOU_STUN_MAX_FAIL_COUNT = 3; /* 3 tries (could be higher?) */ const int32_t TOU_STUN_MAX_FAIL_COUNT = 3; /* 3 tries (could be higher?) */
const int32_t TOU_STUN_MAX_SEND_RATE = 5; /* every 5 seconds */ const int32_t TOU_STUN_MAX_SEND_RATE = 5; /* every 5 seconds */