convert RSNET_NETWORK to enum class

This commit is contained in:
sehraf 2020-02-09 18:23:48 +01:00
parent 101bc32679
commit 0237531322
No known key found for this signature in database
GPG Key ID: DF09F6EAE356B2C6
10 changed files with 68 additions and 85 deletions

View File

@ -21,7 +21,6 @@
*******************************************************************************/
#include "dht/connectstatebox.h"
#include "retroshare/rsconfig.h"
#include "util/rsrandom.h"
#include "util/rsstring.h"
@ -260,11 +259,11 @@ std::string PeerConnectStateBox::connectState() const
}
uint32_t convertNetStateToInternal(uint32_t netmode, uint32_t nathole, uint32_t nattype)
uint32_t convertNetStateToInternal(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype)
{
uint32_t connNet = CSB_NETSTATE_UNKNOWN;
if (netmode == RSNET_NETWORK_EXTERNALIP)
if (netmode == RsNetworkMode::EXTERNALIP)
{
connNet = CSB_NETSTATE_FORWARD;
}
@ -272,7 +271,7 @@ uint32_t convertNetStateToInternal(uint32_t netmode, uint32_t nathole, uint32_t
{
connNet = CSB_NETSTATE_FORWARD;
}
else if (netmode == RSNET_NETWORK_BEHINDNAT)
else if (netmode == RsNetworkMode::BEHINDNAT)
{
if ((nattype == RSNET_NATTYPE_RESTRICTED_CONE) ||
(nattype == RSNET_NATTYPE_FULL_CONE))
@ -300,20 +299,20 @@ bool shouldUseProxyPortInternal(uint32_t netstate)
return true;
}
bool PeerConnectStateBox::shouldUseProxyPort(uint32_t netmode, uint32_t nathole, uint32_t nattype)
bool PeerConnectStateBox::shouldUseProxyPort(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype)
{
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
return shouldUseProxyPortInternal(netstate);
}
uint32_t PeerConnectStateBox::calcNetState(uint32_t netmode, uint32_t nathole, uint32_t nattype)
uint32_t PeerConnectStateBox::calcNetState(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype)
{
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
return netstate;
}
uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, uint32_t netmode, uint32_t nathole, uint32_t nattype)
uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, RsNetworkMode netmode, uint32_t nathole, uint32_t nattype)
{
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);

View File

@ -75,17 +75,19 @@
#include "util/rstime.h"
#include <inttypes.h>
#include <retroshare/rsconfig.h>
class PeerConnectStateBox
{
public:
PeerConnectStateBox();
uint32_t connectCb(uint32_t cbtype, uint32_t netmode, uint32_t nathole, uint32_t nattype);
uint32_t connectCb(uint32_t cbtype, RsNetworkMode netmode, uint32_t nathole, uint32_t nattype);
uint32_t updateCb(uint32_t updateType);
bool shouldUseProxyPort(uint32_t netmode, uint32_t nathole, uint32_t nattype);
bool shouldUseProxyPort(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype);
uint32_t calcNetState(uint32_t netmode, uint32_t nathole, uint32_t nattype);
uint32_t calcNetState(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype);
std::string connectState() const;
std::string mPeerId;

View File

@ -1633,7 +1633,7 @@ uint32_t p3NetMgrIMPL::getNetStateMode()
return mNetStateBox.getNetStateMode();
}
uint32_t p3NetMgrIMPL::getNetworkMode()
RsNetworkMode p3NetMgrIMPL::getNetworkMode()
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetworkMode();

View File

@ -104,7 +104,7 @@ virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode) = 0;
/* Get Network State */
virtual uint32_t getNetStateMode() = 0;
virtual uint32_t getNetworkMode() = 0;
virtual RsNetworkMode getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0;
@ -155,7 +155,7 @@ virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode);
/* Get Network State */
virtual uint32_t getNetStateMode();
virtual uint32_t getNetworkMode();
virtual RsNetworkMode getNetworkMode();
virtual uint32_t getNatTypeMode();
virtual uint32_t getNatHoleMode();
virtual uint32_t getConnectModes();

