From acda7b8cc4ce66c339b0e6f933dff67e29fba252 Mon Sep 17 00:00:00 2001 From: sehraf Date: Sun, 9 Feb 2020 21:45:45 +0100 Subject: [PATCH] convert RSNET_CONNECT to enum class --- libretroshare/src/pqi/p3netmgr.cc | 2 +- libretroshare/src/pqi/p3netmgr.h | 4 +- libretroshare/src/pqi/pqinetstatebox.cc | 56 +++++-------------- libretroshare/src/pqi/pqinetstatebox.h | 6 +- libretroshare/src/retroshare/rsconfig.h | 19 ++++--- libretroshare/src/rsserver/p3serverconfig.cc | 2 +- libretroshare/src/rsserver/p3serverconfig.h | 2 +- .../src/gui/statistics/DhtWindow.cpp | 12 ++-- 8 files changed, 38 insertions(+), 65 deletions(-) diff --git a/libretroshare/src/pqi/p3netmgr.cc b/libretroshare/src/pqi/p3netmgr.cc index f8ba2963b..7e60a9da9 100644 --- a/libretroshare/src/pqi/p3netmgr.cc +++ b/libretroshare/src/pqi/p3netmgr.cc @@ -1651,7 +1651,7 @@ RsNatHoleMode p3NetMgrIMPL::getNatHoleMode() return mNetStateBox.getNatHoleMode(); } -uint32_t p3NetMgrIMPL::getConnectModes() +RsConnectModes p3NetMgrIMPL::getConnectModes() { RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ return mNetStateBox.getConnectModes(); diff --git a/libretroshare/src/pqi/p3netmgr.h b/libretroshare/src/pqi/p3netmgr.h index 513080351..cf9455347 100644 --- a/libretroshare/src/pqi/p3netmgr.h +++ b/libretroshare/src/pqi/p3netmgr.h @@ -107,7 +107,7 @@ virtual uint32_t getNetStateMode() = 0; virtual RsNetworkMode getNetworkMode() = 0; virtual RsNatTypeMode getNatTypeMode() = 0; virtual RsNatHoleMode getNatHoleMode() = 0; -virtual uint32_t getConnectModes() = 0; +virtual RsConnectModes getConnectModes() = 0; /* Shut It Down! */ virtual bool shutdown() = 0; /* blocking shutdown call */ @@ -158,7 +158,7 @@ virtual uint32_t getNetStateMode(); virtual RsNetworkMode getNetworkMode(); virtual RsNatTypeMode getNatTypeMode(); virtual RsNatHoleMode getNatHoleMode(); -virtual uint32_t getConnectModes(); +virtual RsConnectModes getConnectModes(); /* Shut It Down! */ virtual bool shutdown(); /* blocking shutdown call */ diff --git a/libretroshare/src/pqi/pqinetstatebox.cc b/libretroshare/src/pqi/pqinetstatebox.cc index a392f0f74..cc14375f3 100644 --- a/libretroshare/src/pqi/pqinetstatebox.cc +++ b/libretroshare/src/pqi/pqinetstatebox.cc @@ -164,7 +164,7 @@ RsNatHoleMode pqiNetStateBox::getNatHoleMode() return mNatHoleMode; } -uint32_t pqiNetStateBox::getConnectModes() +RsConnectModes pqiNetStateBox::getConnectModes() { updateNetState(); return mConnectModes; @@ -195,7 +195,7 @@ void pqiNetStateBox::reset() mNetworkMode = RsNetworkMode::UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN; mNatHoleMode = RsNatHoleMode::UNKNOWN; - mConnectModes = RSNET_CONNECT_NONE; + mConnectModes = RsConnectModes::NONE; mNetStateMode = RSNET_NETSTATE_BAD_UNKNOWN; /* Parameters set externally */ @@ -552,7 +552,7 @@ void pqiNetStateBox::determineNetworkState() void pqiNetStateBox::workoutNetworkMode() { /* connectModes are dependent on the other modes */ - mConnectModes = RSNET_CONNECT_NONE; + mConnectModes = RsConnectModes::NONE; switch(mNetworkMode) { case RsNetworkMode::UNKNOWN: @@ -562,33 +562,33 @@ void pqiNetStateBox::workoutNetworkMode() /* nothing here */ break; case RsNetworkMode::EXTERNALIP: - mConnectModes = RSNET_CONNECT_OUTGOING_TCP; - mConnectModes |= RSNET_CONNECT_ACCEPT_TCP; + mConnectModes = RsConnectModes::OUTGOING_TCP; + mConnectModes |= RsConnectModes::ACCEPT_TCP; if (mDhtActive) { - mConnectModes |= RSNET_CONNECT_DIRECT_UDP; + mConnectModes |= RsConnectModes::DIRECT_UDP; /* if open port. don't want PROXY or RELAY connect * because we should be able to do direct with EVERYONE. * Ability to do Proxy is dependent on FIREWALL status. * Technically could do RELAY, but disable both. */ - //mConnectModes |= RSNET_CONNECT_PROXY_UDP; - //mConnectModes |= RSNET_CONNECT_RELAY_UDP; + //mConnectModes |= RsConnectModes::PROXY_UDP; + //mConnectModes |= RsConnectModes::RELAY_UDP; } break; case RsNetworkMode::BEHINDNAT: - mConnectModes = RSNET_CONNECT_OUTGOING_TCP; + mConnectModes = RsConnectModes::OUTGOING_TCP; /* we're okay if there's a NAT HOLE */ if ((mNatHoleMode == RsNatHoleMode::UPNP) || (mNatHoleMode == RsNatHoleMode::NATPMP) || (mNatHoleMode == RsNatHoleMode::FORWARDED)) { - mConnectModes |= RSNET_CONNECT_ACCEPT_TCP; + mConnectModes |= RsConnectModes::ACCEPT_TCP; if (mDhtActive) { - mConnectModes |= RSNET_CONNECT_DIRECT_UDP; + mConnectModes |= RsConnectModes::DIRECT_UDP; /* dont want PROXY | RELAY with open ports */ } } @@ -600,14 +600,14 @@ void pqiNetStateBox::workoutNetworkMode() */ if (mDhtActive) { - mConnectModes |= RSNET_CONNECT_DIRECT_UDP; - mConnectModes |= RSNET_CONNECT_RELAY_UDP; + mConnectModes |= RsConnectModes::DIRECT_UDP; + mConnectModes |= RsConnectModes::RELAY_UDP; if ((mNatTypeMode == RsNatTypeMode::RESTRICTED_CONE) || (mNatTypeMode == RsNatTypeMode::FULL_CONE) || (mNatTypeMode == RsNatTypeMode::DETERM_SYM)) { - mConnectModes |= RSNET_CONNECT_PROXY_UDP; + mConnectModes |= RsConnectModes::PROXY_UDP; } } } @@ -616,34 +616,6 @@ void pqiNetStateBox::workoutNetworkMode() } -std::string NetStateConnectModesString(uint32_t connect) -{ - std::string connOut; - if (connect & RSNET_CONNECT_OUTGOING_TCP) - { - connOut += "TCP_OUT "; - } - if (connect & RSNET_CONNECT_ACCEPT_TCP) - { - connOut += "TCP_IN "; - } - if (connect & RSNET_CONNECT_DIRECT_UDP) - { - connOut += "DIRECT_UDP "; - } - if (connect & RSNET_CONNECT_PROXY_UDP) - { - connOut += "PROXY_UDP "; - } - if (connect & RSNET_CONNECT_RELAY_UDP) - { - connOut += "RELAY_UDP "; - } - return connOut; -} - - - std::string NetStateNetStateString(uint32_t netstate) { std::string str; diff --git a/libretroshare/src/pqi/pqinetstatebox.h b/libretroshare/src/pqi/pqinetstatebox.h index 777534aa7..bbda9a135 100644 --- a/libretroshare/src/pqi/pqinetstatebox.h +++ b/libretroshare/src/pqi/pqinetstatebox.h @@ -58,7 +58,7 @@ class pqiNetStateBox RsNetworkMode getNetworkMode(); RsNatTypeMode getNatTypeMode(); RsNatHoleMode getNatHoleMode(); - uint32_t getConnectModes(); + RsConnectModes getConnectModes(); private: @@ -77,7 +77,7 @@ class pqiNetStateBox RsNetworkMode mNetworkMode; RsNatTypeMode mNatTypeMode; RsNatHoleMode mNatHoleMode; - uint32_t mConnectModes; + RsConnectModes mConnectModes; uint32_t mNetStateMode; /* Parameters set externally */ @@ -120,7 +120,5 @@ class pqiNetStateBox std::string NetStateNetStateString(uint32_t netstate); -std::string NetStateConnectModesString(uint32_t connect); - #endif diff --git a/libretroshare/src/retroshare/rsconfig.h b/libretroshare/src/retroshare/rsconfig.h index 6ce03c7e3..b9d7a5dae 100644 --- a/libretroshare/src/retroshare/rsconfig.h +++ b/libretroshare/src/retroshare/rsconfig.h @@ -67,13 +67,16 @@ enum class RsNatHoleMode : uint8_t FORWARDED = 4 }; -// Types of Connections. -#define RSNET_CONNECT_NONE 0x0000 -#define RSNET_CONNECT_ACCEPT_TCP 0x0001 -#define RSNET_CONNECT_OUTGOING_TCP 0x0002 -#define RSNET_CONNECT_DIRECT_UDP 0x0100 -#define RSNET_CONNECT_PROXY_UDP 0x0200 -#define RSNET_CONNECT_RELAY_UDP 0x0400 +enum class RsConnectModes : uint16_t +{ + NONE = 0x0000, + ACCEPT_TCP = 0x0001, + OUTGOING_TCP= 0x0002, + DIRECT_UDP = 0x0100, + PROXY_UDP = 0x0200, + RELAY_UDP = 0x0400 +}; +RS_REGISTER_ENUM_FLAGS_TYPE(RsConnectModes) // net state (good, okay, bad) // BAD. (RED) @@ -361,7 +364,7 @@ public: virtual RsNetworkMode getNetworkMode() = 0; virtual RsNatTypeMode getNatTypeMode() = 0; virtual RsNatHoleMode getNatHoleMode() = 0; - virtual uint32_t getConnectModes() = 0; + virtual RsConnectModes getConnectModes() = 0; virtual bool getConfigurationOption(uint32_t key, std::string &opt) = 0; virtual bool setConfigurationOption(uint32_t key, const std::string &opt) = 0; diff --git a/libretroshare/src/rsserver/p3serverconfig.cc b/libretroshare/src/rsserver/p3serverconfig.cc index fa3e4e0b6..7411eb038 100644 --- a/libretroshare/src/rsserver/p3serverconfig.cc +++ b/libretroshare/src/rsserver/p3serverconfig.cc @@ -349,7 +349,7 @@ RsNatHoleMode p3ServerConfig::getNatHoleMode() return mNetMgr->getNatHoleMode(); } -uint32_t p3ServerConfig::getConnectModes() +RsConnectModes p3ServerConfig::getConnectModes() { return mNetMgr->getConnectModes(); } diff --git a/libretroshare/src/rsserver/p3serverconfig.h b/libretroshare/src/rsserver/p3serverconfig.h index f629ee821..39a3b5138 100644 --- a/libretroshare/src/rsserver/p3serverconfig.h +++ b/libretroshare/src/rsserver/p3serverconfig.h @@ -78,7 +78,7 @@ virtual uint32_t getNetState(); virtual RsNetworkMode getNetworkMode(); virtual RsNatTypeMode getNatTypeMode(); virtual RsNatHoleMode getNatHoleMode(); -virtual uint32_t getConnectModes(); +virtual RsConnectModes getConnectModes(); virtual bool getConfigurationOption(uint32_t key, std::string &opt); virtual bool setConfigurationOption(uint32_t key, const std::string &opt); diff --git a/retroshare-gui/src/gui/statistics/DhtWindow.cpp b/retroshare-gui/src/gui/statistics/DhtWindow.cpp index 7a2048f83..cb0c77a5f 100644 --- a/retroshare-gui/src/gui/statistics/DhtWindow.cpp +++ b/retroshare-gui/src/gui/statistics/DhtWindow.cpp @@ -214,27 +214,27 @@ void DhtWindow::updateNetStatus() break; } - uint32_t connect = rsConfig->getConnectModes(); + RsConnectModes connect = rsConfig->getConnectModes(); label = ui.connectLabel; QString connOut; - if (connect & RSNET_CONNECT_OUTGOING_TCP) + if (!!(connect & RsConnectModes::OUTGOING_TCP)) { connOut += "TCP_OUT "; } - if (connect & RSNET_CONNECT_ACCEPT_TCP) + if (!!(connect & RsConnectModes::ACCEPT_TCP)) { connOut += "TCP_IN "; } - if (connect & RSNET_CONNECT_DIRECT_UDP) + if (!!(connect & RsConnectModes::DIRECT_UDP)) { connOut += "DIRECT_UDP "; } - if (connect & RSNET_CONNECT_PROXY_UDP) + if (!!(connect & RsConnectModes::PROXY_UDP)) { connOut += "PROXY_UDP "; } - if (connect & RSNET_CONNECT_RELAY_UDP) + if (!!(connect & RsConnectModes::RELAY_UDP)) { connOut += "RELAY_UDP "; }