Merge pull request #1785 from sehraf/pr_rsconfig

[NEED REVIEW] Convert #defines to enum class
This commit is contained in:
csoler 2020-10-04 20:50:09 +02:00 committed by GitHub
commit 5006ee1399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 645 additions and 772 deletions

View File

@ -21,7 +21,6 @@
*******************************************************************************/ *******************************************************************************/
#include "dht/connectstatebox.h" #include "dht/connectstatebox.h"
#include "retroshare/rsconfig.h"
#include "util/rsrandom.h" #include "util/rsrandom.h"
#include "util/rsstring.h" #include "util/rsstring.h"
@ -260,26 +259,26 @@ std::string PeerConnectStateBox::connectState() const
} }
uint32_t convertNetStateToInternal(uint32_t netmode, uint32_t nathole, uint32_t nattype) uint32_t convertNetStateToInternal(RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype)
{ {
uint32_t connNet = CSB_NETSTATE_UNKNOWN; uint32_t connNet = CSB_NETSTATE_UNKNOWN;
if (netmode == RSNET_NETWORK_EXTERNALIP) if (netmode == RsNetworkMode::EXTERNALIP)
{ {
connNet = CSB_NETSTATE_FORWARD; connNet = CSB_NETSTATE_FORWARD;
} }
else if ((nathole != RSNET_NATHOLE_UNKNOWN) && (nathole != RSNET_NATHOLE_NONE)) else if ((nathole != RsNatHoleMode::UNKNOWN) && (nathole != RsNatHoleMode::NONE))
{ {
connNet = CSB_NETSTATE_FORWARD; connNet = CSB_NETSTATE_FORWARD;
} }
else if (netmode == RSNET_NETWORK_BEHINDNAT) else if (netmode == RsNetworkMode::BEHINDNAT)
{ {
if ((nattype == RSNET_NATTYPE_RESTRICTED_CONE) || if ((nattype == RsNatTypeMode::RESTRICTED_CONE) ||
(nattype == RSNET_NATTYPE_FULL_CONE)) (nattype == RsNatTypeMode::FULL_CONE))
{ {
connNet = CSB_NETSTATE_STABLENAT; connNet = CSB_NETSTATE_STABLENAT;
} }
else if (nattype == RSNET_NATTYPE_DETERM_SYM) else if (nattype == RsNatTypeMode::DETERM_SYM)
{ {
connNet = CSB_NETSTATE_EXCLUSIVENAT; connNet = CSB_NETSTATE_EXCLUSIVENAT;
} }
@ -300,20 +299,20 @@ bool shouldUseProxyPortInternal(uint32_t netstate)
return true; return true;
} }
bool PeerConnectStateBox::shouldUseProxyPort(uint32_t netmode, uint32_t nathole, uint32_t nattype) bool PeerConnectStateBox::shouldUseProxyPort(RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype)
{ {
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype); uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
return shouldUseProxyPortInternal(netstate); return shouldUseProxyPortInternal(netstate);
} }
uint32_t PeerConnectStateBox::calcNetState(uint32_t netmode, uint32_t nathole, uint32_t nattype) uint32_t PeerConnectStateBox::calcNetState(RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype)
{ {
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype); uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
return netstate; 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, RsNatHoleMode nathole, RsNatTypeMode nattype)
{ {
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype); uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);

View File

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

View File

@ -45,20 +45,20 @@ class DhtPeerDetails
DhtPeerDetails(); DhtPeerDetails();
uint32_t mPeerType; RsDhtPeerType mPeerType;
bdId mDhtId; bdId mDhtId;
RsPeerId mRsId; RsPeerId mRsId;
/* direct from the DHT! */ /* direct from the DHT! */
uint32_t mDhtState; // One of RSDHT_PEERDHT_[...] RsDhtPeerDht mDhtState;
rstime_t mDhtUpdateTS; rstime_t mDhtUpdateTS;
/* internal state */ /* internal state */
PeerConnectStateBox mConnectLogic; PeerConnectStateBox mConnectLogic;
/* Actual Connection Status */ /* Actual Connection Status */
uint32_t mPeerConnectState; // One of RSDHT_PEERCONN_ RsDhtPeerConnectState mPeerConnectState;
std::string mPeerConnectMsg; std::string mPeerConnectMsg;
uint32_t mPeerConnectMode; uint32_t mPeerConnectMode;
bdId mPeerConnectPeerId; bdId mPeerConnectPeerId;
@ -77,7 +77,7 @@ class DhtPeerDetails
/* Connection Request Status */ /* Connection Request Status */
std::string mPeerReqStatusMsg; std::string mPeerReqStatusMsg;
uint32_t mPeerReqState; RsDhtPeerRequest mPeerReqState;
uint32_t mPeerReqMode; uint32_t mPeerReqMode;
bdId mPeerReqProxyId; bdId mPeerReqProxyId;
rstime_t mPeerReqTS; rstime_t mPeerReqTS;
@ -294,11 +294,11 @@ public:
virtual int addRelayServer(std::string ids); virtual int addRelayServer(std::string ids);
virtual int removeRelayServer(std::string ids); virtual int removeRelayServer(std::string ids);
virtual uint32_t getRelayMode(); virtual RsDhtRelayMode getRelayMode();
virtual int setRelayMode(uint32_t mode); virtual int setRelayMode(RsDhtRelayMode mode);
virtual int getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth); virtual int getRelayAllowance(RsDhtRelayClass classIdx, uint32_t &count, uint32_t &bandwidth);
virtual int setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth); virtual int setRelayAllowance(RsDhtRelayClass classIdx, uint32_t count, uint32_t bandwidth);
private: private:
@ -307,7 +307,7 @@ private:
int pushRelayServers(); int pushRelayServers();
std::list<std::string> mRelayServerList; std::list<std::string> mRelayServerList;
uint32_t mRelayMode; RsDhtRelayMode mRelayMode;
protected: protected:
/*****************************************************************/ /*****************************************************************/
@ -348,9 +348,9 @@ public:
private: private:
DhtPeerDetails *addInternalPeer_locked(const RsPeerId& pid, uint32_t type); DhtPeerDetails *addInternalPeer_locked(const RsPeerId& pid, RsDhtPeerType type);
int removeInternalPeer_locked(const RsPeerId& pid); int removeInternalPeer_locked(const RsPeerId& pid);
DhtPeerDetails *findInternalDhtPeer_locked(const bdNodeId *id, uint32_t type); DhtPeerDetails *findInternalDhtPeer_locked(const bdNodeId *id, RsDhtPeerType type);
DhtPeerDetails *findInternalRsPeer_locked(const RsPeerId &pid); DhtPeerDetails *findInternalRsPeer_locked(const RsPeerId &pid);
bool havePeerTranslation_locked(const RsPeerId &pid); bool havePeerTranslation_locked(const RsPeerId &pid);

View File

