Ditto 4.4.0
Loading...
Searching...
No Matches
TransportConfig.hpp
1#ifndef _DITTO_TRANSPORT_CONFIG_
2#define _DITTO_TRANSPORT_CONFIG_
3
4#include <chrono>
5#include <set>
6#include <string>
7
8#include "json.hpp"
9
10namespace ditto {
11
16public:
20 bool enabled = false;
21
25 std::string interface_ip = "0.0.0.0";
26
30 uint16_t port = 4040;
31
32 bool operator==(const TcpListenConfig &other) const {
33 return (enabled == other.enabled && interface_ip == other.interface_ip &&
34 port == other.port);
35 }
36 bool operator!=(const TcpListenConfig &other) const {
37 return !operator==(other);
38 }
39
40 NLOHMANN_DEFINE_TYPE_INTRUSIVE(TcpListenConfig, enabled, interface_ip, port)
41};
42
47public:
51 bool enabled = false;
52
56 std::string interface_ip = "0.0.0.0";
57
61 uint16_t port = 8080;
62
70 bool websocket_sync = false;
71
79
86 std::string tls_key_path;
87
95
96 bool operator==(const HttpListenConfig &other) const {
97 return (enabled == other.enabled && interface_ip == other.interface_ip &&
98 port == other.port && websocket_sync == other.websocket_sync &&
100 tls_key_path == other.tls_key_path &&
102 }
103 bool operator!=(const HttpListenConfig &other) const {
104 return !operator==(other);
105 }
106
107 NLOHMANN_DEFINE_TYPE_INTRUSIVE(HttpListenConfig, enabled, interface_ip, port,
110};
111
115class Listen {
116public:
117 TcpListenConfig tcp;
118 HttpListenConfig http;
119
120 bool operator==(const Listen &other) const {
121 return tcp == other.tcp && http == other.http;
122 }
123 bool operator!=(const Listen &other) const { return !operator==(other); }
124
125 NLOHMANN_DEFINE_TYPE_INTRUSIVE(Listen, tcp, http)
126};
127
133public:
137 bool enabled = false;
138
139 bool operator==(const BluetoothLeConfig &other) const {
140 return enabled == other.enabled;
141 }
142 bool operator!=(const BluetoothLeConfig &other) const {
143 return !operator==(other);
144 }
145
146 NLOHMANN_DEFINE_TYPE_INTRUSIVE(BluetoothLeConfig, enabled)
147};
148
153public:
157 bool enabled = false;
158 bool mdns_enabled = true;
159 bool multicast_enabled = true;
160
161 bool operator==(const LanConfig &other) const {
162 return enabled == other.enabled && mdns_enabled == other.mdns_enabled &&
163 multicast_enabled == other.multicast_enabled;
164 }
165 bool operator!=(const LanConfig &other) const { return !operator==(other); }
166
167 NLOHMANN_DEFINE_TYPE_INTRUSIVE(LanConfig, enabled, mdns_enabled,
168 multicast_enabled)
169};
170
175public:
182 bool enabled = false;
183
184 bool operator==(const AwdlConfig &other) const {
185 return enabled == other.enabled;
186 }
187 bool operator!=(const AwdlConfig &other) const { return !operator==(other); }
188
189 NLOHMANN_DEFINE_TYPE_INTRUSIVE(AwdlConfig, enabled)
190};
191
197public:
204 bool enabled = false;
205
206 bool operator==(const WiFiAwareConfig &other) const {
207 return enabled == other.enabled;
208 }
209 bool operator!=(const WiFiAwareConfig &other) const {
210 return !operator==(other);
211 }
212
213 NLOHMANN_DEFINE_TYPE_INTRUSIVE(WiFiAwareConfig, enabled)
214};
215
221public:
227
232
237
243
244 bool operator==(const PeerToPeer &other) const {
245 return bluetooth_le == other.bluetooth_le && lan == other.lan &&
246 awdl == other.awdl && wifi_aware == other.wifi_aware;
247 }
248 bool operator!=(const PeerToPeer &other) const { return !operator==(other); }
249
250 NLOHMANN_DEFINE_TYPE_INTRUSIVE(PeerToPeer, bluetooth_le, lan, awdl,
252};
253
257class Connect {
258public:
262 std::set<std::string> tcp_servers;
263
267 std::set<std::string> websocket_urls;
268
272 std::chrono::duration<uint32_t, std::milli> retry_interval{5000};
273
274 bool operator==(const Connect &other) const {
275 return tcp_servers == other.tcp_servers &&
278 }
279 bool operator!=(const Connect &other) const { return !operator==(other); }
280};
281
282void from_json(const nlohmann::json &j, Connect &c);
283void to_json(nlohmann::json &j, const Connect &c);
284
285const uint32_t NO_PREFERRED_ROUTE_HINT = 0;
286
291class Global {
292public:
310 uint32_t sync_group = 0;
311
329 uint32_t routing_hint = NO_PREFERRED_ROUTE_HINT;
330
331 bool operator==(const Global &other) const {
332 return sync_group == other.sync_group && routing_hint == other.routing_hint;
333 }
334 bool operator!=(const Global &other) const { return !operator==(other); }
335
336 NLOHMANN_DEFINE_TYPE_INTRUSIVE(Global, sync_group, routing_hint)
337};
338
368public:
374
379
384
389
395 peer_to_peer.lan.enabled = true;
398 }
399
400 bool operator==(const TransportConfig &other) const {
401 return peer_to_peer == other.peer_to_peer && connect == other.connect &&
402 listen == other.listen && global == other.global;
403 }
404 bool operator!=(const TransportConfig &other) const {
405 return !operator==(other);
406 }
407
408 NLOHMANN_DEFINE_TYPE_INTRUSIVE(TransportConfig, peer_to_peer, connect, listen,
409 global)
410};
411} // namespace ditto
412
413#endif // _DITTO_TRANSPORT_CONFIG_
Part of the PeerToPeer config that relates to AWDL connections.
Definition TransportConfig.hpp:174
bool enabled
Definition TransportConfig.hpp:182
Part of the PeerToPeer config that relates to Bluetooth LE connections.
Definition TransportConfig.hpp:132
bool enabled
Definition TransportConfig.hpp:137
Part of the TransportConfig that relates to outgoing connections.
Definition TransportConfig.hpp:257
std::set< std::string > tcp_servers
Definition TransportConfig.hpp:262
std::chrono::duration< uint32_t, std::milli > retry_interval
Definition TransportConfig.hpp:272
std::set< std::string > websocket_urls
Definition TransportConfig.hpp:267
Definition TransportConfig.hpp:291
uint32_t sync_group
Definition TransportConfig.hpp:310
uint32_t routing_hint
Definition TransportConfig.hpp:329
Part of the Listen config that relates to incoming HTTP connections.
Definition TransportConfig.hpp:46
std::string tls_key_path
Definition TransportConfig.hpp:86
uint16_t port
Definition TransportConfig.hpp:61
std::string interface_ip
Definition TransportConfig.hpp:56
bool enabled
Definition TransportConfig.hpp:51
std::string tls_certificate_path
Definition TransportConfig.hpp:94
std::string static_content_path
Definition TransportConfig.hpp:78
bool websocket_sync
Definition TransportConfig.hpp:70
Part of the PeerToPeer config that relates to LAN connections.
Definition TransportConfig.hpp:152
bool enabled
Definition TransportConfig.hpp:157
Part of the TransportConfig that relates to incoming connections.
Definition TransportConfig.hpp:115
Part of the TransportConfig that relates to peer-to-peer connections.
Definition TransportConfig.hpp:220
LanConfig lan
Definition TransportConfig.hpp:231
BluetoothLeConfig bluetooth_le
Definition TransportConfig.hpp:226
AwdlConfig awdl
Definition TransportConfig.hpp:236
WiFiAwareConfig wifi_aware
Definition TransportConfig.hpp:242
Part of the Listen config that relates to incoming TCP connections.
Definition TransportConfig.hpp:15
uint16_t port
Definition TransportConfig.hpp:30
std::string interface_ip
Definition TransportConfig.hpp:25
bool enabled
Definition TransportConfig.hpp:20
A configuration object specifying which network transports Ditto should use to sync data.
Definition TransportConfig.hpp:367
PeerToPeer peer_to_peer
Definition TransportConfig.hpp:373
Connect connect
Definition TransportConfig.hpp:378
Global global
Definition TransportConfig.hpp:388
void enable_all_peer_to_peer()
Definition TransportConfig.hpp:393
Listen listen
Definition TransportConfig.hpp:383
Part of the PeerToPeer transport config that applies to WiFi Aware connections.
Definition TransportConfig.hpp:196
bool enabled
Definition TransportConfig.hpp:204
basic_json<> json
default JSON class
Definition json.hpp:2933