connection bugfixes.

* Print DHT translations (for debugging)
 * enable all connection modes.
 * reduced timeout periods for testing.
 * kill connectionRequest after UDP Fail. (used to restart it).
 * fixed up UDP Fail / Connection Close code.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4450 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-15 16:05:37 +00:00
parent 6609cec94d
commit 44b494e1fd
4 changed files with 89 additions and 59 deletions

View File

@ -29,12 +29,23 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#define FAILED_WAIT_TIME (300) //(1800) // 30 minutes. #define TESTING_PERIODS 1
#define TCP_WAIT_TIME (60) // 1 minutes.
#define DIRECT_WAIT_TIME (60) // 1 minutes. #ifdef TESTING_PERIODS
#define PROXY_WAIT_TIME (60) // 1 minutes. #define FAILED_WAIT_TIME (1800) // 5 minutes.
#define RELAY_WAIT_TIME (60) // 1 minutes. #define TCP_WAIT_TIME (10) // 1/6 minutes.
#define REVERSE_WAIT_TIME (300) // 5 minutes. #define DIRECT_WAIT_TIME (10) // 1/6 minutes.
#define PROXY_WAIT_TIME (30) // 1/6 minutes.
#define RELAY_WAIT_TIME (30) // 1/6 minutes.
#define REVERSE_WAIT_TIME (30) // 1/2 minutes.
#else
#define FAILED_WAIT_TIME (1800) // 30 minutes.
#define TCP_WAIT_TIME (60) // 1 minutes.
#define DIRECT_WAIT_TIME (60) // 1 minutes.
#define PROXY_WAIT_TIME (60) // 1 minutes.
#define RELAY_WAIT_TIME (60) // 1 minutes.
#define REVERSE_WAIT_TIME (300) // 5 minutes.
#endif
#define MAX_DIRECT_ATTEMPTS (3) #define MAX_DIRECT_ATTEMPTS (3)
#define MAX_PROXY_ATTEMPTS (3) #define MAX_PROXY_ATTEMPTS (3)

View File

@ -124,6 +124,11 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm,
p3BdCallback *bdcb = new p3BdCallback(this); p3BdCallback *bdcb = new p3BdCallback(this);
mUdpBitDht->addCallback(bdcb); mUdpBitDht->addCallback(bdcb);
/* enable all modes */
mUdpBitDht->ConnectionOptions(
BITDHT_CONNECT_MODE_DIRECT | BITDHT_CONNECT_MODE_PROXY | BITDHT_CONNECT_MODE_RELAY,
BITDHT_CONNECT_OPTION_AUTOPROXY);
} }
p3BitDht::~p3BitDht() p3BitDht::~p3BitDht()

View File