@ -302,16 +302,16 @@ void convertDhtPeerDetailsToRsDhtNetPeer(RsDhtNetPeer &status, const DhtPeerDeta
switch(details.mPeerConnectMode) switch(details.mPeerConnectMode)
{ {
default: default:
status.mPeerConnectMode = RSDHT_TOU_MODE_NONE; status.mPeerConnectMode = RsDhtTouMode::NONE;
break; break;
case BITDHT_CONNECT_MODE_DIRECT: case BITDHT_CONNECT_MODE_DIRECT:
status.mPeerConnectMode = RSDHT_TOU_MODE_DIRECT; status.mPeerConnectMode = RsDhtTouMode::DIRECT;
break; break;
case BITDHT_CONNECT_MODE_PROXY: case BITDHT_CONNECT_MODE_PROXY:
status.mPeerConnectMode = RSDHT_TOU_MODE_PROXY; status.mPeerConnectMode = RsDhtTouMode::PROXY;
break; break;
case BITDHT_CONNECT_MODE_RELAY: case BITDHT_CONNECT_MODE_RELAY:
status.mPeerConnectMode = RSDHT_TOU_MODE_RELAY; status.mPeerConnectMode = RsDhtTouMode::RELAY;
break; break;
} }

View File

@ -83,7 +83,7 @@ int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
@ -204,7 +204,7 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
@ -222,26 +222,26 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
switch(status) switch(status)
{ {
default: default:
dpd->mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; dpd->mDhtState = RsDhtPeerDht::NOT_ACTIVE;
break; break;
case BITDHT_MGR_QUERY_FAILURE: case BITDHT_MGR_QUERY_FAILURE:
dpd->mDhtState = RSDHT_PEERDHT_FAILURE; dpd->mDhtState = RsDhtPeerDht::FAILURE;
break; break;
case BITDHT_MGR_QUERY_PEER_OFFLINE: case BITDHT_MGR_QUERY_PEER_OFFLINE:
dpd->mDhtState = RSDHT_PEERDHT_OFFLINE; dpd->mDhtState = RsDhtPeerDht::OFFLINE;
break; break;
case BITDHT_MGR_QUERY_PEER_UNREACHABLE: case BITDHT_MGR_QUERY_PEER_UNREACHABLE:
dpd->mDhtState = RSDHT_PEERDHT_UNREACHABLE; dpd->mDhtState = RsDhtPeerDht::UNREACHABLE;
dpd->mDhtId = *id; // set the IP:Port of the unreachable peer. dpd->mDhtId = *id; // set the IP:Port of the unreachable peer.
UnreachablePeerCallback_locked(id, status, dpd); UnreachablePeerCallback_locked(id, status, dpd);
break; break;
case BITDHT_MGR_QUERY_PEER_ONLINE: case BITDHT_MGR_QUERY_PEER_ONLINE:
dpd->mDhtState = RSDHT_PEERDHT_ONLINE; dpd->mDhtState = RsDhtPeerDht::ONLINE;
dpd->mDhtId = *id; // set the IP:Port of the Online peer. dpd->mDhtId = *id; // set the IP:Port of the Online peer.
OnlinePeerCallback_locked(id, status, dpd); OnlinePeerCallback_locked(id, status, dpd);
@ -262,8 +262,8 @@ int p3BitDht::OnlinePeerCallback_locked(const bdId *id, uint32_t /*status*/, Dht
/* remove unused parameter warnings */ /* remove unused parameter warnings */
(void) id; (void) id;
if ((dpd->mPeerConnectState != RSDHT_PEERCONN_DISCONNECTED) || if ((dpd->mPeerConnectState != RsDhtPeerConnectState::DISCONNECTED) ||
(dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING)) (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING))
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
@ -367,8 +367,8 @@ int p3BitDht::OnlinePeerCallback_locked(const bdId *id, uint32_t /*status*/, Dht
int p3BitDht::UnreachablePeerCallback_locked(const bdId *id, uint32_t /*status*/, DhtPeerDetails *dpd) int p3BitDht::UnreachablePeerCallback_locked(const bdId *id, uint32_t /*status*/, DhtPeerDetails *dpd)
{ {
if ((dpd->mPeerConnectState != RSDHT_PEERCONN_DISCONNECTED) || if ((dpd->mPeerConnectState != RsDhtPeerConnectState::DISCONNECTED) ||
(dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING)) (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING))
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
@ -717,7 +717,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
proxyPort = dpd->mConnectLogic.shouldUseProxyPort( proxyPort = dpd->mConnectLogic.shouldUseProxyPort(
@ -811,7 +811,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mExclusiveProxyLock = true; dpd->mExclusiveProxyLock = true;
@ -939,7 +939,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mPeerCbMsg = "ERROR : "; dpd->mPeerCbMsg = "ERROR : ";
@ -980,7 +980,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
if (errcode) if (errcode)
@ -989,7 +989,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
dpd->mPeerReqStatusMsg = "STOPPED: "; dpd->mPeerReqStatusMsg = "STOPPED: ";
dpd->mPeerReqStatusMsg += decodeConnectionError(errcode); dpd->mPeerReqStatusMsg += decodeConnectionError(errcode);
dpd->mPeerReqState = RSDHT_PEERREQ_STOPPED; dpd->mPeerReqState = RsDhtPeerRequest::STOPPED;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
int updatecode = CSB_UPDATE_FAILED_ATTEMPT; int updatecode = CSB_UPDATE_FAILED_ATTEMPT;
@ -1048,7 +1048,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
else // a new connection attempt. else // a new connection attempt.
{ {
dpd->mPeerReqStatusMsg = "Connect Attempt"; dpd->mPeerReqStatusMsg = "Connect Attempt";
dpd->mPeerReqState = RSDHT_PEERREQ_RUNNING; dpd->mPeerReqState = RsDhtPeerRequest::RUNNING;
dpd->mPeerReqMode = mode; dpd->mPeerReqMode = mode;
dpd->mPeerReqProxyId = *proxyId; dpd->mPeerReqProxyId = *proxyId;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
@ -1232,7 +1232,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
connectOk = true; connectOk = true;
@ -1387,11 +1387,11 @@ int p3BitDht::doActions()
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mPeerReqStatusMsg = "Connect Request"; dpd->mPeerReqStatusMsg = "Connect Request";
dpd->mPeerReqState = RSDHT_PEERREQ_RUNNING; dpd->mPeerReqState = RsDhtPeerRequest::RUNNING;
dpd->mPeerReqMode = action.mMode; dpd->mPeerReqMode = action.mMode;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
@ -1428,13 +1428,13 @@ int p3BitDht::doActions()
//} //}
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mConnectLogic.updateCb(failReason); dpd->mConnectLogic.updateCb(failReason);
dpd->mPeerReqStatusMsg = "Req Mode Unavailable"; dpd->mPeerReqStatusMsg = "Req Mode Unavailable";
dpd->mPeerReqState = RSDHT_PEERREQ_STOPPED; dpd->mPeerReqState = RsDhtPeerRequest::STOPPED;
dpd->mPeerReqMode = action.mMode; dpd->mPeerReqMode = action.mMode;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
@ -1496,7 +1496,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mSrcId.id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mSrcId.id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
if (action.mAnswer) if (action.mAnswer)
@ -1604,7 +1604,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
peerRsId = dpd->mRsId; peerRsId = dpd->mRsId;
@ -1730,7 +1730,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
rstime_t now = time(NULL); rstime_t now = time(NULL);
/* check if they are in our friend list */ /* check if they are in our friend list */
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId->id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId->id), RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
@ -1749,14 +1749,14 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
/* flag as failed */ /* flag as failed */
it->second.mDhtId = *peerId; it->second.mDhtId = *peerId;
it->second.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; it->second.mDhtState = RsDhtPeerDht::NOT_ACTIVE;
it->second.mDhtUpdateTS = now; it->second.mDhtUpdateTS = now;
it->second.mPeerType = RSDHT_PEERTYPE_OTHER; it->second.mPeerType = RsDhtPeerType::OTHER;
it->second.mPeerCbMsg = "Denied Non-Friend"; it->second.mPeerCbMsg = "Denied Non-Friend";
it->second.mPeerReqStatusMsg = "Denied Non-Friend"; it->second.mPeerReqStatusMsg = "Denied Non-Friend";
it->second.mPeerReqState = RSDHT_PEERREQ_STOPPED; it->second.mPeerReqState = RsDhtPeerRequest::STOPPED;
it->second.mPeerReqTS = now; it->second.mPeerReqTS = now;
it->second.mPeerReqMode = 0; it->second.mPeerReqMode = 0;
//it->second.mPeerProxyId; //it->second.mPeerProxyId;
@ -1765,7 +1765,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
it->second.mPeerCbMsg = "Denied Non-Friend"; it->second.mPeerCbMsg = "Denied Non-Friend";
it->second.mPeerConnectMsg = "Denied Non-Friend"; it->second.mPeerConnectMsg = "Denied Non-Friend";
it->second.mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; it->second.mPeerConnectState = RsDhtPeerConnectState::DISCONNECTED;
return 0; return 0;
@ -1774,7 +1774,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
/* are a friend */ /* are a friend */
if (dpd->mPeerConnectState == RSDHT_PEERCONN_CONNECTED) if (dpd->mPeerConnectState == RsDhtPeerConnectState::CONNECTED)
{ {
std::cerr << "p3BitDht::checkConnectionAllowed() ERROR Peer Already Connected, DENIED"; std::cerr << "p3BitDht::checkConnectionAllowed() ERROR Peer Already Connected, DENIED";
std::cerr << std::endl; std::cerr << std::endl;
@ -1979,7 +1979,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerConnectId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerConnectId.id), RsDhtPeerType::FRIEND);
/* grab a socket */ /* grab a socket */
if (!dpd) if (!dpd)
{ {
@ -1988,7 +1988,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
return; return;
} }
if (dpd->mPeerConnectState != RSDHT_PEERCONN_DISCONNECTED) if (dpd->mPeerConnectState != RsDhtPeerConnectState::DISCONNECTED)
{ {
std::cerr << "p3BitDht::initiateConnection() ERROR Peer is not Disconnected"; std::cerr << "p3BitDht::initiateConnection() ERROR Peer is not Disconnected";
std::cerr << std::endl; std::cerr << std::endl;
@ -2003,7 +2003,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
{ {
default: default:
case BITDHT_CONNECT_MODE_DIRECT: case BITDHT_CONNECT_MODE_DIRECT:
// touConnectMode = RSDHT_TOU_MODE_DIRECT; // touConnectMode = RsDhtTouMode::DIRECT;
connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT; connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT;
delay = delayOrBandwidth; delay = delayOrBandwidth;
break; break;
@ -2021,12 +2021,12 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
delay = delayOrBandwidth; delay = delayOrBandwidth;
if (useProxyPort) if (useProxyPort)
{ {
// touConnectMode = RSDHT_TOU_MODE_PROXY; // touConnectMode = RsDhtTouMode::PROXY;
connectFlags |= RS_CB_FLAG_MODE_UDP_PROXY; connectFlags |= RS_CB_FLAG_MODE_UDP_PROXY;
} }
else else
{ {
// touConnectMode = RSDHT_TOU_MODE_DIRECT; // touConnectMode = RsDhtTouMode::DIRECT;
connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT; connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT;
} }
@ -2034,7 +2034,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
break; break;
case BITDHT_CONNECT_MODE_RELAY: case BITDHT_CONNECT_MODE_RELAY:
// touConnectMode = RSDHT_TOU_MODE_RELAY; // touConnectMode = RsDhtTouMode::RELAY;
connectFlags |= RS_CB_FLAG_MODE_UDP_RELAY; connectFlags |= RS_CB_FLAG_MODE_UDP_RELAY;
bandwidth = delayOrBandwidth; bandwidth = delayOrBandwidth;
break; break;
@ -2047,7 +2047,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
/* store results in Status */ /* store results in Status */
dpd->mPeerConnectMsg = "UDP started"; dpd->mPeerConnectMsg = "UDP started";
dpd->mPeerConnectState = RSDHT_PEERCONN_UDP_STARTED; dpd->mPeerConnectState = RsDhtPeerConnectState::UDP_STARTED;
dpd->mPeerConnectUdpTS = time(NULL); dpd->mPeerConnectUdpTS = time(NULL);
dpd->mPeerConnectMode = mode; dpd->mPeerConnectMode = mode;
dpd->mPeerConnectPoint = loc; dpd->mPeerConnectPoint = loc;
@ -2092,22 +2092,22 @@ int p3BitDht::installRelayConnection(const bdId *srcId, const bdId *destId, uint
#endif #endif
/* grab a socket */ /* grab a socket */
DhtPeerDetails *dpd_src = findInternalDhtPeer_locked(&(srcId->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd_src = findInternalDhtPeer_locked(&(srcId->id), RsDhtPeerType::ANY);
DhtPeerDetails *dpd_dest = findInternalDhtPeer_locked(&(destId->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd_dest = findInternalDhtPeer_locked(&(destId->id), RsDhtPeerType::ANY);
if ((dpd_src) && (dpd_src->mPeerType == RSDHT_PEERTYPE_FRIEND)) if ((dpd_src) && (dpd_src->mPeerType == RsDhtPeerType::FRIEND))
{ {
relayClass = UDP_RELAY_CLASS_FRIENDS; relayClass = UDP_RELAY_CLASS_FRIENDS;
} }
else if ((dpd_dest) && (dpd_dest->mPeerType == RSDHT_PEERTYPE_FRIEND)) else if ((dpd_dest) && (dpd_dest->mPeerType == RsDhtPeerType::FRIEND))
{ {
relayClass = UDP_RELAY_CLASS_FRIENDS; relayClass = UDP_RELAY_CLASS_FRIENDS;
} }
else if ((dpd_src) && (dpd_src->mPeerType == RSDHT_PEERTYPE_FOF)) else if ((dpd_src) && (dpd_src->mPeerType == RsDhtPeerType::FOF))
{ {
relayClass = UDP_RELAY_CLASS_FOF; relayClass = UDP_RELAY_CLASS_FOF;
} }
else if ((dpd_dest) && (dpd_dest->mPeerType == RSDHT_PEERTYPE_FOF)) else if ((dpd_dest) && (dpd_dest->mPeerType == RsDhtPeerType::FOF))
{ {
relayClass = UDP_RELAY_CLASS_FOF; relayClass = UDP_RELAY_CLASS_FOF;
} }
@ -2178,12 +2178,12 @@ void p3BitDht::monitorConnections()
for(it = mPeers.begin(); it != mPeers.end(); ++it) for(it = mPeers.begin(); it != mPeers.end(); ++it)
{ {
/* ignore ones which aren't friends */ /* ignore ones which aren't friends */
if (it->second.mPeerType != RSDHT_PEERTYPE_FRIEND) if (it->second.mPeerType != RsDhtPeerType::FRIEND)
{ {
continue; continue;
} }
if (it->second.mPeerConnectState == RSDHT_PEERCONN_UDP_STARTED) if (it->second.mPeerConnectState == RsDhtPeerConnectState::UDP_STARTED)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::monitorConnections() Connection in progress to: "; std::cerr << "p3BitDht::monitorConnections() Connection in progress to: ";
@ -2225,7 +2225,7 @@ void p3BitDht::Feedback_Connected(const RsPeerId& pid)
} }
/* sanity checking */ /* sanity checking */
if (dpd->mPeerConnectState != RSDHT_PEERCONN_UDP_STARTED) if (dpd->mPeerConnectState != RsDhtPeerConnectState::UDP_STARTED)
{ {
/* ERROR */ /* ERROR */
std::cerr << "p3BitDht::Feedback_Connected() ERROR not in UDP_STARTED mode for: "; std::cerr << "p3BitDht::Feedback_Connected() ERROR not in UDP_STARTED mode for: ";
@ -2242,7 +2242,7 @@ void p3BitDht::Feedback_Connected(const RsPeerId& pid)
#endif #endif
/* switch state! */ /* switch state! */
dpd->mPeerConnectState = RSDHT_PEERCONN_CONNECTED; dpd->mPeerConnectState = RsDhtPeerConnectState::CONNECTED;
dpd->mPeerConnectTS = time(NULL); dpd->mPeerConnectTS = time(NULL);
dpd->mConnectLogic.updateCb(CSB_UPDATE_CONNECTED); dpd->mConnectLogic.updateCb(CSB_UPDATE_CONNECTED);
@ -2250,7 +2250,7 @@ void p3BitDht::Feedback_Connected(const RsPeerId& pid)
rs_sprintf(dpd->mPeerConnectMsg, "Connected in %ld secs", dpd->mPeerConnectTS - dpd->mPeerConnectUdpTS); rs_sprintf(dpd->mPeerConnectMsg, "Connected in %ld secs", dpd->mPeerConnectTS - dpd->mPeerConnectUdpTS);
// Remove the Connection Request. // Remove the Connection Request.
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) if (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::monitorConnections() Request Active, Stopping Request"; std::cerr << "p3BitDht::monitorConnections() Request Active, Stopping Request";
@ -2334,7 +2334,7 @@ void p3BitDht::Feedback_ConnectionClosed(const RsPeerId& pid)
void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd) void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
{ {
if (dpd->mPeerConnectState == RSDHT_PEERCONN_UDP_STARTED) if (dpd->mPeerConnectState == RsDhtPeerConnectState::UDP_STARTED)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::UdpConnectionFailed_locked() UDP Connection Failed: "; std::cerr << "p3BitDht::UdpConnectionFailed_locked() UDP Connection Failed: ";
@ -2345,11 +2345,11 @@ void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
/* shut it down */ /* shut it down */
/* ONLY need to update ConnectLogic - if it was our Attempt Running */ /* ONLY need to update ConnectLogic - if it was our Attempt Running */
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) if (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING)
{ {
dpd->mConnectLogic.updateCb(CSB_UPDATE_FAILED_ATTEMPT); dpd->mConnectLogic.updateCb(CSB_UPDATE_FAILED_ATTEMPT);
} }
dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; dpd->mPeerConnectState = RsDhtPeerConnectState::DISCONNECTED;
dpd->mPeerConnectMsg = "UDP Failed"; dpd->mPeerConnectMsg = "UDP Failed";
} }
@ -2363,14 +2363,14 @@ void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
dpd->mConnectLogic.updateCb(CSB_UPDATE_DISCONNECTED); dpd->mConnectLogic.updateCb(CSB_UPDATE_DISCONNECTED);
dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; dpd->mPeerConnectState = RsDhtPeerConnectState::DISCONNECTED;
dpd->mPeerConnectClosedTS = time(NULL); dpd->mPeerConnectClosedTS = time(NULL);
rs_sprintf(dpd->mPeerConnectMsg, "Closed, Alive for: %ld secs", dpd->mPeerConnectClosedTS - dpd->mPeerConnectTS); rs_sprintf(dpd->mPeerConnectMsg, "Closed, Alive for: %ld secs", dpd->mPeerConnectClosedTS - dpd->mPeerConnectTS);
} }
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) if (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::UdpConnectionFailed_locked() "; std::cerr << "p3BitDht::UdpConnectionFailed_locked() ";

View File

@ -64,7 +64,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid); DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
if (!dpd) if (!dpd)
{ {
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND); dpd = addInternalPeer_locked(pid, RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
/* ERROR */ /* ERROR */
@ -76,7 +76,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
} }
/* new entry... what do we need to set? */ /* new entry... what do we need to set? */
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING; dpd->mDhtState = RsDhtPeerDht::SEARCHING;
#ifdef DEBUG_BITDHT #ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer() Installed new DhtPeer with pid => NodeId: "; std::cerr << "p3BitDht::findPeer() Installed new DhtPeer with pid => NodeId: ";
@ -93,7 +93,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
if (dpd->mDhtState != RSDHT_PEERDHT_NOT_ACTIVE) if (dpd->mDhtState != RsDhtPeerDht::NOT_ACTIVE)
{ {
#ifdef DEBUG_BITDHT #ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer() WARNING DhtState is Already Active!"; std::cerr << "p3BitDht::findPeer() WARNING DhtState is Already Active!";
@ -104,7 +104,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
else else
{ {
/* flag as searching */ /* flag as searching */
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING; dpd->mDhtState = RsDhtPeerDht::SEARCHING;
#ifdef DEBUG_BITDHT #ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer() Marking Old Peer as SEARCHING"; std::cerr << "p3BitDht::findPeer() Marking Old Peer as SEARCHING";
std::cerr << std::endl; std::cerr << std::endl;
@ -150,13 +150,13 @@ bool p3BitDht::dropPeer(const RsPeerId& pid)
#endif #endif
//addFriend(pid); //addFriend(pid);
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FOF); dpd = addInternalPeer_locked(pid, RsDhtPeerType::FOF);
return false; return false;
} }
/* flag as searching */ /* flag as searching */
dpd->mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; dpd->mDhtState = RsDhtPeerDht::NOT_ACTIVE;
nid = dpd->mDhtId.id; nid = dpd->mDhtId.id;
@ -242,7 +242,7 @@ int p3BitDht::addKnownPeer( const RsPeerId &pid,
addrv4.sin_addr = ap->sin_addr; addrv4.sin_addr = ap->sin_addr;
addrv4.sin_port = ap->sin_port; addrv4.sin_port = ap->sin_port;
int p3type = 0; RsDhtPeerType p3type = RsDhtPeerType::ANY;
int bdflags = 0; int bdflags = 0;
bdId id; bdId id;
bool isOwnId = false; bool isOwnId = false;
@ -253,27 +253,27 @@ int p3BitDht::addKnownPeer( const RsPeerId &pid,
return 0; return 0;
break; break;
case NETASSIST_KNOWN_PEER_WHITELIST: case NETASSIST_KNOWN_PEER_WHITELIST:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST; bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST;
break; break;
case NETASSIST_KNOWN_PEER_FOF: case NETASSIST_KNOWN_PEER_FOF:
p3type = RSDHT_PEERTYPE_FOF; p3type = RsDhtPeerType::FOF;
bdflags = BITDHT_PEER_STATUS_DHT_FOF; bdflags = BITDHT_PEER_STATUS_DHT_FOF;
break; break;
case NETASSIST_KNOWN_PEER_FRIEND: case NETASSIST_KNOWN_PEER_FRIEND:
p3type = RSDHT_PEERTYPE_FRIEND; p3type = RsDhtPeerType::FRIEND;
bdflags = BITDHT_PEER_STATUS_DHT_FRIEND; bdflags = BITDHT_PEER_STATUS_DHT_FRIEND;
break; break;
case NETASSIST_KNOWN_PEER_RELAY: case NETASSIST_KNOWN_PEER_RELAY:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER; bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER;
break; break;
case NETASSIST_KNOWN_PEER_SELF: case NETASSIST_KNOWN_PEER_SELF:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_SELF; bdflags = BITDHT_PEER_STATUS_DHT_SELF;
isOwnId = true; isOwnId = true;
@ -364,7 +364,7 @@ int p3BitDht::addFriend(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::FRIEND));
} }
@ -372,7 +372,7 @@ int p3BitDht::addFriendOfFriend(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_FOF)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::FOF));
} }
@ -380,7 +380,7 @@ int p3BitDht::addOther(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_OTHER)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::OTHER));
} }
#endif #endif
@ -397,7 +397,7 @@ int p3BitDht::removePeer(const RsPeerId& pid)
********************************* Basic Peer Details ************************************* ********************************* Basic Peer Details *************************************
******************************************************************************************/ ******************************************************************************************/
DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t type) DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, RsDhtPeerType type)
{ {
/* create the data structure */ /* create the data structure */
if (!havePeerTranslation_locked(pid)) if (!havePeerTranslation_locked(pid))
@ -411,18 +411,18 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t t
return 0; return 0;
} }
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id, RsDhtPeerType::ANY);
if (!dpd) if (!dpd)
{ {
DhtPeerDetails newdpd; DhtPeerDetails newdpd;
newdpd.mDhtId.id = id; newdpd.mDhtId.id = id;
newdpd.mRsId = pid; newdpd.mRsId = pid;
newdpd.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; newdpd.mDhtState = RsDhtPeerDht::NOT_ACTIVE;
newdpd.mPeerType = RSDHT_PEERTYPE_ANY; newdpd.mPeerType = RsDhtPeerType::ANY;
mPeers[id] = newdpd; mPeers[id] = newdpd;
dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY); dpd = findInternalDhtPeer_locked(&id, RsDhtPeerType::ANY);
if(dpd == NULL) if(dpd == NULL)
{ {
@ -462,14 +462,14 @@ int p3BitDht::removeInternalPeer_locked(const RsPeerId& pid)
/* indexed by bdNodeId, as this is the more used call interface */ /* indexed by bdNodeId, as this is the more used call interface */
DhtPeerDetails *p3BitDht::findInternalDhtPeer_locked(const bdNodeId *id, uint32_t type) DhtPeerDetails *p3BitDht::findInternalDhtPeer_locked(const bdNodeId *id, RsDhtPeerType type)
{ {
std::map<bdNodeId, DhtPeerDetails>::iterator it = mPeers.find(*id); std::map<bdNodeId, DhtPeerDetails>::iterator it = mPeers.find(*id);
if (it == mPeers.end()) if (it == mPeers.end())
{ {
return NULL; return NULL;
} }
if (type) if (type != RsDhtPeerType::ANY)
{ {
if (it->second.mPeerType != type) if (it->second.mPeerType != type)
{ {
@ -495,7 +495,7 @@ DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const RsPeerId &pid)
return NULL; return NULL;
} }
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id,RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id,RsDhtPeerType::ANY);
return dpd; return dpd;
} }
@ -717,13 +717,13 @@ int p3BitDht::calculateNodeId(const RsPeerId& pid, bdNodeId *id)
DhtPeerDetails::DhtPeerDetails() DhtPeerDetails::DhtPeerDetails()
{ {
mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; mDhtState = RsDhtPeerDht::NOT_ACTIVE;
mDhtState = RSDHT_PEERDHT_SEARCHING; mDhtState = RsDhtPeerDht::SEARCHING;
mDhtUpdateTS = time(NULL); mDhtUpdateTS = time(NULL);
mPeerReqStatusMsg = "Just Added"; mPeerReqStatusMsg = "Just Added";
mPeerReqState = RSDHT_PEERREQ_STOPPED; mPeerReqState = RsDhtPeerRequest::STOPPED;
mPeerReqMode = 0; mPeerReqMode = 0;
//mPeerReqProxyId; //mPeerReqProxyId;
mPeerReqTS = time(NULL); mPeerReqTS = time(NULL);
@ -737,7 +737,7 @@ DhtPeerDetails::DhtPeerDetails()
//mPeerCbDestId = 0; //mPeerCbDestId = 0;
mPeerCbTS = 0; mPeerCbTS = 0;
mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; mPeerConnectState = RsDhtPeerConnectState::DISCONNECTED;
mPeerConnectMsg = "Disconnected"; mPeerConnectMsg = "Disconnected";
mPeerConnectMode = 0; mPeerConnectMode = 0;
//dpd->mPeerConnectProxyId; //dpd->mPeerConnectProxyId;

View File

@ -35,7 +35,7 @@
int p3BitDht::setupRelayDefaults() int p3BitDht::setupRelayDefaults()
{ {
uint32_t mode = RSDHT_RELAY_ENABLED | RSDHT_RELAY_MODE_OFF; RsDhtRelayMode mode = RsDhtRelayMode::ENABLED | RsDhtRelayMode::OFF;
setRelayMode(mode); setRelayMode(mode);
return 1; return 1;
@ -111,19 +111,19 @@ int p3BitDht::pushRelayServers()
} }
uint32_t p3BitDht::getRelayMode() RsDhtRelayMode p3BitDht::getRelayMode()
{ {
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/ RsStackMutex stack(dhtMtx); /*********** LOCKED **********/
return mRelayMode; return mRelayMode;
} }
int p3BitDht::setRelayMode(uint32_t mode) int p3BitDht::setRelayMode(RsDhtRelayMode mode)
{ {
std::cerr << "p3BitDht::setRelayMode(" << mode << ")"; std::cerr << "p3BitDht::setRelayMode(" << mode << ")";
std::cerr << std::endl; std::cerr << std::endl;
if (mode & RSDHT_RELAY_ENABLED) if (!!(mode & RsDhtRelayMode::ENABLED))
{ {
mUdpBitDht->ConnectionOptions( mUdpBitDht->ConnectionOptions(
BITDHT_CONNECT_MODE_DIRECT | BITDHT_CONNECT_MODE_PROXY | BITDHT_CONNECT_MODE_RELAY, BITDHT_CONNECT_MODE_DIRECT | BITDHT_CONNECT_MODE_PROXY | BITDHT_CONNECT_MODE_RELAY,
@ -136,18 +136,18 @@ int p3BitDht::setRelayMode(uint32_t mode)
BITDHT_CONNECT_OPTION_AUTOPROXY); BITDHT_CONNECT_OPTION_AUTOPROXY);
} }
int relaymode = mode & RSDHT_RELAY_MODE_MASK; RsDhtRelayMode relaymode = mode & RsDhtRelayMode::MASK;
switch(relaymode) switch(relaymode)
{ {
case RSDHT_RELAY_MODE_OFF: case RsDhtRelayMode::OFF:
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_IGNORED); mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_IGNORED);
break; break;
case RSDHT_RELAY_MODE_ON: case RsDhtRelayMode::ON:
pushRelayServers(); pushRelayServers();
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_FLAGGED); mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_FLAGGED);
break; break;
case RSDHT_RELAY_MODE_SERVER: case RsDhtRelayMode::SERVER:
pushRelayServers(); pushRelayServers();
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_SERVER); mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_SERVER);
break; break;
@ -163,13 +163,13 @@ int p3BitDht::setRelayMode(uint32_t mode)
return 1; return 1;
} }
int p3BitDht::getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth) int p3BitDht::getRelayAllowance(RsDhtRelayClass classIdx, uint32_t &count, uint32_t &bandwidth)
{ {
std::cerr << "p3BitDht::getRelayAllowance(" << classIdx << "): "; std::cerr << "p3BitDht::getRelayAllowance(" << static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx) << "): ";
if ((classIdx >= 0) && (classIdx < RSDHT_RELAY_NUM_CLASS)) if ((classIdx >= RsDhtRelayClass::ALL) && (classIdx < RsDhtRelayClass::NUM_CLASS))
{ {
count = mRelay->getRelayClassMax(classIdx); count = mRelay->getRelayClassMax(static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx));
bandwidth = mRelay->getRelayClassBandwidth(classIdx); bandwidth = mRelay->getRelayClassBandwidth(static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx));
std::cerr << " count: " << count << " bandwidth: " << bandwidth; std::cerr << " count: " << count << " bandwidth: " << bandwidth;
std::cerr << std::endl; std::cerr << std::endl;
@ -181,13 +181,13 @@ int p3BitDht::getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwid
return 0; return 0;
} }
int p3BitDht::setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth) int p3BitDht::setRelayAllowance(RsDhtRelayClass classIdx, uint32_t count, uint32_t bandwidth)
{ {
std::cerr << "p3BitDht::getRelayAllowance(" << classIdx << ", "; std::cerr << "p3BitDht::getRelayAllowance(" << static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx) << ", ";
std::cerr << ", " << count << ", " << bandwidth << ")"; std::cerr << ", " << count << ", " << bandwidth << ")";
std::cerr << std::endl; std::cerr << std::endl;
int retval = mRelay->setRelayClassMax(classIdx, count, bandwidth); int retval = mRelay->setRelayClassMax(static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx), count, bandwidth);
IndicateConfigChanged(); IndicateConfigChanged();
return retval; return retval;
@ -224,7 +224,7 @@ bool p3BitDht::saveList(bool &cleanup, std::list<RsItem *> &saveList)
/* Push Relay Class Stuff */ /* Push Relay Class Stuff */
int i; int i;
for(i = 0; i < RSDHT_RELAY_NUM_CLASS; ++i) for(i = 0; i < static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS); ++i)
{ {
rs_sprintf(kv.key, "RELAY_CLASS%d_COUNT", i); rs_sprintf(kv.key, "RELAY_CLASS%d_COUNT", i);
rs_sprintf(kv.value, "%d", mRelay->getRelayClassMax(i)); rs_sprintf(kv.value, "%d", mRelay->getRelayClassMax(i));
@ -302,11 +302,11 @@ bool p3BitDht::loadList(std::list<RsItem *>& load)
//config->print(std::cerr, 0); //config->print(std::cerr, 0);
std::list<std::string> servers; std::list<std::string> servers;
int peers[RSDHT_RELAY_NUM_CLASS] = {0}; int peers[static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS)] = {0};
int bandwidth[RSDHT_RELAY_NUM_CLASS] = {0}; int bandwidth[static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS)] = {0};
bool haveMode = false; bool haveMode = false;
int mode = 0; RsDhtRelayMode mode = RsDhtRelayMode::DISABLED;
std::list<RsTlvKeyValue>::iterator it; std::list<RsTlvKeyValue>::iterator it;
for(it = config->tlvkvs.pairs.begin(); it != config->tlvkvs.pairs.end(); ++it) for(it = config->tlvkvs.pairs.begin(); it != config->tlvkvs.pairs.end(); ++it)
@ -322,7 +322,7 @@ bool p3BitDht::loadList(std::list<RsItem *>& load)
} }
else if (0 == strncmp(key.c_str(), "RELAY_MODE", 10)) else if (0 == strncmp(key.c_str(), "RELAY_MODE", 10))
{ {
mode = atoi(value.c_str()); mode = static_cast<RsDhtRelayMode>(atoi(value.c_str()));
haveMode = true; haveMode = true;
//std::cerr << "p3BitDht::loadList() Found Mode: " << mode; //std::cerr << "p3BitDht::loadList() Found Mode: " << mode;
@ -386,7 +386,7 @@ bool p3BitDht::loadList(std::list<RsItem *>& load)
} }
int i; int i;
for(i = 0; i < RSDHT_RELAY_NUM_CLASS; ++i) for(i = 0; i < static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS); ++i)
{ {
mRelay->setRelayClassMax(i, peers[i], bandwidth[i]); mRelay->setRelayClassMax(i, peers[i], bandwidth[i]);
} }

