From bc98b9ea7d046b10d085f0fa57abb93656f3d10a Mon Sep 17 00:00:00 2001 From: drbob Date: Sat, 18 Oct 2008 16:02:06 +0000 Subject: [PATCH] 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 --- libretroshare/src/pqi/p3connmgr.cc | 74 +++++++- libretroshare/src/pqi/p3connmgr.h | 26 ++- libretroshare/src/pqi/p3dhtmgr.cc | 2 + libretroshare/src/rsiface/rstypes.h | 10 ++ libretroshare/src/rsserver/p3face-config.cc | 9 + retroshare-gui/src/gui/LibraryDialog.ui | 36 ++-- .../src/gui/Preferences/ServerDialog.cpp | 104 ++++++++++- .../src/gui/Preferences/ServerDialog.h | 5 +- .../src/gui/Preferences/ServerDialog.ui | 168 ++++++++++-------- retroshare-gui/src/gui/svn-commit.tmp | 4 - retroshare-gui/src/main.cpp | 4 +- retroshare-gui/src/rsiface/rstypes.h | 10 ++ 12 files changed, 330 insertions(+), 122 deletions(-) delete mode 100644 retroshare-gui/src/gui/svn-commit.tmp diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index e9b9f1973..7287cdff1 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -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; +} + diff --git a/libretroshare/src/pqi/p3connmgr.h b/libretroshare/src/pqi/p3connmgr.h index ef8cb4365..82752c97b 100644 --- a/libretroshare/src/pqi/p3connmgr.h +++ b/libretroshare/src/pqi/p3connmgr.h @@ -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: diff --git a/libretroshare/src/pqi/p3dhtmgr.cc b/libretroshare/src/pqi/p3dhtmgr.cc index 8fea006a7..9f8ea04a7 100644 --- a/libretroshare/src/pqi/p3dhtmgr.cc +++ b/libretroshare/src/pqi/p3dhtmgr.cc @@ -48,6 +48,8 @@ const int p3dhtzone = 3892; * */ +#define DHT_DEBUG 1 + /**** DHT State Variables ****/ #define DHT_STATE_OFF 0 diff --git a/libretroshare/src/rsiface/rstypes.h b/libretroshare/src/rsiface/rstypes.h index 39094509f..2675c2d5b 100644 --- a/libretroshare/src/rsiface/rstypes.h +++ b/libretroshare/src/rsiface/rstypes.h @@ -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 *****************/ diff --git a/libretroshare/src/rsserver/p3face-config.cc b/libretroshare/src/rsserver/p3face-config.cc index c54b1879f..9501ce73a 100644 --- a/libretroshare/src/rsserver/p3face-config.cc +++ b/libretroshare/src/rsserver/p3face-config.cc @@ -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(); diff --git a/retroshare-gui/src/gui/LibraryDialog.ui b/retroshare-gui/src/gui/LibraryDialog.ui index 7f59de9d8..ebd21ae28 100644 --- a/retroshare-gui/src/gui/LibraryDialog.ui +++ b/retroshare-gui/src/gui/LibraryDialog.ui @@ -487,17 +487,17 @@ Qt::NoContextMenu - + Library - + - background-color: rgb(253, 252, 248); + background-color: rgb(253, 252, 248); Exploring My RetroShare Library @@ -543,7 +543,7 @@ - + Create Album @@ -556,7 +556,7 @@ - + Delete Album @@ -572,7 +572,7 @@ - pushButton_41:hover{ color : white;} + pushButton_41:hover{ color : white;} Find @@ -591,22 +591,14 @@ 1 - - - 0 - 0 - 226 - 345 - - Folder - + - 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)); + 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)); @@ -628,18 +620,10 @@ - - - 0 - 0 - 238 - 390 - - Organizer - + @@ -653,7 +637,7 @@ - border-color: rgb(0, 0, 0); + border-color: rgb(0, 0, 0); Share Files.. diff --git a/retroshare-gui/src/gui/Preferences/ServerDialog.cpp b/retroshare-gui/src/gui/Preferences/ServerDialog.cpp index 838eb1905..7c232340e 100644 --- a/retroshare-gui/src/gui/Preferences/ServerDialog.cpp +++ b/retroshare-gui/src/gui/Preferences/ServerDialog.cpp @@ -28,6 +28,8 @@ #include "rsiface/rsiface.h" #include "rsiface/rspeers.h" +#include + /** 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 diff --git a/retroshare-gui/src/gui/Preferences/ServerDialog.h b/retroshare-gui/src/gui/Preferences/ServerDialog.h index 21ed8e2da..1842f0359 100644 --- a/retroshare-gui/src/gui/Preferences/ServerDialog.h +++ b/retroshare-gui/src/gui/Preferences/ServerDialog.h @@ -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(); diff --git a/retroshare-gui/src/gui/Preferences/ServerDialog.ui b/retroshare-gui/src/gui/Preferences/ServerDialog.ui index c9dc577e9..1db32873c 100644 --- a/retroshare-gui/src/gui/Preferences/ServerDialog.ui +++ b/retroshare-gui/src/gui/Preferences/ServerDialog.ui @@ -518,17 +518,17 @@ - Automatic (Firewalled) + Automatic - Firewalled + No UPnP + Firewalled - External (Forwarded) Port + Forwarded Port @@ -579,77 +579,88 @@ - Server Status And Network Settings + Network Configuration - - - - - - - - - - Network Okay - - - false - - - - - - - UPnP Active - - - false - - - - - - - DHT Okay - - - false - - - - - - - Found Ext IP Addr - - - false - - - - - - - UDP Connections - - - false - - - - - - - TCP server - - - false - - - - + + + + + No Conectivity + + - + + + + UDP Connections + + + false + + + + + + + Limited + + + + + + + Stable External IP Addrress + + + false + + + + + + + Udp + + + + + + + DHT Okay + + + false + + + + + + + UPnP Active + + + false + + + + + + + Retroshare Server + + + + + + + TCP server + + + false + + + + @@ -671,9 +682,6 @@ - - - @@ -694,9 +702,6 @@ - - - @@ -717,6 +722,12 @@ + + + + + + @@ -834,7 +845,6 @@ localAddress localPort - extAddress extPort totalRate indivRate diff --git a/retroshare-gui/src/gui/svn-commit.tmp b/retroshare-gui/src/gui/svn-commit.tmp deleted file mode 100644 index d66575991..000000000 --- a/retroshare-gui/src/gui/svn-commit.tmp +++ /dev/null @@ -1,4 +0,0 @@ - --- Diese und die folgenden Zeilen werden ignoriert -- - -M NetworkDialog.cpp diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index f31e44bc5..f9d50d18b 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -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(); diff --git a/retroshare-gui/src/rsiface/rstypes.h b/retroshare-gui/src/rsiface/rstypes.h index 39094509f..2675c2d5b 100644 --- a/retroshare-gui/src/rsiface/rstypes.h +++ b/retroshare-gui/src/rsiface/rstypes.h @@ -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 *****************/