BugFix: DHT was not turning on.

also updated the ServerDialog with more info on exact network state.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@753 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-10-18 16:02:06 +00:00
parent 95d5f38222
commit bc98b9ea7d
12 changed files with 330 additions and 122 deletions

View File

@ -64,6 +64,7 @@ const uint32_t MAX_UPNP_INIT = 10; /* seconds UPnP timeout */
***/
#define CONN_DEBUG 1
const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
const uint32_t P3CONNMGR_UDP_DHT_DELAY = DHT_NOTIFY_PERIOD + 60; /* + 1 minute for DHT POST */
const uint32_t P3CONNMGR_UDP_PROXY_DELAY = 30; /* 30 seconds (NOT IMPLEMENTED YET!) */
@ -169,7 +170,7 @@ void p3ConnectMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
/* if we've started up - then tweak Dht On/Off */
if (mNetStatus != RS_NET_UNKNOWN)
{
enableNetAssistFirewall(!(ownState.visState & RS_VIS_STATE_NODHT));
enableNetAssistConnect(!(ownState.visState & RS_VIS_STATE_NODHT));
}
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
@ -231,6 +232,17 @@ void p3ConnectMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
*
*/
void p3ConnectMgr::netStatusReset()
{
netFlagOk = true;
netFlagUpnpOk = false;
netFlagDhtOk = false;
netFlagExtOk = false;
netFlagUdpOk = false;
netFlagTcpOk = false;
netFlagResetReq = false;
}
void p3ConnectMgr::netStartup()
{
/* startup stuff */
@ -246,6 +258,7 @@ void p3ConnectMgr::netStartup()
netDhtInit();
netUdpInit();
netStunInit();
netStatusReset();
/* decide which net setup mode we're going into
*/
@ -469,7 +482,7 @@ void p3ConnectMgr::netDhtInit()
connMtx.unlock(); /* UNLOCK MUTEX */
enableNetAssistFirewall(!(vs & RS_VIS_STATE_NODHT));
enableNetAssistConnect(!(vs & RS_VIS_STATE_NODHT));
}
@ -532,6 +545,14 @@ void p3ConnectMgr::netUpnpCheck()
/* switch to UDP startup */
connMtx.lock(); /* LOCK MUTEX */
/* Set Net Status flags ....
* we now have external upnp address. Golden!
* don't set netOk flag until have seen some traffic.
*/
netFlagUpnpOk = true;
netFlagExtOk = true;
mUpnpAddrValid = true;
mUpnpExtAddr = extAddr;
mNetStatus = RS_NET_UDP_SETUP;
@ -778,6 +799,15 @@ bool p3ConnectMgr::udpExtAddressCheck()
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;
@ -1552,6 +1582,11 @@ void p3ConnectMgr::peerStatus(std::string id,
/* If we get a info -> then they are online */
it->second.state |= RS_PEER_S_ONLINE;
it->second.lastavailable = now;
/* if we are recieving these - the dht is definitely up.
*/
netFlagDhtOk = true;
}
else if (source == RS_CB_DISC)
{
@ -3257,5 +3292,40 @@ bool p3ConnectMgr::getDHTEnabled()
bool p3ConnectMgr::getNetStatusOk()
{
return netFlagOk;
}
bool p3ConnectMgr::getNetStatusUpnpOk()
{
return netFlagUpnpOk;
}
bool p3ConnectMgr::getNetStatusDhtOk()
{
return netFlagDhtOk;
}
bool p3ConnectMgr::getNetStatusExtOk()
{
return netFlagExtOk;
}
bool p3ConnectMgr::getNetStatusUdpOk()
{
return netFlagUdpOk;
}
bool p3ConnectMgr::getNetStatusTcpOk()
{
return netFlagTcpOk;
}
bool p3ConnectMgr::getNetResetReq()
{
return netFlagResetReq;
}

View File

@ -81,6 +81,13 @@ const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0;
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001;
const uint32_t RS_NET_CONN_TCP_EXTERNAL = 0x0002;
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0010;
const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */
/* extra flags */
// not sure if needed yet.
//const uint32_t RS_NET_CONN_PEERAGE = 0x0f00;
//const uint32_t RS_NET_CONN_SERVER = 0x0100; /* TCP only */
//const uint32_t RS_NET_CONN_PEER = 0x0200; /* all UDP */
/* flags of peerStatus */
@ -176,6 +183,14 @@ bool getUPnPState();
bool getUPnPEnabled();
bool getDHTEnabled();
bool getNetStatusOk();
bool getNetStatusUpnpOk();
bool getNetStatusDhtOk();
bool getNetStatusExtOk();
bool getNetStatusUdpOk();
bool getNetStatusTcpOk();
bool getNetResetReq();
void setOwnNetConfig(uint32_t netMode, uint32_t visState);
bool setLocalAddress(std::string id, struct sockaddr_in addr);
bool setExtAddress(std::string id, struct sockaddr_in addr);
@ -260,7 +275,7 @@ void netDhtInit();
void netUdpInit();
void netStunInit();
void netStatusReset();
void netInit();
@ -338,6 +353,15 @@ private:
struct sockaddr_in mUpnpExtAddr;
struct sockaddr_in mStunExtAddr;
/* network status flags (read by rsiface) */
bool netFlagOk;
bool netFlagUpnpOk;
bool netFlagDhtOk;
bool netFlagExtOk;
bool netFlagUdpOk;
bool netFlagTcpOk;
bool netFlagResetReq;
/* these are protected for testing */
protected:

View File

@ -48,6 +48,8 @@ const int p3dhtzone = 3892;
*
*/
#define DHT_DEBUG 1
/**** DHT State Variables ****/
#define DHT_STATE_OFF 0

View File

@ -137,11 +137,21 @@ class RsConfig
int promptAtBoot; /* popup the password prompt */
/* older data types */
bool DHTActive;
bool uPnPActive;
int uPnPState;
int DHTPeers;
/* Flags for Network Status */
bool netOk; /* That we've talked to someone! */
bool netUpnpOk; /* upnp is enabled and active */
bool netDhtOk; /* response from dht */
bool netExtOk; /* know our external address */
bool netUdpOk; /* recvd stun / udp packets */
bool netTcpOk; /* recvd incoming tcp */
bool netResetReq;
};
/********************** For Search Interface *****************/

