Ditto 4.9.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 "Helpers.hpp"
9#include "json.hpp"
10
11namespace ditto {
12
17public:
21 bool enabled = false;
22
26 std::string interface_ip = "[::]";
27
31 uint16_t port = 4040;
32
33 bool operator==(const TcpListenConfig &other) const {
34 return (enabled == other.enabled && interface_ip == other.interface_ip &&
35 port == other.port);
36 }
37 bool operator!=(const TcpListenConfig &other) const {
38 return !operator==(other);
39 }
40
41 NLOHMANN_DEFINE_TYPE_INTRUSIVE(TcpListenConfig, enabled, interface_ip, port)
42};
43
48public:
52 bool enabled = false;
53
57 std::string interface_ip = "[::]";
58
62 uint16_t port = 8080;
63
71 bool websocket_sync = false;
72
80
87 std::string tls_key_path;
88
96
97 bool operator==(const HttpListenConfig &other) const {
98 return (enabled == other.enabled && interface_ip == other.interface_ip &&
99 port == other.port && websocket_sync == other.websocket_sync &&
101 tls_key_path == other.tls_key_path &&
103 }
104 bool operator!=(const HttpListenConfig &other) const {
105 return !operator==(other);
106 }
107
108 NLOHMANN_DEFINE_TYPE_INTRUSIVE(HttpListenConfig, enabled, interface_ip, port,
111};
112
116class Listen {
117public:
118 TcpListenConfig tcp;
119 HttpListenConfig http;
120
121 bool operator==(const Listen &other) const {
122 return tcp == other.tcp && http == other.http;
123 }
124 bool operator!=(const Listen &other) const { return !operator==(other); }
125
126 NLOHMANN_DEFINE_TYPE_INTRUSIVE(Listen, tcp, http)
127};
128
134public:
138 bool enabled = false;
139
140 bool operator==(const BluetoothLeConfig &other) const {
141 return enabled == other.enabled;
142 }
143 bool operator!=(const BluetoothLeConfig &other) const {
144 return !operator==(other);
145 }
146
147 NLOHMANN_DEFINE_TYPE_INTRUSIVE(BluetoothLeConfig, enabled)
148};
149
150// Allowing deprecated use of
151// multicast_enabled
152#pragma clang diagnostic push
153#pragma clang diagnostic ignored "-Wdeprecated-declarations"
158public:
162 bool enabled = false;
163 bool mdns_enabled = true;
164 bool multicast_enabled = true;
165 LanConfig();
166 bool operator==(const LanConfig &other) const;
167 bool operator!=(const LanConfig &other) const { return !operator==(other); }
168};
169void from_json(const nlohmann::json &j, LanConfig &c);
170void to_json(nlohmann::json &j, const LanConfig &a);
171#pragma clang diagnostic pop
172
177public:
184 bool enabled = false;
185
186 bool operator==(const AwdlConfig &other) const {
187 return enabled == other.enabled;
188 }
189 bool operator!=(const AwdlConfig &other) const { return !operator==(other); }
190
191 NLOHMANN_DEFINE_TYPE_INTRUSIVE(AwdlConfig, enabled)
192};
193
199public:
206 bool enabled = false;
207
208 bool operator==(const WiFiAwareConfig &other) const {
209 return enabled == other.enabled;
210 }
211 bool operator!=(const WiFiAwareConfig &other) const {
212 return !operator==(other);
213 }
214
215 NLOHMANN_DEFINE_TYPE_INTRUSIVE(WiFiAwareConfig, enabled)
216};
217
223public:
229
234
239
245
246 bool operator==(const PeerToPeer &other) const {
247 return bluetooth_le == other.bluetooth_le && lan == other.lan &&
248 awdl == other.awdl && wifi_aware == other.wifi_aware;
249 }
250 bool operator!=(const PeerToPeer &other) const { return !operator==(other); }
251
252 NLOHMANN_DEFINE_TYPE_INTRUSIVE(PeerToPeer, bluetooth_le, lan, awdl,
254};
255
259class Connect {
260public:
264 std::set<std::string> tcp_servers;
265
269 std::set<std::string> websocket_urls;
270
274 std::chrono::duration<uint32_t, std::milli> retry_interval{5000};
275
276 bool operator==(const Connect &other) const {
277 return tcp_servers == other.tcp_servers &&
280 }
281 bool operator!=(const Connect &other) const { return !operator==(other); }
282};
283
284void from_json(const nlohmann::json &j, Connect &c);
285void to_json(nlohmann::json &j, const Connect &c);
286
287const uint32_t NO_PREFERRED_ROUTE_HINT = 0;
288
293class Global {
294public:
312 uint32_t sync_group = 0;
313
331 uint32_t routing_hint = NO_PREFERRED_ROUTE_HINT;
332
333 bool operator==(const Global &other) const {
334 return sync_group == other.sync_group && routing_hint == other.routing_hint;
335 }
336 bool operator!=(const Global &other) const { return !operator==(other); }
337
338 NLOHMANN_DEFINE_TYPE_INTRUSIVE(Global, sync_group, routing_hint)
339};
340
370public:
376
381
386
391
401
402 bool operator==(const TransportConfig &other) const {
403 return peer_to_peer == other.peer_to_peer && connect == other.connect &&
404 listen == other.listen && global == other.global;
405 }
406 bool operator!=(const TransportConfig &other) const {
407 return !operator==(other);
408 }
409
410 NLOHMANN_DEFINE_TYPE_INTRUSIVE(TransportConfig, peer_to_peer, connect, listen,
411 global)
412};
413} // namespace ditto
414
415#endif // _DITTO_TRANSPORT_CONFIG_
Part of the PeerToPeer config that relates to AWDL connections.
Definition TransportConfig.hpp:176
bool enabled
Definition TransportConfig.hpp:184
Part of the PeerToPeer config that relates to Bluetooth LE connections.
Definition TransportConfig.hpp:133
bool enabled
Definition TransportConfig.hpp:138
Part of the TransportConfig that relates to outgoing connections.
Definition TransportConfig.hpp:259
std::set< std::string > tcp_servers
Definition TransportConfig.hpp:264
std::chrono::duration< uint32_t, std::milli > retry_interval
Definition TransportConfig.hpp:274
std::set< std::string > websocket_urls
Definition TransportConfig.hpp:269
Definition TransportConfig.hpp:293
uint32_t sync_group
Definition TransportConfig.hpp:312
uint32_t routing_hint
Definition TransportConfig.hpp:331
Part of the Listen config that relates to incoming HTTP connections.
Definition TransportConfig.hpp:47
std::string tls_key_path
Definition TransportConfig.hpp:87
uint16_t port
Definition TransportConfig.hpp:62
std::string interface_ip
Definition TransportConfig.hpp:57
bool enabled
Definition TransportConfig.hpp:52
std::string tls_certificate_path
Definition TransportConfig.hpp:95
std::string static_content_path
Definition TransportConfig.hpp:79
bool websocket_sync
Definition TransportConfig.hpp:71
Part of the PeerToPeer config that relates to LAN connections.
Definition TransportConfig.hpp:157
bool enabled
Definition TransportConfig.hpp:162
Part of the TransportConfig that relates to incoming connections.
Definition TransportConfig.hpp:116
Part of the TransportConfig that relates to peer-to-peer connections.
Definition TransportConfig.hpp:222
LanConfig lan
Definition TransportConfig.hpp:233
BluetoothLeConfig bluetooth_le
Definition TransportConfig.hpp:228
AwdlConfig awdl
Definition TransportConfig.hpp:238
WiFiAwareConfig wifi_aware
Definition TransportConfig.hpp:244
Part of the Listen config that relates to incoming TCP connections.
Definition TransportConfig.hpp:16
uint16_t port
Definition TransportConfig.hpp:31
std::string interface_ip
Definition TransportConfig.hpp:26
bool enabled
Definition TransportConfig.hpp:21
A configuration object specifying which network transports Ditto should use to sync data.
Definition TransportConfig.hpp:369
PeerToPeer peer_to_peer
Definition TransportConfig.hpp:375
Connect connect
Definition TransportConfig.hpp:380
Global global
Definition TransportConfig.hpp:390
void enable_all_peer_to_peer()
Definition TransportConfig.hpp:395
Listen listen
Definition TransportConfig.hpp:385
Part of the PeerToPeer transport config that applies to WiFi Aware connections.
Definition TransportConfig.hpp:198
bool enabled
Definition TransportConfig.hpp:206