convert RSDHT_RELAY_MODE_ to enum class

This commit is contained in:
sehraf 2020-02-19 18:57:28 +01:00
parent dfc7212c23
commit 1b29e81e89
No known key found for this signature in database
GPG Key ID: DF09F6EAE356B2C6
4 changed files with 33 additions and 31 deletions

View File

@ -294,8 +294,8 @@ public:
virtual int addRelayServer(std::string ids);
virtual int removeRelayServer(std::string ids);
virtual uint32_t getRelayMode();
virtual int setRelayMode(uint32_t mode);
virtual RsDhtRelayMode getRelayMode();
virtual int setRelayMode(RsDhtRelayMode mode);
virtual int getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth);
virtual int setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth);
@ -307,7 +307,7 @@ private:
int pushRelayServers();
std::list<std::string> mRelayServerList;
uint32_t mRelayMode;
RsDhtRelayMode mRelayMode;
protected:
/*****************************************************************/

View File

@ -35,7 +35,7 @@
int p3BitDht::setupRelayDefaults()
{
uint32_t mode = RSDHT_RELAY_ENABLED | RSDHT_RELAY_MODE_OFF;
RsDhtRelayMode mode = RsDhtRelayMode::ENABLED | RsDhtRelayMode::OFF;
setRelayMode(mode);
return 1;
@ -111,19 +111,19 @@ int p3BitDht::pushRelayServers()
}
uint32_t p3BitDht::getRelayMode()
RsDhtRelayMode p3BitDht::getRelayMode()
{
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/
return mRelayMode;
}
int p3BitDht::setRelayMode(uint32_t mode)
int p3BitDht::setRelayMode(RsDhtRelayMode mode)
{
std::cerr << "p3BitDht::setRelayMode(" << mode << ")";
std::cerr << std::endl;
if (mode & RSDHT_RELAY_ENABLED)
if (!!(mode & RsDhtRelayMode::ENABLED))
{
mUdpBitDht->ConnectionOptions(
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);
}
int relaymode = mode & RSDHT_RELAY_MODE_MASK;
RsDhtRelayMode relaymode = mode & RsDhtRelayMode::MASK;
switch(relaymode)
{
case RSDHT_RELAY_MODE_OFF:
case RsDhtRelayMode::OFF:
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_IGNORED);
break;
case RSDHT_RELAY_MODE_ON:
case RsDhtRelayMode::ON:
pushRelayServers();
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_FLAGGED);
break;
case RSDHT_RELAY_MODE_SERVER:
case RsDhtRelayMode::SERVER:
pushRelayServers();
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_SERVER);
break;
@ -306,7 +306,7 @@ bool p3BitDht::loadList(std::list<RsItem *>& load)
int bandwidth[RSDHT_RELAY_NUM_CLASS] = {0};
bool haveMode = false;
int mode = 0;
RsDhtRelayMode mode = static_cast<RsDhtRelayMode>(0);
std::list<RsTlvKeyValue>::iterator 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))
{
mode = atoi(value.c_str());
mode = static_cast<RsDhtRelayMode>(atoi(value.c_str()));
haveMode = true;
//std::cerr << "p3BitDht::loadList() Found Mode: " << mode;

View File

@ -27,6 +27,7 @@
#include <list>
#include <retroshare/rstypes.h>
#include "util/rsnet.h"
#include "retroshare/rsflags.h"
/* The Main Interface Class - for information about your Peers */
class RsDht;
@ -75,15 +76,16 @@ extern RsDht *rsDht;
#define RSDHT_RELAY_CLASS_FOF 2
#define RSDHT_RELAY_CLASS_FRIENDS 3
enum class RsDhtRelayMode : uint16_t
{
ENABLED = 0x0001,
#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
{
@ -188,8 +190,8 @@ virtual int getRelayServerList(std::list<std::string> &ids) = 0;
virtual int addRelayServer(std::string ids) = 0;
virtual int removeRelayServer(std::string ids) = 0;
virtual uint32_t getRelayMode() = 0;
virtual int setRelayMode(uint32_t mode) = 0;
virtual RsDhtRelayMode getRelayMode() = 0;
virtual int setRelayMode(RsDhtRelayMode mode) = 0;
virtual int getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth) = 0;
virtual int setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth) = 0;

View File

@ -461,11 +461,11 @@ void ServerPage::load()
updateTotals();
uint32_t relayMode = rsDht->getRelayMode();
if (relayMode & RSDHT_RELAY_ENABLED)
RsDhtRelayMode relayMode = rsDht->getRelayMode();
if (!!(relayMode & RsDhtRelayMode::ENABLED))
{
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);
}
@ -1894,23 +1894,23 @@ void ServerPage::updateTotals()
void ServerPage::updateRelayMode()
{
uint32_t relayMode = 0;
RsDhtRelayMode relayMode = static_cast<RsDhtRelayMode>(0);
if (ui.enableCheckBox->isChecked())
{
relayMode |= RSDHT_RELAY_ENABLED;
relayMode |= RsDhtRelayMode::ENABLED;
if (ui.serverCheckBox->isChecked())
{
relayMode |= RSDHT_RELAY_MODE_ON;
relayMode |= RsDhtRelayMode::ON;
}
else
{
relayMode |= RSDHT_RELAY_MODE_OFF;
relayMode |= RsDhtRelayMode::OFF;
}
}
else
{
relayMode |= RSDHT_RELAY_MODE_OFF;
relayMode |= RsDhtRelayMode::OFF;
}
rsDht->setRelayMode(relayMode);