convert RSNET_NATTYPE to enum class

This commit is contained in:
sehraf 2020-02-09 21:11:49 +01:00
parent 0237531322
commit f81755e320
No known key found for this signature in database
GPG Key ID: DF09F6EAE356B2C6
9 changed files with 67 additions and 98 deletions

View File

@ -259,7 +259,7 @@ std::string PeerConnectStateBox::connectState() const
}
uint32_t convertNetStateToInternal(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype)
uint32_t convertNetStateToInternal(RsNetworkMode netmode, uint32_t nathole, RsNatTypeMode nattype)
{
uint32_t connNet = CSB_NETSTATE_UNKNOWN;
@ -273,12 +273,12 @@ uint32_t convertNetStateToInternal(RsNetworkMode netmode, uint32_t nathole, uint
}
else if (netmode == RsNetworkMode::BEHINDNAT)
{
if ((nattype == RSNET_NATTYPE_RESTRICTED_CONE) ||
(nattype == RSNET_NATTYPE_FULL_CONE))
if ((nattype == RsNatTypeMode::RESTRICTED_CONE) ||
(nattype == RsNatTypeMode::FULL_CONE))
{
connNet = CSB_NETSTATE_STABLENAT;
}
else if (nattype == RSNET_NATTYPE_DETERM_SYM)
else if (nattype == RsNatTypeMode::DETERM_SYM)
{
connNet = CSB_NETSTATE_EXCLUSIVENAT;
}
@ -299,20 +299,20 @@ bool shouldUseProxyPortInternal(uint32_t netstate)
return true;
}
bool PeerConnectStateBox::shouldUseProxyPort(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype)
bool PeerConnectStateBox::shouldUseProxyPort(RsNetworkMode netmode, uint32_t nathole, RsNatTypeMode nattype)
{
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
return shouldUseProxyPortInternal(netstate);
}
uint32_t PeerConnectStateBox::calcNetState(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype)
uint32_t PeerConnectStateBox::calcNetState(RsNetworkMode netmode, uint32_t nathole, RsNatTypeMode nattype)
{
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
return netstate;
}
uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, RsNetworkMode netmode, uint32_t nathole, uint32_t nattype)
uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, RsNetworkMode netmode, uint32_t nathole, RsNatTypeMode nattype)
{
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);

View File

@ -82,12 +82,12 @@ class PeerConnectStateBox
public:
PeerConnectStateBox();
uint32_t connectCb(uint32_t cbtype, RsNetworkMode netmode, uint32_t nathole, uint32_t nattype);
uint32_t connectCb(uint32_t cbtype, RsNetworkMode netmode, uint32_t nathole, RsNatTypeMode nattype);
uint32_t updateCb(uint32_t updateType);
bool shouldUseProxyPort(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype);
bool shouldUseProxyPort(RsNetworkMode netmode, uint32_t nathole, RsNatTypeMode nattype);
uint32_t calcNetState(RsNetworkMode netmode, uint32_t nathole, uint32_t nattype);
uint32_t calcNetState(RsNetworkMode netmode, uint32_t nathole, RsNatTypeMode nattype);
std::string connectState() const;
std::string mPeerId;

View File

