mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-26 17:51:26 -05:00
convert RSDHT_RELAY_CLASS_ to enum class
This commit is contained in:
parent
bc1ba3654d
commit
0678226a93
@ -297,8 +297,8 @@ public:
|
|||||||
virtual RsDhtRelayMode getRelayMode();
|
virtual RsDhtRelayMode getRelayMode();
|
||||||
virtual int setRelayMode(RsDhtRelayMode 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:
|
||||||
|
|
||||||
|
@ -163,13 +163,13 @@ int p3BitDht::setRelayMode(RsDhtRelayMode 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 >= static_cast<RsDhtRelayClass>(0)) && (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,8 +302,8 @@ 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;
|
||||||
RsDhtRelayMode mode = static_cast<RsDhtRelayMode>(0);
|
RsDhtRelayMode mode = static_cast<RsDhtRelayMode>(0);
|
||||||
@ -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]);
|
||||||
}
|
}
|
||||||
|
@ -75,12 +75,15 @@ enum class RsDhtTouMode : uint8_t
|
|||||||
RELAY = 3
|
RELAY = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
#define RSDHT_RELAY_NUM_CLASS 4
|
enum class RsDhtRelayClass : uint8_t
|
||||||
|
{
|
||||||
|
ALL = 0,
|
||||||
|
GENERAL = 1,
|
||||||
|
FOF = 2,
|
||||||
|
FRIENDS = 3,
|
||||||
|
|
||||||
#define RSDHT_RELAY_CLASS_ALL 0
|
NUM_CLASS = 4
|
||||||
#define RSDHT_RELAY_CLASS_GENERAL 1
|
};
|
||||||
#define RSDHT_RELAY_CLASS_FOF 2
|
|
||||||
#define RSDHT_RELAY_CLASS_FRIENDS 3
|
|
||||||
|
|
||||||
enum class RsDhtRelayMode : uint16_t
|
enum class RsDhtRelayMode : uint16_t
|
||||||
{
|
{
|
||||||
@ -199,8 +202,8 @@ virtual int removeRelayServer(std::string ids) = 0;
|
|||||||
virtual RsDhtRelayMode getRelayMode() = 0;
|
virtual RsDhtRelayMode getRelayMode() = 0;
|
||||||
virtual int setRelayMode(RsDhtRelayMode 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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -446,15 +446,15 @@ 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);
|
||||||
|
|
||||||
@ -1884,10 +1884,10 @@ 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 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user