@ -20,7 +20,7 @@
#include "pqi/p3netmgr.h" #include "pqi/p3netmgr.h"
#include "pqi/pqimonitor.h" #include "pqi/pqimonitor.h"
#define PEERNET_CONNECT_TIMEOUT 45 #define PEERNET_CONNECT_TIMEOUT 90 // Should be BIGGER than Higher level (but okay if not!)
/*** /***
* *
@ -1884,50 +1884,13 @@ void p3BitDht::Feedback_ConnectionFailed(std::string pid)
return; return;
} }
std::cerr << "p3BitDht::Feedback_ConnectionFailed() UDP Connection Failed: ";
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
std::cerr << std::endl;
return UdpConnectionFailed_locked(dpd); return UdpConnectionFailed_locked(dpd);
} }
void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
{
/* shut id down */
dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED;
dpd->mPeerConnectMsg = "UDP Failed";
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING)
{
std::cerr << "p3BitDht::monitorConnections() Request Active (Paused)... restarting";
std::cerr << std::endl;
/* Push Back PeerAction */
PeerAction ca;
ca.mType = PEERNET_ACTION_TYPE_RESTARTREQ;
ca.mMode = dpd->mPeerConnectMode;
//ca.mProxyId = *proxyId;
//ca.mSrcId = *srcId;
ca.mDestId = dpd->mPeerConnectPeerId;
//ca.mPoint = point;
ca.mAnswer = BITDHT_CONNECT_ERROR_NONE;
mActions.push_back(ca);
// What the Action should do!
// tell it to keep going.
//struct sockaddr_in tmpaddr;
//bdsockaddr_clear(&tmpaddr);
//int start = 1;
//mUdpBitDht->ConnectionRequest(&tmpaddr, &(it->second.mPeerConnectPeerId.id), it->second.mPeerConnectMode, start);
}
// only an error if we initiated the connection.
else if (dpd->mPeerConnectPoint == BD_PROXY_CONNECTION_START_POINT)
{
std::cerr << "p3BitDht::monitorConnections() ERROR Request not active, can't stop";
std::cerr << std::endl;
}
}
void p3BitDht::Feedback_ConnectionClosed(std::string pid) void p3BitDht::Feedback_ConnectionClosed(std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
@ -1942,7 +1905,31 @@ void p3BitDht::Feedback_ConnectionClosed(std::string pid)
return; return;
} }
std::cerr << "p3BitDht::monitorConnections() Active Connection Closed: "; std::cerr << "p3BitDht::Feedback_ConnectionClosed() Active Connection Closed: ";
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
std::cerr << std::endl;
return UdpConnectionFailed_locked(dpd);
}
void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
{
if (dpd->mPeerConnectState == RSDHT_PEERCONN_UDP_STARTED)
{
std::cerr << "p3BitDht::UdpConnectionFailed_locked() UDP Connection Failed: ";
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
std::cerr << std::endl;
/* shut id down */
dpd->mConnectLogic.updateCb(CSB_UPDATE_FAILED_ATTEMPT);
dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED;
dpd->mPeerConnectMsg = "UDP Failed";
}
else
{
std::cerr << "p3BitDht::UdpConnectionFailed_locked() Active Connection Closed: ";
bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id)); bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id));
std::cerr << std::endl; std::cerr << std::endl;
@ -1954,6 +1941,33 @@ void p3BitDht::Feedback_ConnectionClosed(std::string pid)
msg << "Closed, Alive for: " << dpd->mPeerConnectClosedTS - dpd->mPeerConnectTS; msg << "Closed, Alive for: " << dpd->mPeerConnectClosedTS - dpd->mPeerConnectTS;
msg << " secs"; msg << " secs";
dpd->mPeerConnectMsg = msg.str(); dpd->mPeerConnectMsg = msg.str();
}
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING)
{
std::cerr << "p3BitDht::monitorConnections() Request Active (Paused)... Killing for next Attempt";
std::cerr << std::endl;
/* Push Back PeerAction */
PeerAction ca;
ca.mType = PEERNET_ACTION_TYPE_KILLREQ;
ca.mMode = dpd->mPeerConnectMode;
//ca.mProxyId = *proxyId;
//ca.mSrcId = *srcId;
ca.mDestId = dpd->mPeerConnectPeerId;
//ca.mPoint = point;
ca.mAnswer = BITDHT_CONNECT_ERROR_NONE;
mActions.push_back(ca);
}
// only an error if we initiated the connection.
else if (dpd->mPeerConnectPoint == BD_PROXY_CONNECTION_START_POINT)
{
std::cerr << "p3BitDht::monitorConnections() ERROR Request not active, can't stop";
std::cerr << std::endl;
}
} }

View File

@ -425,26 +425,26 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid)
int p3BitDht::storeTranslation_locked(const std::string pid) int p3BitDht::storeTranslation_locked(const std::string pid)
{ {
#ifdef DEBUG_BITDHT_TRANSLATE
std::cerr << "p3BitDht::storeTranslation_locked(" << pid << ")"; std::cerr << "p3BitDht::storeTranslation_locked(" << pid << ")";
std::cerr << std::endl; std::cerr << std::endl;
#ifdef DEBUG_BITDHT_TRANSLATE
#endif #endif
bdNodeId nid; bdNodeId nid;
calculateNodeId(pid, &nid); calculateNodeId(pid, &nid);
#ifdef DEBUG_BITDHT_TRANSLATE
std::cerr << "p3BitDht::storeTranslation_locked() Converts to NodeId: "; std::cerr << "p3BitDht::storeTranslation_locked() Converts to NodeId: ";
bdStdPrintNodeId(std::cerr, &(nid)); bdStdPrintNodeId(std::cerr, &(nid));
std::cerr << std::endl; std::cerr << std::endl;
#ifdef DEBUG_BITDHT_TRANSLATE
#endif #endif
mTransToNodeId[pid] = nid; mTransToNodeId[pid] = nid;
mTransToRsId[nid] = pid; mTransToRsId[nid] = pid;
#ifdef DEBUG_BITDHT_TRANSLATE
std::cerr << "p3BitDht::storeTranslation_locked() Success"; std::cerr << "p3BitDht::storeTranslation_locked() Success";
std::cerr << std::endl; std::cerr << std::endl;
#ifdef DEBUG_BITDHT_TRANSLATE
#endif #endif
return 1; return 1;