From 09a80406c1652adcb2fb416a3f50828c45d20ad5 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Fri, 24 Mar 2023 23:51:14 -0700 Subject: [PATCH] DHT data --- reflector/Makefile | 4 +- reflector/Reflector.h | 22 +++++++++- reflector/urfd-dht-values.h | 86 +++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 reflector/urfd-dht-values.h diff --git a/reflector/Makefile b/reflector/Makefile index 86a9d26..3116642 100644 --- a/reflector/Makefile +++ b/reflector/Makefile @@ -27,9 +27,9 @@ DBUTIL = dbutil include urfd.mk ifeq ($(debug), true) -CFLAGS = -ggdb3 -DDEBUG -W -Werror -std=c++11 -MMD -MD +CFLAGS = -ggdb3 -DDEBUG -W -Werror -std=c++17 -MMD -MD else -CFLAGS = -W -Werror -std=c++11 -MMD -MD +CFLAGS = -W -Werror -std=c++17 -MMD -MD endif LDFLAGS=-pthread -lcurl diff --git a/reflector/Reflector.h b/reflector/Reflector.h index efe22ea..432ce68 100644 --- a/reflector/Reflector.h +++ b/reflector/Reflector.h @@ -27,6 +27,10 @@ #include "PacketStream.h" #include "NotificationQueue.h" +#ifndef NO_DHT +#include "urfd-dht-values.h" +#endif + //////////////////////////////////////////////////////////////////////////////////////// // define @@ -78,6 +82,15 @@ public: void OnStreamOpen(const CCallsign &); void OnStreamClose(const CCallsign &); +#ifndef NO_DHT + // Publish DHT + void PutDHTConfig(); + void PutDHTPeers(); + void PutDHTClients(); + void PutDHTUsers(); + void GetDHTConfig(const std::string &cs); +#endif + protected: // threads void RouterThread(const char); @@ -92,7 +105,6 @@ protected: void WriteXmlFile(std::ofstream &); void JsonReport(nlohmann::json &report); -protected: // identity CCallsign m_Callsign; std::string m_Modules, m_TCmodules; @@ -113,4 +125,12 @@ protected: // notifications CNotificationQueue m_Notifications; + +#ifndef NO_DHT + // Distributed Hash Table + dht::DhtRunner node; + dht::InfoHash refhash; + unsigned int peers_put_count, clients_put_count, users_put_count; +#endif + }; diff --git a/reflector/urfd-dht-values.h b/reflector/urfd-dht-values.h new file mode 100644 index 0000000..50a4438 --- /dev/null +++ b/reflector/urfd-dht-values.h @@ -0,0 +1,86 @@ +// 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 */ +template constexpr auto toUType(E enumerator) noexcept +{ + return static_cast>(enumerator); +} // Item #10 in "Effective Modern C++", by Scott Meyers, O'REILLY + +enum class EUrfdValueID : uint64_t { Config=1, Peers=2, Clients=3, Users=4 }; + +/* PEERS */ +using PeerTuple = std::tuple; +enum class EUrfdPeerFields { Callsign, Modules, ConnectTime }; +struct SUrfdPeers0 +{ + std::time_t timestamp; + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +/* CLIENTS */ +using ClientTuple = std::tuple; +enum class EUrfdClientFields { Callsign, Ip, Module, ConnectTime, LastHeardTime }; +struct SUrfdClients0 +{ + std::time_t timestamp; + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +/* USERS */ +using UserTuple = std::tuple; +enum class EUrfdUserFields { Source, Destination, Reflector, LastHeardTime }; +struct SUrfdUsers0 +{ + std::time_t timestamp; + unsigned int sequence; + std::list list; + + MSGPACK_DEFINE(timestamp, sequence, list) +}; + +/* CONFIGURATION */ +// 'SIZE' has to be last!! +enum class EUrfdPorts : unsigned { dcs, dextra, dmrplus, dplus, m17, mmdvm, nxdn, p25, urf, usrprx, usrptx, 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 SUrfdConfig0 +{ + std::time_t timestamp; + std::string cs, ipv4, ipv6, mods, 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, url, email, sponsor, country, version, almod, ysffreq, refid, g3enabled, port, description) +};