View File

@ -124,6 +124,15 @@ int RsServer::UpdateAllConfig()
config.maxIndivDataRate = (int) pqih -> getMaxIndivRate(true);/* kb */
config.promptAtBoot = true; /* popup the password prompt */
/* update network configuration */
config.netOk = mConnMgr->getNetStatusOk();
config.netUpnpOk = mConnMgr->getNetStatusUpnpOk();
config.netDhtOk = mConnMgr->getNetStatusDhtOk();
config.netExtOk = mConnMgr->getNetStatusExtOk();
config.netUdpOk = mConnMgr->getNetStatusUdpOk();
config.netTcpOk = mConnMgr->getNetStatusTcpOk();
/* update DHT/UPnP config */
config.uPnPState = mConnMgr->getUPnPState();

View File

@ -487,17 +487,17 @@
<property name="contextMenuPolicy" >
<enum>Qt::NoContextMenu</enum>
</property>
<layout class="QGridLayout" name="gridLayout" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QGroupBox" name="groupBox_5" >
<property name="title" >
<string>Library</string>
</property>
<layout class="QGridLayout" name="gridLayout_8" >
<layout class="QGridLayout" >
<item row="0" column="1" colspan="2" >
<widget class="QLabel" name="label_3" >
<property name="styleSheet" >
<string notr="true" >background-color: rgb(253, 252, 248);</string>
<string>background-color: rgb(253, 252, 248);</string>
</property>
<property name="text" >
<string>Exploring My RetroShare Library</string>
@ -543,7 +543,7 @@
<item row="2" column="1" >
<widget class="QPushButton" name="createAlbum_btn_library" >
<property name="styleSheet" >
<string notr="true" />
<string/>
</property>
<property name="text" >
<string>Create Album</string>
@ -556,7 +556,7 @@
<item row="2" column="2" >
<widget class="QPushButton" name="deleteAlbum_btn_library" >
<property name="styleSheet" >
<string notr="true" />
<string/>
</property>
<property name="text" >
<string>Delete Album</string>
@ -572,7 +572,7 @@
<item row="2" column="4" >
<widget class="QPushButton" name="find_btn_library" >
<property name="styleSheet" >
<string notr="true" >pushButton_41:hover{ color : white;}</string>
<string>pushButton_41:hover{ color : white;}</string>
</property>
<property name="text" >
<string>Find</string>
@ -591,22 +591,14 @@
<number>1</number>
</property>
<widget class="QWidget" name="tab_13" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>226</width>
<height>345</height>
</rect>
</property>
<attribute name="title" >
<string>Folder</string>
</attribute>
<layout class="QFormLayout" name="formLayout" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QComboBox" name="comboBox" >
<property name="styleSheet" >
<string notr="true" >border-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));</string>
<string>border-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));</string>
</property>
<item>
<property name="text" >
@ -628,18 +620,10 @@
</layout>
</widget>
<widget class="QWidget" name="tab_14" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>238</width>
<height>390</height>
</rect>
</property>
<attribute name="title" >
<string>Organizer</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_25" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QTreeView" name="organizertreeView" >
<property name="font" >
@ -653,7 +637,7 @@
<item row="1" column="0" >
<widget class="QPushButton" name="shareFiles_btn" >
<property name="styleSheet" >
<string notr="true" >border-color: rgb(0, 0, 0);</string>
<string>border-color: rgb(0, 0, 0);</string>
</property>
<property name="text" >
<string>Share Files..</string>