View File

@ -1063,8 +1063,12 @@ void p3LinkMgrIMPL::peerStatus(const RsPeerId& id, const pqiIpAddrSet &addrs,
uint32_t peer_vs_dht = 0; uint32_t peer_vs_dht = 0;
uint32_t peerNetMode = 0; uint32_t peerNetMode = 0;
uint32_t ownNetMode = mNetMgr->getNetworkMode(); int ownNetMode;
{
peerState ps;
mPeerMgr->getOwnNetStatus(ps);
ownNetMode = ps.netMode;
}
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/

View File

@ -124,8 +124,8 @@ p3NetMgrIMPL::p3NetMgrIMPL() : mPeerMgr(nullptr), mLinkMgr(nullptr),
mNetFlags = pqiNetStatus(); mNetFlags = pqiNetStatus();
mOldNetFlags = pqiNetStatus(); mOldNetFlags = pqiNetStatus();
mOldNatType = RSNET_NATTYPE_UNKNOWN; mOldNatType = RsNatTypeMode::UNKNOWN;
mOldNatHole = RSNET_NATHOLE_UNKNOWN; mOldNatHole = RsNatHoleMode::UNKNOWN;
sockaddr_storage_clear(mLocalAddr); sockaddr_storage_clear(mLocalAddr);
sockaddr_storage_clear(mExtAddr); sockaddr_storage_clear(mExtAddr);
@ -1629,31 +1629,31 @@ void p3NetMgrIMPL::setIPServersEnabled(bool b)
************************************** NetStateBox ****************************************** ************************************** NetStateBox ******************************************
**********************************************************************************************/ **********************************************************************************************/
uint32_t p3NetMgrIMPL::getNetStateMode() RsNetState p3NetMgrIMPL::getNetStateMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetStateMode(); return mNetStateBox.getNetStateMode();
} }
uint32_t p3NetMgrIMPL::getNetworkMode() RsNetworkMode p3NetMgrIMPL::getNetworkMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetworkMode(); return mNetStateBox.getNetworkMode();
} }
uint32_t p3NetMgrIMPL::getNatTypeMode() RsNatTypeMode p3NetMgrIMPL::getNatTypeMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatTypeMode(); return mNetStateBox.getNatTypeMode();
} }
uint32_t p3NetMgrIMPL::getNatHoleMode() RsNatHoleMode p3NetMgrIMPL::getNatHoleMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatHoleMode(); return mNetStateBox.getNatHoleMode();
} }
uint32_t p3NetMgrIMPL::getConnectModes() RsConnectModes p3NetMgrIMPL::getConnectModes()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getConnectModes(); return mNetStateBox.getConnectModes();
@ -1768,8 +1768,8 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
void p3NetMgrIMPL::updateNatSetting() void p3NetMgrIMPL::updateNatSetting()
{ {
bool updateRefreshRate = false; bool updateRefreshRate = false;
uint32_t natType = RSNET_NATTYPE_UNKNOWN; RsNatTypeMode natType = RsNatTypeMode::UNKNOWN;
uint32_t natHole = RSNET_NATHOLE_UNKNOWN; RsNatHoleMode natHole = RsNatHoleMode::UNKNOWN;
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
@ -1806,9 +1806,9 @@ void p3NetMgrIMPL::updateNatSetting()
if (mProxyStunner) { if (mProxyStunner) {
switch(natType) switch(natType)
{ {
case RSNET_NATTYPE_RESTRICTED_CONE: case RsNatTypeMode::RESTRICTED_CONE:
{ {
if ((natHole == RSNET_NATHOLE_NONE) || (natHole == RSNET_NATHOLE_UNKNOWN)) if ((natHole == RsNatHoleMode::NONE) || (natHole == RsNatHoleMode::UNKNOWN))
{ {
mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_FAST); mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_FAST);
} }
@ -1818,12 +1818,12 @@ void p3NetMgrIMPL::updateNatSetting()
} }
break; break;
} }
case RSNET_NATTYPE_NONE: case RsNatTypeMode::NONE:
case RSNET_NATTYPE_UNKNOWN: case RsNatTypeMode::UNKNOWN:
case RSNET_NATTYPE_SYMMETRIC: case RsNatTypeMode::SYMMETRIC:
case RSNET_NATTYPE_DETERM_SYM: case RsNatTypeMode::DETERM_SYM:
case RSNET_NATTYPE_FULL_CONE: case RsNatTypeMode::FULL_CONE:
case RSNET_NATTYPE_OTHER: case RsNatTypeMode::OTHER:
mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_SLOW); mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_SLOW);
break; break;
@ -1836,22 +1836,22 @@ void p3NetMgrIMPL::updateNatSetting()
* So that messages can get through. * So that messages can get through.
* We only want to be attached - if we don't have a stable DHT port. * We only want to be attached - if we don't have a stable DHT port.
*/ */
if ((natHole == RSNET_NATHOLE_NONE) || (natHole == RSNET_NATHOLE_UNKNOWN)) if ((natHole == RsNatHoleMode::NONE) || (natHole == RsNatHoleMode::UNKNOWN))
{ {
switch(natType) switch(natType)
{ {
/* switch to attach mode if we have a bad firewall */ /* switch to attach mode if we have a bad firewall */
case RSNET_NATTYPE_UNKNOWN: case RsNatTypeMode::UNKNOWN:
case RSNET_NATTYPE_SYMMETRIC: case RsNatTypeMode::SYMMETRIC:
case RSNET_NATTYPE_RESTRICTED_CONE: case RsNatTypeMode::RESTRICTED_CONE:
case RSNET_NATTYPE_DETERM_SYM: case RsNatTypeMode::DETERM_SYM:
case RSNET_NATTYPE_OTHER: case RsNatTypeMode::OTHER:
netAssistAttach(true); netAssistAttach(true);
break; break;
/* switch off attach mode if we have a nice firewall */ /* switch off attach mode if we have a nice firewall */
case RSNET_NATTYPE_NONE: case RsNatTypeMode::NONE:
case RSNET_NATTYPE_FULL_CONE: case RsNatTypeMode::FULL_CONE:
netAssistAttach(false); netAssistAttach(false);
break; break;
} }
@ -1970,8 +1970,8 @@ void p3NetMgrIMPL::updateNetStateBox_reset()
mNetStateBox.reset(); mNetStateBox.reset();
mOldNatHole = RSNET_NATHOLE_UNKNOWN; mOldNatHole = RsNatHoleMode::UNKNOWN;
mOldNatType = RSNET_NATTYPE_UNKNOWN; mOldNatType = RsNatTypeMode::UNKNOWN;
} }
} }

View File

@ -103,11 +103,11 @@ virtual bool netAssistBadPeer(const struct sockaddr_storage &addr, uint32_t reas
virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode) = 0; virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode) = 0;
/* Get Network State */ /* Get Network State */
virtual uint32_t getNetStateMode() = 0; virtual RsNetState getNetStateMode() = 0;
virtual uint32_t getNetworkMode() = 0; virtual RsNetworkMode getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0; virtual RsNatTypeMode getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0; virtual RsNatHoleMode getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0; virtual RsConnectModes getConnectModes() = 0;
/* Shut It Down! */ /* Shut It Down! */
virtual bool shutdown() = 0; /* blocking shutdown call */ virtual bool shutdown() = 0; /* blocking shutdown call */
@ -154,11 +154,11 @@ virtual bool netAssistBadPeer(const struct sockaddr_storage &addr, uint32_t reas
virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode); virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode);
/* Get Network State */ /* Get Network State */
virtual uint32_t getNetStateMode(); virtual RsNetState getNetStateMode();
virtual uint32_t getNetworkMode(); virtual RsNetworkMode getNetworkMode();
virtual uint32_t getNatTypeMode(); virtual RsNatTypeMode getNatTypeMode();
virtual uint32_t getNatHoleMode(); virtual RsNatHoleMode getNatHoleMode();
virtual uint32_t getConnectModes(); virtual RsConnectModes getConnectModes();
/* Shut It Down! */ /* Shut It Down! */
virtual bool shutdown(); /* blocking shutdown call */ virtual bool shutdown(); /* blocking shutdown call */
@ -323,8 +323,8 @@ void netStatusReset_locked();
pqiNetStateBox mNetStateBox; pqiNetStateBox mNetStateBox;
rstime_t mDoNotNetCheckUntilTs; rstime_t mDoNotNetCheckUntilTs;
uint32_t mOldNatType; RsNatTypeMode mOldNatType;
uint32_t mOldNatHole; RsNatHoleMode mOldNatHole;
RS_SET_CONTEXT_DEBUG_LEVEL(2) RS_SET_CONTEXT_DEBUG_LEVEL(2)
}; };

View File