@ -124,7 +124,7 @@ p3NetMgrIMPL::p3NetMgrIMPL() : mPeerMgr(nullptr), mLinkMgr(nullptr),
mNetFlags = pqiNetStatus();
mOldNetFlags = pqiNetStatus();
mOldNatType = RSNET_NATTYPE_UNKNOWN;
mOldNatType = RsNatTypeMode::UNKNOWN;
mOldNatHole = RSNET_NATHOLE_UNKNOWN;
sockaddr_storage_clear(mLocalAddr);
sockaddr_storage_clear(mExtAddr);
@ -1639,7 +1639,7 @@ RsNetworkMode p3NetMgrIMPL::getNetworkMode()
return mNetStateBox.getNetworkMode();
}
uint32_t p3NetMgrIMPL::getNatTypeMode()
RsNatTypeMode p3NetMgrIMPL::getNatTypeMode()
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatTypeMode();
@ -1766,7 +1766,7 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
void p3NetMgrIMPL::updateNatSetting()
{
bool updateRefreshRate = false;
uint32_t natType = RSNET_NATTYPE_UNKNOWN;
RsNatTypeMode natType = RsNatTypeMode::UNKNOWN;
uint32_t natHole = RSNET_NATHOLE_UNKNOWN;
{
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
@ -1803,7 +1803,7 @@ void p3NetMgrIMPL::updateNatSetting()
#ifdef RS_USE_DHT_STUNNER
switch(natType)
{
case RSNET_NATTYPE_RESTRICTED_CONE:
case RsNatTypeMode::RESTRICTED_CONE:
{
if ((natHole == RSNET_NATHOLE_NONE) || (natHole == RSNET_NATHOLE_UNKNOWN))
{
@ -1815,12 +1815,12 @@ void p3NetMgrIMPL::updateNatSetting()
}
break;
}
case RSNET_NATTYPE_NONE:
case RSNET_NATTYPE_UNKNOWN:
case RSNET_NATTYPE_SYMMETRIC:
case RSNET_NATTYPE_DETERM_SYM:
case RSNET_NATTYPE_FULL_CONE:
case RSNET_NATTYPE_OTHER:
case RsNatTypeMode::NONE:
case RsNatTypeMode::UNKNOWN:
case RsNatTypeMode::SYMMETRIC:
case RsNatTypeMode::DETERM_SYM:
case RsNatTypeMode::FULL_CONE:
case RsNatTypeMode::OTHER:
mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_SLOW);
break;
@ -1837,17 +1837,17 @@ void p3NetMgrIMPL::updateNatSetting()
switch(natType)
{
/* switch to attach mode if we have a bad firewall */
case RSNET_NATTYPE_UNKNOWN:
case RSNET_NATTYPE_SYMMETRIC:
case RSNET_NATTYPE_RESTRICTED_CONE:
case RSNET_NATTYPE_DETERM_SYM:
case RSNET_NATTYPE_OTHER:
case RsNatTypeMode::UNKNOWN:
case RsNatTypeMode::SYMMETRIC:
case RsNatTypeMode::RESTRICTED_CONE:
case RsNatTypeMode::DETERM_SYM:
case RsNatTypeMode::OTHER:
netAssistAttach(true);
break;
/* switch off attach mode if we have a nice firewall */
case RSNET_NATTYPE_NONE:
case RSNET_NATTYPE_FULL_CONE:
case RsNatTypeMode::NONE:
case RsNatTypeMode::FULL_CONE:
netAssistAttach(false);
break;
}
@ -1967,7 +1967,7 @@ void p3NetMgrIMPL::updateNetStateBox_reset()
mNetStateBox.reset();
mOldNatHole = RSNET_NATHOLE_UNKNOWN;
mOldNatType = RSNET_NATTYPE_UNKNOWN;
mOldNatType = RsNatTypeMode::UNKNOWN;
}
}

View File

@ -105,7 +105,7 @@ virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode) = 0;
/* Get Network State */
virtual uint32_t getNetStateMode() = 0;
virtual RsNetworkMode getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0;
virtual RsNatTypeMode getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0;
@ -156,7 +156,7 @@ virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode);
/* Get Network State */
virtual uint32_t getNetStateMode();
virtual RsNetworkMode getNetworkMode();
virtual uint32_t getNatTypeMode();
virtual RsNatTypeMode getNatTypeMode();
virtual uint32_t getNatHoleMode();
virtual uint32_t getConnectModes();
@ -323,7 +323,7 @@ void netStatusReset_locked();
pqiNetStateBox mNetStateBox;
rstime_t mDoNotNetCheckUntilTs;
uint32_t mOldNatType;
RsNatTypeMode mOldNatType;
uint32_t mOldNatHole;
RS_SET_CONTEXT_DEBUG_LEVEL(2)

View File

