Fixed Bug in choosing port for Proxy UDP. Chooses a Random one between 30000-50000.

It was using the same port as the DHT, and switching to a Random one, on its own.
 * Added debugging for net reset.
 * Added further debugging for ssl (reset + killing existing connections)



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4530 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-08-04 22:57:12 +00:00
parent 91b37be2e5
commit 8066862833
3 changed files with 55 additions and 8 deletions

View File

@ -30,13 +30,14 @@
#include "util/rsnet.h"
#include "util/rsrandom.h"
#include "util/rsdebug.h"
#include "util/extaddrfinder.h"
#include "util/dnsresolver.h"
//#include "util/rsprint.h"
//#include "util/rsdebug.h"
//const int p3connectzone = 3431;
const int p3netmgrzone = 7563;
#include "serialiser/rsconfigitems.h"
#include "pqi/pqinotify.h"
@ -137,6 +138,11 @@ p3NetMgrIMPL::p3NetMgrIMPL()
std::cerr << "p3NetMgr() Startup" << std::endl;
#endif
{
std::ostringstream out;
out << "p3NetMgr() Startup, resetting network";
rslog(RSL_WARNING, p3netmgrzone, out.str());
}
netReset();
return;
@ -229,6 +235,11 @@ void p3NetMgrIMPL::netReset()
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgrIMPL::netReset() Called" << std::endl;
#endif
{
std::ostringstream out;
out << "p3NetMgr::netReset() Called";
rslog(RSL_ALERT, p3netmgrzone, out.str());
}
shutdown(); /* blocking shutdown call */
@ -471,6 +482,12 @@ void p3NetMgrIMPL::netTick()
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgrIMPL::netTick() STATUS: NEEDS_RESET" << std::endl;
#endif
{
std::ostringstream out;
out << "p3NetMgr::netTick() RS_NET_NEEDS_RESET, resetting network";
rslog(RSL_WARNING, p3netmgrzone, out.str());
}
netReset();
break;
@ -870,6 +887,10 @@ void p3NetMgrIMPL::netExtCheck()
/* update PeerMgr with correct info */
mPeerMgr->UpdateOwnAddress(mLocalAddr, mExtAddr);
std::ostringstream out;
out << "p3NetMgr::netExtCheck() Network Setup Complete";
rslog(RSL_WARNING, p3netmgrzone, out.str());
}
}
@ -895,6 +916,11 @@ bool p3NetMgrIMPL::checkNetAddress()
std::cerr << "p3NetMgrIMPL::checkNetAddress() no Valid Network Address, resetting network." << std::endl;
std::cerr << std::endl;
#endif
{
std::ostringstream out;
out << "p3NetMgr::checkNetAddress() No Valid Network Address, resetting network";
rslog(RSL_WARNING, p3netmgrzone, out.str());
}
netReset();
return false;
}
@ -1005,6 +1031,11 @@ bool p3NetMgrIMPL::checkNetAddress()
mPeerMgr->UpdateOwnAddress(mLocalAddr, mExtAddr);
{
std::ostringstream out;
out << "p3NetMgr::checkNetAddress() local address changed, resetting network";
rslog(RSL_WARNING, p3netmgrzone, out.str());
}
netReset();
}
@ -1044,6 +1075,11 @@ bool p3NetMgrIMPL::setLocalAddress(struct sockaddr_in addr)
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgrIMPL::setLocalAddress() Calling NetReset" << std::endl;
#endif
{
std::ostringstream out;
out << "p3NetMgr::setLocalAddress() local address changed, resetting network";
rslog(RSL_WARNING, p3netmgrzone, out.str());
}
netReset();
}
return true;
@ -1068,6 +1104,11 @@ bool p3NetMgrIMPL::setExtAddress(struct sockaddr_in addr)
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgrIMPL::setExtAddress() Calling NetReset" << std::endl;
#endif
{
std::ostringstream out;
out << "p3NetMgr::setExtAddress() ext address changed, resetting network";
rslog(RSL_WARNING, p3netmgrzone, out.str());
}
netReset();
}
return true;
@ -1111,6 +1152,11 @@ bool p3NetMgrIMPL::setNetworkMode(uint32_t netMode)
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgrIMPL::setNetworkMode() Calling NetReset" << std::endl;
#endif
{
std::ostringstream out;
out << "p3NetMgr::setNetworkMode() Net Mode changed, resetting network";
rslog(RSL_WARNING, p3netmgrzone, out.str());
}
netReset();
}
return true;

View File

@ -255,7 +255,8 @@ int pqissl::reset()
}
out << "pqissl::reset() Complete!" << std::endl;
rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
//rslog(RSL_DEBUG_BASIC, pqisslzone, out.str());
rslog(RSL_WARNING, pqisslzone, out.str());
// notify people of problem!
// but only if we really shut something down.
@ -1294,14 +1295,14 @@ int pqissl::accept(SSL *ssl, int fd, struct sockaddr_in foreign_addr) // initiat
/* shutdown existing - in all cases use the new one */
if ((ssl_connection) && (ssl_connection != ssl))
{
rslog(RSL_DEBUG_BASIC, pqisslzone,
rslog(RSL_ALERT, pqisslzone,
"pqissl::accept() closing Previous/Existing ssl_connection");
SSL_shutdown(ssl_connection);
}
if ((sockfd > -1) && (sockfd != fd))
{
rslog(RSL_DEBUG_BASIC, pqisslzone,
rslog(RSL_ALERT, pqisslzone,
"pqissl::accept() closing Previous/Existing sockfd");
net_internal_close(sockfd);
}

View File

@ -1939,14 +1939,14 @@ int RsServer::StartupRetroShare()
// NOW WE BUILD THE SECOND STACK.
// Create the Second UdpStack... Port should be random (but openable!).
// XXX TODO
#define MIN_RANDOM_PORT 10000
#define MAX_RANDOM_PORT 30000
#define MIN_RANDOM_PORT 30000
#define MAX_RANDOM_PORT 50000
struct sockaddr_in sndladdr;
sockaddr_clear(&sndladdr);
uint16_t rndport = MIN_RANDOM_PORT + RSRandom::random_u32() % (MAX_RANDOM_PORT - MIN_RANDOM_PORT);
sndladdr.sin_port = htons(RsInitConfig::port);
sndladdr.sin_port = htons(rndport);
rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(sndladdr);
// FIRSTLY THE PROXY STUNNER.