@ -20,7 +20,6 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "retroshare/rsconfig.h"
#include "util/rsnet.h" #include "util/rsnet.h"
#include "pqi/pqinetstatebox.h" #include "pqi/pqinetstatebox.h"
#include "util/rstime.h" #include "util/rstime.h"
@ -147,32 +146,32 @@ void pqiNetStateBox::setDhtState(bool on, bool active)
/* Extract Net State */ /* Extract Net State */
uint32_t pqiNetStateBox::getNetworkMode() RsNetworkMode pqiNetStateBox::getNetworkMode()
{ {
updateNetState(); updateNetState();
return mNetworkMode; return mNetworkMode;
} }
uint32_t pqiNetStateBox::getNatTypeMode() RsNatTypeMode pqiNetStateBox::getNatTypeMode()
{ {
updateNetState(); updateNetState();
return mNatTypeMode; return mNatTypeMode;
} }
uint32_t pqiNetStateBox::getNatHoleMode() RsNatHoleMode pqiNetStateBox::getNatHoleMode()
{ {
updateNetState(); updateNetState();
return mNatHoleMode; return mNatHoleMode;
} }
uint32_t pqiNetStateBox::getConnectModes() RsConnectModes pqiNetStateBox::getConnectModes()
{ {
updateNetState(); updateNetState();
return mConnectModes; return mConnectModes;
} }
uint32_t pqiNetStateBox::getNetStateMode() RsNetState pqiNetStateBox::getNetStateMode()
{ {
updateNetState(); updateNetState();
return mNetStateMode; return mNetStateMode;
@ -193,11 +192,11 @@ void pqiNetStateBox::reset()
mStatusOkay = false; mStatusOkay = false;
//rstime_t mStatusTS; //rstime_t mStatusTS;
mNetworkMode = RSNET_NETWORK_UNKNOWN; mNetworkMode = RsNetworkMode::UNKNOWN;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UNKNOWN; mNatHoleMode = RsNatHoleMode::UNKNOWN;
mConnectModes = RSNET_CONNECT_NONE; mConnectModes = RsConnectModes::NONE;
mNetStateMode = RSNET_NETSTATE_BAD_UNKNOWN; mNetStateMode = RsNetState::BAD_UNKNOWN;
/* Parameters set externally */ /* Parameters set externally */
@ -302,11 +301,11 @@ void pqiNetStateBox::determineNetworkState()
/* firstly lets try to identify OFFLINE / UNKNOWN */ /* firstly lets try to identify OFFLINE / UNKNOWN */
if ((!mStunProxySet) || (!mStunDhtSet)) if ((!mStunProxySet) || (!mStunDhtSet))
{ {
mNetworkMode = RSNET_NETWORK_UNKNOWN; mNetworkMode = RsNetworkMode::UNKNOWN;
// Assume these. // Assume these.
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_BAD_UNKNOWN; mNetStateMode = RsNetState::BAD_UNKNOWN;
//mExtAddress = .... unknown; //mExtAddress = .... unknown;
//mExtAddrStable = false; //mExtAddrStable = false;
@ -335,19 +334,19 @@ void pqiNetStateBox::determineNetworkState()
* *
*/ */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_DETERM_SYM; mNatTypeMode = RsNatTypeMode::DETERM_SYM;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED; mNetStateMode = RsNetState::WARNING_NATTED;
} }
else if (!mStunProxyStable) else if (!mStunProxyStable)
{ {
/* both unstable, Symmetric NAT, Firewalled, No UDP Hole */ /* both unstable, Symmetric NAT, Firewalled, No UDP Hole */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_SYMMETRIC; mNatTypeMode = RsNatTypeMode::SYMMETRIC;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_BAD_NATSYM; mNetStateMode = RsNetState::BAD_NATSYM;
} }
else else
{ {
@ -366,10 +365,10 @@ void pqiNetStateBox::determineNetworkState()
* but that label is really fully accurate. (gray area). * but that label is really fully accurate. (gray area).
*/ */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_RESTRICTED_CONE; mNatTypeMode = RsNatTypeMode::RESTRICTED_CONE;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED; mNetStateMode = RsNetState::WARNING_NATTED;
} }
} }
else // Dht Stable. else // Dht Stable.
@ -392,47 +391,47 @@ void pqiNetStateBox::determineNetworkState()
if (mStunProxySemiStable) if (mStunProxySemiStable)
{ {
/* must be a forwarded port/ext or something similar */ /* must be a forwarded port/ext or something similar */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_DETERM_SYM; mNatTypeMode = RsNatTypeMode::DETERM_SYM;
mNatHoleMode = RSNET_NATHOLE_FORWARDED; mNatHoleMode = RsNatHoleMode::FORWARDED;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
} }
else if (!mStunProxyStable) else if (!mStunProxyStable)
{ {
/* must be a forwarded port/ext or something similar */ /* must be a forwarded port/ext or something similar */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_SYMMETRIC; mNatTypeMode = RsNatTypeMode::SYMMETRIC;
mNatHoleMode = RSNET_NATHOLE_FORWARDED; mNatHoleMode = RsNatHoleMode::FORWARDED;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
} }
else else
{ {
/* fallback is FULL CONE NAT */ /* fallback is FULL CONE NAT */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_FULL_CONE; mNatTypeMode = RsNatTypeMode::FULL_CONE;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED; mNetStateMode = RsNetState::WARNING_NATTED;
} }
if (mUPnPActive) if (mUPnPActive)
{ {
// This Mode is OKAY. // This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess. // Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN; //mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UPNP; mNatHoleMode = RsNatHoleMode::UPNP;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
//mExtAddress = ... from UPnP, should match StunDht. //mExtAddress = ... from UPnP, should match StunDht.
//mExtAddrStable = true; //mExtAddrStable = true;
} }
else if (mNatPMPActive) else if (mNatPMPActive)
{ {
// This Mode is OKAY. // This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess. // Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN; //mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NATPMP; mNatHoleMode = RsNatHoleMode::NATPMP;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
//mExtAddress = ... from NatPMP, should match NatPMP //mExtAddress = ... from NatPMP, should match NatPMP
//mExtAddrStable = true; //mExtAddrStable = true;
} }
@ -442,20 +441,20 @@ void pqiNetStateBox::determineNetworkState()
if (isExtAddress) if (isExtAddress)
{ {
mNetworkMode = RSNET_NETWORK_EXTERNALIP; mNetworkMode = RsNetworkMode::EXTERNALIP;
mNatTypeMode = RSNET_NATTYPE_NONE; mNatTypeMode = RsNatTypeMode::NONE;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
//mExtAddrStable = true; //mExtAddrStable = true;
} }
else if (mPortForwardSet) else if (mPortForwardSet)
{ {
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess. // Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN; //mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_FORWARDED; mNatHoleMode = RsNatHoleMode::FORWARDED;
mNetStateMode = RSNET_NETSTATE_ADV_FORWARD; mNetStateMode = RsNetState::ADV_FORWARD;
//mExtAddrStable = true; // Probably, makin assumption. //mExtAddrStable = true; // Probably, makin assumption.
} }
@ -479,22 +478,22 @@ void pqiNetStateBox::determineNetworkState()
if (mUPnPActive) if (mUPnPActive)
{ {
// This Mode is OKAY. // This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UPNP; mNatHoleMode = RsNatHoleMode::UPNP;
//mExtAddress = ... from UPnP. //mExtAddress = ... from UPnP.
//mExtAddrStable = true; //mExtAddrStable = true;
mNetStateMode = RSNET_NETSTATE_WARNING_NODHT; mNetStateMode = RsNetState::WARNING_NODHT;
} }
else if (mNatPMPActive) else if (mNatPMPActive)
{ {
// This Mode is OKAY. // This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NATPMP; mNatHoleMode = RsNatHoleMode::NATPMP;
//mExtAddress = ... from NatPMP. //mExtAddress = ... from NatPMP.
//mExtAddrStable = true; //mExtAddrStable = true;
mNetStateMode = RSNET_NETSTATE_WARNING_NODHT; mNetStateMode = RsNetState::WARNING_NODHT;
} }
else else
{ {
@ -506,21 +505,21 @@ void pqiNetStateBox::determineNetworkState()
if (isExtAddress) if (isExtAddress)
{ {
mNetworkMode = RSNET_NETWORK_EXTERNALIP; mNetworkMode = RsNetworkMode::EXTERNALIP;
mNatTypeMode = RSNET_NATTYPE_NONE; mNatTypeMode = RsNatTypeMode::NONE;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
//mExtAddrStable = true; //mExtAddrStable = true;
mNetStateMode = RSNET_NETSTATE_WARNING_NODHT; mNetStateMode = RsNetState::WARNING_NODHT;
} }
else if (mPortForwardSet) else if (mPortForwardSet)
{ {
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_FORWARDED; mNatHoleMode = RsNatHoleMode::FORWARDED;
//mExtAddrStable = true; // Probably, makin assumption. //mExtAddrStable = true; // Probably, makin assumption.
mNetStateMode = RSNET_NETSTATE_WARNING_NODHT; mNetStateMode = RsNetState::WARNING_NODHT;
} }
else else
{ {
@ -528,10 +527,10 @@ void pqiNetStateBox::determineNetworkState()
* These people have destroyed the possibility of making connections ;( * These people have destroyed the possibility of making connections ;(
* Should WARN about this. * Should WARN about this.
*/ */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_BAD_NODHT_NAT; mNetStateMode = RsNetState::BAD_NODHT_NAT;
//mExtAddrStable = false; // Unlikely to be stable. //mExtAddrStable = false; // Unlikely to be stable.
} }
@ -553,42 +552,43 @@ void pqiNetStateBox::determineNetworkState()
void pqiNetStateBox::workoutNetworkMode() void pqiNetStateBox::workoutNetworkMode()
{ {
/* connectModes are dependent on the other modes */ /* connectModes are dependent on the other modes */
mConnectModes = RSNET_CONNECT_NONE; mConnectModes = RsConnectModes::NONE;
switch(mNetworkMode) switch(mNetworkMode)
{ {
case RSNET_NETWORK_UNKNOWN: case RsNetworkMode::UNKNOWN:
case RSNET_NETWORK_OFFLINE: case RsNetworkMode::OFFLINE:
case RSNET_NETWORK_LOCALNET: case RsNetworkMode::LOCALNET:
case RsNetworkMode::RESTARTING:
/* nothing here */ /* nothing here */
break; break;
case RSNET_NETWORK_EXTERNALIP: case RsNetworkMode::EXTERNALIP:
mConnectModes = RSNET_CONNECT_OUTGOING_TCP; mConnectModes = RsConnectModes::OUTGOING_TCP;
mConnectModes |= RSNET_CONNECT_ACCEPT_TCP; mConnectModes |= RsConnectModes::ACCEPT_TCP;
if (mDhtActive) if (mDhtActive)
{ {
mConnectModes |= RSNET_CONNECT_DIRECT_UDP; mConnectModes |= RsConnectModes::DIRECT_UDP;
/* if open port. don't want PROXY or RELAY connect /* if open port. don't want PROXY or RELAY connect
* because we should be able to do direct with EVERYONE. * because we should be able to do direct with EVERYONE.
* Ability to do Proxy is dependent on FIREWALL status. * Ability to do Proxy is dependent on FIREWALL status.
* Technically could do RELAY, but disable both. * Technically could do RELAY, but disable both.
*/ */
//mConnectModes |= RSNET_CONNECT_PROXY_UDP; //mConnectModes |= RsConnectModes::PROXY_UDP;
//mConnectModes |= RSNET_CONNECT_RELAY_UDP; //mConnectModes |= RsConnectModes::RELAY_UDP;
} }
break; break;
case RSNET_NETWORK_BEHINDNAT: case RsNetworkMode::BEHINDNAT:
mConnectModes = RSNET_CONNECT_OUTGOING_TCP; mConnectModes = RsConnectModes::OUTGOING_TCP;
/* we're okay if there's a NAT HOLE */ /* we're okay if there's a NAT HOLE */
if ((mNatHoleMode == RSNET_NATHOLE_UPNP) || if ((mNatHoleMode == RsNatHoleMode::UPNP) ||
(mNatHoleMode == RSNET_NATHOLE_NATPMP) || (mNatHoleMode == RsNatHoleMode::NATPMP) ||
(mNatHoleMode == RSNET_NATHOLE_FORWARDED)) (mNatHoleMode == RsNatHoleMode::FORWARDED))
{ {
mConnectModes |= RSNET_CONNECT_ACCEPT_TCP; mConnectModes |= RsConnectModes::ACCEPT_TCP;
if (mDhtActive) if (mDhtActive)
{ {
mConnectModes |= RSNET_CONNECT_DIRECT_UDP; mConnectModes |= RsConnectModes::DIRECT_UDP;
/* dont want PROXY | RELAY with open ports */ /* dont want PROXY | RELAY with open ports */
} }
} }
@ -600,175 +600,17 @@ void pqiNetStateBox::workoutNetworkMode()
*/ */
if (mDhtActive) if (mDhtActive)
{ {
mConnectModes |= RSNET_CONNECT_DIRECT_UDP; mConnectModes |= RsConnectModes::DIRECT_UDP;
mConnectModes |= RSNET_CONNECT_RELAY_UDP; mConnectModes |= RsConnectModes::RELAY_UDP;
if ((mNatTypeMode == RSNET_NATTYPE_RESTRICTED_CONE) || if ((mNatTypeMode == RsNatTypeMode::RESTRICTED_CONE) ||
(mNatTypeMode == RSNET_NATTYPE_FULL_CONE) || (mNatTypeMode == RsNatTypeMode::FULL_CONE) ||
(mNatTypeMode == RSNET_NATTYPE_DETERM_SYM)) (mNatTypeMode == RsNatTypeMode::DETERM_SYM))
{ {
mConnectModes |= RSNET_CONNECT_PROXY_UDP; mConnectModes |= RsConnectModes::PROXY_UDP;
} }
} }
} }
break; break;
} }
} }
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;
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)
{
std::string str;
switch(natHole)
{
default:
case RSNET_NATHOLE_UNKNOWN:
str = "UNKNOWN NAT HOLE STATUS";
break;
case RSNET_NATHOLE_NONE:
str = "NO NAT HOLE";
break;
case RSNET_NATHOLE_UPNP:
str = "UPNP FORWARD";
break;
case RSNET_NATHOLE_NATPMP:
str = "NATPMP FORWARD";
break;
case RSNET_NATHOLE_FORWARDED:
str = "MANUAL FORWARD";
break;
}
return str;
}
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;
switch(netstate)
{
case RSNET_NETSTATE_BAD_UNKNOWN:
str = "NET BAD: Unknown State";
break;
case RSNET_NETSTATE_BAD_OFFLINE:
str = "NET BAD: Offline";
break;
case RSNET_NETSTATE_BAD_NATSYM:
str = "NET BAD: Behind Symmetric NAT";
break;
case RSNET_NETSTATE_BAD_NODHT_NAT:
str = "NET BAD: Behind NAT & No DHT";
break;
case RSNET_NETSTATE_WARNING_RESTART:
str = "NET WARNING: NET Restart";
break;
case RSNET_NETSTATE_WARNING_NATTED:
str = "NET WARNING: Behind NAT";
break;
case RSNET_NETSTATE_WARNING_NODHT:
str = "NET WARNING: No DHT";
break;
case RSNET_NETSTATE_GOOD:
str = "NET STATE GOOD!";
break;
case RSNET_NETSTATE_ADV_FORWARD:
str = "CAUTION: UNVERIFABLE FORWARD!";
break;
case RSNET_NETSTATE_ADV_DARK_FORWARD:
str = "CAUTION: UNVERIFABLE FORWARD & NO DHT";
break;
}
return str;
}

View File

@ -27,6 +27,9 @@
#include <string> #include <string>
#include <list> #include <list>
#include <util/rstime.h>
#include <retroshare/rsconfig.h>
/*** Network state /*** Network state
* Want this to be all encompassing. * Want this to be all encompassing.
* *
@ -51,11 +54,11 @@ class pqiNetStateBox
void setDhtState(bool dhtOn, bool dhtActive); void setDhtState(bool dhtOn, bool dhtActive);
uint32_t getNetStateMode(); RsNetState getNetStateMode();
uint32_t getNetworkMode(); RsNetworkMode getNetworkMode();
uint32_t getNatTypeMode(); RsNatTypeMode getNatTypeMode();
uint32_t getNatHoleMode(); RsNatHoleMode getNatHoleMode();
uint32_t getConnectModes(); RsConnectModes getConnectModes();
private: private:
@ -71,11 +74,11 @@ class pqiNetStateBox
bool mStatusOkay; bool mStatusOkay;
rstime_t mStatusTS; rstime_t mStatusTS;
uint32_t mNetworkMode; RsNetworkMode mNetworkMode;
uint32_t mNatTypeMode; RsNatTypeMode mNatTypeMode;
uint32_t mNatHoleMode; RsNatHoleMode mNatHoleMode;
uint32_t mConnectModes; RsConnectModes mConnectModes;
uint32_t mNetStateMode; RsNetState mNetStateMode;
/* Parameters set externally */ /* Parameters set externally */
@ -114,13 +117,4 @@ class pqiNetStateBox
uint16_t mPortForwarded; uint16_t mPortForwarded;
}; };
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 #endif

View File

