From 06a582564d4b20a7186335e7a828b83b1ffa0b8b Mon Sep 17 00:00:00 2001 From: drbob Date: Sun, 19 Jan 2014 11:35:31 +0000 Subject: [PATCH] Fixes for failed Proxy Connection Attempts: - create Timeout Fn so it can be called by classes derived from pqissl. - set HIDDEN timeout to 30 seconds. - add reset_locked() calls on errors in pqisslproxy. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@7039 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3linkmgr.h | 2 ++ libretroshare/src/pqi/pqipersongrp.cc | 3 ++- libretroshare/src/pqi/pqissl.cc | 25 ++++++++++++++++++------- libretroshare/src/pqi/pqissl.h | 3 +++ libretroshare/src/pqi/pqisslproxy.cc | 13 ++++++++++--- libretroshare/src/pqi/pqissludp.cc | 12 +----------- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/libretroshare/src/pqi/p3linkmgr.h b/libretroshare/src/pqi/p3linkmgr.h index a4513ea83..ea294c1dd 100644 --- a/libretroshare/src/pqi/p3linkmgr.h +++ b/libretroshare/src/pqi/p3linkmgr.h @@ -51,7 +51,9 @@ const uint32_t RS_NET_CONN_TCP_HIDDEN = 0x0008; const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0010; const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */ +// These are set in pqipersongroup. const uint32_t RS_TCP_STD_TIMEOUT_PERIOD = 5; /* 5 seconds! */ +const uint32_t RS_TCP_HIDDEN_TIMEOUT_PERIOD = 30; /* 30 seconds! */ const uint32_t RS_UDP_STD_TIMEOUT_PERIOD = 80; /* 80 secs, allows UDP TTL to get to 40! - Plenty of time (30+80) = 110 secs */ class peerAddrInfo diff --git a/libretroshare/src/pqi/pqipersongrp.cc b/libretroshare/src/pqi/pqipersongrp.cc index e3128c6ed..9dc994b9e 100644 --- a/libretroshare/src/pqi/pqipersongrp.cc +++ b/libretroshare/src/pqi/pqipersongrp.cc @@ -620,12 +620,13 @@ int pqipersongrp::connectPeer(std::string id if (type == RS_NET_CONN_TCP_HIDDEN) { ptype = PQI_CONNECT_HIDDEN_TCP; + timeout = RS_TCP_HIDDEN_TIMEOUT_PERIOD; } else { ptype = PQI_CONNECT_TCP; + timeout = RS_TCP_STD_TIMEOUT_PERIOD; } - timeout = RS_TCP_STD_TIMEOUT_PERIOD; #ifdef PGRP_DEBUG std::cerr << " pqipersongrp::connectPeer() connecting with TCP: Timeout :" << timeout; std::cerr << std::endl; diff --git a/libretroshare/src/pqi/pqissl.cc b/libretroshare/src/pqi/pqissl.cc index 32fefbffa..aebe05550 100644 --- a/libretroshare/src/pqi/pqissl.cc +++ b/libretroshare/src/pqi/pqissl.cc @@ -823,13 +823,8 @@ int pqissl::Initiate_Connection() * */ -int pqissl::Basic_Connection_Complete() +bool pqissl::CheckConnectionTimeout() { -#ifdef PQISSL_LOG_DEBUG - rslog(RSL_DEBUG_BASIC, pqisslzone, - "pqissl::Basic_Connection_Complete()..."); -#endif - /* new TimeOut code. */ if (time(NULL) > mTimeoutTS) { @@ -841,10 +836,26 @@ int pqissl::Basic_Connection_Complete() rslog(RSL_ALERT, pqisslzone, "pqissl::Basic_Connection_Complete() -> calling reset()"); reset_locked(); + return true; + } + return false; +} + + + +int pqissl::Basic_Connection_Complete() +{ +#ifdef PQISSL_LOG_DEBUG + rslog(RSL_DEBUG_BASIC, pqisslzone, + "pqissl::Basic_Connection_Complete()..."); +#endif + + if (CheckConnectionTimeout()) + { + // calls reset. return -1; } - if (waiting != WAITING_SOCK_CONNECT) { rslog(RSL_ALERT, pqisslzone, diff --git a/libretroshare/src/pqi/pqissl.h b/libretroshare/src/pqi/pqissl.h index de8813cd9..915e71173 100644 --- a/libretroshare/src/pqi/pqissl.h +++ b/libretroshare/src/pqi/pqissl.h @@ -165,6 +165,9 @@ int Authorise_SSL_Connection(); int Extract_Failed_SSL_Certificate(); // try to get cert anyway. + // check connection timeout. +bool CheckConnectionTimeout(); + //protected internal fns that are overloaded for udp case. virtual int net_internal_close(int fd); diff --git a/libretroshare/src/pqi/pqisslproxy.cc b/libretroshare/src/pqi/pqisslproxy.cc index 45c9d4c19..e8bcea8bf 100755 --- a/libretroshare/src/pqi/pqisslproxy.cc +++ b/libretroshare/src/pqi/pqisslproxy.cc @@ -96,6 +96,12 @@ int pqisslproxy::Basic_Connection_Complete() std::cerr << std::endl; #endif + if (CheckConnectionTimeout()) + { + // calls reset. + return -1; + } + int ret = 0; switch(mProxyState) { @@ -127,6 +133,7 @@ int pqisslproxy::Basic_Connection_Complete() std::cerr << std::endl; #endif + reset_locked(); return -1; } @@ -134,10 +141,10 @@ int pqisslproxy::Basic_Connection_Complete() { #ifdef PROXY_DEBUG - std::cerr << "pqisslproxy::Basic_Connection_Complete() FAILED(2)"; - std::cerr << std::endl; + std::cerr << "pqisslproxy::Basic_Connection_Complete() FAILED(2)"; + std::cerr << std::endl; #endif - + reset_locked(); return -1; // FAILURE. } diff --git a/libretroshare/src/pqi/pqissludp.cc b/libretroshare/src/pqi/pqissludp.cc index fef91d8db..bc8f750b3 100644 --- a/libretroshare/src/pqi/pqissludp.cc +++ b/libretroshare/src/pqi/pqissludp.cc @@ -351,21 +351,11 @@ int pqissludp::Basic_Connection_Complete() rslog(RSL_DEBUG_BASIC, pqissludpzone, "pqissludp::Basic_Connection_Complete()..."); - - if (time(NULL) > mTimeoutTS) + if (CheckConnectionTimeout()) { - std::string out = "pqissludp::Basic_Connection_Complete() Connection Timed Out. Peer: " + PeerId(); - rs_sprintf_append(out, " Period: %lu", mConnectTimeout); - - rslog(RSL_WARNING, pqissludpzone, out); - - /* as sockfd is valid, this should close it all up */ - - reset_locked(); return -1; } - if (waiting != WAITING_SOCK_CONNECT) { rslog(RSL_DEBUG_BASIC, pqissludpzone,