fips_core/config/transport/
aggregate.rs1use super::*;
2
3#[derive(Debug, Clone, Default, Serialize, Deserialize)]
12pub struct TransportsConfig {
13 #[serde(default, skip_serializing_if = "is_transport_empty")]
15 pub udp: TransportInstances<UdpConfig>,
16
17 #[serde(default, skip_serializing_if = "is_transport_empty")]
19 pub nostr_relay: TransportInstances<NostrRelayConfig>,
20
21 #[cfg(feature = "sim-transport")]
23 #[serde(default, skip_serializing_if = "is_transport_empty")]
24 pub sim: TransportInstances<SimTransportConfig>,
25
26 #[serde(default, skip_serializing_if = "is_transport_empty")]
28 pub ethernet: TransportInstances<EthernetConfig>,
29
30 #[serde(default, skip_serializing_if = "is_transport_empty")]
32 pub tcp: TransportInstances<TcpConfig>,
33
34 #[serde(default, skip_serializing_if = "is_transport_empty")]
36 pub tor: TransportInstances<TorConfig>,
37
38 #[serde(default, skip_serializing_if = "is_transport_empty")]
40 pub webrtc: TransportInstances<WebRtcConfig>,
41
42 #[serde(default, skip_serializing_if = "is_transport_empty")]
44 pub ble: TransportInstances<BleConfig>,
45}
46
47fn is_transport_empty<T>(instances: &TransportInstances<T>) -> bool {
49 instances.is_empty()
50}
51
52impl TransportsConfig {
53 pub fn is_empty(&self) -> bool {
55 self.udp.is_empty()
56 && self.nostr_relay.is_empty()
57 && {
58 #[cfg(feature = "sim-transport")]
59 {
60 self.sim.is_empty()
61 }
62 #[cfg(not(feature = "sim-transport"))]
63 {
64 true
65 }
66 }
67 && self.ethernet.is_empty()
68 && self.tcp.is_empty()
69 && self.tor.is_empty()
70 && self.webrtc.is_empty()
71 && self.ble.is_empty()
72 }
73
74 pub fn merge(&mut self, other: TransportsConfig) {
78 if !other.udp.is_empty() {
79 self.udp = other.udp;
80 }
81 if !other.nostr_relay.is_empty() {
82 self.nostr_relay = other.nostr_relay;
83 }
84 #[cfg(feature = "sim-transport")]
85 if !other.sim.is_empty() {
86 self.sim = other.sim;
87 }
88 if !other.ethernet.is_empty() {
89 self.ethernet = other.ethernet;
90 }
91 if !other.tcp.is_empty() {
92 self.tcp = other.tcp;
93 }
94 if !other.tor.is_empty() {
95 self.tor = other.tor;
96 }
97 if !other.webrtc.is_empty() {
98 self.webrtc = other.webrtc;
99 }
100 if !other.ble.is_empty() {
101 self.ble = other.ble;
102 }
103 }
104}