mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-02 11:26:31 -05:00
rewrite connection manager
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1769 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a20d09f0f4
commit
2e5130a1da
@ -43,7 +43,7 @@ const uint32_t RS_NET_NEED_RESET = 0x0000;
|
|||||||
const uint32_t RS_NET_UNKNOWN = 0x0001;
|
const uint32_t RS_NET_UNKNOWN = 0x0001;
|
||||||
const uint32_t RS_NET_UPNP_INIT = 0x0002;
|
const uint32_t RS_NET_UPNP_INIT = 0x0002;
|
||||||
const uint32_t RS_NET_UPNP_SETUP = 0x0003;
|
const uint32_t RS_NET_UPNP_SETUP = 0x0003;
|
||||||
const uint32_t RS_NET_UDP_SETUP = 0x0004;
|
const uint32_t RS_NET_EXT_ADDR_FINDER = 0x0004;
|
||||||
const uint32_t RS_NET_DONE = 0x0005;
|
const uint32_t RS_NET_DONE = 0x0005;
|
||||||
const uint32_t RS_NET_LOOPBACK = 0x0006;
|
const uint32_t RS_NET_LOOPBACK = 0x0006;
|
||||||
const uint32_t RS_NET_MODE_DOWN = 0x0007;
|
const uint32_t RS_NET_MODE_DOWN = 0x0007;
|
||||||
@ -54,8 +54,8 @@ const uint32_t RS_STUN_DONE = 0x0002;
|
|||||||
const uint32_t RS_STUN_LIST_MIN = 100;
|
const uint32_t RS_STUN_LIST_MIN = 100;
|
||||||
const uint32_t RS_STUN_FOUND_MIN = 10;
|
const uint32_t RS_STUN_FOUND_MIN = 10;
|
||||||
|
|
||||||
const uint32_t MAX_UPNP_INIT = 80; /* seconds UPnP timeout */
|
const uint32_t MAX_UPNP_INIT = 70; /* seconds UPnP timeout */
|
||||||
const uint32_t MAX_UDP_INIT = 100; /* seconds Udp timeout */
|
const uint32_t MAX_NETWORK_INIT = 75; /* seconds Udp timeout */
|
||||||
|
|
||||||
const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
|
const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
|
||||||
|
|
||||||
@ -132,10 +132,6 @@ p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am)
|
|||||||
mStunStatus(0), mStunFound(0), mStunMoreRequired(true),
|
mStunStatus(0), mStunFound(0), mStunMoreRequired(true),
|
||||||
mStatusChanged(false)
|
mStatusChanged(false)
|
||||||
{
|
{
|
||||||
mUpnpAddrValid = false;
|
|
||||||
mStunAddrValid = false;
|
|
||||||
mStunAddrStable = false;
|
|
||||||
|
|
||||||
/* setup basics of own state */
|
/* setup basics of own state */
|
||||||
if (am)
|
if (am)
|
||||||
{
|
{
|
||||||
@ -345,14 +341,12 @@ void p3ConnectMgr::addNetListener(pqiNetListener *listener)
|
|||||||
|
|
||||||
void p3ConnectMgr::netStatusReset()
|
void p3ConnectMgr::netStatusReset()
|
||||||
{
|
{
|
||||||
std::cerr << "p3ConnectMgr::netStatusReset()";
|
//std::cerr << "p3ConnectMgr::netStatusReset()" << std::endl;;
|
||||||
netFlagOk = false;
|
netFlagExtraAddressCheckOk = false;
|
||||||
|
netFlagLocalOk = false;
|
||||||
netFlagUpnpOk = false;
|
netFlagUpnpOk = false;
|
||||||
netFlagDhtOk = false;
|
netFlagDhtOk = false;
|
||||||
netFlagExtOk = false;
|
netFlagStunOk = false;
|
||||||
netFlagUdpOk = false;
|
|
||||||
netFlagTcpOk = false;
|
|
||||||
netFlagResetReq = false;
|
|
||||||
IndicateConfigChanged();
|
IndicateConfigChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,12 +386,13 @@ void p3ConnectMgr::netStartup()
|
|||||||
|
|
||||||
case RS_NET_MODE_TRY_EXT: /* v similar to UDP */
|
case RS_NET_MODE_TRY_EXT: /* v similar to UDP */
|
||||||
ownState.netMode |= RS_NET_MODE_EXT;
|
ownState.netMode |= RS_NET_MODE_EXT;
|
||||||
mNetStatus = RS_NET_UDP_SETUP;
|
mNetStatus = RS_NET_EXT_ADDR_FINDER;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RS_NET_MODE_TRY_UDP:
|
case RS_NET_MODE_TRY_UDP:
|
||||||
ownState.netMode |= RS_NET_MODE_UDP;
|
ownState.netMode |= RS_NET_MODE_UDP;
|
||||||
mNetStatus = RS_NET_UDP_SETUP;
|
//let's do a stun check
|
||||||
|
mNetStatus = RS_NET_DONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RS_NET_MODE_TRY_UPNP:
|
case RS_NET_MODE_TRY_UPNP:
|
||||||
@ -509,9 +504,8 @@ void p3ConnectMgr::netTick()
|
|||||||
// the computer is not yet connected to the internet. In such a case we
|
// the computer is not yet connected to the internet. In such a case we
|
||||||
// periodically check for a local net address.
|
// periodically check for a local net address.
|
||||||
//
|
//
|
||||||
|
|
||||||
// if(isLoopbackNet(&(ownState.localaddr.sin_addr)))
|
|
||||||
checkNetAddress() ;
|
checkNetAddress() ;
|
||||||
|
networkConsistencyCheck(); /* check consistency. If not consistent, do a reset inside networkConsistencyCheck() */
|
||||||
|
|
||||||
connMtx.lock(); /* LOCK MUTEX */
|
connMtx.lock(); /* LOCK MUTEX */
|
||||||
|
|
||||||
@ -550,18 +544,19 @@ void p3ConnectMgr::netTick()
|
|||||||
netUpnpCheck();
|
netUpnpCheck();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RS_NET_UDP_SETUP:
|
case RS_NET_EXT_ADDR_FINDER:
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::netTick() STATUS: UDP_SETUP" << std::endl;
|
std::cerr << "p3ConnectMgr::netTick() STATUS: RS_NET_EXT_ADDR_FINDER" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
netUdpCheck();
|
netExtraAddressCheck();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RS_NET_DONE:
|
case RS_NET_DONE:
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
//std::cerr << "p3ConnectMgr::netTick() STATUS: DONE" << std::endl;
|
//std::cerr << "p3ConnectMgr::netTick() STATUS: DONE" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
stunCheck(); /* Keep on stunning until its happy */
|
stunCheck(); /* Keep on stunning */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RS_NET_LOOPBACK:
|
case RS_NET_LOOPBACK:
|
||||||
@ -659,8 +654,7 @@ void p3ConnectMgr::netUpnpCheck()
|
|||||||
connMtx.lock(); /* LOCK MUTEX */
|
connMtx.lock(); /* LOCK MUTEX */
|
||||||
|
|
||||||
/* UPnP Failed us! */
|
/* UPnP Failed us! */
|
||||||
mUpnpAddrValid = false;
|
mNetStatus = RS_NET_DONE;
|
||||||
mNetStatus = RS_NET_UDP_SETUP;
|
|
||||||
|
|
||||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
}
|
}
|
||||||
@ -679,11 +673,8 @@ void p3ConnectMgr::netUpnpCheck()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
netFlagUpnpOk = true;
|
netFlagUpnpOk = true;
|
||||||
netFlagExtOk = true;
|
|
||||||
|
|
||||||
mUpnpAddrValid = true;
|
mNetStatus = RS_NET_DONE;
|
||||||
mUpnpExtAddr = extAddr;
|
|
||||||
mNetStatus = RS_NET_UDP_SETUP;
|
|
||||||
/* Fix netMode & Clear others! */
|
/* Fix netMode & Clear others! */
|
||||||
ownState.netMode = RS_NET_MODE_TRY_UPNP | RS_NET_MODE_UPNP;
|
ownState.netMode = RS_NET_MODE_TRY_UPNP | RS_NET_MODE_UPNP;
|
||||||
|
|
||||||
@ -691,140 +682,233 @@ void p3ConnectMgr::netUpnpCheck()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3ConnectMgr::netUdpCheck()
|
void p3ConnectMgr::networkConsistencyCheck()
|
||||||
{
|
{
|
||||||
|
//don't do a check if there is no local network
|
||||||
|
if (!netFlagLocalOk) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() don't check if there is no local network." << std::endl;
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t delta;
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::netUdpCheck()" << std::endl;
|
delta = time(NULL) - mNetInitTS;
|
||||||
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() time since last rest : " << delta << std::endl;
|
||||||
#endif
|
#endif
|
||||||
struct sockaddr_in tmpip ;
|
bool doNetReset = false;
|
||||||
|
//if one of the flag is degrated from true to false during last tick, let's do a reset
|
||||||
|
//storing old flags
|
||||||
|
// #ifdef CONN_DEBUG
|
||||||
|
// std::cerr << "p3ConnectMgr::networkConsistencyCheck() net flags : " << std::endl;
|
||||||
|
// std::cerr << " oldnetFlagLocalOk : " << oldnetFlagLocalOk << ". netFlagLocalOk : " << netFlagLocalOk << "." << std::endl;
|
||||||
|
// std::cerr << " oldnetFlagUpnpOk : " << oldnetFlagUpnpOk << ". netFlagUpnpOk : " << netFlagUpnpOk << "." << std::endl;
|
||||||
|
// std::cerr << " oldnetFlagDhtOk : " << oldnetFlagDhtOk << ". netFlagDhtOk : " << netFlagDhtOk << "." << std::endl;
|
||||||
|
// std::cerr << " oldnetFlagStunOk : " << oldnetFlagStunOk << ". netFlagStunOk : " << netFlagStunOk << "." << std::endl;
|
||||||
|
// std::cerr << " oldnetFlagExtraAddressCheckOk : " << oldnetFlagExtraAddressCheckOk << ". netFlagExtraAddressCheckOk : " << netFlagExtraAddressCheckOk << "." << std::endl;
|
||||||
|
// #endif
|
||||||
|
oldnetFlagLocalOk = netFlagLocalOk;
|
||||||
|
oldnetFlagUpnpOk = netFlagUpnpOk;
|
||||||
|
oldnetFlagDhtOk = netFlagDhtOk;
|
||||||
|
oldnetFlagStunOk = netFlagStunOk;
|
||||||
|
oldnetFlagExtraAddressCheckOk = netFlagExtraAddressCheckOk;
|
||||||
|
if ((!netFlagLocalOk && oldnetFlagLocalOk)
|
||||||
|
|| (!netFlagUpnpOk && oldnetFlagUpnpOk)
|
||||||
|
|| (!netFlagDhtOk && oldnetFlagDhtOk)
|
||||||
|
|| (!netFlagStunOk && oldnetFlagStunOk)
|
||||||
|
|| (!netFlagExtraAddressCheckOk && oldnetFlagExtraAddressCheckOk)
|
||||||
|
) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() A net flag went down." << std::endl;
|
||||||
|
#endif
|
||||||
|
doNetReset = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
connMtx.lock(); /* LOCK MUTEX */
|
||||||
|
//storing old flags
|
||||||
|
oldnetFlagLocalOk = netFlagLocalOk;
|
||||||
|
oldnetFlagUpnpOk = netFlagUpnpOk;
|
||||||
|
oldnetFlagDhtOk = netFlagDhtOk;
|
||||||
|
oldnetFlagStunOk = netFlagStunOk;
|
||||||
|
oldnetFlagExtraAddressCheckOk = netFlagExtraAddressCheckOk;
|
||||||
|
|
||||||
if (udpExtAddressCheck() || (mUpnpAddrValid) || (use_extr_addr_finder && mExtAddrFinder->hasValidIP(&tmpip)))
|
//if ip adresses are different, let's use the stun address, then the extaddrfinder and then the upnp address.
|
||||||
{
|
struct sockaddr_in extAddr;
|
||||||
bool extValid = false;
|
if (getStunExtAddress(extAddr)) {
|
||||||
bool extAddrStable = false;
|
#ifdef CONN_DEBUG
|
||||||
struct sockaddr_in extAddr;
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() using STUN for ownState.serveraddr." << std::endl;
|
||||||
uint32_t mode = 0;
|
#endif
|
||||||
|
ownState.serveraddr = extAddr;
|
||||||
connMtx.lock(); /* LOCK MUTEX */
|
} else if (getExtFinderExtAddress(extAddr)) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
mNetStatus = RS_NET_DONE;
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() using External address finder for ownState.serveraddr." << std::endl;
|
||||||
|
#endif
|
||||||
/* get the addr from the configuration */
|
ownState.serveraddr = extAddr;
|
||||||
struct sockaddr_in iaddr = ownState.localaddr;
|
} else if (getUpnpExtAddress(extAddr)) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
if (mUpnpAddrValid)
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() using UPNP for ownState.serveraddr." << std::endl;
|
||||||
{
|
#endif
|
||||||
extValid = true;
|
ownState.serveraddr = extAddr;
|
||||||
extAddr = mUpnpExtAddr;
|
|
||||||
extAddrStable = true;
|
|
||||||
}
|
|
||||||
else if (mStunAddrValid)
|
|
||||||
{
|
|
||||||
extValid = true;
|
|
||||||
extAddr = mStunExtAddr;
|
|
||||||
extAddrStable = mStunAddrStable;
|
|
||||||
}
|
|
||||||
else if(use_extr_addr_finder && mExtAddrFinder->hasValidIP(&tmpip))
|
|
||||||
{
|
|
||||||
extValid = true;
|
|
||||||
extAddr = tmpip ;
|
|
||||||
extAddr.sin_port = iaddr.sin_port ;
|
|
||||||
extAddrStable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extValid)
|
|
||||||
{
|
|
||||||
ownState.serveraddr = extAddr;
|
|
||||||
mode = RS_NET_CONN_TCP_LOCAL;
|
|
||||||
|
|
||||||
if (!extAddrStable)
|
|
||||||
{
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "p3ConnectMgr::netUdpCheck() UDP Unstable :( ";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
std::cerr << "p3ConnectMgr::netUdpCheck() We are unreachable";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
std::cerr << "netMode => RS_NET_MODE_UNREACHABLE";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
ownState.netMode &= ~(RS_NET_MODE_ACTUAL);
|
|
||||||
ownState.netMode |= RS_NET_MODE_UNREACHABLE;
|
|
||||||
|
|
||||||
/* send a system warning message */
|
|
||||||
pqiNotify *notify = getPqiNotify();
|
|
||||||
if (notify)
|
|
||||||
{
|
|
||||||
std::string title =
|
|
||||||
"Warning: Bad Firewall Configuration";
|
|
||||||
|
|
||||||
std::string msg;
|
|
||||||
msg += " **** WARNING **** \n";
|
|
||||||
msg += "Retroshare has detected that you are behind";
|
|
||||||
msg += " a restrictive Firewall\n";
|
|
||||||
msg += "\n";
|
|
||||||
msg += "You cannot connect to other firewalled peers\n";
|
|
||||||
msg += "\n";
|
|
||||||
msg += "You can fix this by:\n";
|
|
||||||
msg += " (1) opening an External Port\n";
|
|
||||||
msg += " (2) enabling UPnP, or\n";
|
|
||||||
msg += " (3) get a new (approved) Firewall/Router\n";
|
|
||||||
|
|
||||||
notify->AddSysMessage(0, RS_SYS_WARNING, title, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (mUpnpAddrValid || (ownState.netMode & RS_NET_MODE_EXT))
|
|
||||||
{
|
|
||||||
mode |= RS_NET_CONN_TCP_EXTERNAL;
|
|
||||||
mode |= RS_NET_CONN_UDP_DHT_SYNC;
|
|
||||||
}
|
|
||||||
else // if (extAddrStable)
|
|
||||||
{
|
|
||||||
/* Check if extAddr == intAddr (Not Firewalled) */
|
|
||||||
if ((0 == inaddr_cmp(iaddr, extAddr)) &&
|
|
||||||
isExternalNet(&(extAddr.sin_addr)))
|
|
||||||
{
|
|
||||||
mode |= RS_NET_CONN_TCP_EXTERNAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
mode |= RS_NET_CONN_UDP_DHT_SYNC;
|
|
||||||
}
|
|
||||||
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
||||||
}
|
|
||||||
|
|
||||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
|
||||||
|
|
||||||
if (extValid)
|
|
||||||
{
|
|
||||||
netAssistSetAddress(iaddr, extAddr, mode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* mode = 0 for error */
|
|
||||||
netAssistSetAddress(iaddr, extAddr, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* flag unreachables! */
|
|
||||||
if ((extValid) && (!extAddrStable))
|
|
||||||
{
|
|
||||||
netUnreachableCheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//don't do a reset it if the udp init is not finished
|
#ifdef CONN_DEBUG
|
||||||
time_t delta = time(NULL) - mNetInitTS;
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() no external ip address." << std::endl;
|
||||||
#ifdef CONN_DEBUG
|
#endif
|
||||||
std::cerr << "p3ConnectMgr time since last reset : " << delta << std::endl;
|
doNetReset = true;
|
||||||
#endif
|
}
|
||||||
if (delta > MAX_UDP_INIT) {
|
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "we got no external ip address from udp stun, let's do a network reset." << delta << std::endl;
|
|
||||||
#endif
|
//if there is no external ip address, let's do a net reset
|
||||||
|
if (doNetReset) {
|
||||||
|
//don't do a reset it if the network init is not finished
|
||||||
|
delta = time(NULL) - mNetInitTS;
|
||||||
|
if (delta > MAX_NETWORK_INIT) {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() doing a net reset." << std::endl;
|
||||||
|
#endif
|
||||||
netReset();
|
netReset();
|
||||||
|
} else {
|
||||||
|
#ifdef CONN_DEBUG
|
||||||
|
std::cerr << "p3ConnectMgr::networkConsistencyCheck() reset delayed : p3ConnectMgr time since last reset : " << delta;
|
||||||
|
std::cerr << ". Cannot reset before : " << MAX_NETWORK_INIT << " sec" << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// struct sockaddr_in tmpip ;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if (udpExtAddressCheck() || (mUpnpAddrValid) || (use_extr_addr_finder && mExtAddrFinder->hasValidIP(&tmpip)))
|
||||||
|
// {
|
||||||
|
// bool extValid = false;
|
||||||
|
// bool extAddrStable = false;
|
||||||
|
// struct sockaddr_in extAddr;
|
||||||
|
// uint32_t mode = 0;
|
||||||
|
//
|
||||||
|
// connMtx.lock(); /* LOCK MUTEX */
|
||||||
|
//
|
||||||
|
// mNetStatus = RS_NET_DONE;
|
||||||
|
//
|
||||||
|
// /* get the addr from the configuration */
|
||||||
|
// struct sockaddr_in iaddr = ownState.localaddr;
|
||||||
|
//
|
||||||
|
// if (mUpnpAddrValid)
|
||||||
|
// {
|
||||||
|
// extValid = true;
|
||||||
|
// extAddr = mUpnpExtAddr;
|
||||||
|
// extAddrStable = true;
|
||||||
|
// }
|
||||||
|
// else if (mStunAddrValid)
|
||||||
|
// {
|
||||||
|
// extValid = true;
|
||||||
|
// extAddr = mStunExtAddr;
|
||||||
|
// extAddrStable = mStunAddrStable;
|
||||||
|
// }
|
||||||
|
// else if(use_extr_addr_finder && mExtAddrFinder->hasValidIP(&tmpip))
|
||||||
|
// {
|
||||||
|
// extValid = true;
|
||||||
|
// extAddr = tmpip ;
|
||||||
|
// extAddr.sin_port = iaddr.sin_port ;
|
||||||
|
// extAddrStable = true;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (extValid)
|
||||||
|
// {
|
||||||
|
// ownState.serveraddr = extAddr;
|
||||||
|
// mode = RS_NET_CONN_TCP_LOCAL;
|
||||||
|
//
|
||||||
|
// if (!extAddrStable)
|
||||||
|
// {
|
||||||
|
//#ifdef CONN_DEBUG
|
||||||
|
// std::cerr << "p3ConnectMgr::netUdpCheck() UDP Unstable :( ";
|
||||||
|
// std::cerr << std::endl;
|
||||||
|
// std::cerr << "p3ConnectMgr::netUdpCheck() We are unreachable";
|
||||||
|
// std::cerr << std::endl;
|
||||||
|
// std::cerr << "netMode => RS_NET_MODE_UNREACHABLE";
|
||||||
|
// std::cerr << std::endl;
|
||||||
|
//#endif
|
||||||
|
// ownState.netMode &= ~(RS_NET_MODE_ACTUAL);
|
||||||
|
// ownState.netMode |= RS_NET_MODE_UNREACHABLE;
|
||||||
|
//
|
||||||
|
// /* send a system warning message */
|
||||||
|
// pqiNotify *notify = getPqiNotify();
|
||||||
|
// if (notify)
|
||||||
|
// {
|
||||||
|
// std::string title =
|
||||||
|
// "Warning: Bad Firewall Configuration";
|
||||||
|
//
|
||||||
|
// std::string msg;
|
||||||
|
// msg += " **** WARNING **** \n";
|
||||||
|
// msg += "Retroshare has detected that you are behind";
|
||||||
|
// msg += " a restrictive Firewall\n";
|
||||||
|
// msg += "\n";
|
||||||
|
// msg += "You cannot connect to other firewalled peers\n";
|
||||||
|
// msg += "\n";
|
||||||
|
// msg += "You can fix this by:\n";
|
||||||
|
// msg += " (1) opening an External Port\n";
|
||||||
|
// msg += " (2) enabling UPnP, or\n";
|
||||||
|
// msg += " (3) get a new (approved) Firewall/Router\n";
|
||||||
|
//
|
||||||
|
// notify->AddSysMessage(0, RS_SYS_WARNING, title, msg);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// else if (mUpnpAddrValid || (ownState.netMode & RS_NET_MODE_EXT))
|
||||||
|
// {
|
||||||
|
// mode |= RS_NET_CONN_TCP_EXTERNAL;
|
||||||
|
// mode |= RS_NET_CONN_UDP_DHT_SYNC;
|
||||||
|
// }
|
||||||
|
// else // if (extAddrStable)
|
||||||
|
// {
|
||||||
|
// /* Check if extAddr == intAddr (Not Firewalled) */
|
||||||
|
// if ((0 == inaddr_cmp(iaddr, extAddr)) &&
|
||||||
|
// isExternalNet(&(extAddr.sin_addr)))
|
||||||
|
// {
|
||||||
|
// mode |= RS_NET_CONN_TCP_EXTERNAL;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// mode |= RS_NET_CONN_UDP_DHT_SYNC;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// connMtx.unlock(); /* UNLOCK MUTEX */
|
||||||
|
//
|
||||||
|
// netAssistSetAddress(iaddr, extAddr, mode);
|
||||||
|
//
|
||||||
|
// /* flag unreachables! */
|
||||||
|
// if ((extValid) && (!extAddrStable))
|
||||||
|
// {
|
||||||
|
// netUnreachableCheck();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// //don't do a reset it if the udp init is not finished
|
||||||
|
// time_t delta = time(NULL) - mNetInitTS;
|
||||||
|
// #ifdef CONN_DEBUG
|
||||||
|
// std::cerr << "p3ConnectMgr time since last reset : " << delta << std::endl;
|
||||||
|
// #endif
|
||||||
|
// if (delta > MAX_UDP_INIT) {
|
||||||
|
// #ifdef CONN_DEBUG
|
||||||
|
// std::cerr << "we got no external ip address from udp stun, let's do a network reset." << delta << std::endl;
|
||||||
|
// #endif
|
||||||
|
// netReset();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3ConnectMgr::netExtraAddressCheck()
|
||||||
|
{ struct sockaddr_in tmpip;
|
||||||
|
if (use_extr_addr_finder && mExtAddrFinder->hasValidIP(&tmpip)) {
|
||||||
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
netFlagExtraAddressCheckOk = true;
|
||||||
|
} else {
|
||||||
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
netFlagExtraAddressCheckOk = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3ConnectMgr::netUnreachableCheck()
|
void p3ConnectMgr::netUnreachableCheck()
|
||||||
@ -905,59 +989,6 @@ void p3ConnectMgr::netUnreachableCheck()
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool p3ConnectMgr::udpInternalAddress(struct sockaddr_in iaddr)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool p3ConnectMgr::udpExtAddressCheck()
|
|
||||||
{
|
|
||||||
/* three possibilities:
|
|
||||||
* (1) not found yet.
|
|
||||||
* (2) Found!
|
|
||||||
* (3) bad udp (port switching).
|
|
||||||
*/
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
socklen_t len = sizeof(addr);
|
|
||||||
uint8_t stable;
|
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "p3ConnectMgr::udpExtAddressCheck()" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (0 < tou_extaddr((struct sockaddr *) &addr, &len, &stable))
|
|
||||||
{
|
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
|
||||||
|
|
||||||
|
|
||||||
/* update UDP information */
|
|
||||||
mStunExtAddr = addr;
|
|
||||||
mStunAddrValid = true;
|
|
||||||
mStunAddrStable = (stable != 0);
|
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "p3ConnectMgr::udpExtAddressCheck() Got ";
|
|
||||||
std::cerr << " addr: " << inet_ntoa(mStunExtAddr.sin_addr);
|
|
||||||
std::cerr << ":" << ntohs(mStunExtAddr.sin_port);
|
|
||||||
std::cerr << " stable: " << mStunAddrStable;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* update net Status flags ....
|
|
||||||
* we've got stun information via udp...
|
|
||||||
* so up is okay, and ext address is known stable or not.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (mStunAddrStable) {
|
|
||||||
netFlagExtOk = true;
|
|
||||||
netFlagUdpOk = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void p3ConnectMgr::udpStunPeer(std::string id, struct sockaddr_in &addr)
|
void p3ConnectMgr::udpStunPeer(std::string id, struct sockaddr_in &addr)
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
@ -1017,7 +1048,6 @@ bool p3ConnectMgr::stunCheck()
|
|||||||
/* check udp address stability */
|
/* check udp address stability */
|
||||||
|
|
||||||
bool netDone = false;
|
bool netDone = false;
|
||||||
bool doNetReset = false;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
@ -1027,106 +1057,68 @@ bool p3ConnectMgr::stunCheck()
|
|||||||
|
|
||||||
struct sockaddr_in raddr;
|
struct sockaddr_in raddr;
|
||||||
socklen_t rlen = sizeof(raddr);
|
socklen_t rlen = sizeof(raddr);
|
||||||
struct sockaddr_in eaddr;
|
|
||||||
socklen_t elen = sizeof(eaddr);
|
|
||||||
uint8_t stable;
|
uint8_t stable;
|
||||||
uint32_t failCount;
|
|
||||||
time_t lastSent;
|
|
||||||
time_t now = time(NULL);
|
|
||||||
|
|
||||||
if (netDone)
|
if (netDone)
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "NetSetupDone: Checking if network is same" << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (0 < tou_extaddr((struct sockaddr *) &raddr, &rlen, &stable))
|
if (0 < tou_extaddr((struct sockaddr *) &raddr, &rlen, &stable))
|
||||||
{
|
{
|
||||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
mStunAddrStable = (stable != 0);
|
|
||||||
|
|
||||||
if ((mStunExtAddr.sin_addr.s_addr != raddr.sin_addr.s_addr) ||
|
|
||||||
(mStunAddrStable != true))
|
|
||||||
{
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "mStunExtAddr.sin_addr.s_addr : " << inet_ntoa(mStunExtAddr.sin_addr) << std::endl;
|
std::cerr << "mStunExtAddr.sin_addr.s_addr : " << inet_ntoa(mStunExtAddr.sin_addr) << std::endl;
|
||||||
std::cerr << "raddr.sin_addr.s_addr : " << inet_ntoa(raddr.sin_addr) << std::endl;
|
std::cerr << "raddr.sin_addr.s_addr : " << inet_ntoa(raddr.sin_addr) << std::endl;
|
||||||
std::cerr << "mStunAddrStable : " << mStunAddrStable << std::endl;
|
std::cerr << "stable : " << stable << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
doNetReset = true;
|
if ((mStunExtAddr.sin_addr.s_addr != raddr.sin_addr.s_addr) ||
|
||||||
|
(stable == 0))
|
||||||
|
{
|
||||||
|
netFlagStunOk = false;
|
||||||
|
mStunExtAddr = raddr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
netFlagUdpOk = true;
|
netFlagStunOk = true;
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "Ext Address Same: ok!" << std::endl;
|
std::cerr << "p3ConnectMgr::stunCheck() Stun ext : ok !" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
netFlagStunOk = false;
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "Stun : No Ext Address. Checking upnp ext address." << std::endl;
|
std::cerr << "p3ConnectMgr::stunCheck() Stun : No Ext Address." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
struct sockaddr_in extAddr;
|
|
||||||
bool upnpExtAdress = netAssistExtAddress(extAddr);
|
|
||||||
if (upnpExtAdress) {
|
|
||||||
//don't do a reset
|
|
||||||
mStunExtAddr = extAddr;
|
|
||||||
netFlagUdpOk = false;
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "Found upnp Ext Address. don't do a reset." << std::endl;
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "No upnp Ext Address. doing a reset." << std::endl;
|
|
||||||
#endif
|
|
||||||
doNetReset = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doNetReset)
|
//#ifdef CONN_DEBUG
|
||||||
{
|
// uint32_t failCount;
|
||||||
#ifdef CONN_DEBUG
|
// time_t lastSent;
|
||||||
std::cerr << "Stun trying to reeset Network" << std::endl;
|
// time_t now = time(NULL);
|
||||||
#endif
|
// struct sockaddr_in eaddr;
|
||||||
|
// socklen_t elen = sizeof(eaddr);
|
||||||
//don't do a reset it if the udp init is not finished
|
// int i = 0;
|
||||||
time_t delta = time(NULL) - mNetInitTS;
|
// for(i = 0; tou_getstunpeer(i, (struct sockaddr *) &raddr, &rlen,
|
||||||
#ifdef CONN_DEBUG
|
// (struct sockaddr *) &eaddr, &elen,
|
||||||
std::cerr << "p3ConnectMgr time since last reset : " << delta << std::endl;
|
// &failCount, &lastSent); i++)
|
||||||
#endif
|
// {
|
||||||
if (delta > MAX_UDP_INIT) {
|
// std::cerr << "STUN PEERS: ";
|
||||||
//stun failed let's do a network reset
|
// std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
|
||||||
netReset();
|
// std::cerr << " eaddr: " << inet_ntoa(eaddr.sin_addr) << ":" << ntohs(eaddr.sin_port);
|
||||||
} else {
|
// if (lastSent)
|
||||||
doNetReset = false;;
|
// {
|
||||||
}
|
// std::cerr << " failCount: " << failCount << " lastSent: " << now-lastSent;
|
||||||
}
|
// }
|
||||||
|
// else
|
||||||
#ifdef CONN_DEBUG
|
// {
|
||||||
int i = 0;
|
// std::cerr << " Unused ";
|
||||||
for(i = 0; tou_getstunpeer(i, (struct sockaddr *) &raddr, &rlen,
|
// }
|
||||||
(struct sockaddr *) &eaddr, &elen,
|
// std::cerr << std::endl;
|
||||||
&failCount, &lastSent); i++)
|
// }
|
||||||
{
|
//#endif
|
||||||
std::cerr << "STUN PEERS: ";
|
|
||||||
std::cerr << " raddr: " << inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
|
|
||||||
std::cerr << " eaddr: " << inet_ntoa(eaddr.sin_addr) << ":" << ntohs(eaddr.sin_port);
|
|
||||||
if (lastSent)
|
|
||||||
{
|
|
||||||
std::cerr << " failCount: " << failCount << " lastSent: " << now-lastSent;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << " Unused ";
|
|
||||||
}
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* pass on udp status to dht */
|
/* pass on udp status to dht */
|
||||||
if (tou_needstunpeers())
|
if (tou_needstunpeers())
|
||||||
@ -3055,11 +3047,6 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
|
|||||||
|
|
||||||
bool p3ConnectMgr::checkNetAddress()
|
bool p3ConnectMgr::checkNetAddress()
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "p3ConnectMgr::checkNetAddress()";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::list<std::string> addrs = getLocalInterfaces();
|
std::list<std::string> addrs = getLocalInterfaces();
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
|
|
||||||
@ -3072,10 +3059,10 @@ bool p3ConnectMgr::checkNetAddress()
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
for(it = addrs.begin(); (!found) && (it != addrs.end()); it++)
|
for(it = addrs.begin(); (!found) && (it != addrs.end()); it++)
|
||||||
{
|
{
|
||||||
#ifdef CONN_DEBUG
|
// #ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::checkNetAddress() Local Interface: " << *it;
|
// std::cerr << "p3ConnectMgr::checkNetAddress() Local Interface: " << *it;
|
||||||
std::cerr << std::endl;
|
// std::cerr << std::endl;
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
// Ive added the 'isNotLoopbackNet' to prevent re-using the lo address if this was saved in the
|
// Ive added the 'isNotLoopbackNet' to prevent re-using the lo address if this was saved in the
|
||||||
// configuration. In such a case, lo should only be chosen from getPreferredInterface as a last resort
|
// configuration. In such a case, lo should only be chosen from getPreferredInterface as a last resort
|
||||||
@ -3084,12 +3071,12 @@ bool p3ConnectMgr::checkNetAddress()
|
|||||||
if ((!isLoopbackNet(&ownState.localaddr.sin_addr)) && (*it) == inet_ntoa(ownState.localaddr.sin_addr))
|
if ((!isLoopbackNet(&ownState.localaddr.sin_addr)) && (*it) == inet_ntoa(ownState.localaddr.sin_addr))
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
if (netFlagOk != true) {
|
if (netFlagLocalOk != true) {
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::checkNetAddress() changing netFlagOk to true.";
|
std::cerr << "p3ConnectMgr::checkNetAddress() changing netFlagOk to true.";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
netFlagOk = true;
|
netFlagLocalOk = true;
|
||||||
IndicateConfigChanged();
|
IndicateConfigChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3104,11 +3091,11 @@ bool p3ConnectMgr::checkNetAddress()
|
|||||||
{
|
{
|
||||||
ownState.localaddr.sin_addr = getPreferredInterface();
|
ownState.localaddr.sin_addr = getPreferredInterface();
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
// #ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::checkNetAddress() Local Address Not Found: Using Preferred Interface: ";
|
// std::cerr << "p3ConnectMgr::checkNetAddress() Local Address Not Found: Using Preferred Interface: ";
|
||||||
std::cerr << inet_ntoa(ownState.localaddr.sin_addr);
|
// std::cerr << inet_ntoa(ownState.localaddr.sin_addr);
|
||||||
std::cerr << std::endl;
|
// std::cerr << std::endl;
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||||
|
|
||||||
@ -3140,23 +3127,17 @@ bool p3ConnectMgr::checkNetAddress()
|
|||||||
ownState.localaddr.sin_family = AF_INET;
|
ownState.localaddr.sin_family = AF_INET;
|
||||||
ownState.serveraddr.sin_family = AF_INET;
|
ownState.serveraddr.sin_family = AF_INET;
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
// #ifdef CONN_DEBUG
|
||||||
std::cerr << "p3ConnectMgr::checkNetAddress() Final Local Address: ";
|
// std::cerr << "p3ConnectMgr::checkNetAddress() Final Local Address: ";
|
||||||
std::cerr << inet_ntoa(ownState.localaddr.sin_addr);
|
// std::cerr << inet_ntoa(ownState.localaddr.sin_addr);
|
||||||
std::cerr << ":" << ntohs(ownState.localaddr.sin_port);
|
// std::cerr << ":" << ntohs(ownState.localaddr.sin_port);
|
||||||
std::cerr << std::endl;
|
// std::cerr << std::endl;
|
||||||
#endif
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONN_DEBUG
|
|
||||||
std::cerr << "old_in_addr : " << old_in_addr << std::endl;
|
|
||||||
std::cerr << "ownState.localaddr.sin_addr.s_addr : " << ownState.localaddr.sin_addr.s_addr << std::endl;
|
|
||||||
std::cerr << "old_in_port : " << old_in_port << std::endl;
|
|
||||||
std::cerr << "ownState.localaddr.sin_port : " << ownState.localaddr.sin_port << std::endl;
|
|
||||||
#endif
|
|
||||||
if ((old_in_addr != ownState.localaddr.sin_addr.s_addr) || (old_in_port != ownState.localaddr.sin_port)) {
|
if ((old_in_addr != ownState.localaddr.sin_addr.s_addr) || (old_in_port != ownState.localaddr.sin_port)) {
|
||||||
#ifdef CONN_DEBUG
|
#ifdef CONN_DEBUG
|
||||||
std::cerr << "local address changed, resetting network." << std::endl;
|
std::cerr << "p3ConnectMgr::checkNetAddress() local address changed, resetting network." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
//local address changed, resetting network
|
//local address changed, resetting network
|
||||||
netReset();
|
netReset();
|
||||||
@ -3619,11 +3600,9 @@ bool p3ConnectMgr::getDHTEnabled()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool p3ConnectMgr::getNetStatusLocalOk()
|
||||||
bool p3ConnectMgr::getNetStatusOk()
|
|
||||||
{
|
{
|
||||||
std::cerr << "netFlagOk : " << netFlagOk << std::endl;
|
return netFlagLocalOk;
|
||||||
return netFlagOk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ConnectMgr::getNetStatusUpnpOk()
|
bool p3ConnectMgr::getNetStatusUpnpOk()
|
||||||
@ -3636,25 +3615,44 @@ bool p3ConnectMgr::getNetStatusDhtOk()
|
|||||||
return netFlagDhtOk;
|
return netFlagDhtOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ConnectMgr::getNetStatusExtOk()
|
bool p3ConnectMgr::getNetStatusStunOk()
|
||||||
{
|
{
|
||||||
return netFlagExtOk;
|
return netFlagStunOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ConnectMgr::getNetStatusUdpOk()
|
bool p3ConnectMgr::getNetStatusExtraAddressCheckOk()
|
||||||
{
|
{
|
||||||
return netFlagUdpOk;
|
return netFlagExtraAddressCheckOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ConnectMgr::getNetStatusTcpOk()
|
bool p3ConnectMgr::getUpnpExtAddress(struct sockaddr_in &addr) {
|
||||||
{
|
return netAssistExtAddress(addr);
|
||||||
return netFlagTcpOk;
|
}
|
||||||
|
|
||||||
|
bool p3ConnectMgr::getStunExtAddress(struct sockaddr_in &addr) {
|
||||||
|
struct sockaddr_in temp_addr;
|
||||||
|
socklen_t len = sizeof(temp_addr);
|
||||||
|
uint8_t stable;
|
||||||
|
|
||||||
|
if (0 < tou_extaddr((struct sockaddr *) &temp_addr, &len, &stable))
|
||||||
|
{
|
||||||
|
addr = temp_addr;
|
||||||
|
|
||||||
|
//#ifdef CONN_DEBUG
|
||||||
|
// std::cerr << "p3ConnectMgr::getStunExtAddress() Got ";
|
||||||
|
// std::cerr << " addr: " << inet_ntoa(addr.sin_addr);
|
||||||
|
// std::cerr << ":" << ntohs(addr.sin_port);
|
||||||
|
// std::cerr << std::endl;
|
||||||
|
//#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//#ifdef CONN_DEBUG
|
||||||
|
// std::cerr << "p3ConnectMgr::getStunExtAddress() No ext address found." << std::endl;
|
||||||
|
//#endif
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3ConnectMgr::getNetResetReq()
|
bool p3ConnectMgr::getExtFinderExtAddress(struct sockaddr_in &addr) {
|
||||||
{
|
return (use_extr_addr_finder && mExtAddrFinder->hasValidIP(&addr));
|
||||||
return netFlagResetReq;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -194,13 +194,11 @@ bool getIPServersEnabled() { return use_extr_addr_finder ;}
|
|||||||
void setIPServersEnabled(bool b) ;
|
void setIPServersEnabled(bool b) ;
|
||||||
void getIPServersList(std::list<std::string>& ip_servers) ;
|
void getIPServersList(std::list<std::string>& ip_servers) ;
|
||||||
|
|
||||||
bool getNetStatusOk();
|
bool getNetStatusLocalOk();
|
||||||
bool getNetStatusUpnpOk();
|
bool getNetStatusUpnpOk();
|
||||||
bool getNetStatusDhtOk();
|
bool getNetStatusDhtOk();
|
||||||
bool getNetStatusExtOk();
|
bool getNetStatusStunOk();
|
||||||
bool getNetStatusUdpOk();
|
bool getNetStatusExtraAddressCheckOk();
|
||||||
bool getNetStatusTcpOk();
|
|
||||||
bool getNetResetReq();
|
|
||||||
|
|
||||||
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
|
||||||
bool setLocalAddress(std::string id, struct sockaddr_in addr);
|
bool setLocalAddress(std::string id, struct sockaddr_in addr);
|
||||||
@ -299,12 +297,10 @@ void netExtCheck();
|
|||||||
void netUpnpInit();
|
void netUpnpInit();
|
||||||
void netUpnpCheck();
|
void netUpnpCheck();
|
||||||
|
|
||||||
void netUdpCheck();
|
void netExtraAddressCheck();
|
||||||
void netUnreachableCheck();
|
void netUnreachableCheck();
|
||||||
|
|
||||||
/* Udp / Stun functions */
|
/* Udp / Stun functions */
|
||||||
bool udpInternalAddress(struct sockaddr_in iaddr);
|
|
||||||
bool udpExtAddressCheck();
|
|
||||||
void udpStunPeer(std::string id, struct sockaddr_in &addr);
|
void udpStunPeer(std::string id, struct sockaddr_in &addr);
|
||||||
|
|
||||||
void stunInit();
|
void stunInit();
|
||||||
@ -312,6 +308,8 @@ bool stunCheck();
|
|||||||
void stunCollect(std::string id, struct sockaddr_in addr, uint32_t flags);
|
void stunCollect(std::string id, struct sockaddr_in addr, uint32_t flags);
|
||||||
bool addBootstrapStunPeers();
|
bool addBootstrapStunPeers();
|
||||||
|
|
||||||
|
void networkConsistencyCheck();
|
||||||
|
|
||||||
/* monitor control */
|
/* monitor control */
|
||||||
void tickMonitors();
|
void tickMonitors();
|
||||||
|
|
||||||
@ -319,6 +317,10 @@ void tickMonitors();
|
|||||||
bool retryConnectTCP(std::string id);
|
bool retryConnectTCP(std::string id);
|
||||||
bool retryConnectNotify(std::string id);
|
bool retryConnectNotify(std::string id);
|
||||||
|
|
||||||
|
bool getUpnpExtAddress(struct sockaddr_in &addr);
|
||||||
|
bool getStunExtAddress(struct sockaddr_in &addr);
|
||||||
|
bool getExtFinderExtAddress(struct sockaddr_in &addr);
|
||||||
|
|
||||||
/* temporary for testing */
|
/* temporary for testing */
|
||||||
//virtual void loadConfiguration() { return; }
|
//virtual void loadConfiguration() { return; }
|
||||||
|
|
||||||
@ -365,24 +367,25 @@ private:
|
|||||||
bool use_extr_addr_finder ;
|
bool use_extr_addr_finder ;
|
||||||
|
|
||||||
/* external Address determination */
|
/* external Address determination */
|
||||||
bool mUpnpAddrValid, mStunAddrValid;
|
//bool mUpnpAddrValid, mStunAddrValid;
|
||||||
bool mStunAddrStable;
|
//bool mStunAddrStable;
|
||||||
struct sockaddr_in mUpnpExtAddr;
|
//struct sockaddr_in mUpnpExtAddr;
|
||||||
struct sockaddr_in mStunExtAddr;
|
struct sockaddr_in mStunExtAddr;
|
||||||
|
|
||||||
/* network status flags (read by rsiface) */
|
/* network status flags (read by rsiface) */
|
||||||
bool netFlagOk;
|
bool netFlagLocalOk;
|
||||||
bool netFlagUpnpOk;
|
bool netFlagUpnpOk;
|
||||||
bool netFlagDhtOk;
|
bool netFlagDhtOk;
|
||||||
bool netFlagExtOk;
|
bool netFlagStunOk;
|
||||||
bool netFlagUdpOk;
|
bool netFlagExtraAddressCheckOk;
|
||||||
bool netFlagResetReq;
|
|
||||||
|
|
||||||
//tcp connection test is not implemented
|
/* old network status flags in order to detect changes */
|
||||||
bool netFlagTcpOk;
|
bool oldnetFlagLocalOk;
|
||||||
|
bool oldnetFlagUpnpOk;
|
||||||
|
bool oldnetFlagDhtOk;
|
||||||
|
bool oldnetFlagStunOk;
|
||||||
|
bool oldnetFlagExtraAddressCheckOk;
|
||||||
|
|
||||||
|
|
||||||
/* these are protected for testing */
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void addPeer(std::string id, std::string name); /* tmp fn */
|
void addPeer(std::string id, std::string name); /* tmp fn */
|
||||||
@ -395,7 +398,3 @@ void addPeer(std::string id, std::string name); /* tmp fn */
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif // MRK_PQI_CONNECTION_MANAGER_HEADER
|
#endif // MRK_PQI_CONNECTION_MANAGER_HEADER
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,13 +140,11 @@ class RsConfig
|
|||||||
int DHTPeers;
|
int DHTPeers;
|
||||||
|
|
||||||
/* Flags for Network Status */
|
/* Flags for Network Status */
|
||||||
bool netOk; /* That we've talked to someone! */
|
bool netLocalOk; /* That we've talked to someone! */
|
||||||
bool netUpnpOk; /* upnp is enabled and active */
|
bool netUpnpOk; /* upnp is enabled and active */
|
||||||
bool netDhtOk; /* response from dht */
|
bool netDhtOk; /* response from dht */
|
||||||
bool netExtOk; /* know our external address */
|
bool netStunOk; /* recvd stun / udp packets */
|
||||||
bool netUdpOk; /* recvd stun / udp packets */
|
bool netExtraAddressOk; /* recvd ip address with external finder*/
|
||||||
//bool netTcpOk; /* recvd incoming tcp */
|
|
||||||
bool netResetReq;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/********************** For Search Interface *****************/
|
/********************** For Search Interface *****************/
|
||||||
|
@ -125,12 +125,11 @@ int RsServer::UpdateAllConfig()
|
|||||||
|
|
||||||
/* update network configuration */
|
/* update network configuration */
|
||||||
|
|
||||||
config.netOk = mConnMgr->getNetStatusOk();
|
config.netLocalOk = mConnMgr->getNetStatusLocalOk();
|
||||||
config.netUpnpOk = mConnMgr->getNetStatusUpnpOk();
|
config.netUpnpOk = mConnMgr->getNetStatusUpnpOk();
|
||||||
config.netDhtOk = mConnMgr->getNetStatusDhtOk();
|
config.netDhtOk = mConnMgr->getNetStatusDhtOk();
|
||||||
config.netExtOk = mConnMgr->getNetStatusExtOk();
|
config.netStunOk = mConnMgr->getNetStatusStunOk();
|
||||||
config.netUdpOk = mConnMgr->getNetStatusUdpOk();
|
config.netExtraAddressOk = mConnMgr->getNetStatusExtraAddressCheckOk();
|
||||||
//config.netTcpOk = mConnMgr->getNetStatusTcpOk();
|
|
||||||
|
|
||||||
/* update DHT/UPnP config */
|
/* update DHT/UPnP config */
|
||||||
|
|
||||||
|
@ -338,14 +338,18 @@ bool UdpSorter::externalAddr(struct sockaddr_in &external, uint8_t &stable)
|
|||||||
else
|
else
|
||||||
stable = 0;
|
stable = 0;
|
||||||
|
|
||||||
|
#ifdef DEBUG_UDP_SORTER
|
||||||
std::cerr << "UdpSorter::externalAddr() eaddr:" << inet_ntoa(external.sin_addr);
|
std::cerr << "UdpSorter::externalAddr() eaddr:" << inet_ntoa(external.sin_addr);
|
||||||
std::cerr << ":" << ntohs(external.sin_port) << " stable: " << (int) stable;
|
std::cerr << ":" << ntohs(external.sin_port) << " stable: " << (int) stable;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_UDP_SORTER
|
||||||
std::cerr << "UdpSorter::externalAddr() eaddr unknown";
|
std::cerr << "UdpSorter::externalAddr() eaddr unknown";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -735,52 +735,40 @@ void NetworkDialog::getNetworkStatus()
|
|||||||
|
|
||||||
if(config.netDhtOk)
|
if(config.netDhtOk)
|
||||||
{
|
{
|
||||||
setLogInfo(tr("DHT OK"), QString::fromUtf8("green"));
|
setLogInfo(tr("DHT OK."), QString::fromUtf8("green"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setLogInfo(tr("DHT is not working (down)."), QString::fromUtf8("red"));
|
setLogInfo(tr("DHT is not working (down)."), QString::fromUtf8("red"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(config.netStunOk)
|
||||||
if(config.netExtOk)
|
|
||||||
{
|
{
|
||||||
setLogInfo(tr("Stable External IP Address"), QString::fromUtf8("green"));
|
setLogInfo(tr("Stun external address detection is working."), QString::fromUtf8("green"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setLogInfo(tr("Not Found External Address"), QString::fromUtf8("red"));
|
setLogInfo(tr("Stun is not working."), QString::fromUtf8("red"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config.netUdpOk)
|
if (config.netLocalOk)
|
||||||
{
|
{
|
||||||
setLogInfo(tr("UDP Port is active (UDP Connections)"), QString::fromUtf8("green"));
|
setLogInfo(tr("Local network detected"), QString::fromUtf8("magenta"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setLogInfo(tr("UDP Port is not active"), QString::fromUtf8("red"));
|
setLogInfo(tr("No local network detected"), QString::fromUtf8("red"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.netExtOk)
|
if (config.netExtraAddressOk)
|
||||||
{
|
{
|
||||||
if (config.netUpnpOk)
|
setLogInfo(tr("ip found via external address finder"), QString::fromUtf8("magenta"));
|
||||||
{
|
|
||||||
setLogInfo(tr("RetroShare Server"), QString::fromUtf8("green"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setLogInfo(tr("UDP Server"), QString::fromUtf8("green"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (config.netOk)
|
|
||||||
{
|
|
||||||
setLogInfo(tr("Net Limited"), QString::fromUtf8("magenta"));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setLogInfo(tr("No Conectivity"), QString::fromUtf8("red"));
|
setLogInfo(tr("external address finder didn't found anything"), QString::fromUtf8("red"));
|
||||||
}
|
}
|
||||||
|
|
||||||
rsiface->unlockData(); /* UnLock Interface */
|
rsiface->unlockData(); /* UnLock Interface */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -811,17 +799,8 @@ void NetworkDialog::updateNetworkStatus()
|
|||||||
{
|
{
|
||||||
ui.iconlabel_dht->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
ui.iconlabel_dht->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config.netExtOk)
|
if(config.netStunOk)
|
||||||
{
|
|
||||||
ui.iconlabel_ext->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ui.iconlabel_ext->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.netUdpOk)
|
|
||||||
{
|
{
|
||||||
ui.iconlabel_udp->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
ui.iconlabel_udp->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
||||||
}
|
}
|
||||||
@ -830,31 +809,33 @@ void NetworkDialog::updateNetworkStatus()
|
|||||||
ui.iconlabel_udp->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
ui.iconlabel_udp->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.netExtOk)
|
if (config.netLocalOk)
|
||||||
{
|
|
||||||
if (config.netUpnpOk)
|
|
||||||
{
|
|
||||||
ui.iconlabel_netUdp->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
|
||||||
ui.iconlabel_netLimited->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ui.iconlabel_netUdp->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
|
||||||
ui.iconlabel_netLimited->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (config.netOk)
|
|
||||||
{
|
{
|
||||||
ui.iconlabel_netLimited->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
ui.iconlabel_netLimited->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
||||||
|
|
||||||
ui.iconlabel_netUdp->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui.iconlabel_netUdp->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
|
||||||
ui.iconlabel_netLimited->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
ui.iconlabel_netLimited->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.netExtraAddressOk)
|
||||||
|
{
|
||||||
|
ui.iconlabel_ext->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui.iconlabel_ext->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.netExtraAddressOk || config.netStunOk || config.netUpnpOk)
|
||||||
|
{
|
||||||
|
ui.iconlabel_netInternetConnection->setPixmap(QPixmap::QPixmap(":/images/ledon1.png"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui.iconlabel_netInternetConnection->setPixmap(QPixmap::QPixmap(":/images/ledoff1.png"));
|
||||||
|
}
|
||||||
|
|
||||||
rsiface->unlockData(); /* UnLock Interface */
|
rsiface->unlockData(); /* UnLock Interface */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@
|
|||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<layout class="QGridLayout">
|
<layout class="QGridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="iconlabel_netUdp">
|
<widget class="QLabel" name="iconlabel_netInternetConnection">
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>16</width>
|
<width>16</width>
|
||||||
@ -228,7 +228,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="textlabel_netUdp">
|
<widget class="QLabel" name="iconlabel_netInternetConnection_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Internet connection</string>
|
<string>Internet connection</string>
|
||||||
</property>
|
</property>
|
||||||
@ -315,7 +315,7 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="textlabel_ext">
|
<widget class="QLabel" name="textlabel_ext">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Stable external IP address</string>
|
<string>External ip adress finder</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -103,32 +103,27 @@ void NATStatus::getNATStatus()
|
|||||||
// iconLabel->setToolTip(tr("UDP Port is not reachable"));
|
// iconLabel->setToolTip(tr("UDP Port is not reachable"));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (config.netExtOk)
|
if (config.netUpnpOk)
|
||||||
{
|
{
|
||||||
if (config.netUpnpOk)
|
iconLabel->setPixmap(QPixmap::QPixmap(":/images/greenled.png"));
|
||||||
{
|
iconLabel->setToolTip(tr("OK | RetroShare Server"));
|
||||||
iconLabel->setPixmap(QPixmap::QPixmap(":/images/greenled.png"));
|
|
||||||
iconLabel->setToolTip(tr("OK | RetroShare Server"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iconLabel->setPixmap(QPixmap::QPixmap(":/images/greenled.png"));
|
|
||||||
iconLabel->setToolTip(tr("OK | UDP Server"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (config.netOk)
|
else if (config.netStunOk || config.netExtraAddressOk)
|
||||||
{
|
{
|
||||||
iconLabel->setPixmap(QPixmap::QPixmap(":/images/grayled.png"));
|
iconLabel->setPixmap(QPixmap::QPixmap(":/images/grayled.png"));
|
||||||
iconLabel->setToolTip(tr("Net Limited"));
|
iconLabel->setToolTip(tr("Internet connection"));
|
||||||
|
}
|
||||||
|
else if (config.netLocalOk)
|
||||||
|
{
|
||||||
|
iconLabel->setPixmap(QPixmap::QPixmap(":/images/grayled.png"));
|
||||||
|
iconLabel->setToolTip(tr("No internet connection"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iconLabel->setPixmap(QPixmap::QPixmap(":/images/redled.png"));
|
iconLabel->setPixmap(QPixmap::QPixmap(":/images/redled.png"));
|
||||||
iconLabel->setToolTip(tr("No Conectivity"));
|
iconLabel->setToolTip(tr("No local network"));
|
||||||
}
|
}
|
||||||
|
|
||||||
rsiface->unlockData(); /* UnLock Interface */
|
rsiface->unlockData(); /* UnLock Interface */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,13 +140,11 @@ class RsConfig
|
|||||||
int DHTPeers;
|
int DHTPeers;
|
||||||
|
|
||||||
/* Flags for Network Status */
|
/* Flags for Network Status */
|
||||||
bool netOk; /* That we've talked to someone! */
|
bool netLocalOk; /* That we've talked to someone! */
|
||||||
bool netUpnpOk; /* upnp is enabled and active */
|
bool netUpnpOk; /* upnp is enabled and active */
|
||||||
bool netDhtOk; /* response from dht */
|
bool netDhtOk; /* response from dht */
|
||||||
bool netExtOk; /* know our external address */
|
bool netStunOk; /* recvd stun / udp packets */
|
||||||
bool netUdpOk; /* recvd stun / udp packets */
|
bool netExtraAddressOk; /* recvd ip address with external finder*/
|
||||||
//bool netTcpOk; /* recvd incoming tcp not implemented */
|
|
||||||
bool netResetReq;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/********************** For Search Interface *****************/
|
/********************** For Search Interface *****************/
|
||||||
|
Loading…
Reference in New Issue
Block a user