diff --git a/reflector/Reflector.cpp b/reflector/Reflector.cpp index afe9505..b02f8f7 100644 --- a/reflector/Reflector.cpp +++ b/reflector/Reflector.cpp @@ -555,7 +555,7 @@ void CReflector::PutDHTPeers() ReleasePeers(); auto nv = std::make_shared(p); - nv->user_type.assign("urfd-peers-1"); + nv->user_type.assign(URFD_PEERS_1); nv->id = toUType(EUrfdValueID::Peers); node.putSigned( @@ -584,7 +584,7 @@ void CReflector::PutDHTClients() ReleaseClients(); auto nv = std::make_shared(c); - nv->user_type.assign("urfd-clients-1"); + nv->user_type.assign(URFD_CLIENTS_1); nv->id = toUType(EUrfdValueID::Clients); node.putSigned( @@ -613,7 +613,7 @@ void CReflector::PutDHTUsers() ReleaseUsers(); auto nv = std::make_shared(u); - nv->user_type.assign("urfd-users-1"); + nv->user_type.assign(URFD_USERS_1); nv->id = toUType(EUrfdValueID::Users); node.putSigned( @@ -633,11 +633,11 @@ void CReflector::PutDHTConfig() const std::string cs(g_Configure.GetString(g_Keys.names.callsign)); SUrfdConfig1 cfg; time(&cfg.timestamp); - cfg.cs.assign(cs); - cfg.ipv4.assign(g_Configure.GetString(g_Keys.ip.ipv4address)); - cfg.ipv6.assign(g_Configure.GetString(g_Keys.ip.ipv6address)); - cfg.mods.assign(g_Configure.GetString(g_Keys.modules.modules)); - cfg.tcmods.assign(g_Configure.GetString(g_Keys.modules.tcmodules)); + cfg.callsign.assign(cs); + cfg.ipv4addr.assign(g_Configure.GetString(g_Keys.ip.ipv4address)); + cfg.ipv6addr.assign(g_Configure.GetString(g_Keys.ip.ipv6address)); + cfg.modules.assign(g_Configure.GetString(g_Keys.modules.modules)); + cfg.transcodedmods.assign(g_Configure.GetString(g_Keys.modules.tcmodules)); cfg.url.assign(g_Configure.GetString(g_Keys.names.url)); cfg.email.assign(g_Configure.GetString(g_Keys.names.email)); cfg.country.assign(g_Configure.GetString(g_Keys.names.country)); @@ -663,11 +663,11 @@ void CReflector::PutDHTConfig() cfg.port[toUType(EUrfdPorts::urf)] = (uint16_t)g_Configure.GetUnsigned(g_Keys.urf.port); cfg.port[toUType(EUrfdPorts::ysf)] = (uint16_t)g_Configure.GetUnsigned(g_Keys.ysf.port); cfg.g3enabled = g_Configure.GetBoolean(g_Keys.g3.enable); - for (const auto m : cfg.mods) + for (const auto m : cfg.modules) cfg.description[m] = g_Configure.GetString(g_Keys.modules.descriptor[m-'A']); auto nv = std::make_shared(cfg); - nv->user_type.assign("urfd-config-1"); + nv->user_type.assign(URFD_CONFIG_1); nv->id = toUType(EUrfdValueID::Config); node.putSigned( @@ -696,7 +696,7 @@ void CReflector::GetDHTConfig(const std::string &cs) node.get( dht::InfoHash::get(cs), [](const std::shared_ptr &v) { - if (0 == v->user_type.compare("urfd-config-1")) + if (0 == v->user_type.compare(URFD_CONFIG_1)) { auto rdat = dht::Value::unpack(*v); if (rdat.timestamp > cfg.timestamp) @@ -717,7 +717,7 @@ void CReflector::GetDHTConfig(const std::string &cs) if (cfg.timestamp) { // if the get() call was successful and there is a nonzero timestamp, then do the update - g_GateKeeper.GetInterlinkMap()->Update(cfg.cs, cfg.mods, cfg.ipv4, cfg.ipv6, cfg.port[toUType(EUrfdPorts::urf)], cfg.tcmods); + g_GateKeeper.GetInterlinkMap()->Update(cfg.callsign, cfg.modules, cfg.ipv4addr, cfg.ipv6addr, cfg.port[toUType(EUrfdPorts::urf)], cfg.transcodedmods); g_GateKeeper.ReleaseInterlinkMap(); } else diff --git a/reflector/Reflector.h b/reflector/Reflector.h index 9f3c925..5d8fb52 100644 --- a/reflector/Reflector.h +++ b/reflector/Reflector.h @@ -27,7 +27,7 @@ #include "PacketStream.h" #ifndef NO_DHT -#include "urfd-dht-values.h" +#include "dht-values.h" #endif diff --git a/reflector/dht-values.h b/reflector/dht-values.h new file mode 100644 index 0000000..8919a2e --- /dev/null +++ b/reflector/dht-values.h @@ -0,0 +1,156 @@ +// Copyright © 2022 Thomas A. Early, N7TAE +// +// ---------------------------------------------------------------------------- +// This is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// with this software. If not, see . +// ---------------------------------------------------------------------------- + +#pragma once + +#include + +//#define USE_MREFD_VALUES +#define USE_URFD_VALUES + +/* HELPERS */ +template constexpr auto toUType(E enumerator) noexcept +{ + return static_cast>(enumerator); +} // Item #10 in "Effective Modern C++", by Scott Meyers, O'REILLY + +// every value type needs a const user_type and a timestamp +struct SDhtValueBase +{ + SDhtValueBase(const std::string &s) : user_type(s) {} + std::string user_type; + std::time_t timestamp; +}; + +#ifdef USE_MREFD_VALUES + +// user_type for mrefd values +#define MREFD_USERS_1 "mrefd-users-1" +#define MREFD_PEERS_1 "mrefd-peers-1" +#define MREFD_CONFIG_1 "mrefd-config-1" +#define MREFD_CLIENTS_1 "mrefd-clients-1" + +// dht::Value ids of the different parts of the document +// can be assigned any unsigned value except 0 +enum class EMrefdValueID : uint64_t { Config=1, Peers=2, Clients=3, Users=4 }; + +using MrefdPeerTuple = std::tuple; +enum class EMrefdPeerFields { Callsign, Modules, ConnectTime }; +struct SMrefdPeers1 : public SDhtValueBase +{ + SMrefdPeers1() : SDhtValueBase(MREFD_PEERS_1) {} + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +using MrefdClientTuple = std::tuple; +enum class EMrefdClientFields { Callsign, Ip, Module, ConnectTime, LastHeardTime }; +struct SMrefdClients1 : public SDhtValueBase +{ + SMrefdClients1() : SDhtValueBase(MREFD_CLIENTS_1) {} + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +using MrefdUserTuple = std::tuple; +enum class EMrefdUserFields { Source, Destination, Reflector, LastHeardTime }; +struct SMrefdUsers1 : public SDhtValueBase +{ + SMrefdUsers1() : SDhtValueBase(MREFD_USERS_1) {} + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +struct SMrefdConfig1 : public SDhtValueBase +{ + SMrefdConfig1() : SDhtValueBase(MREFD_CONFIG_1) {} + std::string callsign, ipv4addr, ipv6addr, modules, encryptedmods, url, email, sponsor, country, version; + uint16_t port; + + MSGPACK_DEFINE(timestamp, callsign, ipv4addr, ipv6addr, modules, encryptedmods, url, email, sponsor, country, version, port) +}; + +#endif + +#ifdef USE_URFD_VALUES + +#define URFD_PEERS_1 "urfd-peers-1" +#define URFD_USERS_1 "urfd-users-1" +#define URFD_CONFIG_1 "urfd-config-1" +#define URFD_CLIENTS_1 "urfd-clients-1" + +enum class EUrfdValueID : uint64_t { Config=1, Peers=2, Clients=3, Users=4 }; + +using UrfdPeerTuple = std::tuple; +enum class EUrfdPeerFields { Callsign, Modules, ConnectTime }; +struct SUrfdPeers1 : public SDhtValueBase +{ + SUrfdPeers1() : SDhtValueBase(URFD_PEERS_1) {} + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +using UrfdClientTuple = std::tuple; +enum class EUrfdClientFields { Callsign, Ip, Module, ConnectTime, LastHeardTime }; +struct SUrfdClients1 : public SDhtValueBase +{ + SUrfdClients1() : SDhtValueBase(URFD_CLIENTS_1) {} + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +using UrfdUserTuple = std::tuple; +enum class EUrfdUserFields { Callsign, ViaNode, OnModule, ViaPeer, LastHeardTime }; +struct SUrfdUsers1 : public SDhtValueBase +{ + SUrfdUsers1() : SDhtValueBase(URFD_USERS_1) {} + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +// 'SIZE' has to be last value for these scoped enums +enum class EUrfdPorts : unsigned { dcs, dextra, dmrplus, dplus, m17, mmdvm, nxdn, p25, urf, ysf, SIZE }; +enum class EUrfdAlMod : unsigned { nxdn, p25, ysf, SIZE }; +enum class EUrfdTxRx : unsigned { rx, tx, SIZE }; +enum class EUrfdRefId : unsigned { nxdn, p25, SIZE }; +struct SUrfdConfig1 : public SDhtValueBase +{ + SUrfdConfig1() : SDhtValueBase(URFD_CONFIG_1) {} + std::string callsign, ipv4addr, ipv6addr, modules, transcodedmods, url, email, sponsor, country, version; + std::array port; + std::array almod; + std::array ysffreq; + std::array refid; + std::unordered_map description; + bool g3enabled; + + MSGPACK_DEFINE(timestamp, callsign, ipv4addr, ipv6addr, modules, transcodedmods, url, email, sponsor, country, version, almod, ysffreq, refid, g3enabled, port, description) +}; + +#endif diff --git a/reflector/urfd-dht-values.h b/reflector/urfd-dht-values.h deleted file mode 100644 index ee147e6..0000000 --- a/reflector/urfd-dht-values.h +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright © 2023 Thomas A. Early, N7TAE -// -// ---------------------------------------------------------------------------- -// This file is part of urfd. -// -// M17Refd is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// M17Refd is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// with this software. If not, see . -// ---------------------------------------------------------------------------- - -#pragma once - -#include - -/* HELPERS */ -#ifndef TO_U_TYPE_DEF -#define TO_U_TYPE_DEF -template constexpr auto toUType(E enumerator) noexcept -{ - return static_cast>(enumerator); -} // Item #10 in "Effective Modern C++", by Scott Meyers, O'REILLY -#endif - -enum class EUrfdValueID : uint64_t { Config=1, Peers=2, Clients=3, Users=4 }; - -/* PEERS */ -using UrfdPeerTuple = std::tuple; -enum class EUrfdPeerFields { Callsign, Modules, ConnectTime }; -struct SUrfdPeers1 -{ - std::time_t timestamp; - unsigned int sequence; - std::list list; - - MSGPACK_DEFINE(timestamp, sequence, list) -}; - -/* CLIENTS */ -using UrfdClientTuple = std::tuple; -enum class EUrfdClientFields { Callsign, Ip, Module, ConnectTime, LastHeardTime }; -struct SUrfdClients1 -{ - std::time_t timestamp; - unsigned int sequence; - std::list list; - - MSGPACK_DEFINE(timestamp, sequence, list) -}; - -/* USERS */ -using UrfdUserTuple = std::tuple; -enum class EUrfdUserFields { Callsign, ViaNode, OnModule, ViaPeer, LastHeardTime }; -struct SUrfdUsers1 -{ - std::time_t timestamp; - unsigned int sequence; - std::list list; - - MSGPACK_DEFINE(timestamp, sequence, list) -}; - -/* CONFIGURATION */ -// 'SIZE' has to be last for these scoped enums -enum class EUrfdPorts : unsigned { dcs, dextra, dmrplus, dplus, m17, mmdvm, nxdn, p25, urf, ysf, SIZE }; -enum class EUrfdAlMod : unsigned { nxdn, p25, ysf, SIZE }; -enum class EUrfdTxRx : unsigned { rx, tx, SIZE }; -enum class EUrfdRefId : unsigned { nxdn, p25, SIZE }; -struct SUrfdConfig1 -{ - std::time_t timestamp; - std::string cs, ipv4, ipv6, mods, tcmods, url, email, sponsor, country, version; - std::array port; - std::array almod; - std::array ysffreq; - std::array refid; - std::unordered_map description; - bool g3enabled; - - MSGPACK_DEFINE(timestamp, cs, ipv4, ipv6, mods, tcmods, url, email, sponsor, country, version, almod, ysffreq, refid, g3enabled, port, description) -};