mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-24 23:19:29 -05:00
Tweaks to get the UPnP working. Corrected network address passing,
and also adjusted DHT timeout periods. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@345 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
ade0665664
commit
98a14ba715
@ -43,7 +43,7 @@ const uint32_t RS_STUN_DHT = 0x0001;
|
||||
const uint32_t RS_STUN_DONE = 0x0002;
|
||||
const uint32_t RS_STUN_LIST_MIN = 100;
|
||||
|
||||
const uint32_t MAX_UPNP_INIT = 10; /* seconds UPnP timeout */
|
||||
const uint32_t MAX_UPNP_INIT = 60; /* seconds UPnP timeout */
|
||||
|
||||
#define CONN_DEBUG 1
|
||||
|
||||
@ -308,6 +308,12 @@ void p3ConnectMgr::netUpnpInit()
|
||||
/* get the ports from the configuration */
|
||||
|
||||
mNetStatus = RS_NET_UPNP_SETUP;
|
||||
iport = ntohs(ownState.localaddr.sin_port);
|
||||
eport = ntohs(ownState.serveraddr.sin_port);
|
||||
if ((eport < 1000) || (eport > 10000))
|
||||
{
|
||||
eport = iport;
|
||||
}
|
||||
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
@ -337,7 +343,7 @@ void p3ConnectMgr::netUpnpCheck()
|
||||
|
||||
mUpnpAddrValid = false;
|
||||
mNetStatus = RS_NET_UDP_SETUP;
|
||||
ownState.netMode = RS_NET_MODE_UDP; /* UPnP Failed us! */
|
||||
//ownState.netMode = RS_NET_MODE_UDP; /* UPnP Failed us! */
|
||||
|
||||
connMtx.unlock(); /* UNLOCK MUTEX */
|
||||
}
|
||||
@ -360,7 +366,7 @@ void p3ConnectMgr::netUdpCheck()
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::netUdpCheck()" << std::endl;
|
||||
#endif
|
||||
if (stunCheck())
|
||||
if (stunCheck() || (mUpnpAddrValid))
|
||||
{
|
||||
bool extValid = false;
|
||||
struct sockaddr_in extAddr;
|
||||
@ -390,8 +396,7 @@ void p3ConnectMgr::netUdpCheck()
|
||||
{
|
||||
ownState.serveraddr = extAddr;
|
||||
mode = RS_NET_CONN_TCP_LOCAL | RS_NET_CONN_UDP_DHT_SYNC;
|
||||
if ((ownState.netMode == RS_NET_MODE_UPNP) ||
|
||||
(ownState.netMode == RS_NET_MODE_EXT))
|
||||
if (mUpnpAddrValid || (ownState.netMode == RS_NET_MODE_EXT))
|
||||
{
|
||||
mode |= RS_NET_CONN_TCP_EXTERNAL;
|
||||
}
|
||||
|
@ -51,10 +51,10 @@
|
||||
#define DHT_STATE_ACTIVE 4
|
||||
|
||||
/* TIMEOUTS */
|
||||
#define DHT_SEARCH_PERIOD 600 /* 10 min */
|
||||
#define DHT_CHECK_PERIOD 60 //1800 /* 30 min */
|
||||
#define DHT_PUBLISH_PERIOD 1800 /* 30 min */
|
||||
#define DHT_NOTIFY_PERIOD 20 //120 /* 2 min - Notify Check period */
|
||||
#define DHT_SEARCH_PERIOD 1800 /* PeerKeys: if we haven't found them: 30 min */
|
||||
#define DHT_CHECK_PERIOD 3600 /* PeerKeys: re-lookup peer: 60 min */
|
||||
#define DHT_PUBLISH_PERIOD 1800 /* OwnKey 30 min */
|
||||
#define DHT_NOTIFY_PERIOD 600 /* 10 min - Notify Check period */
|
||||
#define DHT_RESTART_PERIOD 300 /* 5 min */
|
||||
|
||||
#define DHT_DEFAULT_PERIOD 600 /* Default period if no work to do */
|
||||
@ -63,7 +63,7 @@
|
||||
#define DHT_DEFAULT_WAITTIME 1 /* Std sleep break period */
|
||||
|
||||
/* TTLs for DHTs posts */
|
||||
#define DHT_TTL_PUBLISH DHT_PUBLISH_PERIOD
|
||||
#define DHT_TTL_PUBLISH (DHT_PUBLISH_PERIOD + 30)
|
||||
#define DHT_TTL_NOTIFY DHT_NOTIFY_PERIOD
|
||||
|
||||
|
||||
|
@ -631,7 +631,13 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
/* Force Any Last Configuration Options */
|
||||
/**************************************************************************/
|
||||
|
||||
/**************************************************************************/
|
||||
/* Start up Threads */
|
||||
/**************************************************************************/
|
||||
|
||||
server->StartupMonitor();
|
||||
mUpnpMgr->start();
|
||||
|
||||
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
server->setP3Channel(pqih->getP3Channel());
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
#include "udpsorter.h"
|
||||
#include "util/rsnet.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@ -38,8 +39,10 @@ static const int STUN_TTL = 64;
|
||||
#define DEBUG_UDP_SORTER 1
|
||||
|
||||
UdpSorter::UdpSorter(struct sockaddr_in &local)
|
||||
: udpLayer(NULL), laddr(local)
|
||||
:udpLayer(NULL), laddr(local), eaddrKnown(false)
|
||||
{
|
||||
sockaddr_clear(&eaddr);
|
||||
|
||||
openSocket();
|
||||
return;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ class uPnPConfigData
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "util/rsnet.h"
|
||||
|
||||
|
||||
void upnphandler::run()
|
||||
{
|
||||
@ -73,8 +75,8 @@ void upnphandler::run()
|
||||
case RS_UPNP_S_TCP_FAILED:
|
||||
case RS_UPNP_S_UDP_FAILED:
|
||||
case RS_UPNP_S_ACTIVE:
|
||||
/* working ... normal 15 seconds */
|
||||
allowedSleep = 15;
|
||||
/* working ... normal 10 seconds */
|
||||
allowedSleep = 10;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -243,7 +245,7 @@ bool upnphandler::updateUPnP()
|
||||
char eport2[256];
|
||||
|
||||
snprintf(eport1, 256, "%d", eport_curr);
|
||||
snprintf(eport2, 256, "%d", eport_curr + 1);
|
||||
snprintf(eport2, 256, "%d", eport_curr);
|
||||
|
||||
std::cerr << "Attempting To Remove Redirection: port: " << eport1;
|
||||
std::cerr << " Prot: " << eprot1;
|
||||
@ -297,7 +299,7 @@ bool upnphandler::updateUPnP()
|
||||
struct sockaddr_in localAddr = upnp_iaddr;
|
||||
|
||||
snprintf(in_port1, 256, "%d", ntohs(localAddr.sin_port));
|
||||
snprintf(in_port2, 256, "%d", ntohs(localAddr.sin_port) + 1);
|
||||
snprintf(in_port2, 256, "%d", ntohs(localAddr.sin_port));
|
||||
snprintf(in_addr, 256, "%d.%d.%d.%d",
|
||||
((localAddr.sin_addr.s_addr >> 0) & 0xff),
|
||||
((localAddr.sin_addr.s_addr >> 8) & 0xff),
|
||||
@ -305,7 +307,7 @@ bool upnphandler::updateUPnP()
|
||||
((localAddr.sin_addr.s_addr >> 24) & 0xff));
|
||||
|
||||
snprintf(eport1, 256, "%d", eport_curr);
|
||||
snprintf(eport2, 256, "%d", eport_curr + 1);
|
||||
snprintf(eport2, 256, "%d", eport_curr);
|
||||
|
||||
std::cerr << "Attempting Redirection: InAddr: " << in_addr;
|
||||
std::cerr << " InPort: " << in_port1;
|
||||
@ -327,11 +329,35 @@ bool upnphandler::updateUPnP()
|
||||
{
|
||||
upnpState = RS_UPNP_S_ACTIVE;
|
||||
}
|
||||
|
||||
|
||||
/* now store the external address */
|
||||
char externalIPAddress[32];
|
||||
UPNP_GetExternalIPAddress(config -> urls.controlURL,
|
||||
config->data.servicetype,
|
||||
externalIPAddress);
|
||||
|
||||
sockaddr_clear(&upnp_eaddr);
|
||||
|
||||
if(externalIPAddress[0])
|
||||
{
|
||||
std::cerr << "Stored External address: " << externalIPAddress;
|
||||
std::cerr << ":" << eport_curr;
|
||||
std::cerr << std::endl;
|
||||
|
||||
inet_aton(externalIPAddress, &(upnp_eaddr.sin_addr));
|
||||
upnp_eaddr.sin_family = AF_INET;
|
||||
upnp_eaddr.sin_port = htons(eport_curr);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "FAILED To get external Address";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
dataMtx.unlock(); /* UNLOCK MUTEX */
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -418,6 +444,9 @@ void upnphandler::setInternalPort(unsigned short iport_in)
|
||||
dataMtx.lock(); /*** LOCK MUTEX ***/
|
||||
// std::cerr << "UPnPHandler::setInternalAddress() postLock!" << std::endl;
|
||||
|
||||
std::cerr << "UPnPHandler::setInternalPort(" << iport_in << ") current port: ";
|
||||
std::cerr << iport << std::endl;
|
||||
|
||||
if (iport != iport_in)
|
||||
{
|
||||
iport = iport_in;
|
||||
@ -437,6 +466,9 @@ void upnphandler::setExternalPort(unsigned short eport_in)
|
||||
dataMtx.lock(); /*** LOCK MUTEX ***/
|
||||
// std::cerr << "UPnPHandler::getExternalPort() postLock!" << std::endl;
|
||||
|
||||
std::cerr << "UPnPHandler::setExternalPort(" << eport_in << ") current port: ";
|
||||
std::cerr << eport << std::endl;
|
||||
|
||||
/* flag both shutdown/start -> for restart */
|
||||
if (eport != eport_in)
|
||||
{
|
||||
@ -459,8 +491,10 @@ bool upnphandler::getInternalAddress(struct sockaddr_in &addr)
|
||||
dataMtx.lock(); /*** LOCK MUTEX ***/
|
||||
// std::cerr << "UPnPHandler::getInternalAddress() postLock!" << std::endl;
|
||||
|
||||
std::cerr << "UPnPHandler::getInternalAddress()" << std::endl;
|
||||
|
||||
addr = upnp_iaddr;
|
||||
bool valid = (upnpState >= RS_UPNP_S_READY);
|
||||
bool valid = (upnpState >= RS_UPNP_S_ACTIVE);
|
||||
|
||||
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
||||
|
||||
@ -473,8 +507,9 @@ bool upnphandler::getExternalAddress(struct sockaddr_in &addr)
|
||||
dataMtx.lock(); /*** LOCK MUTEX ***/
|
||||
// std::cerr << "UPnPHandler::getExternalAddress() postLock!" << std::endl;
|
||||
|
||||
std::cerr << "UPnPHandler::getExternalAddress()" << std::endl;
|
||||
addr = upnp_eaddr;
|
||||
bool valid = (upnpState >= RS_UPNP_S_READY);
|
||||
bool valid = (upnpState == RS_UPNP_S_ACTIVE);
|
||||
|
||||
dataMtx.unlock(); /*** UNLOCK MUTEX ***/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user