@ -37,77 +37,82 @@ class RsServerConfig;
*/ */
extern RsServerConfig *rsConfig; extern RsServerConfig *rsConfig;
#define RSNET_NETWORK_UNKNOWN 1 enum class RsNetworkMode : uint8_t
#define RSNET_NETWORK_RESTARTING 2 {
#define RSNET_NETWORK_OFFLINE 3 UNKNOWN = 1,
#define RSNET_NETWORK_LOCALNET 4 RESTARTING = 2,
#define RSNET_NETWORK_BEHINDNAT 5 OFFLINE = 3,
#define RSNET_NETWORK_EXTERNALIP 6 LOCALNET = 4,
BEHINDNAT = 5,
EXTERNALIP = 6
};
// WHAT TYPE OF FIREWALL? enum class RsNatTypeMode : uint8_t
#define RSNET_NATTYPE_NONE 1 {
#define RSNET_NATTYPE_UNKNOWN 2 NONE = 1,
#define RSNET_NATTYPE_SYMMETRIC 3 UNKNOWN = 2,
#define RSNET_NATTYPE_DETERM_SYM 4 SYMMETRIC = 3,
#define RSNET_NATTYPE_RESTRICTED_CONE 5 DETERM_SYM = 4,
#define RSNET_NATTYPE_FULL_CONE 6 RESTRICTED_CONE = 5,
#define RSNET_NATTYPE_OTHER 7 FULL_CONE = 6,
OTHER = 7
};
// WHAT TYPE OF HOLE? enum class RsNatHoleMode : uint8_t
#define RSNET_NATHOLE_UNKNOWN 0 {
#define RSNET_NATHOLE_NONE 1 UNKNOWN = 0,
#define RSNET_NATHOLE_UPNP 2 NONE = 1,
#define RSNET_NATHOLE_NATPMP 3 UPNP = 2,
#define RSNET_NATHOLE_FORWARDED 4 NATPMP = 3,
FORWARDED = 4
};
// Types of Connections. enum class RsConnectModes : uint16_t
#define RSNET_CONNECT_NONE 0x0000 {
#define RSNET_CONNECT_ACCEPT_TCP 0x0001 NONE = 0x0000,
#define RSNET_CONNECT_OUTGOING_TCP 0x0002 ACCEPT_TCP = 0x0001,
#define RSNET_CONNECT_DIRECT_UDP 0x0100 OUTGOING_TCP= 0x0002,
#define RSNET_CONNECT_PROXY_UDP 0x0200 DIRECT_UDP = 0x0100,
#define RSNET_CONNECT_RELAY_UDP 0x0400 PROXY_UDP = 0x0200,
RELAY_UDP = 0x0400
};
RS_REGISTER_ENUM_FLAGS_TYPE(RsConnectModes)
// net state (good, okay, bad) enum class RsNetState : uint8_t
// BAD. (RED) {
#define RSNET_NETSTATE_BAD_UNKNOWN 1 // BAD. (RED)
#define RSNET_NETSTATE_BAD_OFFLINE 2 BAD_UNKNOWN = 1,
#define RSNET_NETSTATE_BAD_NATSYM 3 BAD_OFFLINE = 2,
#define RSNET_NETSTATE_BAD_NODHT_NAT 4 BAD_NATSYM = 3,
BAD_NODHT_NAT = 4,
// CAUTION. (ORANGE) // CAUTION. (ORANGE)
#define RSNET_NETSTATE_WARNING_RESTART 5 WARNING_RESTART = 5,
#define RSNET_NETSTATE_WARNING_NATTED 6 WARNING_NATTED = 6,
#define RSNET_NETSTATE_WARNING_NODHT 7 WARNING_NODHT = 7,
// GOOD (GREEN) // GOOD (GREEN)
// NAT with forwarded port, or EXT port. // NAT with forwarded port, or EXT port.
#define RSNET_NETSTATE_GOOD 8 GOOD = 8,
// ADVANCED MODE (BLUE)
// If the user knows what they are doing... we cannot confirm this.
#define RSNET_NETSTATE_ADV_FORWARD 9
#define RSNET_NETSTATE_ADV_DARK_FORWARD 10
/* matched to the uPnP states */
#define UPNP_STATE_UNINITIALISED 0
#define UPNP_STATE_UNAVAILABILE 1
#define UPNP_STATE_READY 2
#define UPNP_STATE_FAILED_TCP 3
#define UPNP_STATE_FAILED_UDP 4
#define UPNP_STATE_ACTIVE 5
// ADVANCED MODE (BLUE)
// If the user knows what they are doing... we cannot confirm this.
ADV_FORWARD = 9,
ADV_DARK_FORWARD= 10
};
/************************** Indicate How experienced the RsUser is... based on Friends / Firewall status ******/ /************************** Indicate How experienced the RsUser is... based on Friends / Firewall status ******/
#define RSCONFIG_USER_LEVEL_NEW 0x0001 /* no friends */ enum class RsConfigUserLvl : uint8_t
#define RSCONFIG_USER_LEVEL_BASIC 0x0002 /* no connections */ {
#define RSCONFIG_USER_LEVEL_CASUAL 0x0003 /* firewalled */ NEW = 1, /* no friends */
#define RSCONFIG_USER_LEVEL_POWER 0x0004 /* good! */ BASIC = 2, /* no connections */
#define RSCONFIG_USER_LEVEL_OVERRIDE 0x0005 /* forced to POWER level */ CASUAL = 3, /* firewalled */
POWER = 4, /* good! */
OVERRIDE= 5 /* forced to POWER level */
};
@ -115,10 +120,13 @@ extern RsServerConfig *rsConfig;
#define RS_CONFIG_ADVANCED 0x0101 #define RS_CONFIG_ADVANCED 0x0101
#define RS_OPMODE_FULL 0x0001 enum class RsOpMode : uint8_t
#define RS_OPMODE_NOTURTLE 0x0002 {
#define RS_OPMODE_GAMING 0x0003 FULL = 1,
#define RS_OPMODE_MINIMAL 0x0004 NOTURTLE= 2,
GAMING = 3,
MINIMAL = 4
};
class RsConfigStartup class RsConfigStartup
@ -348,13 +356,13 @@ public:
/* New Stuff */ /* New Stuff */
virtual uint32_t getUserLevel() = 0; virtual RsConfigUserLvl getUserLevel() = 0;
virtual uint32_t getNetState() = 0; virtual RsNetState getNetState() = 0;
virtual uint32_t getNetworkMode() = 0; virtual RsNetworkMode getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0; virtual RsNatTypeMode getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 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 getConfigurationOption(uint32_t key, std::string &opt) = 0;
virtual bool setConfigurationOption(uint32_t key, const std::string &opt) = 0; virtual bool setConfigurationOption(uint32_t key, const std::string &opt) = 0;
@ -366,7 +374,7 @@ public:
* @jsonapi{development} * @jsonapi{development}
* @return return the current operating mode * @return return the current operating mode
*/ */
virtual uint32_t getOperatingMode() = 0; virtual RsOpMode getOperatingMode() = 0;
/** /**
* @brief setOperatingMode set the current oprating mode * @brief setOperatingMode set the current oprating mode
@ -374,7 +382,7 @@ public:
* @param[in] opMode new opearting mode * @param[in] opMode new opearting mode
* @return * @return
*/ */
virtual bool setOperatingMode(uint32_t opMode) = 0; virtual bool setOperatingMode(RsOpMode opMode) = 0;
/** /**
* @brief setOperatingMode set the current operating mode from string * @brief setOperatingMode set the current operating mode from string

View File

@ -27,6 +27,7 @@
#include <list> #include <list>
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
#include "util/rsnet.h" #include "util/rsnet.h"
#include "retroshare/rsflags.h"
/* The Main Interface Class - for information about your Peers */ /* The Main Interface Class - for information about your Peers */
class RsDht; class RsDht;
@ -35,55 +36,66 @@ extern RsDht *rsDht;
//std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail); //std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail);
//std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail); //std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
#define RSDHT_NETSTART_NETWORKMODE 0x0001 enum class RsDhtPeerType : uint8_t
#define RSDHT_NETSTART_NATTYPE 0x0002 {
#define RSDHT_NETSTART_NATHOLE 0x0003 ANY = 0,
#define RSDHT_NETSTART_CONNECTMODES 0x0004 OTHER = 1,
#define RSDHT_NETSTART_NETSTATE 0x0005 FOF = 2,
FRIEND = 3
};
enum class RsDhtPeerDht : uint8_t
{
NOT_ACTIVE = 0,
SEARCHING = 1,
FAILURE = 2,
OFFLINE = 3,
UNREACHABLE = 4,
ONLINE = 5
};
enum class RsDhtPeerConnectState : uint8_t
{
DISCONNECTED = 1,
UDP_STARTED = 2,
CONNECTED = 3
};
#define RSDHT_PEERTYPE_ANY 0x0000 enum class RsDhtPeerRequest : uint8_t
#define RSDHT_PEERTYPE_OTHER 0x0001 {
#define RSDHT_PEERTYPE_FOF 0x0002 STOPPED = 1,
#define RSDHT_PEERTYPE_FRIEND 0x0003 RUNNING = 2
};
#define RSDHT_PEERDHT_NOT_ACTIVE 0x0000 enum class RsDhtTouMode : uint8_t
#define RSDHT_PEERDHT_SEARCHING 0x0001 {
#define RSDHT_PEERDHT_FAILURE 0x0002 NONE = 0,
#define RSDHT_PEERDHT_OFFLINE 0x0003 DIRECT = 1,
#define RSDHT_PEERDHT_UNREACHABLE 0x0004 PROXY = 2,
#define RSDHT_PEERDHT_ONLINE 0x0005 RELAY = 3
};
#define RSDHT_PEERCONN_DISCONNECTED 1 enum class RsDhtRelayClass : uint8_t
#define RSDHT_PEERCONN_UDP_STARTED 2 {
#define RSDHT_PEERCONN_CONNECTED 3 ALL = 0,
GENERAL = 1,
FOF = 2,
FRIENDS = 3,
#define RSDHT_PEERREQ_STOPPED 1 NUM_CLASS = 4
#define RSDHT_PEERREQ_RUNNING 2 };
#define RSDHT_TOU_MODE_NONE 0 enum class RsDhtRelayMode : uint16_t
#define RSDHT_TOU_MODE_DIRECT 1 {
#define RSDHT_TOU_MODE_PROXY 2 DISABLED= 0x0000,
#define RSDHT_TOU_MODE_RELAY 3 ENABLED = 0x0001,
#define RSDHT_RELAY_NUM_CLASS 4
#define RSDHT_RELAY_CLASS_ALL 0
#define RSDHT_RELAY_CLASS_GENERAL 1
#define RSDHT_RELAY_CLASS_FOF 2
#define RSDHT_RELAY_CLASS_FRIENDS 3
#define RSDHT_RELAY_MODE_MASK 0x00f0
#define RSDHT_RELAY_ENABLED 0x0001
#define RSDHT_RELAY_MODE_OFF 0x0010
#define RSDHT_RELAY_MODE_ON 0x0020
#define RSDHT_RELAY_MODE_SERVER 0x0040
MASK = 0x00f0,
OFF = 0x0010,
ON = 0x0020,
SERVER = 0x0040
};
RS_REGISTER_ENUM_FLAGS_TYPE(RsDhtRelayMode)
class RsDhtPeer class RsDhtPeer
{ {
@ -108,18 +120,18 @@ class RsDhtNetPeer
std::string mDhtId; std::string mDhtId;
RsPeerId mRsId; RsPeerId mRsId;
uint32_t mPeerType; RsDhtPeerType mPeerType;
uint32_t mDhtState; RsDhtPeerDht mDhtState;
std::string mConnectState; // connectLogic. std::string mConnectState; // connectLogic.
uint32_t mPeerConnectState; // connect Status RsDhtPeerConnectState mPeerConnectState;
uint32_t mPeerConnectMode; // connect mode RsDhtTouMode mPeerConnectMode;
bool mExclusiveProxyLock; bool mExclusiveProxyLock;
std::string mPeerConnectProxyId; std::string mPeerConnectProxyId;
uint32_t mPeerReqState; // Req Status. RsDhtPeerRequest mPeerReqState;
std::string mCbPeerMsg; // Peer Cb Mgs. std::string mCbPeerMsg; // Peer Cb Mgs.
}; };
@ -188,11 +200,11 @@ virtual int getRelayServerList(std::list<std::string> &ids) = 0;
virtual int addRelayServer(std::string ids) = 0; virtual int addRelayServer(std::string ids) = 0;
virtual int removeRelayServer(std::string ids) = 0; virtual int removeRelayServer(std::string ids) = 0;
virtual uint32_t getRelayMode() = 0; virtual RsDhtRelayMode getRelayMode() = 0;
virtual int setRelayMode(uint32_t mode) = 0; virtual int setRelayMode(RsDhtRelayMode mode) = 0;
virtual int getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth) = 0; virtual int getRelayAllowance(RsDhtRelayClass classIdx, uint32_t &count, uint32_t &bandwidth) = 0;
virtual int setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth) = 0; virtual int setRelayAllowance(RsDhtRelayClass classIdx, uint32_t count, uint32_t bandwidth) = 0;
// So we can provide to clients. // So we can provide to clients.
virtual bool getOwnDhtId(std::string &ownDhtId) = 0; virtual bool getOwnDhtId(std::string &ownDhtId) = 0;

View File

@ -37,7 +37,13 @@ using rs_is_scoped_enum = std::integral_constant< bool,
* it as flags type passing it as parameter of this macro. * it as flags type passing it as parameter of this macro.
* The result will be type safe flags, that cannot be mixed up with flag of a * The result will be type safe flags, that cannot be mixed up with flag of a
* different type, but that are very comfortable to operate like plain old * different type, but that are very comfortable to operate like plain old
* integers. * integers. All commom operation like &, | or ! can be used. To convert
* the result of such operation to boolean use !!:
@code{.cpp}
RsConnectModes connect = rsConfig->getConnectModes();
if (!!(connect & RsConnectModes::OUTGOING_TCP))
@endcode
*
* This macro support flag fields of different lenght depending on what * This macro support flag fields of different lenght depending on what
* underlining type (usually from uint8_t up to uint64_t) has been declared for * underlining type (usually from uint8_t up to uint64_t) has been declared for
* the enum class. * the enum class.
@ -45,6 +51,7 @@ using rs_is_scoped_enum = std::integral_constant< bool,
* underlining type of the enum otherwise different compilers may serialize a * underlining type of the enum otherwise different compilers may serialize a
* flag variable with different lenght, potentially causing interoperability * flag variable with different lenght, potentially causing interoperability
* issues between differents builds. * issues between differents builds.
*
* Usage example: * Usage example:
@code{.cpp} @code{.cpp}
enum class RsGrouterItemFlags : uint32_t enum class RsGrouterItemFlags : uint32_t

View File

