mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-17 10:59:38 -04:00
work on the timeout for tcp and udp connection
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1884 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6f0e7de534
commit
8e4ce11532
4 changed files with 51 additions and 26 deletions
|
@ -73,7 +73,7 @@ const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 6;
|
||||||
|
|
||||||
const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
||||||
const uint32_t P3CONNMGR_UDP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
const uint32_t P3CONNMGR_UDP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
||||||
const uint32_t P3CONNMGR_UDP_DEFAULT_TIMEOUT = 40; //a random timeout is set between P3CONNMGR_UDP_DEFAULT_TIMEOUT and 2 * P3CONNMGR_UDP_DEFAULT_TIMEOUT in the implementation
|
const uint32_t P3CONNMGR_UDP_DEFAULT_PERIOD = 20; //a random timeout is set between P3CONNMGR_UDP_DEFAULT_PERIOD and 2 * P3CONNMGR_UDP_DEFAULT_PERIOD in the implementation
|
||||||
|
|
||||||
#define MAX_AVAIL_PERIOD 180 //times a peer stay in available state when not connected
|
#define MAX_AVAIL_PERIOD 180 //times a peer stay in available state when not connected
|
||||||
#define MIN_RETRY_PERIOD 90
|
#define MIN_RETRY_PERIOD 90
|
||||||
|
@ -2228,7 +2228,7 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "Adding tcp connection attempt list." << std::endl;
|
std::cerr << "Adding tcp connection attempt list." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
peerConnectAddress pca;
|
peerConnectAddress pca;
|
||||||
pca.addr = ipListIt->ipAddr;
|
pca.addr = ipListIt->ipAddr;
|
||||||
pca.type = RS_NET_CONN_TCP_UNKNOW_TOPOLOGY;
|
pca.type = RS_NET_CONN_TCP_UNKNOW_TOPOLOGY;
|
||||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||||
|
@ -2276,7 +2276,7 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
|
||||||
pca.delay = P3CONNMGR_UDP_DEFAULT_DELAY;
|
pca.delay = P3CONNMGR_UDP_DEFAULT_DELAY;
|
||||||
pca.ts = time(NULL);
|
pca.ts = time(NULL);
|
||||||
// pseudo random number generator from Wikipedia/Numerical Recipies.
|
// pseudo random number generator from Wikipedia/Numerical Recipies.
|
||||||
pca.period = P3CONNMGR_UDP_DEFAULT_TIMEOUT + ((time(NULL)*1664525 + 1013904223) % P3CONNMGR_UDP_DEFAULT_TIMEOUT); //add a random timeout between 1 and 2 times P3CONNMGR_UDP_DEFAULT_TIMEOUT
|
pca.period = P3CONNMGR_UDP_DEFAULT_PERIOD + ((time(NULL)*1664525 + 1013904223) % P3CONNMGR_UDP_DEFAULT_PERIOD); //add a random period between 1 and 2 times P3CONNMGR_UDP_DEFAULT_PERIOD
|
||||||
it->second.connAddrs.push_back(pca);
|
it->second.connAddrs.push_back(pca);
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
|
@ -2506,14 +2506,22 @@ bool p3ConnectMgr::setAddressList(std::string id, std::list<IpAddressTimed> I
|
||||||
&& (ipListIt->ipAddr.sin_addr.s_addr != 0)
|
&& (ipListIt->ipAddr.sin_addr.s_addr != 0)
|
||||||
&& (!isLoopbackNet(&ipListIt->ipAddr.sin_addr))
|
&& (!isLoopbackNet(&ipListIt->ipAddr.sin_addr))
|
||||||
) {
|
) {
|
||||||
//the pointer ipListIt is pointing to an external address
|
//Let's check if the address is not to old
|
||||||
#ifdef CONN_DEBUG
|
if ((time(NULL) - ipListIt->seenTime) < P3CONNMGR_UDP_DEFAULT_PERIOD) {
|
||||||
std::cerr << "p3ConnectMgr::setAddressList() setting own ext adress from p3disc : ";
|
//the pointer ipListIt is pointing to an external address
|
||||||
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr) << ":" << ntohs(ipListIt->ipAddr.sin_port) << " seenTime : " << ipListIt->seenTime << std::endl;
|
#ifdef CONN_DEBUG
|
||||||
#endif
|
std::cerr << "p3ConnectMgr::setAddressList() setting own ext adress from p3disc : ";
|
||||||
|
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr) << ":" << ntohs(ipListIt->ipAddr.sin_port) << " seenTime : " << ipListIt->seenTime << std::endl;
|
||||||
setExtAddress(getOwnId(), ipListIt->ipAddr);
|
#endif
|
||||||
break;
|
setExtAddress(getOwnId(), ipListIt->ipAddr);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3ConnectMgr::setAddressList() own ext adress from p3disc is too old to be used : ";
|
||||||
|
std::cerr << inet_ntoa(ipListIt->ipAddr.sin_addr) << ":" << ntohs(ipListIt->ipAddr.sin_port) << " seenTime : " << ipListIt->seenTime << std::endl;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ const int PQISSL_UDP_FLAG = 0x02;
|
||||||
***********/
|
***********/
|
||||||
|
|
||||||
static const int PQISSL_MAX_READ_ZERO_COUNT = 20;
|
static const int PQISSL_MAX_READ_ZERO_COUNT = 20;
|
||||||
static const int PQISSL_SSL_CONNECT_TIMEOUT = 30;
|
|
||||||
|
|
||||||
/********** PQI SSL STUFF ******************************************
|
/********** PQI SSL STUFF ******************************************
|
||||||
*
|
*
|
||||||
|
@ -94,7 +93,6 @@ pqissl::pqissl(pqissllistener *l, PQInterface *parent, p3AuthMgr *am, p3ConnectM
|
||||||
sslmode(PQISSL_ACTIVE), ssl_connection(NULL), sockfd(-1),
|
sslmode(PQISSL_ACTIVE), ssl_connection(NULL), sockfd(-1),
|
||||||
pqil(l), // no init for remote_addr.
|
pqil(l), // no init for remote_addr.
|
||||||
readpkt(NULL), pktlen(0),
|
readpkt(NULL), pktlen(0),
|
||||||
attempt_ts(0),
|
|
||||||
net_attempt(0), net_failure(0), net_unreachable(0),
|
net_attempt(0), net_failure(0), net_unreachable(0),
|
||||||
sameLAN(false), n_read_zero(0),
|
sameLAN(false), n_read_zero(0),
|
||||||
mConnectDelay(0), mConnectTS(0),
|
mConnectDelay(0), mConnectTS(0),
|
||||||
|
@ -241,6 +239,7 @@ int pqissl::reset()
|
||||||
sameLAN = false;
|
sameLAN = false;
|
||||||
n_read_zero = 0;
|
n_read_zero = 0;
|
||||||
total_len = 0 ;
|
total_len = 0 ;
|
||||||
|
mTimeoutTS = 0;
|
||||||
|
|
||||||
if (neededReset)
|
if (neededReset)
|
||||||
{
|
{
|
||||||
|
@ -369,7 +368,15 @@ int pqissl::tick()
|
||||||
out << "Continuing Connection Attempt!";
|
out << "Continuing Connection Attempt!";
|
||||||
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
|
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
|
||||||
|
|
||||||
ConnectAttempt();
|
if (mTimeoutTS != 0 && time(NULL) > mTimeoutTS)
|
||||||
|
{
|
||||||
|
rslog(RSL_DEBUG_BASIC, pqisslzone,
|
||||||
|
"pqissl::Authorise_SSL_Connection() Connection Timed Out!");
|
||||||
|
/* as sockfd is valid, this should close it all up */
|
||||||
|
reset();
|
||||||
|
} else {
|
||||||
|
ConnectAttempt();
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -928,9 +935,6 @@ int pqissl::Initiate_SSL_Connection()
|
||||||
rslog(RSL_DEBUG_BASIC, pqisslzone,
|
rslog(RSL_DEBUG_BASIC, pqisslzone,
|
||||||
"pqissl::Initiate_SSL_Connection() Basic Connection Okay");
|
"pqissl::Initiate_SSL_Connection() Basic Connection Okay");
|
||||||
|
|
||||||
// setup timeout value.
|
|
||||||
ssl_connect_timeout = time(NULL) + PQISSL_SSL_CONNECT_TIMEOUT;
|
|
||||||
|
|
||||||
// Perform SSL magic.
|
// Perform SSL magic.
|
||||||
// library already inited by sslroot().
|
// library already inited by sslroot().
|
||||||
SSL *ssl = SSL_new(mAuthMgr->getCTX());
|
SSL *ssl = SSL_new(mAuthMgr->getCTX());
|
||||||
|
@ -1095,10 +1099,9 @@ int pqissl::Extract_Failed_SSL_Certificate()
|
||||||
int pqissl::Authorise_SSL_Connection()
|
int pqissl::Authorise_SSL_Connection()
|
||||||
{
|
{
|
||||||
rslog(RSL_DEBUG_BASIC, pqisslzone,
|
rslog(RSL_DEBUG_BASIC, pqisslzone,
|
||||||
"pqissl::Authorise_SSL_Connection()");
|
"pqissl::Authorise_SSL_Connection()");
|
||||||
ssl_connect_timeout = time(NULL) + PQISSL_SSL_CONNECT_TIMEOUT;
|
|
||||||
|
|
||||||
if (time(NULL) > ssl_connect_timeout)
|
if (time(NULL) > mTimeoutTS)
|
||||||
{
|
{
|
||||||
rslog(RSL_DEBUG_BASIC, pqisslzone,
|
rslog(RSL_DEBUG_BASIC, pqisslzone,
|
||||||
"pqissl::Authorise_SSL_Connection() Connection Timed Out!");
|
"pqissl::Authorise_SSL_Connection() Connection Timed Out!");
|
||||||
|
|
|
@ -184,7 +184,7 @@ virtual int net_internal_fcntl_nonblock(int fd) { return unix_fcntl_nonblock(fd)
|
||||||
int pktlen;
|
int pktlen;
|
||||||
int total_len ; // saves the reading state accross successive calls.
|
int total_len ; // saves the reading state accross successive calls.
|
||||||
|
|
||||||
int attempt_ts;
|
//int attempt_ts;
|
||||||
|
|
||||||
// Some flags to indicate
|
// Some flags to indicate
|
||||||
// the status of the various interfaces
|
// the status of the various interfaces
|
||||||
|
@ -197,7 +197,7 @@ virtual int net_internal_fcntl_nonblock(int fd) { return unix_fcntl_nonblock(fd)
|
||||||
|
|
||||||
int n_read_zero; /* a counter to determine if the connection is really dead */
|
int n_read_zero; /* a counter to determine if the connection is really dead */
|
||||||
|
|
||||||
int ssl_connect_timeout; /* timeout to ensure that we don't get stuck (can happen on udp!) */
|
//int ssl_connect_timeout; /* timeout to ensure that we don't get stuck (can happen on udp!) */
|
||||||
|
|
||||||
uint32_t mConnectDelay;
|
uint32_t mConnectDelay;
|
||||||
time_t mConnectTS;
|
time_t mConnectTS;
|
||||||
|
|
|
@ -253,7 +253,7 @@ int pqissludp::Basic_Connection_Complete()
|
||||||
{
|
{
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "pqissludp::Basic_Connection_Complete() Connection Timed Out. ";
|
out << "pqissludp::Basic_Connection_Complete() Connection Timed Out. ";
|
||||||
out << "Peer: " << PeerId() << " Period: ";
|
out << "Peer: " << PeerId() << " Timeout: ";
|
||||||
out << mConnectTimeout;
|
out << mConnectTimeout;
|
||||||
|
|
||||||
rslog(RSL_WARNING, pqissludpzone, out.str());
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
||||||
|
@ -411,11 +411,25 @@ bool pqissludp::connect_parameter(uint32_t type, uint32_t value)
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " PERIOD: " << value;
|
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " PERIOD: " << value;
|
||||||
rslog(RSL_WARNING, pqissludpzone, out.str());
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
||||||
|
|
||||||
mConnectPeriod = value;
|
mConnectPeriod = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}else if (type == NET_PARAM_CONNECT_DELAY)
|
||||||
return pqissl::connect_parameter(type, value);
|
{
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " DELAY: " << value;
|
||||||
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
||||||
|
mConnectDelay = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (type == NET_PARAM_CONNECT_TIMEOUT)
|
||||||
|
{
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " TIMEOUT: " << value;
|
||||||
|
rslog(RSL_WARNING, pqissludpzone, out.str());
|
||||||
|
mConnectTimeout = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return pqissl::connect_parameter(type, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/********** PQI STREAMER OVERLOADING *********************************/
|
/********** PQI STREAMER OVERLOADING *********************************/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue