diff --git a/libretroshare/src/dht/p3bitdht.h b/libretroshare/src/dht/p3bitdht.h index 277054494..844a7d051 100644 --- a/libretroshare/src/dht/p3bitdht.h +++ b/libretroshare/src/dht/p3bitdht.h @@ -297,8 +297,8 @@ public: 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); + virtual int getRelayAllowance(RsDhtRelayClass classIdx, uint32_t &count, uint32_t &bandwidth); + virtual int setRelayAllowance(RsDhtRelayClass classIdx, uint32_t count, uint32_t bandwidth); private: diff --git a/libretroshare/src/dht/p3bitdht_relay.cc b/libretroshare/src/dht/p3bitdht_relay.cc index 2011530b1..e5afd4b31 100644 --- a/libretroshare/src/dht/p3bitdht_relay.cc +++ b/libretroshare/src/dht/p3bitdht_relay.cc @@ -163,13 +163,13 @@ int p3BitDht::setRelayMode(RsDhtRelayMode mode) 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 << "): "; - if ((classIdx >= 0) && (classIdx < RSDHT_RELAY_NUM_CLASS)) + std::cerr << "p3BitDht::getRelayAllowance(" << static_cast::type>(classIdx) << "): "; + if ((classIdx >= static_cast(0)) && (classIdx < RsDhtRelayClass::NUM_CLASS)) { - count = mRelay->getRelayClassMax(classIdx); - bandwidth = mRelay->getRelayClassBandwidth(classIdx); + count = mRelay->getRelayClassMax(static_cast::type>(classIdx)); + bandwidth = mRelay->getRelayClassBandwidth(static_cast::type>(classIdx)); std::cerr << " count: " << count << " bandwidth: " << bandwidth; std::cerr << std::endl; @@ -181,13 +181,13 @@ int p3BitDht::getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwid 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::type>(classIdx) << ", "; std::cerr << ", " << count << ", " << bandwidth << ")"; std::cerr << std::endl; - int retval = mRelay->setRelayClassMax(classIdx, count, bandwidth); + int retval = mRelay->setRelayClassMax(static_cast::type>(classIdx), count, bandwidth); IndicateConfigChanged(); return retval; @@ -224,7 +224,7 @@ bool p3BitDht::saveList(bool &cleanup, std::list &saveList) /* Push Relay Class Stuff */ int i; - for(i = 0; i < RSDHT_RELAY_NUM_CLASS; ++i) + for(i = 0; i < static_cast::type>(RsDhtRelayClass::NUM_CLASS); ++i) { rs_sprintf(kv.key, "RELAY_CLASS%d_COUNT", i); rs_sprintf(kv.value, "%d", mRelay->getRelayClassMax(i)); @@ -302,8 +302,8 @@ bool p3BitDht::loadList(std::list& load) //config->print(std::cerr, 0); std::list servers; - int peers[RSDHT_RELAY_NUM_CLASS] = {0}; - int bandwidth[RSDHT_RELAY_NUM_CLASS] = {0}; + int peers[static_cast::type>(RsDhtRelayClass::NUM_CLASS)] = {0}; + int bandwidth[static_cast::type>(RsDhtRelayClass::NUM_CLASS)] = {0}; bool haveMode = false; RsDhtRelayMode mode = static_cast(0); @@ -386,7 +386,7 @@ bool p3BitDht::loadList(std::list& load) } int i; - for(i = 0; i < RSDHT_RELAY_NUM_CLASS; ++i) + for(i = 0; i < static_cast::type>(RsDhtRelayClass::NUM_CLASS); ++i) { mRelay->setRelayClassMax(i, peers[i], bandwidth[i]); } diff --git a/libretroshare/src/retroshare/rsdht.h b/libretroshare/src/retroshare/rsdht.h index 4aa3cc5c8..b52e2ba73 100644 --- a/libretroshare/src/retroshare/rsdht.h +++ b/libretroshare/src/retroshare/rsdht.h @@ -75,12 +75,15 @@ enum class RsDhtTouMode : uint8_t 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 -#define RSDHT_RELAY_CLASS_GENERAL 1 -#define RSDHT_RELAY_CLASS_FOF 2 -#define RSDHT_RELAY_CLASS_FRIENDS 3 + NUM_CLASS = 4 +}; enum class RsDhtRelayMode : uint16_t { @@ -199,8 +202,8 @@ virtual int removeRelayServer(std::string ids) = 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; +virtual int getRelayAllowance(RsDhtRelayClass 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. virtual bool getOwnDhtId(std::string &ownDhtId) = 0; diff --git a/libretroshare/src/tcponudp/udprelay.cc b/libretroshare/src/tcponudp/udprelay.cc index fa988ec09..68062b860 100644 --- a/libretroshare/src/tcponudp/udprelay.cc +++ b/libretroshare/src/tcponudp/udprelay.cc @@ -298,13 +298,13 @@ int UdpRelayReceiver::checkRelays() switch(rit->second.mRelayClass) { default: - case UDP_RELAY_CLASS_GENERAL: + case UDP_RELAY_CLASS_GENERAL: lifetime = UDP_RELAY_LIFETIME_GENERAL; break; - case UDP_RELAY_CLASS_FOF: + case UDP_RELAY_CLASS_FOF: lifetime = UDP_RELAY_LIFETIME_FOF; break; - case UDP_RELAY_CLASS_FRIENDS: + case UDP_RELAY_CLASS_FRIENDS: lifetime = UDP_RELAY_LIFETIME_FRIENDS; break; } @@ -1048,13 +1048,13 @@ UdpRelayProxy::UdpRelayProxy(UdpRelayAddrSet *addrSet, int relayClass, uint32_t switch(relayClass) { default: - case UDP_RELAY_CLASS_GENERAL: + case UDP_RELAY_CLASS_GENERAL: mBandwidthLimit = RELAY_MAX_BANDWIDTH; break; - case UDP_RELAY_CLASS_FOF: + case UDP_RELAY_CLASS_FOF: mBandwidthLimit = RELAY_MAX_BANDWIDTH; break; - case UDP_RELAY_CLASS_FRIENDS: + case UDP_RELAY_CLASS_FRIENDS: mBandwidthLimit = RELAY_MAX_BANDWIDTH; break; } diff --git a/libretroshare/src/tcponudp/udprelay.h b/libretroshare/src/tcponudp/udprelay.h index ecc65834b..ba412ac5a 100644 --- a/libretroshare/src/tcponudp/udprelay.h +++ b/libretroshare/src/tcponudp/udprelay.h @@ -101,12 +101,14 @@ std::ostream &operator<<(std::ostream &out, const UdpRelayEnd &ure); /**** 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::type>(RsDhtRelayClass::NUM_CLASS) -#define UDP_RELAY_CLASS_ALL RSDHT_RELAY_CLASS_ALL -#define UDP_RELAY_CLASS_GENERAL RSDHT_RELAY_CLASS_GENERAL -#define UDP_RELAY_CLASS_FOF RSDHT_RELAY_CLASS_FOF -#define UDP_RELAY_CLASS_FRIENDS RSDHT_RELAY_CLASS_FRIENDS +#define UDP_RELAY_CLASS_ALL static_cast::type>(RsDhtRelayClass::ALL) +#define UDP_RELAY_CLASS_GENERAL static_cast::type>(RsDhtRelayClass::GENERAL) +#define UDP_RELAY_CLASS_FOF static_cast::type>(RsDhtRelayClass::FOF) +#define UDP_RELAY_CLASS_FRIENDS static_cast::type>(RsDhtRelayClass::FRIENDS) // Just for some testing fun! //#define UDP_RELAY_LIFETIME_GENERAL 180 // 3 minutes diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index b041e1f31..6cc23cb38 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -446,15 +446,15 @@ void ServerPage::load() //Relay Tab uint32_t count; uint32_t bandwidth; - rsDht->getRelayAllowance(RSDHT_RELAY_CLASS_FRIENDS, count, bandwidth); + rsDht->getRelayAllowance(RsDhtRelayClass::FRIENDS, count, bandwidth); whileBlocking(ui.noFriendSpinBox)->setValue(count); 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.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.bandGeneralSpinBox)->setValue(bandwidth / 1024); @@ -1884,10 +1884,10 @@ void ServerPage::updateTotals() int total = nFriends + nFOF + nGeneral; - rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_ALL, total, 0); - rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_FRIENDS, nFriends, 1024 * friendBandwidth); - rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_FOF, nFOF, 1024 * fofBandwidth); - rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_GENERAL, nGeneral, 1024 * genBandwidth); + rsDht->setRelayAllowance(RsDhtRelayClass::ALL, total, 0); + rsDht->setRelayAllowance(RsDhtRelayClass::FRIENDS, nFriends, 1024 * friendBandwidth); + rsDht->setRelayAllowance(RsDhtRelayClass::FOF, nFOF, 1024 * fofBandwidth); + rsDht->setRelayAllowance(RsDhtRelayClass::GENERAL, nGeneral, 1024 * genBandwidth); } /** Saves the changes on this page */