@ -48,11 +48,11 @@ p3ServerConfig::p3ServerConfig(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr
RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/
mUserLevel = RSCONFIG_USER_LEVEL_NEW; /* START LEVEL */ mUserLevel = RsConfigUserLvl::NEW; /* START LEVEL */
mRateDownload = DEFAULT_DOWNLOAD_KB_RATE; mRateDownload = DEFAULT_DOWNLOAD_KB_RATE;
mRateUpload = DEFAULT_UPLOAD_KB_RATE; mRateUpload = DEFAULT_UPLOAD_KB_RATE;
mOpMode = RS_OPMODE_FULL; mOpMode = RsOpMode::FULL;
rsConfig = this; rsConfig = this;
} }
@ -86,7 +86,7 @@ void p3ServerConfig::load_config()
} }
/* enable operating mode */ /* enable operating mode */
uint32_t opMode = getOperatingMode(); RsOpMode opMode = getOperatingMode();
switchToOperatingMode(opMode); switchToOperatingMode(opMode);
} }
@ -264,9 +264,9 @@ std::string p3ServerConfig::getRetroshareDataDirectory()
/* New Stuff */ /* New Stuff */
uint32_t p3ServerConfig::getUserLevel() RsConfigUserLvl p3ServerConfig::getUserLevel()
{ {
uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW; RsConfigUserLvl userLevel = RsConfigUserLvl::NEW;
{ {
RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/
userLevel = mUserLevel; userLevel = mUserLevel;
@ -274,47 +274,47 @@ uint32_t p3ServerConfig::getUserLevel()
switch(userLevel) switch(userLevel)
{ {
case RSCONFIG_USER_LEVEL_OVERRIDE: case RsConfigUserLvl::OVERRIDE:
break; break;
#define MIN_BASIC_FRIENDS 2 #define MIN_BASIC_FRIENDS 2
// FALL THROUGH EVERYTHING. // FALL THROUGH EVERYTHING.
default: default:
case RSCONFIG_USER_LEVEL_NEW: case RsConfigUserLvl::NEW:
{ {
if (mPeerMgr->getFriendCount(true, false) > MIN_BASIC_FRIENDS) if (mPeerMgr->getFriendCount(true, false) > MIN_BASIC_FRIENDS)
{ {
userLevel = RSCONFIG_USER_LEVEL_BASIC; userLevel = RsConfigUserLvl::BASIC;
} }
} }
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_BASIC: case RsConfigUserLvl::BASIC:
{ {
/* check that we have some lastConnect > 0 */ /* check that we have some lastConnect > 0 */
if (mPeerMgr->haveOnceConnected()) if (mPeerMgr->haveOnceConnected())
{ {
userLevel = RSCONFIG_USER_LEVEL_CASUAL; userLevel = RsConfigUserLvl::CASUAL;
} }
} }
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_CASUAL: case RsConfigUserLvl::CASUAL:
case RSCONFIG_USER_LEVEL_POWER: case RsConfigUserLvl::POWER:
{ {
/* check that the firewall is open */ /* check that the firewall is open */
uint32_t netMode = mNetMgr->getNetworkMode(); RsNetworkMode netMode = mNetMgr->getNetworkMode();
uint32_t firewallMode = mNetMgr->getNatHoleMode(); RsNatHoleMode firewallMode = mNetMgr->getNatHoleMode();
if ((RSNET_NETWORK_EXTERNALIP == netMode) || if ((RsNetworkMode::EXTERNALIP == netMode) ||
((RSNET_NETWORK_BEHINDNAT == netMode) && ((RsNetworkMode::BEHINDNAT == netMode) &&
((RSNET_NATHOLE_UPNP == firewallMode) || (RsNatHoleMode::UPNP == firewallMode ||
(RSNET_NATHOLE_NATPMP == firewallMode) || (RsNatHoleMode::NATPMP == firewallMode) ||
(RSNET_NATHOLE_FORWARDED == firewallMode)))) (RsNatHoleMode::FORWARDED == firewallMode))))
{ {
userLevel = RSCONFIG_USER_LEVEL_POWER; userLevel = RsConfigUserLvl::POWER;
} }
} }
break; /* for all */ break; /* for all */
@ -329,27 +329,27 @@ uint32_t p3ServerConfig::getUserLevel()
} }
uint32_t p3ServerConfig::getNetState() RsNetState p3ServerConfig::getNetState()
{ {
return mNetMgr->getNetStateMode(); return mNetMgr->getNetStateMode();
} }
uint32_t p3ServerConfig::getNetworkMode() RsNetworkMode p3ServerConfig::getNetworkMode()
{ {
return mNetMgr->getNetworkMode(); return mNetMgr->getNetworkMode();
} }
uint32_t p3ServerConfig::getNatTypeMode() RsNatTypeMode p3ServerConfig::getNatTypeMode()
{ {
return mNetMgr->getNatTypeMode(); return mNetMgr->getNatTypeMode();
} }
uint32_t p3ServerConfig::getNatHoleMode() RsNatHoleMode p3ServerConfig::getNatHoleMode()
{ {
return mNetMgr->getNatHoleMode(); return mNetMgr->getNatHoleMode();
} }
uint32_t p3ServerConfig::getConnectModes() RsConnectModes p3ServerConfig::getConnectModes()
{ {
return mNetMgr->getConnectModes(); return mNetMgr->getConnectModes();
} }
@ -357,27 +357,27 @@ uint32_t p3ServerConfig::getConnectModes()
/* Operating Mode */ /* Operating Mode */
#define RS_CONFIG_OPERATING_STRING "OperatingMode" #define RS_CONFIG_OPERATING_STRING "OperatingMode"
uint32_t p3ServerConfig::getOperatingMode() RsOpMode p3ServerConfig::getOperatingMode()
{ {
#ifdef SAVE_OPERATING_MODE #ifdef SAVE_OPERATING_MODE
std::string modestr = mGeneralConfig->getSetting(RS_CONFIG_OPERATING_STRING); std::string modestr = mGeneralConfig->getSetting(RS_CONFIG_OPERATING_STRING);
uint32_t mode = RS_OPMODE_FULL; uint32_t mode = RsOpMode::FULL;
if (modestr == "FULL") if (modestr == "FULL")
{ {
mode = RS_OPMODE_FULL; mode = RsOpMode::FULL;
} }
else if (modestr == "NOTURTLE") else if (modestr == "NOTURTLE")
{ {
mode = RS_OPMODE_NOTURTLE; mode = RsOpMode::NOTURTLE;
} }
else if (modestr == "GAMING") else if (modestr == "GAMING")
{ {
mode = RS_OPMODE_GAMING; mode = RsOpMode::GAMING;
} }
else if (modestr == "MINIMAL") else if (modestr == "MINIMAL")
{ {
mode = RS_OPMODE_MINIMAL; mode = RsOpMode::MINIMAL;
} }
return mode; return mode;
#else #else
@ -387,24 +387,24 @@ uint32_t p3ServerConfig::getOperatingMode()
} }
bool p3ServerConfig::setOperatingMode(uint32_t opMode) bool p3ServerConfig::setOperatingMode(RsOpMode opMode)
{ {
#ifdef SAVE_OPERATING_MODE #ifdef SAVE_OPERATING_MODE
std::string modestr = "FULL"; std::string modestr = "FULL";
switch(opMode) switch(opMode)
{ {
case RS_OPMODE_FULL: case RsOpMode::FULL:
modestr = "FULL"; modestr = "FULL";
break; break;
case RS_OPMODE_NOTURTLE: case RsOpMode::NOTURTLE:
modestr = "NOTURTLE"; modestr = "NOTURTLE";
break; break;
case RS_OPMODE_GAMING: case RsOpMode::GAMING:
modestr = "GAMING"; modestr = "GAMING";
break; break;
case RS_OPMODE_MINIMAL: case RsOpMode::MINIMAL:
modestr = "MINIMAL"; modestr = "MINIMAL";
break; break;
} }
@ -420,31 +420,31 @@ bool p3ServerConfig::setOperatingMode(uint32_t opMode)
bool p3ServerConfig::setOperatingMode(const std::string &opModeStr) bool p3ServerConfig::setOperatingMode(const std::string &opModeStr)
{ {
uint32_t opMode = RS_OPMODE_FULL; RsOpMode opMode = RsOpMode::FULL;
std::string upper; std::string upper;
stringToUpperCase(opModeStr, upper); stringToUpperCase(opModeStr, upper);
if (upper == "NOTURTLE") if (upper == "NOTURTLE")
{ {
opMode = RS_OPMODE_NOTURTLE; opMode = RsOpMode::NOTURTLE;
} }
else if (upper == "GAMING") else if (upper == "GAMING")
{ {
opMode = RS_OPMODE_GAMING; opMode = RsOpMode::GAMING;
} }
else if (upper == "MINIMAL") else if (upper == "MINIMAL")
{ {
opMode = RS_OPMODE_MINIMAL; opMode = RsOpMode::MINIMAL;
} }
else // "FULL" by default else // "FULL" by default
{ {
opMode = RS_OPMODE_FULL; opMode = RsOpMode::FULL;
} }
return setOperatingMode(opMode); return setOperatingMode(opMode);
} }
bool p3ServerConfig::switchToOperatingMode(uint32_t opMode) bool p3ServerConfig::switchToOperatingMode(RsOpMode opMode)
{ {
float dl_rate = 0; float dl_rate = 0;
float ul_rate = 0; float ul_rate = 0;
@ -456,13 +456,13 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
ul_rate = mRateUpload; ul_rate = mRateUpload;
} }
std::cerr << "p3ServerConfig::switchToOperatingMode(" << opMode << ")"; std::cerr << "p3ServerConfig::switchToOperatingMode(" << static_cast<typename std::underlying_type<RsOpMode>::type>(opMode) << ")";
std::cerr << std::endl; std::cerr << std::endl;
switch (opMode) switch (opMode)
{ {
default: default:
case RS_OPMODE_FULL: case RsOpMode::FULL:
/* switch on all transfers */ /* switch on all transfers */
/* 100% bandwidth */ /* 100% bandwidth */
/* switch on popups, enable hashing */ /* switch on popups, enable hashing */
@ -470,14 +470,14 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
//setMaxRate(false, mro); // Out / Upload. //setMaxRate(false, mro); // Out / Upload.
turtle_enabled = true; turtle_enabled = true;
break; break;
case RS_OPMODE_NOTURTLE: case RsOpMode::NOTURTLE:
/* switch on all transfers - except turtle, enable hashing */ /* switch on all transfers - except turtle, enable hashing */
/* 100% bandwidth */ /* 100% bandwidth */
/* switch on popups, enable hashing */ /* switch on popups, enable hashing */
turtle_enabled = false; turtle_enabled = false;
break; break;
case RS_OPMODE_GAMING: case RsOpMode::GAMING:
/* switch on all transfers */ /* switch on all transfers */
/* reduce bandwidth to 25% */ /* reduce bandwidth to 25% */
/* switch off popups, enable hashing */ /* switch off popups, enable hashing */
@ -486,7 +486,7 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
dl_rate *= 0.25; dl_rate *= 0.25;
ul_rate *= 0.25; ul_rate *= 0.25;
break; break;
case RS_OPMODE_MINIMAL: case RsOpMode::MINIMAL:
/* switch off all transfers */ /* switch off all transfers */
/* reduce bandwidth to 10%, but make sure there is enough for VoIP */ /* reduce bandwidth to 10%, but make sure there is enough for VoIP */
/* switch on popups, enable hashing */ /* switch on popups, enable hashing */

View File

@ -72,20 +72,20 @@ virtual std::string getRetroshareDataDirectory();
/* New Stuff */ /* New Stuff */
virtual uint32_t getUserLevel(); virtual RsConfigUserLvl getUserLevel();
virtual uint32_t getNetState(); virtual RsNetState getNetState();
virtual uint32_t getNetworkMode(); virtual RsNetworkMode getNetworkMode();
virtual uint32_t getNatTypeMode(); virtual RsNatTypeMode getNatTypeMode();
virtual uint32_t getNatHoleMode(); virtual RsNatHoleMode getNatHoleMode();
virtual uint32_t getConnectModes(); virtual RsConnectModes getConnectModes();
virtual bool getConfigurationOption(uint32_t key, std::string &opt); virtual bool getConfigurationOption(uint32_t key, std::string &opt);
virtual bool setConfigurationOption(uint32_t key, const std::string &opt); virtual bool setConfigurationOption(uint32_t key, const std::string &opt);
/* Operating Mode */ /* Operating Mode */
virtual uint32_t getOperatingMode(); virtual RsOpMode getOperatingMode();
virtual bool setOperatingMode(uint32_t opMode); virtual bool setOperatingMode(RsOpMode opMode);
virtual bool setOperatingMode(const std::string &opModeStr); virtual bool setOperatingMode(const std::string &opModeStr);
virtual int SetMaxDataRates( int downKb, int upKb ); virtual int SetMaxDataRates( int downKb, int upKb );
@ -97,7 +97,7 @@ virtual int GetTrafficSum( uint64_t &inb, uint64_t &outb );
private: private:
bool switchToOperatingMode(uint32_t opMode); bool switchToOperatingMode(RsOpMode opMode);
bool findConfigurationOption(uint32_t key, std::string &keystr); bool findConfigurationOption(uint32_t key, std::string &keystr);
@ -108,11 +108,11 @@ bool findConfigurationOption(uint32_t key, std::string &keystr);
p3GeneralConfig *mGeneralConfig; p3GeneralConfig *mGeneralConfig;
RsMutex configMtx; RsMutex configMtx;
uint32_t mUserLevel; // store last one... will later be a config Item too. RsConfigUserLvl mUserLevel; // store last one... will later be a config Item too.
float mRateDownload; float mRateDownload;
float mRateUpload; float mRateUpload;
uint32_t mOpMode; RsOpMode mOpMode;
}; };
#endif #endif

View File

@ -298,13 +298,13 @@ int UdpRelayReceiver::checkRelays()
switch(rit->second.mRelayClass) switch(rit->second.mRelayClass)
{ {
default: default:
case UDP_RELAY_CLASS_GENERAL: case UDP_RELAY_CLASS_GENERAL:
lifetime = UDP_RELAY_LIFETIME_GENERAL; lifetime = UDP_RELAY_LIFETIME_GENERAL;
break; break;
case UDP_RELAY_CLASS_FOF: case UDP_RELAY_CLASS_FOF:
lifetime = UDP_RELAY_LIFETIME_FOF; lifetime = UDP_RELAY_LIFETIME_FOF;
break; break;
case UDP_RELAY_CLASS_FRIENDS: case UDP_RELAY_CLASS_FRIENDS:
lifetime = UDP_RELAY_LIFETIME_FRIENDS; lifetime = UDP_RELAY_LIFETIME_FRIENDS;
break; break;
} }
@ -1048,13 +1048,13 @@ UdpRelayProxy::UdpRelayProxy(UdpRelayAddrSet *addrSet, int relayClass, uint32_t
switch(relayClass) switch(relayClass)
{ {
default: default:
case UDP_RELAY_CLASS_GENERAL: case UDP_RELAY_CLASS_GENERAL:
mBandwidthLimit = RELAY_MAX_BANDWIDTH; mBandwidthLimit = RELAY_MAX_BANDWIDTH;
break; break;
case UDP_RELAY_CLASS_FOF: case UDP_RELAY_CLASS_FOF:
mBandwidthLimit = RELAY_MAX_BANDWIDTH; mBandwidthLimit = RELAY_MAX_BANDWIDTH;
break; break;
case UDP_RELAY_CLASS_FRIENDS: case UDP_RELAY_CLASS_FRIENDS:
mBandwidthLimit = RELAY_MAX_BANDWIDTH; mBandwidthLimit = RELAY_MAX_BANDWIDTH;
break; break;
} }

View File

@ -101,12 +101,14 @@ std::ostream &operator<<(std::ostream &out, const UdpRelayEnd &ure);
/**** DEFINED IN EXTERNAL HEADER FILE ***/ /**** DEFINED IN EXTERNAL HEADER FILE ***/
#define UDP_RELAY_NUM_CLASS RSDHT_RELAY_NUM_CLASS // sehraf: this is a bit ugly but since the int is used as an integer i'lll stick to this hack for now
/// TODO fix me!
#define UDP_RELAY_NUM_CLASS static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS)
#define UDP_RELAY_CLASS_ALL RSDHT_RELAY_CLASS_ALL #define UDP_RELAY_CLASS_ALL static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::ALL)
#define UDP_RELAY_CLASS_GENERAL RSDHT_RELAY_CLASS_GENERAL #define UDP_RELAY_CLASS_GENERAL static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::GENERAL)
#define UDP_RELAY_CLASS_FOF RSDHT_RELAY_CLASS_FOF #define UDP_RELAY_CLASS_FOF static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::FOF)
#define UDP_RELAY_CLASS_FRIENDS RSDHT_RELAY_CLASS_FRIENDS #define UDP_RELAY_CLASS_FRIENDS static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::FRIENDS)
// Just for some testing fun! // Just for some testing fun!
//#define UDP_RELAY_LIFETIME_GENERAL 180 // 3 minutes //#define UDP_RELAY_LIFETIME_GENERAL 180 // 3 minutes

View File

@ -105,7 +105,7 @@ void GetStartedDialog::showEvent ( QShowEvent * /*event*/ )
void GetStartedDialog::updateFromUserLevel() void GetStartedDialog::updateFromUserLevel()
{ {
uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW; RsConfigUserLvl userLevel = RsConfigUserLvl::NEW;
userLevel = rsConfig->getUserLevel(); userLevel = rsConfig->getUserLevel();
ui.inviteCheckBox->setChecked(false); ui.inviteCheckBox->setChecked(false);
@ -116,19 +116,19 @@ void GetStartedDialog::updateFromUserLevel()
switch(userLevel) switch(userLevel)
{ {
// FALLS THROUGH EVERYWHERE. // FALLS THROUGH EVERYWHERE.
case RSCONFIG_USER_LEVEL_POWER: case RsConfigUserLvl::POWER:
case RSCONFIG_USER_LEVEL_OVERRIDE: case RsConfigUserLvl::OVERRIDE:
ui.firewallCheckBox->setChecked(true); ui.firewallCheckBox->setChecked(true);
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_CASUAL: case RsConfigUserLvl::CASUAL:
ui.connectCheckBox->setChecked(true); ui.connectCheckBox->setChecked(true);
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_BASIC: case RsConfigUserLvl::BASIC:
ui.addCheckBox->setChecked(true); ui.addCheckBox->setChecked(true);
ui.inviteCheckBox->setChecked(true); ui.inviteCheckBox->setChecked(true);
default: default:
case RSCONFIG_USER_LEVEL_NEW: case RsConfigUserLvl::NEW:
break; break;
} }
@ -325,7 +325,7 @@ void GetStartedDialog::emailSupport()
return; return;
} }
uint32_t userLevel; RsConfigUserLvl userLevel;
{ {
RsAutoUpdatePage::lockAllEvents(); RsAutoUpdatePage::lockAllEvents();
@ -427,7 +427,7 @@ void GetStartedDialog::emailSupport()
sysVersion = "Linux"; sysVersion = "Linux";
#endif #endif
#endif #endif
text += QString("My RetroShare Configuration is: (%1, %2, 0x60%3)").arg(Rshare::retroshareVersion(true)).arg(sysVersion).arg(userLevel) + "\n"; text += QString("My RetroShare Configuration is: (%1, %2, %3)").arg(Rshare::retroshareVersion(true)).arg(sysVersion).arg(static_cast<typename std::underlying_type<RsConfigUserLvl>::type>(userLevel)) + "\n";
text += "\n"; text += "\n";
text += QString("I am having trouble with RetroShare."); text += QString("I am having trouble with RetroShare.");

View File

@ -1563,13 +1563,13 @@ void MainWindow::processLastArgs()
if (opModeStatus) { if (opModeStatus) {
QString opmode = Rshare::opmode().toLower(); QString opmode = Rshare::opmode().toLower();
if (opmode == "noturtle") { if (opmode == "noturtle") {
opModeStatus->setCurrentIndex(RS_OPMODE_NOTURTLE - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE) - 1);
} else if (opmode == "gaming") { } else if (opmode == "gaming") {
opModeStatus->setCurrentIndex(RS_OPMODE_GAMING - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::GAMING) - 1);
} else if (opmode == "minimal") { } else if (opmode == "minimal") {
opModeStatus->setCurrentIndex(RS_OPMODE_MINIMAL - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::MINIMAL) - 1);
} else if (opmode != "") { } else if (opmode != "") {
opModeStatus->setCurrentIndex(RS_OPMODE_FULL - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::FULL) - 1);
} }
opModeStatus->setOpMode(); opModeStatus->setOpMode();
} else { } else {

View File

@ -282,39 +282,39 @@ void ConnectProgressDialog::stopAndClose()
void ConnectProgressDialog::updateNetworkStatus() void ConnectProgressDialog::updateNetworkStatus()
{ {
uint32_t netState = rsConfig->getNetState(); RsNetState netState = rsConfig->getNetState();
QLabel *label = ui->NetResult; QLabel *label = ui->NetResult;
switch(netState) switch(netState)
{ {
case RSNET_NETSTATE_BAD_UNKNOWN: case RsNetState::BAD_UNKNOWN:
label->setText(tr("Unknown State")); label->setText(tr("Unknown State"));
break; break;
case RSNET_NETSTATE_BAD_OFFLINE: case RsNetState::BAD_OFFLINE:
label->setText(tr("Offline")); label->setText(tr("Offline"));
break; break;
case RSNET_NETSTATE_BAD_NATSYM: case RsNetState::BAD_NATSYM:
label->setText(tr("Behind Symmetric NAT")); label->setText(tr("Behind Symmetric NAT"));
break; break;
case RSNET_NETSTATE_BAD_NODHT_NAT: case RsNetState::BAD_NODHT_NAT:
label->setText(tr("Behind NAT & No DHT")); label->setText(tr("Behind NAT & No DHT"));
break; break;
case RSNET_NETSTATE_WARNING_RESTART: case RsNetState::WARNING_RESTART:
label->setText(tr("NET Restart")); label->setText(tr("NET Restart"));
break; break;
case RSNET_NETSTATE_WARNING_NATTED: case RsNetState::WARNING_NATTED:
label->setText(tr("Behind NAT")); label->setText(tr("Behind NAT"));
break; break;
case RSNET_NETSTATE_WARNING_NODHT: case RsNetState::WARNING_NODHT:
label->setText(tr("No DHT")); label->setText(tr("No DHT"));
break; break;
case RSNET_NETSTATE_GOOD: case RsNetState::GOOD:
label->setText(tr("NET STATE GOOD!")); label->setText(tr("NET STATE GOOD!"));
break; break;
case RSNET_NETSTATE_ADV_FORWARD: case RsNetState::ADV_FORWARD:
label->setText(tr("UNVERIFIABLE FORWARD!")); label->setText(tr("UNVERIFIABLE FORWARD!"));
break; break;
case RSNET_NETSTATE_ADV_DARK_FORWARD: case RsNetState::ADV_DARK_FORWARD:
label->setText(tr("UNVERIFIABLE FORWARD & NO DHT")); label->setText(tr("UNVERIFIABLE FORWARD & NO DHT"));
break; break;
} }
@ -522,30 +522,30 @@ void ConnectProgressDialog::updateLookupStatus()
switch(status.mDhtState) switch(status.mDhtState)
{ {
default: default:
case RSDHT_PEERDHT_NOT_ACTIVE: case RsDhtPeerDht::NOT_ACTIVE:
ui->LookupProgressBar->setValue(0); ui->LookupProgressBar->setValue(0);
ui->LookupResult->setText(tr("Peer DHT NOT ACTIVE")); ui->LookupResult->setText(tr("Peer DHT NOT ACTIVE"));
mLookupStatus = CONNECT_LOOKUP_NODHTCONFIG; mLookupStatus = CONNECT_LOOKUP_NODHTCONFIG;
break; break;
case RSDHT_PEERDHT_SEARCHING: case RsDhtPeerDht::SEARCHING:
ui->LookupResult->setText(tr("Searching")); ui->LookupResult->setText(tr("Searching"));
break; break;
case RSDHT_PEERDHT_FAILURE: case RsDhtPeerDht::FAILURE:
ui->LookupProgressBar->setValue(0); ui->LookupProgressBar->setValue(0);
ui->LookupResult->setText(tr("Lookup Failure")); ui->LookupResult->setText(tr("Lookup Failure"));
mLookupStatus = CONNECT_LOOKUP_FAIL; mLookupStatus = CONNECT_LOOKUP_FAIL;
break; break;
case RSDHT_PEERDHT_OFFLINE: case RsDhtPeerDht::OFFLINE:
ui->LookupProgressBar->setValue(100); ui->LookupProgressBar->setValue(100);
ui->LookupResult->setText(tr("Peer Offline")); ui->LookupResult->setText(tr("Peer Offline"));
mLookupStatus = CONNECT_LOOKUP_OFFLINE; mLookupStatus = CONNECT_LOOKUP_OFFLINE;
break; break;
case RSDHT_PEERDHT_UNREACHABLE: case RsDhtPeerDht::UNREACHABLE:
ui->LookupProgressBar->setValue(100); ui->LookupProgressBar->setValue(100);
ui->LookupResult->setText(tr("Peer Firewalled")); ui->LookupResult->setText(tr("Peer Firewalled"));
mLookupStatus = CONNECT_LOOKUP_UNREACHABLE; mLookupStatus = CONNECT_LOOKUP_UNREACHABLE;
break; break;
case RSDHT_PEERDHT_ONLINE: case RsDhtPeerDht::ONLINE:
ui->LookupProgressBar->setValue(100); ui->LookupProgressBar->setValue(100);
ui->LookupResult->setText(tr("Peer Online")); ui->LookupResult->setText(tr("Peer Online"));
mLookupStatus = CONNECT_LOOKUP_ONLINE; mLookupStatus = CONNECT_LOOKUP_ONLINE;

View File

@ -448,26 +448,26 @@ void ServerPage::load()
//Relay Tab //Relay Tab
uint32_t count; uint32_t count;
uint32_t bandwidth; uint32_t bandwidth;
rsDht->getRelayAllowance(RSDHT_RELAY_CLASS_FRIENDS, count, bandwidth); rsDht->getRelayAllowance(RsDhtRelayClass::FRIENDS, count, bandwidth);
whileBlocking(ui.noFriendSpinBox)->setValue(count); whileBlocking(ui.noFriendSpinBox)->setValue(count);
whileBlocking(ui.bandFriendSpinBox)->setValue(bandwidth / 1024); whileBlocking(ui.bandFriendSpinBox)->setValue(bandwidth / 1024);
rsDht->getRelayAllowance(RSDHT_RELAY_CLASS_FOF, count, bandwidth); rsDht->getRelayAllowance(RsDhtRelayClass::FOF, count, bandwidth);
whileBlocking(ui.noFOFSpinBox)->setValue(count); whileBlocking(ui.noFOFSpinBox)->setValue(count);
whileBlocking(ui.bandFOFSpinBox)->setValue(bandwidth / 1024); whileBlocking(ui.bandFOFSpinBox)->setValue(bandwidth / 1024);
rsDht->getRelayAllowance(RSDHT_RELAY_CLASS_GENERAL, count, bandwidth); rsDht->getRelayAllowance(RsDhtRelayClass::GENERAL, count, bandwidth);
whileBlocking(ui.noGeneralSpinBox)->setValue(count); whileBlocking(ui.noGeneralSpinBox)->setValue(count);
whileBlocking(ui.bandGeneralSpinBox)->setValue(bandwidth / 1024); whileBlocking(ui.bandGeneralSpinBox)->setValue(bandwidth / 1024);
updateTotals(); updateTotals();
uint32_t relayMode = rsDht->getRelayMode(); RsDhtRelayMode relayMode = rsDht->getRelayMode();
if (relayMode & RSDHT_RELAY_ENABLED) if (!!(relayMode & RsDhtRelayMode::ENABLED))
{ {
whileBlocking(ui.enableCheckBox)->setCheckState(Qt::Checked); whileBlocking(ui.enableCheckBox)->setCheckState(Qt::Checked);
if ((relayMode & RSDHT_RELAY_MODE_MASK) == RSDHT_RELAY_MODE_OFF) if ((relayMode & RsDhtRelayMode::MASK) == RsDhtRelayMode::OFF)
{ {
whileBlocking(ui.serverCheckBox)->setCheckState(Qt::Unchecked); whileBlocking(ui.serverCheckBox)->setCheckState(Qt::Unchecked);
} }
@ -1887,33 +1887,33 @@ void ServerPage::updateTotals()
int total = nFriends + nFOF + nGeneral; int total = nFriends + nFOF + nGeneral;
rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_ALL, total, 0); rsDht->setRelayAllowance(RsDhtRelayClass::ALL, total, 0);
rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_FRIENDS, nFriends, 1024 * friendBandwidth); rsDht->setRelayAllowance(RsDhtRelayClass::FRIENDS, nFriends, 1024 * friendBandwidth);
rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_FOF, nFOF, 1024 * fofBandwidth); rsDht->setRelayAllowance(RsDhtRelayClass::FOF, nFOF, 1024 * fofBandwidth);
rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_GENERAL, nGeneral, 1024 * genBandwidth); rsDht->setRelayAllowance(RsDhtRelayClass::GENERAL, nGeneral, 1024 * genBandwidth);
} }
/** Saves the changes on this page */ /** Saves the changes on this page */
void ServerPage::updateRelayMode() void ServerPage::updateRelayMode()
{ {
uint32_t relayMode = 0; RsDhtRelayMode relayMode = static_cast<RsDhtRelayMode>(0);
if (ui.enableCheckBox->isChecked()) if (ui.enableCheckBox->isChecked())
{ {
relayMode |= RSDHT_RELAY_ENABLED; relayMode |= RsDhtRelayMode::ENABLED;
if (ui.serverCheckBox->isChecked()) if (ui.serverCheckBox->isChecked())
{ {
relayMode |= RSDHT_RELAY_MODE_ON; relayMode |= RsDhtRelayMode::ON;
} }
else else
{ {
relayMode |= RSDHT_RELAY_MODE_OFF; relayMode |= RsDhtRelayMode::OFF;
} }
} }
else else
{ {
relayMode |= RSDHT_RELAY_MODE_OFF; relayMode |= RsDhtRelayMode::OFF;
} }
rsDht->setRelayMode(relayMode); rsDht->setRelayMode(relayMode);

View File

@ -137,52 +137,55 @@ void DhtWindow::updateNetStatus()
ui.peerAddressLabel->setText(status); ui.peerAddressLabel->setText(status);
} }
uint32_t netMode = rsConfig->getNetworkMode(); RsNetworkMode netMode = rsConfig->getNetworkMode();
QLabel *label = ui.networkLabel; QLabel *label = ui.networkLabel;
switch(netMode) switch(netMode)
{ {
case RSNET_NETWORK_UNKNOWN: case RsNetworkMode::UNKNOWN:
label->setText(tr("Unknown NetState")); label->setText(tr("Unknown NetState"));
break; break;
case RSNET_NETWORK_OFFLINE: case RsNetworkMode::RESTARTING:
label->setText(tr("Restarting"));
break;
case RsNetworkMode::OFFLINE:
label->setText(tr("Offline")); label->setText(tr("Offline"));
break; break;
case RSNET_NETWORK_LOCALNET: case RsNetworkMode::LOCALNET:
label->setText(tr("Local Net")); label->setText(tr("Local Net"));
break; break;
case RSNET_NETWORK_BEHINDNAT: case RsNetworkMode::BEHINDNAT:
label->setText(tr("Behind NAT")); label->setText(tr("Behind NAT"));
break; break;
case RSNET_NETWORK_EXTERNALIP: case RsNetworkMode::EXTERNALIP:
label->setText(tr("External IP")); label->setText(tr("External IP"));
break; break;
} }
label = ui.natTypeLabel; label = ui.natTypeLabel;
uint32_t natType = rsConfig->getNatTypeMode(); RsNatTypeMode natType = rsConfig->getNatTypeMode();
switch(natType) switch(natType)
{ {
case RSNET_NATTYPE_UNKNOWN: case RsNatTypeMode::UNKNOWN:
label->setText(tr("UNKNOWN NAT STATE")); label->setText(tr("UNKNOWN NAT STATE"));
break; break;
case RSNET_NATTYPE_SYMMETRIC: case RsNatTypeMode::SYMMETRIC:
label->setText(tr("SYMMETRIC NAT")); label->setText(tr("SYMMETRIC NAT"));
break; break;
case RSNET_NATTYPE_DETERM_SYM: case RsNatTypeMode::DETERM_SYM:
label->setText(tr("DETERMINISTIC SYM NAT")); label->setText(tr("DETERMINISTIC SYM NAT"));
break; break;
case RSNET_NATTYPE_RESTRICTED_CONE: case RsNatTypeMode::RESTRICTED_CONE:
label->setText(tr("RESTRICTED CONE NAT")); label->setText(tr("RESTRICTED CONE NAT"));
break; break;
case RSNET_NATTYPE_FULL_CONE: case RsNatTypeMode::FULL_CONE:
label->setText(tr("FULL CONE NAT")); label->setText(tr("FULL CONE NAT"));
break; break;
case RSNET_NATTYPE_OTHER: case RsNatTypeMode::OTHER:
label->setText(tr("OTHER NAT")); label->setText(tr("OTHER NAT"));
break; break;
case RSNET_NATTYPE_NONE: case RsNatTypeMode::NONE:
label->setText(tr("NO NAT")); label->setText(tr("NO NAT"));
break; break;
} }
@ -190,87 +193,87 @@ void DhtWindow::updateNetStatus()
label = ui.natHoleLabel; label = ui.natHoleLabel;
uint32_t natHole = rsConfig->getNatHoleMode(); RsNatHoleMode natHole = rsConfig->getNatHoleMode();
switch(natHole) switch(natHole)
{ {
case RSNET_NATHOLE_UNKNOWN: case RsNatHoleMode::UNKNOWN:
label->setText(tr("UNKNOWN NAT HOLE STATUS")); label->setText(tr("UNKNOWN NAT HOLE STATUS"));
break; break;
case RSNET_NATHOLE_NONE: case RsNatHoleMode::NONE:
label->setText(tr("NO NAT HOLE")); label->setText(tr("NO NAT HOLE"));
break; break;
case RSNET_NATHOLE_UPNP: case RsNatHoleMode::UPNP:
label->setText(tr("UPNP FORWARD")); label->setText(tr("UPNP FORWARD"));
break; break;
case RSNET_NATHOLE_NATPMP: case RsNatHoleMode::NATPMP:
label->setText(tr("NATPMP FORWARD")); label->setText(tr("NATPMP FORWARD"));
break; break;
case RSNET_NATHOLE_FORWARDED: case RsNatHoleMode::FORWARDED:
label->setText(tr("MANUAL FORWARD")); label->setText(tr("MANUAL FORWARD"));
break; break;
} }
uint32_t connect = rsConfig->getConnectModes(); RsConnectModes connect = rsConfig->getConnectModes();
label = ui.connectLabel; label = ui.connectLabel;
QString connOut; QString connOut;
if (connect & RSNET_CONNECT_OUTGOING_TCP) if (!!(connect & RsConnectModes::OUTGOING_TCP))
{ {
connOut += "TCP_OUT "; connOut += "TCP_OUT ";
} }
if (connect & RSNET_CONNECT_ACCEPT_TCP) if (!!(connect & RsConnectModes::ACCEPT_TCP))
{ {
connOut += "TCP_IN "; connOut += "TCP_IN ";
} }
if (connect & RSNET_CONNECT_DIRECT_UDP) if (!!(connect & RsConnectModes::DIRECT_UDP))
{ {
connOut += "DIRECT_UDP "; connOut += "DIRECT_UDP ";
} }
if (connect & RSNET_CONNECT_PROXY_UDP) if (!!(connect & RsConnectModes::PROXY_UDP))
{ {
connOut += "PROXY_UDP "; connOut += "PROXY_UDP ";
} }
if (connect & RSNET_CONNECT_RELAY_UDP) if (!!(connect & RsConnectModes::RELAY_UDP))
{ {
connOut += "RELAY_UDP "; connOut += "RELAY_UDP ";
} }
label->setText(connOut); label->setText(connOut);
uint32_t netState = rsConfig->getNetState(); RsNetState netState = rsConfig->getNetState();
label = ui.netStatusLabel; label = ui.netStatusLabel;
switch(netState) switch(netState)
{ {
case RSNET_NETSTATE_BAD_UNKNOWN: case RsNetState::BAD_UNKNOWN:
label->setText(tr("NET BAD: Unknown State")); label->setText(tr("NET BAD: Unknown State"));
break; break;
case RSNET_NETSTATE_BAD_OFFLINE: case RsNetState::BAD_OFFLINE:
label->setText(tr("NET BAD: Offline")); label->setText(tr("NET BAD: Offline"));
break; break;
case RSNET_NETSTATE_BAD_NATSYM: case RsNetState::BAD_NATSYM:
label->setText(tr("NET BAD: Behind Symmetric NAT")); label->setText(tr("NET BAD: Behind Symmetric NAT"));
break; break;
case RSNET_NETSTATE_BAD_NODHT_NAT: case RsNetState::BAD_NODHT_NAT:
label->setText(tr("NET BAD: Behind NAT & No DHT")); label->setText(tr("NET BAD: Behind NAT & No DHT"));
break; break;
case RSNET_NETSTATE_WARNING_RESTART: case RsNetState::WARNING_RESTART:
label->setText(tr("NET WARNING: NET Restart")); label->setText(tr("NET WARNING: NET Restart"));
break; break;
case RSNET_NETSTATE_WARNING_NATTED: case RsNetState::WARNING_NATTED:
label->setText(tr("NET WARNING: Behind NAT")); label->setText(tr("NET WARNING: Behind NAT"));
break; break;
case RSNET_NETSTATE_WARNING_NODHT: case RsNetState::WARNING_NODHT:
label->setText(tr("NET WARNING: No DHT")); label->setText(tr("NET WARNING: No DHT"));
break; break;
case RSNET_NETSTATE_GOOD: case RsNetState::GOOD:
label->setText(tr("NET STATE GOOD!")); label->setText(tr("NET STATE GOOD!"));
break; break;
case RSNET_NETSTATE_ADV_FORWARD: case RsNetState::ADV_FORWARD:
label->setText(tr("CAUTION: UNVERIFIABLE FORWARD!")); label->setText(tr("CAUTION: UNVERIFIABLE FORWARD!"));
break; break;
case RSNET_NETSTATE_ADV_DARK_FORWARD: case RsNetState::ADV_DARK_FORWARD:
label->setText(tr("CAUTION: UNVERIFIABLE FORWARD & NO DHT")); label->setText(tr("CAUTION: UNVERIFIABLE FORWARD & NO DHT"));
break; break;
} }
@ -378,24 +381,24 @@ void DhtWindow::updateNetPeers()
switch(status.mDhtState) switch(status.mDhtState)
{ {
default: default:
case RSDHT_PEERDHT_NOT_ACTIVE: case RsDhtPeerDht::NOT_ACTIVE:
dhtstate = tr("Not Active (Maybe Connected!)"); dhtstate = tr("Not Active (Maybe Connected!)");
break; break;
case RSDHT_PEERDHT_SEARCHING: case RsDhtPeerDht::SEARCHING:
dhtstate = tr("Searching"); dhtstate = tr("Searching");
break; break;
case RSDHT_PEERDHT_FAILURE: case RsDhtPeerDht::FAILURE:
dhtstate = tr("Failed"); dhtstate = tr("Failed");
break; break;
case RSDHT_PEERDHT_OFFLINE: case RsDhtPeerDht::OFFLINE:
dhtstate = tr("offline"); dhtstate = tr("offline");
++nOfflinePeers; ++nOfflinePeers;
break; break;
case RSDHT_PEERDHT_UNREACHABLE: case RsDhtPeerDht::UNREACHABLE:
dhtstate = tr("Unreachable"); dhtstate = tr("Unreachable");
++nUnreachablePeers; ++nUnreachablePeers;
break; break;
case RSDHT_PEERDHT_ONLINE: case RsDhtPeerDht::ONLINE:
dhtstate = tr("ONLINE"); dhtstate = tr("ONLINE");
++nOnlinePeers; ++nOnlinePeers;
break; break;
@ -407,17 +410,17 @@ void DhtWindow::updateNetPeers()
QString cpmstr; QString cpmstr;
switch(status.mPeerConnectMode) switch(status.mPeerConnectMode)
{ {
case RSDHT_TOU_MODE_DIRECT: case RsDhtTouMode::DIRECT:
cpmstr = tr("Direct"); cpmstr = tr("Direct");
break; break;
case RSDHT_TOU_MODE_PROXY: case RsDhtTouMode::PROXY:
cpmstr = tr("Proxy VIA")+" " + QString::fromStdString(status.mPeerConnectProxyId); cpmstr = tr("Proxy VIA")+" " + QString::fromStdString(status.mPeerConnectProxyId);
break; break;
case RSDHT_TOU_MODE_RELAY: case RsDhtTouMode::RELAY:
cpmstr = tr("Relay VIA")+" " + QString::fromStdString(status.mPeerConnectProxyId); cpmstr = tr("Relay VIA")+" " + QString::fromStdString(status.mPeerConnectProxyId);
break; break;
default: default:
case RSDHT_TOU_MODE_NONE: case RsDhtTouMode::NONE:
cpmstr = tr("None"); cpmstr = tr("None");
break; break;
} }
@ -427,27 +430,27 @@ void DhtWindow::updateNetPeers()
switch(status.mPeerConnectState) switch(status.mPeerConnectState)
{ {
default: default:
case RSDHT_PEERCONN_DISCONNECTED: case RsDhtPeerConnectState::DISCONNECTED:
cpsstr = tr("Disconnected"); cpsstr = tr("Disconnected");
++nDisconnPeers; ++nDisconnPeers;
break; break;
case RSDHT_PEERCONN_UDP_STARTED: case RsDhtPeerConnectState::UDP_STARTED:
cpsstr = tr("Udp Started"); cpsstr = tr("Udp Started");
break; break;
case RSDHT_PEERCONN_CONNECTED: case RsDhtPeerConnectState::CONNECTED:
{ {
cpsstr = tr("Connected"); cpsstr = tr("Connected");
switch(status.mPeerConnectMode) switch(status.mPeerConnectMode)
{ {
default: default:
case RSDHT_TOU_MODE_DIRECT: case RsDhtTouMode::DIRECT:
++nDirectPeers; ++nDirectPeers;
break; break;
case RSDHT_TOU_MODE_PROXY: case RsDhtTouMode::PROXY:
++nProxyPeers; ++nProxyPeers;
break; break;
case RSDHT_TOU_MODE_RELAY: case RsDhtTouMode::RELAY:
++nRelayPeers; ++nRelayPeers;
break; break;
} }
@ -457,7 +460,7 @@ void DhtWindow::updateNetPeers()
peer_item -> setData(PTW_COL_PEER_CONNECT_STATUS, Qt::DisplayRole, cpsstr); peer_item -> setData(PTW_COL_PEER_CONNECT_STATUS, Qt::DisplayRole, cpsstr);
if (status.mPeerConnectState == RSDHT_PEERCONN_DISCONNECTED) if (status.mPeerConnectState == RsDhtPeerConnectState::DISCONNECTED)
{ {
peer_item -> setData(PTW_COL_PEER_CONNECT_MODE, Qt::DisplayRole, ""); peer_item -> setData(PTW_COL_PEER_CONNECT_MODE, Qt::DisplayRole, "");
} }
@ -474,10 +477,10 @@ void DhtWindow::updateNetPeers()
} }
switch(status.mPeerReqState) switch(status.mPeerReqState)
{ {
case RSDHT_PEERREQ_RUNNING: case RsDhtPeerRequest::RUNNING:
reqstr += tr("Request Active"); reqstr += tr("Request Active");
break; break;
case RSDHT_PEERREQ_STOPPED: case RsDhtPeerRequest::STOPPED:
reqstr += tr("No Request"); reqstr += tr("No Request");
break; break;
default: default:

View File

@ -39,13 +39,13 @@ OpModeStatus::OpModeStatus(QWidget *parent)
opMode_Minimal_Color = QColor("#FFCCCC"); opMode_Minimal_Color = QColor("#FFCCCC");
/* add the options */ /* add the options */
addItem(tr("Normal Mode"), RS_OPMODE_FULL); addItem(tr("Normal Mode"), static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::FULL));
setItemData(0, opMode_Full_Color, Qt::BackgroundRole); setItemData(0, opMode_Full_Color, Qt::BackgroundRole);
addItem(tr("No Anon D/L"), RS_OPMODE_NOTURTLE); addItem(tr("No Anon D/L"), static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE));
setItemData(1, opMode_NoTurtle_Color, Qt::BackgroundRole); setItemData(1, opMode_NoTurtle_Color, Qt::BackgroundRole);
addItem(tr("Gaming Mode"), RS_OPMODE_GAMING); addItem(tr("Gaming Mode"), static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::GAMING));
setItemData(2, opMode_Gaming_Color, Qt::BackgroundRole); setItemData(2, opMode_Gaming_Color, Qt::BackgroundRole);
addItem(tr("Low Traffic"), RS_OPMODE_MINIMAL); addItem(tr("Low Traffic"), static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::MINIMAL));
setItemData(3, opMode_Minimal_Color, Qt::BackgroundRole); setItemData(3, opMode_Minimal_Color, Qt::BackgroundRole);
connect(this, SIGNAL(activated( int )), this, SLOT(setOpMode())); connect(this, SIGNAL(activated( int )), this, SLOT(setOpMode()));
@ -59,23 +59,23 @@ OpModeStatus::OpModeStatus(QWidget *parent)
void OpModeStatus::getOpMode() void OpModeStatus::getOpMode()
{ {
int opMode = rsConfig->getOperatingMode(); RsOpMode opMode = rsConfig->getOperatingMode();
switch(opMode) switch(opMode)
{ {
default: default:
case RS_OPMODE_FULL: case RsOpMode::FULL:
setCurrentIndex(0); setCurrentIndex(0);
setProperty("opMode", "Full"); setProperty("opMode", "Full");
break; break;
case RS_OPMODE_NOTURTLE: case RsOpMode::NOTURTLE:
setCurrentIndex(1); setCurrentIndex(1);
setProperty("opMode", "NoTurtle"); setProperty("opMode", "NoTurtle");
break; break;
case RS_OPMODE_GAMING: case RsOpMode::GAMING:
setCurrentIndex(2); setCurrentIndex(2);
setProperty("opMode", "Gaming"); setProperty("opMode", "Gaming");
break; break;
case RS_OPMODE_MINIMAL: case RsOpMode::MINIMAL:
setCurrentIndex(3); setCurrentIndex(3);
setProperty("opMode", "Minimal"); setProperty("opMode", "Minimal");
break; break;
@ -94,19 +94,19 @@ void OpModeStatus::setOpMode()
int idx = currentIndex(); int idx = currentIndex();
QVariant var = itemData(idx); QVariant var = itemData(idx);
uint32_t opMode = var.toUInt(); RsOpMode opMode = static_cast<RsOpMode>(var.toUInt());
QString message = tr("<p>Warning: This Operating mode disables the tunneling service. This means you can use distant chat not anonymously download files and the mail service will be slower.</p><p>This state will be saved after restart, so do not forget that you changed it!</p>"); QString message = tr("<p>Warning: This Operating mode disables the tunneling service. This means you can use distant chat not anonymously download files and the mail service will be slower.</p><p>This state will be saved after restart, so do not forget that you changed it!</p>");
if(opMode == RS_OPMODE_NOTURTLE && ! Settings->getPageAlreadyDisplayed(QString("RS_OPMODE_NO_TURTLE"))) if(opMode == RsOpMode::NOTURTLE && ! Settings->getPageAlreadyDisplayed(QString("RsOpMode::NO_TURTLE")))
{ {
QMessageBox::warning(NULL,tr("Turtle routing disabled!"),message); QMessageBox::warning(NULL,tr("Turtle routing disabled!"),message);
Settings->setPageAlreadyDisplayed(QString("RS_OPMODE_NO_TURTLE"),true) ; Settings->setPageAlreadyDisplayed(QString("RsOpMode::NO_TURTLE"),true) ;
} }
if( (opMode == RS_OPMODE_MINIMAL && ! Settings->getPageAlreadyDisplayed(QString("RS_OPMODE_MINIMAL")))) if( (opMode == RsOpMode::MINIMAL && ! Settings->getPageAlreadyDisplayed(QString("RsOpMode::MINIMAL"))))
{ {
QMessageBox::warning(NULL,tr("Turtle routing disabled!"),message); QMessageBox::warning(NULL,tr("Turtle routing disabled!"),message);
Settings->setPageAlreadyDisplayed(QString("RS_OPMODE_MINIMAL"),true) ; Settings->setPageAlreadyDisplayed(QString("RsOpMode::MINIMAL"),true) ;
} }
rsConfig->setOperatingMode(opMode); rsConfig->setOperatingMode(opMode);

View File

@ -52,7 +52,7 @@ NATStatus::NATStatus(QWidget *parent)
void NATStatus::getNATStatus() void NATStatus::getNATStatus()
{ {
uint32_t netState = rsConfig -> getNetState(); RsNetState netState = rsConfig -> getNetState();
statusNAT->setVisible(!_compactMode); statusNAT->setVisible(!_compactMode);
QString text = _compactMode?statusNAT->text():""; QString text = _compactMode?statusNAT->text():"";
@ -61,14 +61,14 @@ void NATStatus::getNATStatus()
switch(netState) switch(netState)
{ {
default: default:
case RSNET_NETSTATE_BAD_UNKNOWN: case RsNetState::BAD_UNKNOWN:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_yellow_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_yellow_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("Network Status Unknown")) ; iconLabel->setToolTip( text + tr("Network Status Unknown")) ;
} }
break ; break ;
case RSNET_NETSTATE_BAD_OFFLINE: case RsNetState::BAD_OFFLINE:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_grey_129.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_grey_129.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("Offline")) ; iconLabel->setToolTip( text + tr("Offline")) ;
@ -76,14 +76,14 @@ void NATStatus::getNATStatus()
break ; break ;
// BAD. (RED) // BAD. (RED)
case RSNET_NETSTATE_BAD_NATSYM: case RsNetState::BAD_NATSYM:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_red_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_red_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("Nasty Firewall")) ; iconLabel->setToolTip( text + tr("Nasty Firewall")) ;
} }
break ; break ;
case RSNET_NETSTATE_BAD_NODHT_NAT: case RsNetState::BAD_NODHT_NAT:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_red_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_red_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("DHT Disabled and Firewalled")) ; iconLabel->setToolTip( text + tr("DHT Disabled and Firewalled")) ;
@ -91,21 +91,21 @@ void NATStatus::getNATStatus()
break ; break ;
// CAUTION. (ORANGE) // CAUTION. (ORANGE)
case RSNET_NETSTATE_WARNING_RESTART: case RsNetState::WARNING_RESTART:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_yellow_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_yellow_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("Network Restarting")) ; iconLabel->setToolTip( text + tr("Network Restarting")) ;
} }
break ; break ;
case RSNET_NETSTATE_WARNING_NATTED: case RsNetState::WARNING_NATTED:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_yellow_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_yellow_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("Behind Firewall")) ; iconLabel->setToolTip( text + tr("Behind Firewall")) ;
} }
break ; break ;
case RSNET_NETSTATE_WARNING_NODHT: case RsNetState::WARNING_NODHT:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_yellow_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_yellow_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("DHT Disabled")) ; iconLabel->setToolTip( text + tr("DHT Disabled")) ;
@ -113,14 +113,14 @@ void NATStatus::getNATStatus()
break ; break ;
// GOOD (GREEN) // GOOD (GREEN)
case RSNET_NETSTATE_GOOD: case RsNetState::GOOD:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_green_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_green_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("RetroShare Server")) ; iconLabel->setToolTip( text + tr("RetroShare Server")) ;
} }
break ; break ;
case RSNET_NETSTATE_ADV_FORWARD: case RsNetState::ADV_FORWARD:
{ {
iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_green_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ; iconLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/bullet_green_128.png").scaledToHeight(S,Qt::SmoothTransformation)) ;
iconLabel->setToolTip( text + tr("Forwarded Port")) ; iconLabel->setToolTip( text + tr("Forwarded Port")) ;

View File

@ -61,24 +61,24 @@ void TorStatus::getTorStatus()
QString text = _compactMode?statusTor->text():""; QString text = _compactMode?statusTor->text():"";
/* check local network state. We cannot make sure that Tor is running yet. */ /* check local network state. We cannot make sure that Tor is running yet. */
uint32_t netState = rsConfig -> getNetState(); RsNetState netState = rsConfig -> getNetState();
bool online ; bool online ;
switch(netState) switch(netState)
{ {
default: default:
case RSNET_NETSTATE_BAD_UNKNOWN: case RsNetState::BAD_UNKNOWN:
case RSNET_NETSTATE_BAD_OFFLINE: online = false ; case RsNetState::BAD_OFFLINE: online = false ;
break ; break ;
case RSNET_NETSTATE_WARNING_RESTART: case RsNetState::WARNING_RESTART:
case RSNET_NETSTATE_BAD_NATSYM: case RsNetState::BAD_NATSYM:
case RSNET_NETSTATE_BAD_NODHT_NAT: case RsNetState::BAD_NODHT_NAT:
case RSNET_NETSTATE_WARNING_NATTED: case RsNetState::WARNING_NATTED:
case RSNET_NETSTATE_WARNING_NODHT: case RsNetState::WARNING_NODHT:
case RSNET_NETSTATE_GOOD: case RsNetState::GOOD:
case RSNET_NETSTATE_ADV_FORWARD: online = true ; case RsNetState::ADV_FORWARD: online = true ;
break ; break ;
} }