View File

@ -28,6 +28,8 @@
#include "rsiface/rsiface.h"
#include "rsiface/rspeers.h"
#include <QTimer>
/** Constructor */
@ -42,6 +44,10 @@ ServerDialog::ServerDialog(QWidget *parent)
connect( ui.netModeComboBox, SIGNAL( activated ( int ) ), this, SLOT( toggleUPnP( ) ) );
QTimer *timer = new QTimer(this);
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
timer->start(1000);
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -109,15 +115,69 @@ void ServerDialog::load()
}
ui.discComboBox->setCurrentIndex(netIndex);
rsiface->lockData(); /* Lock Interface */
/* set the addresses */
ui.totalRate->setValue(rsiface->getConfig().maxDataRate);
ui.indivRate->setValue(rsiface->getConfig().maxIndivDataRate);
rsiface->unlockData(); /* UnLock Interface */
toggleUPnP();
//ui.check_net->setCheckable(true);
ui.check_upnp->setCheckable(true);
ui.check_dht->setCheckable(true);
ui.check_ext->setCheckable(true);
ui.check_udp->setCheckable(true);
ui.check_tcp->setCheckable(true);
//ui.check_net->setEnabled(false);
ui.check_upnp->setEnabled(false);
ui.check_dht->setEnabled(false);
ui.check_ext->setEnabled(false);
ui.check_udp->setEnabled(false);
ui.check_tcp->setEnabled(false);
ui.radio_nonet->setEnabled(false);
ui.radio_netLimited->setEnabled(false);
ui.radio_netUdp->setEnabled(false);
ui.radio_netServer->setEnabled(false);
/* Addresses must be set here - otherwise can't edit it */
/* set local address */
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
ui.localPort -> setValue(detail.localPort);
/* set the server address */
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
ui.extPort -> setValue(detail.extPort);
}
/** Loads the settings for this page */
void ServerDialog::updateStatus()
{
/* load up configuration from rsPeers */
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
{
return;
}
/* only update if can't edit */
if (!ui.localPort->isEnabled())
{
/* set local address */
ui.localPort -> setValue(detail.localPort);
ui.extPort -> setValue(detail.extPort);
}
/* set local address */
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
/* set the server address */
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
#if 0
/* set status */
std::ostringstream out;
out << "Attempted Network Mode: ";
@ -131,6 +191,7 @@ void ServerDialog::load()
break;
default:
case RS_NETMODE_UPNP:
out << "Automatic: UPnP Forwarded Port";
break;
}
@ -178,7 +239,6 @@ void ServerDialog::load()
out << std::endl;
if (detail.netMode == RS_NETMODE_UNREACHABLE)
{
ui.netStatusBox->setTextColor( Qt::red );
@ -190,17 +250,47 @@ void ServerDialog::load()
ui.netStatusBox->setText(QString::fromStdString(out.str()));
ui.netStatusBox ->setReadOnly(true);
#endif
rsiface->lockData(); /* Lock Interface */
ui.totalRate->setValue(rsiface->getConfig().maxDataRate);
ui.indivRate->setValue(rsiface->getConfig().maxIndivDataRate);
/* now the extra bit .... switch on check boxes */
const RsConfig &config = rsiface->getConfig();
//ui.check_net->setChecked(config.netOk);
ui.check_upnp->setChecked(config.netUpnpOk);
ui.check_dht->setChecked(config.netDhtOk);
ui.check_ext->setChecked(config.netExtOk);
ui.check_udp->setChecked(config.netUdpOk);
ui.check_tcp->setChecked(config.netTcpOk);
if (config.netExtOk)
{
if (config.netUpnpOk || config.netTcpOk)
{
ui.radio_netServer->setChecked(true);
}
else
{
ui.radio_netUdp->setChecked(true);
}
}
else if (config.netOk)
{
ui.radio_netLimited->setChecked(true);
}
else
{
ui.radio_nonet->setChecked(true);
}
rsiface->unlockData(); /* UnLock Interface */
toggleUPnP();
}
void ServerDialog::toggleUPnP()
{
/* switch on the radioButton */
@ -217,9 +307,9 @@ void ServerDialog::toggleUPnP()
//ui.discComboBox->setEnabled(true);
ui.discComboBox->setEnabled(false);
ui.localAddress->setEnabled(true);
ui.localAddress->setEnabled(false);
ui.localPort -> setEnabled(true);
ui.extAddress -> setEnabled(true);
ui.extAddress -> setEnabled(false);
ui.extPort -> setEnabled(true);
}
else

