Ditto 4.9.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 = 80;
63
71 bool websocket_sync = false;
72
73 // TODO(v5): This should somehow be optional so that it doesn't default to an
74 // empty string but instead defaults to `nullptr`, or something like that
82
83 // TODO(v5): This should somehow be optional so that it doesn't default to an
84 // empty string but instead defaults to `nullptr`, or something like that
91 std::string tls_key_path;
92
93 // TODO(v5): This should somehow be optional so that it doesn't default to an
94 // empty string but instead defaults to `nullptr`, or something like that
102
103 bool operator==(const HttpListenConfig &other) const {
104 return (enabled == other.enabled && interface_ip == other.interface_ip &&
105 port == other.port && websocket_sync == other.websocket_sync &&
107 tls_key_path == other.tls_key_path &&
109 }
110 bool operator!=(const HttpListenConfig &other) const {
111 return !operator==(other);
112 }
113};
114
115void from_json(const nlohmann::json &j, HttpListenConfig &c);
116void to_json(nlohmann::json &j, const HttpListenConfig &c);
117
121class Listen {
122public:
123 TcpListenConfig tcp;
124 HttpListenConfig http;
125
126 bool operator==(const Listen &other) const {
127 return tcp == other.tcp && http == other.http;
128 }
129 bool operator!=(const Listen &other) const { return !operator==(other); }
130
131 NLOHMANN_DEFINE_TYPE_INTRUSIVE(Listen, tcp, http)
132};
133
139public:
143 bool enabled = false;
144
145 bool operator==(const BluetoothLeConfig &other) const {
146 return enabled == other.enabled;
147 }
148 bool operator!=(const BluetoothLeConfig &other) const {
149 return !operator==(other);
150 }
151
152 NLOHMANN_DEFINE_TYPE_INTRUSIVE(BluetoothLeConfig, enabled)
153};
154
155// Allowing deprecated use of multicast_enabled
156#pragma clang diagnostic push
157#pragma clang diagnostic ignored "-Wdeprecated-declarations"
161class LanConfig {
162public:
166 bool enabled = false;
167 bool mdns_enabled = true;
168 bool multicast_enabled = true;
169 LanConfig();
170 bool operator==(const LanConfig &other) const;
171 bool operator!=(const LanConfig &other) const { return !operator==(other); }
172};
173
174void from_json(const nlohmann::json &j, LanConfig &c);
175void to_json(nlohmann::json &j, const LanConfig &c);
176#pragma clang diagnostic pop
177
182public:
189 bool enabled = false;
190
191 bool operator==(const AwdlConfig &other) const {
192 return enabled == other.enabled;
193 }
194 bool operator!=(const AwdlConfig &other) const { return !operator==(other); }
195
196 NLOHMANN_DEFINE_TYPE_INTRUSIVE(AwdlConfig, enabled)
197};
198
204public:
211 bool enabled = false;
212
213 bool operator==(const WiFiAwareConfig &other) const {
214 return enabled == other.enabled;
215 }
216 bool operator!=(const WiFiAwareConfig &other) const {
217 return !operator==(other);
218 }
219
220 NLOHMANN_DEFINE_TYPE_INTRUSIVE(WiFiAwareConfig, enabled)
221};
222
228public:
234
239
244
250
251 bool operator==(const PeerToPeer &other) const {
252 return bluetooth_le == other.bluetooth_le && lan == other.lan &&
253 awdl == other.awdl && wifi_aware == other.wifi_aware;
254 }
255 bool operator!=(const PeerToPeer &other) const { return !operator==(other); }
256
257 NLOHMANN_DEFINE_TYPE_INTRUSIVE(PeerToPeer, bluetooth_le, lan, awdl,
259};
260
264class Connect {
265public:
269 std::set<std::string> tcp_servers;
270
274 std::set<std::string> websocket_urls;
275
279 std::chrono::duration<uint32_t, std::milli> retry_interval{5000};
280
281 bool operator==(const Connect &other) const {
282 return tcp_servers == other.tcp_servers &&
285 }
286 bool operator!=(const Connect &other) const { return !operator==(other); }
287};
288
289void from_json(const nlohmann::json &j, Connect &c);
290void to_json(nlohmann::json &j, const Connect &c);
291
292const uint32_t NO_PREFERRED_ROUTE_HINT = 0;
293
298class Global {
299public:
317 uint32_t sync_group = 0;
318
336 uint32_t routing_hint = NO_PREFERRED_ROUTE_HINT;
337
338 bool operator==(const Global &other) const {
339 return sync_group == other.sync_group && routing_hint == other.routing_hint;
340 }
341 bool operator!=(const Global &other) const { return !operator==(other); }
342
343 NLOHMANN_DEFINE_TYPE_INTRUSIVE(Global, sync_group, routing_hint)
344};
345
375public:
381
386
391
396
401 peer_to_peer.bluetooth_le.enabled = true;
402 peer_to_peer.lan.enabled = true;
403 peer_to_peer.awdl.enabled = true;
404 peer_to_peer.wifi_aware.enabled = true;
405 }
406
407 bool operator==(const TransportConfig &other) const {
408 return peer_to_peer == other.peer_to_peer && connect == other.connect &&
409 listen == other.listen && global == other.global;
410 }
411 bool operator!=(const TransportConfig &other) const {
412 return !operator==(other);
413 }
414
415 NLOHMANN_DEFINE_TYPE_INTRUSIVE(TransportConfig, peer_to_peer, connect, listen,
416 global)
417};
418} // namespace ditto
419
420#endif // _DITTO_TRANSPORT_CONFIG_
Part of the PeerToPeer config that relates to AWDL connections.
Definition TransportConfig.hpp:181
bool enabled
Definition TransportConfig.hpp:189
Part of the PeerToPeer config that relates to Bluetooth LE connections.
Definition TransportConfig.hpp:138
bool enabled
Definition TransportConfig.hpp:143
Part of the TransportConfig that relates to outgoing connections.
Definition TransportConfig.hpp:264
std::set< std::string > tcp_servers
Definition TransportConfig.hpp:269
std::chrono::duration< uint32_t, std::milli > retry_interval
Definition TransportConfig.hpp:279
std::set< std::string > websocket_urls
Definition TransportConfig.hpp:274
Definition TransportConfig.hpp:298
uint32_t sync_group
Definition TransportConfig.hpp:317
uint32_t routing_hint
Definition TransportConfig.hpp:336
Part of the Listen config that relates to incoming HTTP connections.
Definition TransportConfig.hpp:47
std::string tls_key_path
Definition TransportConfig.hpp:91
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:101
std::string static_content_path
Definition TransportConfig.hpp:81
bool websocket_sync
Definition TransportConfig.hpp:71
Part of the PeerToPeer config that relates to LAN connections.
Definition TransportConfig.hpp:161
bool enabled
Definition TransportConfig.hpp:166
Part of the TransportConfig that relates to incoming connections.
Definition TransportConfig.hpp:121
Part of the TransportConfig that relates to peer-to-peer connections.
Definition TransportConfig.hpp:227
LanConfig lan
Definition TransportConfig.hpp:238
BluetoothLeConfig bluetooth_le
Definition TransportConfig.hpp:233
AwdlConfig awdl
Definition TransportConfig.hpp:243
WiFiAwareConfig wifi_aware
Definition TransportConfig.hpp:249
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:374
PeerToPeer peer_to_peer
Definition TransportConfig.hpp:380
Connect connect
Definition TransportConfig.hpp:385
Global global
Definition TransportConfig.hpp:395
void enable_all_peer_to_peer()
Definition TransportConfig.hpp:400
Listen listen
Definition TransportConfig.hpp:390
Part of the PeerToPeer transport config that applies to WiFi Aware connections.
Definition TransportConfig.hpp:203
bool enabled
Definition TransportConfig.hpp:211