diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index c82df8c5f..443a08b10 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -100,7 +100,7 @@ peerConnectState::peerConnectState() lastcontact(0), connecttype(0), lastavailable(0), - lastattempt(time(NULL) - MIN_RETRY_PERIOD + 6), //start connection in 6 sec + lastattempt(time(NULL) - MIN_RETRY_PERIOD + MIN_TIME_BETWEEN_NET_RESET + 2), //start connection 2 second after the possible next one net reset name("nameless"), state(0), actions(0), source(0), inConnAttempt(0) @@ -320,26 +320,6 @@ void p3ConnectMgr::netReset() /* check Network Address */ checkNetAddress(); - /* reset udp network - handled by tou_init! */ - /* reset tcp network - if necessary */ - { - /* NOTE: nNetListeners should be protected via the Mutex. - * HOWEVER, as we NEVER change this list - once its setup - * we can get away without it - and assume its constant. - * - * NB: (*it)->reset_listener must be out of the mutex, - * as it calls back to p3ConnMgr. - */ - - std::cerr << "p3ConnectMgr::netReset() resetting listeners" << std::endl; - std::list::const_iterator it; - for(it = mNetListeners.begin(); it != mNetListeners.end(); it++) - { - std::cerr << "p3ConnectMgr::netReset() reset listener" << std::endl; - (*it)->reset_listener(); - } - } - std::cerr << "p3ConnectMgr::netReset() done" << std::endl; } @@ -350,6 +330,29 @@ void p3ConnectMgr::addNetListener(pqiNetListener *listener) mNetListeners.push_back(listener); } +void p3ConnectMgr::startListeners() { + /* NOTE: nNetListeners should be protected via the Mutex. + * HOWEVER, as we NEVER change this list - once its setup + * we can get away without it - and assume its constant. + * + * NB: (*it)->reset_listener must be out of the mutex, + * as it calls back to p3ConnMgr. + */ + + std::cerr << "p3ConnectMgr::netReset() resetting listeners" << std::endl; + std::list::const_iterator it; + for(it = mNetListeners.begin(); it != mNetListeners.end(); it++) + { + std::cerr << "p3ConnectMgr::netReset() reset listener" << std::endl; + (*it)->reset_listener(); + } + mListenerActive = true; +} + +void p3ConnectMgr::stopListeners() { + //TODO implement it + mListenerActive = false; +} void p3ConnectMgr::netStatusReset() { @@ -442,6 +445,7 @@ bool p3ConnectMgr::shutdown() /* blocking shutdown call */ } netAssistFirewallShutdown(); netAssistConnectShutdown(); + stopListeners(); //not implemented yet return true; } @@ -530,6 +534,12 @@ void p3ConnectMgr::netTick() uint32_t netStatus = mNetStatus; connMtx.unlock(); /* UNLOCK MUTEX */ + /* start tcp network - if necessary */ + //TODO : implement stop listeners in net reset + if (!mListenerActive && netStatus != RS_NET_NEED_RESET && (time(NULL) - mNetInitTS) > (MIN_TIME_BETWEEN_NET_RESET + 2)) {//start connection 2 second after the possible next one net reset + startListeners(); + } + switch(netStatus) { diff --git a/libretroshare/src/pqi/p3connmgr.h b/libretroshare/src/pqi/p3connmgr.h index 29d2c841f..9f9c4a2d5 100644 --- a/libretroshare/src/pqi/p3connmgr.h +++ b/libretroshare/src/pqi/p3connmgr.h @@ -382,9 +382,12 @@ private: RsMutex connMtx; /* protects below */ std::list mNetListeners; + void stopListeners(); + void startListeners(); time_t mNetInitTS; uint32_t mNetStatus; + bool mListenerActive; uint32_t mStunStatus; uint32_t mStunFound; diff --git a/libretroshare/src/pqi/pqissltunnel.cc b/libretroshare/src/pqi/pqissltunnel.cc index d1ad2cc47..64370eb81 100644 --- a/libretroshare/src/pqi/pqissltunnel.cc +++ b/libretroshare/src/pqi/pqissltunnel.cc @@ -119,7 +119,7 @@ pqissltunnel::pqissltunnel(PQInterface *parent, p3AuthMgr *am, p3ConnectMgr *cm) pqissltunnel::~pqissltunnel() { rslog(RSL_ALERT, pqisslzone, "pqissltunnel::~pqissltunnel -> destroying pqissl"); - stoplistening(); /* remove from pqissllistener only */ + //stoplistening(); reset(); return; }