Ditto 4.7.4
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 // Multicast is deprecated. Please use mDNS instead.
165 DITTO_DEPRECATED bool multicast_enabled = true;
166 LanConfig();
167 bool operator==(const LanConfig &other) const;
168 bool operator!=(const LanConfig &other) const { return !operator==(other); }
169};
170void from_json(const nlohmann::json &j, LanConfig &c);
171void to_json(nlohmann::json &j, const LanConfig &a);
172#pragma clang diagnostic pop
173
178public:
185 bool enabled = false;
186
187 bool operator==(const AwdlConfig &other) const {
188 return enabled == other.enabled;
189 }
190 bool operator!=(const AwdlConfig &other) const { return !operator==(other); }
191
192 NLOHMANN_DEFINE_TYPE_INTRUSIVE(AwdlConfig, enabled)
193};
194
200public:
207 bool enabled = false;
208
209 bool operator==(const WiFiAwareConfig &other) const {
210 return enabled == other.enabled;
211 }
212 bool operator!=(const WiFiAwareConfig &other) const {
213 return !operator==(other);
214 }
215
216 NLOHMANN_DEFINE_TYPE_INTRUSIVE(WiFiAwareConfig, enabled)
217};
218
224public:
230
235
240
246
247 bool operator==(const PeerToPeer &other) const {
248 return bluetooth_le == other.bluetooth_le && lan == other.lan &&
249 awdl == other.awdl && wifi_aware == other.wifi_aware;
250 }
251 bool operator!=(const PeerToPeer &other) const { return !operator==(other); }
252
253 NLOHMANN_DEFINE_TYPE_INTRUSIVE(PeerToPeer, bluetooth_le, lan, awdl,
255};
256
260class Connect {
261public:
265 std::set<std::string> tcp_servers;
266
270 std::set<std::string> websocket_urls;
271
275 std::chrono::duration<uint32_t, std::milli> retry_interval{5000};
276
277 bool operator==(const Connect &other) const {
278 return tcp_servers == other.tcp_servers &&
281 }
282 bool operator!=(const Connect &other) const { return !operator==(other); }
283};
284
285void from_json(const nlohmann::json &j, Connect &c);
286void to_json(nlohmann::json &j, const Connect &c);
287
288const uint32_t NO_PREFERRED_ROUTE_HINT = 0;
289
294class Global {
295public:
313 uint32_t sync_group = 0;
314
332 uint32_t routing_hint = NO_PREFERRED_ROUTE_HINT;
333
334 bool operator==(const Global &other) const {
335 return sync_group == other.sync_group && routing_hint == other.routing_hint;
336 }
337 bool operator!=(const Global &other) const { return !operator==(other); }
338
339 NLOHMANN_DEFINE_TYPE_INTRUSIVE(Global, sync_group, routing_hint)
340};
341
371public:
377
382
387
392
402
403 bool operator==(const TransportConfig &other) const {
404 return peer_to_peer == other.peer_to_peer && connect == other.connect &&
405 listen == other.listen && global == other.global;
406 }
407 bool operator!=(const TransportConfig &other) const {
408 return !operator==(other);
409 }
410
411 NLOHMANN_DEFINE_TYPE_INTRUSIVE(TransportConfig, peer_to_peer, connect, listen,
412 global)
413};
414} // namespace ditto
415
416#endif // _DITTO_TRANSPORT_CONFIG_
Part of the PeerToPeer config that relates to AWDL connections.
Definition TransportConfig.hpp:177
bool enabled
Definition TransportConfig.hpp:185
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:260
std::set< std::string > tcp_servers
Definition TransportConfig.hpp:265
std::chrono::duration< uint32_t, std::milli > retry_interval
Definition TransportConfig.hpp:275
std::set< std::string > websocket_urls
Definition TransportConfig.hpp:270
Definition TransportConfig.hpp:294
uint32_t sync_group
Definition TransportConfig.hpp:313
uint32_t routing_hint
Definition TransportConfig.hpp:332
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:223
LanConfig lan
Definition TransportConfig.hpp:234
BluetoothLeConfig bluetooth_le
Definition TransportConfig.hpp:229
AwdlConfig awdl
Definition TransportConfig.hpp:239
WiFiAwareConfig wifi_aware
Definition TransportConfig.hpp:245
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:370
PeerToPeer peer_to_peer
Definition TransportConfig.hpp:376
Connect connect
Definition TransportConfig.hpp:381
Global global
Definition TransportConfig.hpp:391
void enable_all_peer_to_peer()
Definition TransportConfig.hpp:396
Listen listen
Definition TransportConfig.hpp:386
Part of the PeerToPeer transport config that applies to WiFi Aware connections.
Definition TransportConfig.hpp:199
bool enabled
Definition TransportConfig.hpp:207
basic_json<> json
default JSON class
Definition json.hpp:2933