View File

@ -20,7 +20,6 @@
* *
*******************************************************************************/
#include "retroshare/rsconfig.h"
#include "util/rsnet.h"
#include "pqi/pqinetstatebox.h"
#include "util/rstime.h"
@ -147,7 +146,7 @@ void pqiNetStateBox::setDhtState(bool on, bool active)
/* Extract Net State */
uint32_t pqiNetStateBox::getNetworkMode()
RsNetworkMode pqiNetStateBox::getNetworkMode()
{
updateNetState();
return mNetworkMode;
@ -193,7 +192,7 @@ void pqiNetStateBox::reset()
mStatusOkay = false;
//rstime_t mStatusTS;
mNetworkMode = RSNET_NETWORK_UNKNOWN;
mNetworkMode = RsNetworkMode::UNKNOWN;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UNKNOWN;
mConnectModes = RSNET_CONNECT_NONE;
@ -302,7 +301,7 @@ void pqiNetStateBox::determineNetworkState()
/* firstly lets try to identify OFFLINE / UNKNOWN */
if ((!mStunProxySet) || (!mStunDhtSet))
{
mNetworkMode = RSNET_NETWORK_UNKNOWN;
mNetworkMode = RsNetworkMode::UNKNOWN;
// Assume these.
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NONE;
@ -335,7 +334,7 @@ void pqiNetStateBox::determineNetworkState()
*
*/
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_DETERM_SYM;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED;
@ -344,7 +343,7 @@ void pqiNetStateBox::determineNetworkState()
else if (!mStunProxyStable)
{
/* both unstable, Symmetric NAT, Firewalled, No UDP Hole */
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_SYMMETRIC;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_BAD_NATSYM;
@ -366,7 +365,7 @@ void pqiNetStateBox::determineNetworkState()
* but that label is really fully accurate. (gray area).
*/
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_RESTRICTED_CONE;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED;
@ -392,7 +391,7 @@ void pqiNetStateBox::determineNetworkState()
if (mStunProxySemiStable)
{
/* must be a forwarded port/ext or something similar */
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_DETERM_SYM;
mNatHoleMode = RSNET_NATHOLE_FORWARDED;
mNetStateMode = RSNET_NETSTATE_GOOD;
@ -400,7 +399,7 @@ void pqiNetStateBox::determineNetworkState()
else if (!mStunProxyStable)
{
/* must be a forwarded port/ext or something similar */
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_SYMMETRIC;
mNatHoleMode = RSNET_NATHOLE_FORWARDED;
mNetStateMode = RSNET_NETSTATE_GOOD;
@ -408,7 +407,7 @@ void pqiNetStateBox::determineNetworkState()
else
{
/* fallback is FULL CONE NAT */
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_FULL_CONE;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED;
@ -417,7 +416,7 @@ void pqiNetStateBox::determineNetworkState()
if (mUPnPActive)
{
// This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UPNP;
@ -428,7 +427,7 @@ void pqiNetStateBox::determineNetworkState()
else if (mNatPMPActive)
{
// This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NATPMP;
@ -442,7 +441,7 @@ void pqiNetStateBox::determineNetworkState()
if (isExtAddress)
{
mNetworkMode = RSNET_NETWORK_EXTERNALIP;
mNetworkMode = RsNetworkMode::EXTERNALIP;
mNatTypeMode = RSNET_NATTYPE_NONE;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_GOOD;
@ -451,7 +450,7 @@ void pqiNetStateBox::determineNetworkState()
}
else if (mPortForwardSet)
{
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_FORWARDED;
@ -479,7 +478,7 @@ void pqiNetStateBox::determineNetworkState()
if (mUPnPActive)
{
// This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UPNP;
//mExtAddress = ... from UPnP.
@ -489,7 +488,7 @@ void pqiNetStateBox::determineNetworkState()
else if (mNatPMPActive)
{
// This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NATPMP;
//mExtAddress = ... from NatPMP.
@ -506,7 +505,7 @@ void pqiNetStateBox::determineNetworkState()
if (isExtAddress)
{
mNetworkMode = RSNET_NETWORK_EXTERNALIP;
mNetworkMode = RsNetworkMode::EXTERNALIP;
mNatTypeMode = RSNET_NATTYPE_NONE;
mNatHoleMode = RSNET_NATHOLE_NONE;
@ -515,7 +514,7 @@ void pqiNetStateBox::determineNetworkState()
}
else if (mPortForwardSet)
{
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_FORWARDED;
@ -528,7 +527,7 @@ void pqiNetStateBox::determineNetworkState()
* These people have destroyed the possibility of making connections ;(
* Should WARN about this.
*/
mNetworkMode = RSNET_NETWORK_BEHINDNAT;
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_BAD_NODHT_NAT;
@ -556,12 +555,13 @@ void pqiNetStateBox::workoutNetworkMode()
mConnectModes = RSNET_CONNECT_NONE;
switch(mNetworkMode)
{
case RSNET_NETWORK_UNKNOWN:
case RSNET_NETWORK_OFFLINE:
case RSNET_NETWORK_LOCALNET:
case RsNetworkMode::UNKNOWN:
case RsNetworkMode::OFFLINE:
case RsNetworkMode::LOCALNET:
case RsNetworkMode::RESTARTING:
/* nothing here */
break;
case RSNET_NETWORK_EXTERNALIP:
case RsNetworkMode::EXTERNALIP:
mConnectModes = RSNET_CONNECT_OUTGOING_TCP;
mConnectModes |= RSNET_CONNECT_ACCEPT_TCP;
@ -577,7 +577,7 @@ void pqiNetStateBox::workoutNetworkMode()
//mConnectModes |= RSNET_CONNECT_RELAY_UDP;
}
break;
case RSNET_NETWORK_BEHINDNAT:
case RsNetworkMode::BEHINDNAT:
mConnectModes = RSNET_CONNECT_OUTGOING_TCP;
/* we're okay if there's a NAT HOLE */
@ -616,33 +616,6 @@ void pqiNetStateBox::workoutNetworkMode()
}
std::string NetStateNetworkModeString(uint32_t netMode)
{
std::string str;
switch(netMode)
{
default:
case RSNET_NETWORK_UNKNOWN:
str = "Unknown NetState";
break;
case RSNET_NETWORK_OFFLINE:
str = "Offline";
break;
case RSNET_NETWORK_LOCALNET:
str = "Local Net";
break;
case RSNET_NETWORK_BEHINDNAT:
str = "Behind NAT";
break;
case RSNET_NETWORK_EXTERNALIP:
str = "External IP";
break;
}
return str;
}
std::string NetStateNatTypeString(uint32_t natType)
{
std::string str;

View File

@ -27,6 +27,9 @@
#include <string>
#include <list>
#include <util/rstime.h>
#include <retroshare/rsconfig.h>
/*** Network state
* Want this to be all encompassing.
*
@ -52,7 +55,7 @@ class pqiNetStateBox
void setDhtState(bool dhtOn, bool dhtActive);
uint32_t getNetStateMode();
uint32_t getNetworkMode();
RsNetworkMode getNetworkMode();
uint32_t getNatTypeMode();
uint32_t getNatHoleMode();
uint32_t getConnectModes();
@ -71,7 +74,7 @@ class pqiNetStateBox
bool mStatusOkay;
rstime_t mStatusTS;
uint32_t mNetworkMode;
RsNetworkMode mNetworkMode;
uint32_t mNatTypeMode;
uint32_t mNatHoleMode;
uint32_t mConnectModes;
@ -120,7 +123,6 @@ std::string NetStateNetStateString(uint32_t netstate);
std::string NetStateConnectModesString(uint32_t connect);
std::string NetStateNatHoleString(uint32_t natHole);
std::string NetStateNatTypeString(uint32_t natType);
std::string NetStateNetworkModeString(uint32_t netMode);
#endif

View File

@ -37,12 +37,16 @@ class RsServerConfig;
*/
extern RsServerConfig *rsConfig;
#define RSNET_NETWORK_UNKNOWN 1
#define RSNET_NETWORK_RESTARTING 2
#define RSNET_NETWORK_OFFLINE 3
#define RSNET_NETWORK_LOCALNET 4
#define RSNET_NETWORK_BEHINDNAT 5
#define RSNET_NETWORK_EXTERNALIP 6
enum class RsNetworkMode : uint8_t
{
UNKNOWN = 1,
RESTARTING = 2,
OFFLINE = 3,
LOCALNET = 4,
BEHINDNAT = 5,
EXTERNALIP = 6
};
// WHAT TYPE OF FIREWALL?
#define RSNET_NATTYPE_NONE 1
@ -351,7 +355,7 @@ public:
virtual uint32_t getUserLevel() = 0;
virtual uint32_t getNetState() = 0;
virtual uint32_t getNetworkMode() = 0;
virtual RsNetworkMode getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0;

View File

@ -305,11 +305,11 @@ uint32_t p3ServerConfig::getUserLevel()
{
/* check that the firewall is open */
uint32_t netMode = mNetMgr->getNetworkMode();
RsNetworkMode netMode = mNetMgr->getNetworkMode();
uint32_t firewallMode = mNetMgr->getNatHoleMode();
if ((RSNET_NETWORK_EXTERNALIP == netMode) ||
((RSNET_NETWORK_BEHINDNAT == netMode) &&
if ((RsNetworkMode::EXTERNALIP == netMode) ||
((RsNetworkMode::BEHINDNAT == netMode) &&
((RSNET_NATHOLE_UPNP == firewallMode) ||
(RSNET_NATHOLE_NATPMP == firewallMode) ||
(RSNET_NATHOLE_FORWARDED == firewallMode))))
@ -334,7 +334,7 @@ uint32_t p3ServerConfig::getNetState()
return mNetMgr->getNetStateMode();
}
uint32_t p3ServerConfig::getNetworkMode()
RsNetworkMode p3ServerConfig::getNetworkMode()
{
return mNetMgr->getNetworkMode();
}

View File

@ -75,7 +75,7 @@ virtual std::string getRetroshareDataDirectory();
virtual uint32_t getUserLevel();
virtual uint32_t getNetState();
virtual uint32_t getNetworkMode();
virtual RsNetworkMode getNetworkMode();
virtual uint32_t getNatTypeMode();
virtual uint32_t getNatHoleMode();
virtual uint32_t getConnectModes();

View File

@ -137,24 +137,27 @@ void DhtWindow::updateNetStatus()
ui.peerAddressLabel->setText(status);
}
uint32_t netMode = rsConfig->getNetworkMode();
RsNetworkMode netMode = rsConfig->getNetworkMode();
QLabel *label = ui.networkLabel;
switch(netMode)
{
case RSNET_NETWORK_UNKNOWN:
case RsNetworkMode::UNKNOWN:
label->setText(tr("Unknown NetState"));
break;
case RSNET_NETWORK_OFFLINE:
case RsNetworkMode::RESTARTING:
label->setText(tr("Restarting"));
break;
case RsNetworkMode::OFFLINE:
label->setText(tr("Offline"));
break;
case RSNET_NETWORK_LOCALNET:
case RsNetworkMode::LOCALNET:
label->setText(tr("Local Net"));
break;
case RSNET_NETWORK_BEHINDNAT:
case RsNetworkMode::BEHINDNAT:
label->setText(tr("Behind NAT"));
break;
case RSNET_NETWORK_EXTERNALIP:
case RsNetworkMode::EXTERNALIP:
label->setText(tr("External IP"));
break;
}