View File

@ -42,7 +42,10 @@ public:
bool save(QString &errmsg);
/** Loads the settings for this page */
void load();
public slots:
void updateStatus();
private slots:
void saveAddresses();
void toggleUPnP();

View File

@ -518,17 +518,17 @@
<widget class="QComboBox" name="netModeComboBox" >
<item>
<property name="text" >
<string>Automatic (Firewalled)</string>
<string>Automatic</string>
</property>
</item>
<item>
<property name="text" >
<string>Firewalled + No UPnP</string>
<string>Firewalled</string>
</property>
</item>
<item>
<property name="text" >
<string>External (Forwarded) Port</string>
<string>Forwarded Port</string>
</property>
</item>
</widget>
@ -579,77 +579,88 @@
</sizepolicy>
</property>
<property name="title" >
<string>Server Status And Network Settings</string>
<string>Network Configuration</string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QGridLayout" >
<item rowspan="6" row="0" column="0" >
<widget class="QTextEdit" name="netStatusBox" />
</item>
<item row="0" column="1" >
<widget class="QCheckBox" name="checkBox" >
<property name="text" >
<string>Network Okay</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QCheckBox" name="checkBox_6" >
<property name="text" >
<string>UPnP Active</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QCheckBox" name="checkBox_5" >
<property name="text" >
<string>DHT Okay</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QCheckBox" name="checkBox_2" >
<property name="text" >
<string>Found Ext IP Addr</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QCheckBox" name="checkBox_3" >
<property name="text" >
<string>UDP Connections</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="5" column="1" >
<widget class="QCheckBox" name="checkBox_4" >
<property name="text" >
<string>TCP server</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QRadioButton" name="radio_nonet" >
<property name="text" >
<string>No Conectivity</string>
</property>
</widget>
</item>
<item>
<item row="0" column="1" >
<widget class="QCheckBox" name="check_udp" >
<property name="text" >
<string>UDP Connections</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QRadioButton" name="radio_netLimited" >
<property name="text" >
<string>Limited</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QCheckBox" name="check_ext" >
<property name="text" >
<string>Stable External IP Addrress</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item rowspan="2" row="2" column="0" >
<widget class="QRadioButton" name="radio_netUdp" >
<property name="text" >
<string>Udp</string>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QCheckBox" name="check_dht" >
<property name="text" >
<string>DHT Okay</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QCheckBox" name="check_upnp" >
<property name="text" >
<string>UPnP Active</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0" >
<widget class="QRadioButton" name="radio_netServer" >
<property name="text" >
<string>Retroshare Server</string>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QCheckBox" name="check_tcp" >
<property name="text" >
<string>TCP server</string>
</property>
<property name="checkable" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<item>
<layout class="QVBoxLayout" >
@ -671,9 +682,6 @@
</item>
<item>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLineEdit" name="localAddress" />
</item>
<item row="0" column="1" >
<widget class="QLabel" name="label_5" >
<property name="text" >
@ -694,9 +702,6 @@
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLineEdit" name="extAddress" />
</item>
<item row="1" column="1" >
<widget class="QLabel" name="label_4" >
<property name="text" >
@ -717,6 +722,12 @@
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLineEdit" name="extAddress" />
</item>
<item row="0" column="0" >
<widget class="QLineEdit" name="localAddress" />
</item>
</layout>
</item>
</layout>
@ -834,7 +845,6 @@
<tabstops>
<tabstop>localAddress</tabstop>
<tabstop>localPort</tabstop>
<tabstop>extAddress</tabstop>
<tabstop>extPort</tabstop>
<tabstop>totalRate</tabstop>
<tabstop>indivRate</tabstop>

View File

@ -1,4 +0,0 @@
-- Diese und die folgenden Zeilen werden ignoriert --
M NetworkDialog.cpp

View File

@ -151,13 +151,13 @@ int main(int argc, char *argv[])
notify->setMessengerWindow(w->messengerWindow);
/* only show window, if not startMinimized */
/*if (!startMinimised)
if (!startMinimised)
{
w->show();
//skinWindow->show();
}*/
}
/* Run Retroshare */
//int ret = rshare.run();

View File

@ -137,11 +137,21 @@ class RsConfig
int promptAtBoot; /* popup the password prompt */
/* older data types */
bool DHTActive;
bool uPnPActive;
int uPnPState;
int DHTPeers;
/* Flags for Network Status */
bool netOk; /* That we've talked to someone! */
bool netUpnpOk; /* upnp is enabled and active */
bool netDhtOk; /* response from dht */
bool netExtOk; /* know our external address */
bool netUdpOk; /* recvd stun / udp packets */
bool netTcpOk; /* recvd incoming tcp */
bool netResetReq;
};
/********************** For Search Interface *****************/