-
Notifications
You must be signed in to change notification settings - Fork 1
/
dht-values.h
243 lines (204 loc) · 9.33 KB
/
dht-values.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
* Copyright (c) 2022-2024 by Thomas A. Early N7TAE
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#pragma once
#include <opendht.h>
// comment out sections you don't need for your application
#define USE_MREFD_VALUES
#define USE_URFD_VALUES
// a typesafe way to extract the numeric value from a enum class
// note that this is a constexpr and so can even be used in an
// array declaration or as a tuple index
template<typename E> constexpr auto toUType(E enumerator) noexcept
{
return static_cast<std::underlying_type_t<E>>(enumerator);
} // Item #10 in "Effective Modern C++", by Scott Meyers, O'REILLY
#ifdef USE_MREFD_VALUES
// DHT::value::user_type for mrefd values
// These are the value release version strings in a
// preprocessor definition for your convience
// if your app needs a particular part, then it should handle all versions of that part
#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 mrefd document
// can be assigned any unsigned value except 0
// more parts can be added, but don't change the value of any existing part
// using toUType, you can set or query a user_type to determine the value part
// this can be done before unpacking the MSGPACK
enum class EMrefdValueID : uint64_t { Config=1, Peers=2, Clients=3, Users=4 };
///////////////// MREFD PART VALUES ///////////////
// the configuration part
struct SMrefdConfig1 // user_type is MREFD_CONFIG_1
{
std::time_t timestamp; // when this value was set
std::string callsign; // the callsign of the mrefd reflector
std::string ipv4addr; // the external IPv4 address
std::string ipv6addr; // the external IPv6 address
std::string modules; // all the configured modules, [A-Z]
std::string encryptedmods; // modules that will pass encrypted streams
std::string url; // the URL of the dashboard
std::string email; // the email of the responsible owner
std::string sponsor; // the organization or individual sponsoring the reflector
std::string country; // the 2-letter country code
std::string version; // the version of the reflector software
uint16_t port; // the connection listening UDP port, usually 17000
// the order in which MSGPACK serializes the data
MSGPACK_DEFINE(timestamp, callsign, ipv4addr, ipv6addr, modules, encryptedmods, url, email, sponsor, country, version, port)
};
// peer list part. stored as a list of 3-field tuples
using MrefdPeerTuple = std::tuple<std::string, std::string, std::time_t>;
enum class EMrefdPeerFields // by using using toUType, you can use these members to reference a specific tuple field
{
Callsign, // the callsign of the connected peer
Modules, // modules that are shared
ConnectTime // when was it connected
};
struct SMrefdPeers1 // MREFD_PEERS_1
{
std::time_t timestamp; // when this data was created
unsigned int sequence; // since timestamp is to the nearest second, in incremented sequence number is also set
// upon boot, sequence starts at zero
std::list<MrefdPeerTuple> list; // here is the list of tuples
MSGPACK_DEFINE(timestamp, sequence, list)
};
// client list part. stored as a list of 5-field tuples
using MrefdClientTuple = std::tuple<std::string, std::string, char, std::time_t, std::time_t>;
enum class EMrefdClientFields
{
Callsign, // the callsign of the client
Ip, // the IP of the client
Module, // the module to which the client is connected
ConnectTime, // when the client connected
LastHeardTime // the last time it was heard
};
struct SMrefdClients1 // user_type is MREFD_CLIENTS_1
{
std::time_t timestamp; // see SMrefdPeers1::timestamp
unsigned int sequence; // see SMrefdPeers1::sequence
std::list<MrefdClientTuple> list;
MSGPACK_DEFINE(timestamp, sequence, list)
};
// user list (a last heard list). stored as a list of 4-field tuples
using MrefdUserTuple = std::tuple<std::string, std::string, std::string, std::time_t>;
enum class EMrefdUserFields
{
Source, // the callsign of the source
Destination, // the callsign of the destination
Reflector, // the reflector (and module where this was heard
LastHeardTime // the time it was heard
};
struct SMrefdUsers1 // user_type is MREFD_USERS_1
{
std::time_t timestamp;
unsigned int sequence;
std::list<MrefdUserTuple> list;
MSGPACK_DEFINE(timestamp, sequence, list)
};
#endif // USE_MREFD_VALUES
#ifdef USE_URFD_VALUES
// DHT::value::user_type for urfd values
// These are the value release version strings in a
// preprocessor definition for your convience
// if your app needs a particular part, then it should handle all versions of that part
#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"
#define URFD_CONFIG_2 "urfd-config-2"
#define URFD_CLIENTS_2 "urfd-clients-2"
// dht::Value::id of the different parts of the urfd document
// can be assigned any unsigned value except 0
// more parts can be added, but don't change the value of any existing part
// using toUType, you can set or query a user_type to determine the value part
// this can be done before unpacking the MSGPACK
enum class EUrfdValueID : uint64_t { Config=1, Peers=2, Clients=3, Users=4 };
// the following enum classes can be used to reference a particular value in a fixed array
// 'SIZE' has to be last value for these scoped enums as this is used to declare these arrays
//
// all the configurable ports in urfd (G3 and BM are not configurable)
enum class EUrfdPorts : unsigned { dcs, dextra, dmrplus, dplus, m17, mmdvm, nxdn, p25, urf, ysf, SIZE };
// autolink modules for these protocols
enum class EUrfdAlMod : unsigned { nxdn, p25, ysf, SIZE };
// default TX/RX values for ysf
enum class EUrfdTxRx : unsigned { rx, tx, SIZE };
// reflector ID values for these two modes
enum class EUrfdRefId : unsigned { nxdn, p25, SIZE };
struct SUrfdConfig1 // user_type is URFD_CONFIG_1
{
std::time_t timestamp;
std::string callsign, ipv4addr, ipv6addr, modules, transcodedmods, url, email, sponsor, country, version;
// transcodedmods are those modules that support full transcoding
std::array<uint16_t, toUType(EUrfdPorts::SIZE)> port;
std::array<char, toUType(EUrfdAlMod::SIZE)> almod;
std::array<unsigned long, toUType(EUrfdTxRx::SIZE)> ysffreq;
std::array<unsigned, toUType(EUrfdRefId::SIZE)> refid;
std::unordered_map<char, std::string> description;
bool g3enabled;
MSGPACK_DEFINE(timestamp, callsign, ipv4addr, ipv6addr, modules, transcodedmods, url, email, sponsor, country, version, almod, ysffreq, refid, g3enabled, port, description)
};
enum class EUrfdPorts2 : unsigned { dcs, dextra, dmrplus, dplus, dsd, m17, mmdvm, nxdn, p25, urf, ysf, SIZE };
struct SUrfdConfig2
{
std::time_t timestamp;
std::string callsign, ipv4addr, ipv6addr, modules, transcodedmods, url, email, sponsor, country, version;
std::array<uint16_t, toUType(EUrfdPorts2::SIZE)> port;
std::array<char, toUType(EUrfdAlMod::SIZE)> almod;
std::array<unsigned long, toUType(EUrfdTxRx::SIZE)> ysffreq;
std::array<unsigned, toUType(EUrfdRefId::SIZE)> refid;
std::unordered_map<char, std::string> description;
bool g3enabled;
MSGPACK_DEFINE(timestamp, callsign, ipv4addr, ipv6addr, modules, transcodedmods, url, email, sponsor, country, version, almod, ysffreq, refid, g3enabled, port, description)
};
using UrfdPeerTuple = std::tuple<std::string, std::string, std::time_t>;
enum class EUrfdPeerFields { Callsign, Modules, ConnectTime };
struct SUrfdPeers1
{
std::time_t timestamp;
unsigned int sequence;
std::list<UrfdPeerTuple> list;
MSGPACK_DEFINE(timestamp, sequence, list)
};
using UrfdClientTuple1 = std::tuple<std::string, std::string, char, std::time_t, std::time_t>;
enum class EUrfdClientFields1 { Callsign, Ip, Module, ConnectTime, LastHeardTime };
struct SUrfdClients1
{
std::time_t timestamp;
unsigned int sequence;
std::list<UrfdClientTuple1> list;
MSGPACK_DEFINE(timestamp, sequence, list)
};
using UrfdClientTuple2 = std::tuple<std::string, std::string, std::string, char, std::time_t, std::time_t>;
enum class EUrfdClientFields2 { Callsign, Protocol, Ip, Module, ConnectTime, LastHeardTime };
struct SUrfdClients2
{
std::time_t timestamp;
unsigned int sequence;
std::list<UrfdClientTuple2> list;
MSGPACK_DEFINE(timestamp, sequence, list)
};
using UrfdUserTuple = std::tuple<std::string, std::string, char, std::string, std::time_t>;
enum class EUrfdUserFields { Callsign, ViaNode, OnModule, ViaPeer, LastHeardTime };
struct SUrfdUsers1
{
std::time_t timestamp;
unsigned int sequence;
std::list<UrfdUserTuple> list;
MSGPACK_DEFINE(timestamp, sequence, list)
};
#endif // USE_URFD_VALUES