@ -152,7 +152,7 @@ RsNetworkMode pqiNetStateBox::getNetworkMode()
return mNetworkMode;
}
uint32_t pqiNetStateBox::getNatTypeMode()
RsNatTypeMode pqiNetStateBox::getNatTypeMode()
{
updateNetState();
return mNatTypeMode;
@ -193,7 +193,7 @@ void pqiNetStateBox::reset()
//rstime_t mStatusTS;
mNetworkMode = RsNetworkMode::UNKNOWN;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UNKNOWN;
mConnectModes = RSNET_CONNECT_NONE;
mNetStateMode = RSNET_NETSTATE_BAD_UNKNOWN;
@ -303,7 +303,7 @@ void pqiNetStateBox::determineNetworkState()
{
mNetworkMode = RsNetworkMode::UNKNOWN;
// Assume these.
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_BAD_UNKNOWN;
@ -335,7 +335,7 @@ void pqiNetStateBox::determineNetworkState()
*/
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_DETERM_SYM;
mNatTypeMode = RsNatTypeMode::DETERM_SYM;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED;
@ -344,7 +344,7 @@ void pqiNetStateBox::determineNetworkState()
{
/* both unstable, Symmetric NAT, Firewalled, No UDP Hole */
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_SYMMETRIC;
mNatTypeMode = RsNatTypeMode::SYMMETRIC;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_BAD_NATSYM;
}
@ -366,7 +366,7 @@ void pqiNetStateBox::determineNetworkState()
*/
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_RESTRICTED_CONE;
mNatTypeMode = RsNatTypeMode::RESTRICTED_CONE;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED;
}
@ -392,7 +392,7 @@ void pqiNetStateBox::determineNetworkState()
{
/* must be a forwarded port/ext or something similar */
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_DETERM_SYM;
mNatTypeMode = RsNatTypeMode::DETERM_SYM;
mNatHoleMode = RSNET_NATHOLE_FORWARDED;
mNetStateMode = RSNET_NETSTATE_GOOD;
}
@ -400,7 +400,7 @@ void pqiNetStateBox::determineNetworkState()
{
/* must be a forwarded port/ext or something similar */
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_SYMMETRIC;
mNatTypeMode = RsNatTypeMode::SYMMETRIC;
mNatHoleMode = RSNET_NATHOLE_FORWARDED;
mNetStateMode = RSNET_NETSTATE_GOOD;
}
@ -408,7 +408,7 @@ void pqiNetStateBox::determineNetworkState()
{
/* fallback is FULL CONE NAT */
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_FULL_CONE;
mNatTypeMode = RsNatTypeMode::FULL_CONE;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED;
}
@ -418,7 +418,7 @@ void pqiNetStateBox::determineNetworkState()
// This Mode is OKAY.
mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
//mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UPNP;
mNetStateMode = RSNET_NETSTATE_GOOD;
//mExtAddress = ... from UPnP, should match StunDht.
@ -429,7 +429,7 @@ void pqiNetStateBox::determineNetworkState()
// This Mode is OKAY.
mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
//mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NATPMP;
mNetStateMode = RSNET_NETSTATE_GOOD;
//mExtAddress = ... from NatPMP, should match NatPMP
@ -442,7 +442,7 @@ void pqiNetStateBox::determineNetworkState()
if (isExtAddress)
{
mNetworkMode = RsNetworkMode::EXTERNALIP;
mNatTypeMode = RSNET_NATTYPE_NONE;
mNatTypeMode = RsNatTypeMode::NONE;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_GOOD;
@ -452,7 +452,7 @@ void pqiNetStateBox::determineNetworkState()
{
mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
//mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_FORWARDED;
mNetStateMode = RSNET_NETSTATE_ADV_FORWARD;
@ -479,7 +479,7 @@ void pqiNetStateBox::determineNetworkState()
{
// This Mode is OKAY.
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UPNP;
//mExtAddress = ... from UPnP.
//mExtAddrStable = true;
@ -489,7 +489,7 @@ void pqiNetStateBox::determineNetworkState()
{
// This Mode is OKAY.
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NATPMP;
//mExtAddress = ... from NatPMP.
//mExtAddrStable = true;
@ -506,7 +506,7 @@ void pqiNetStateBox::determineNetworkState()
if (isExtAddress)
{
mNetworkMode = RsNetworkMode::EXTERNALIP;
mNatTypeMode = RSNET_NATTYPE_NONE;
mNatTypeMode = RsNatTypeMode::NONE;
mNatHoleMode = RSNET_NATHOLE_NONE;
//mExtAddrStable = true;
@ -515,7 +515,7 @@ void pqiNetStateBox::determineNetworkState()
else if (mPortForwardSet)
{
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_FORWARDED;
//mExtAddrStable = true; // Probably, makin assumption.
@ -528,7 +528,7 @@ void pqiNetStateBox::determineNetworkState()
* Should WARN about this.
*/
mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN;
mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NONE;
mNetStateMode = RSNET_NETSTATE_BAD_NODHT_NAT;
@ -603,9 +603,9 @@ void pqiNetStateBox::workoutNetworkMode()
mConnectModes |= RSNET_CONNECT_DIRECT_UDP;
mConnectModes |= RSNET_CONNECT_RELAY_UDP;
if ((mNatTypeMode == RSNET_NATTYPE_RESTRICTED_CONE) ||
(mNatTypeMode == RSNET_NATTYPE_FULL_CONE) ||
(mNatTypeMode == RSNET_NATTYPE_DETERM_SYM))
if ((mNatTypeMode == RsNatTypeMode::RESTRICTED_CONE) ||
(mNatTypeMode == RsNatTypeMode::FULL_CONE) ||
(mNatTypeMode == RsNatTypeMode::DETERM_SYM))
{
mConnectModes |= RSNET_CONNECT_PROXY_UDP;
}
@ -615,38 +615,6 @@ void pqiNetStateBox::workoutNetworkMode()
}
}
std::string NetStateNatTypeString(uint32_t natType)
{
std::string str;
switch(natType)
{
default:
case RSNET_NATTYPE_UNKNOWN:
str = "UNKNOWN NAT STATE";
break;
case RSNET_NATTYPE_SYMMETRIC:
str = "SYMMETRIC NAT";
break;
case RSNET_NATTYPE_DETERM_SYM:
str = "DETERMINISTIC SYM NAT";
break;
case RSNET_NATTYPE_RESTRICTED_CONE:
str = "RESTRICTED CONE NAT";
break;
case RSNET_NATTYPE_FULL_CONE:
str = "FULL CONE NAT";
break;
case RSNET_NATTYPE_OTHER:
str = "OTHER NAT";
break;
case RSNET_NATTYPE_NONE:
str = "NO NAT";
break;
}
return str;
}
std::string NetStateNatHoleString(uint32_t natHole)
{

View File

@ -56,7 +56,7 @@ class pqiNetStateBox
uint32_t getNetStateMode();
RsNetworkMode getNetworkMode();
uint32_t getNatTypeMode();
RsNatTypeMode getNatTypeMode();
uint32_t getNatHoleMode();
uint32_t getConnectModes();
@ -75,7 +75,7 @@ class pqiNetStateBox
rstime_t mStatusTS;
RsNetworkMode mNetworkMode;
uint32_t mNatTypeMode;
RsNatTypeMode mNatTypeMode;
uint32_t mNatHoleMode;
uint32_t mConnectModes;
uint32_t mNetStateMode;
@ -122,7 +122,6 @@ class pqiNetStateBox
std::string NetStateNetStateString(uint32_t netstate);
std::string NetStateConnectModesString(uint32_t connect);
std::string NetStateNatHoleString(uint32_t natHole);
std::string NetStateNatTypeString(uint32_t natType);
#endif

View File

@ -48,14 +48,16 @@ enum class RsNetworkMode : uint8_t
};
// WHAT TYPE OF FIREWALL?
#define RSNET_NATTYPE_NONE 1
#define RSNET_NATTYPE_UNKNOWN 2
#define RSNET_NATTYPE_SYMMETRIC 3
#define RSNET_NATTYPE_DETERM_SYM 4
#define RSNET_NATTYPE_RESTRICTED_CONE 5
#define RSNET_NATTYPE_FULL_CONE 6
#define RSNET_NATTYPE_OTHER 7
enum class RsNatTypeMode : uint8_t
{
NONE = 1,
UNKNOWN = 2,
SYMMETRIC = 3,
DETERM_SYM = 4,
RESTRICTED_CONE = 5,
FULL_CONE = 6,
OTHER = 7
};
// WHAT TYPE OF HOLE?
#define RSNET_NATHOLE_UNKNOWN 0
@ -356,7 +358,7 @@ public:
virtual uint32_t getNetState() = 0;
virtual RsNetworkMode getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0;
virtual RsNatTypeMode getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0;

View File

@ -339,7 +339,7 @@ RsNetworkMode p3ServerConfig::getNetworkMode()
return mNetMgr->getNetworkMode();
}
uint32_t p3ServerConfig::getNatTypeMode()
RsNatTypeMode p3ServerConfig::getNatTypeMode()
{
return mNetMgr->getNatTypeMode();
}

View File

@ -76,7 +76,7 @@ virtual uint32_t getUserLevel();
virtual uint32_t getNetState();
virtual RsNetworkMode getNetworkMode();
virtual uint32_t getNatTypeMode();
virtual RsNatTypeMode getNatTypeMode();
virtual uint32_t getNatHoleMode();
virtual uint32_t getConnectModes();