Skip to main content

fips_core/config/transport/
aggregate.rs

1use super::*;
2
3// ============================================================================
4// TransportsConfig
5// ============================================================================
6
7/// Transports configuration section.
8///
9/// Each transport type can have either a single instance (config directly
10/// under the type name) or multiple named instances.
11#[derive(Debug, Clone, Default, Serialize, Deserialize)]
12pub struct TransportsConfig {
13    /// UDP transport instances.
14    #[serde(default, skip_serializing_if = "is_transport_empty")]
15    pub udp: TransportInstances<UdpConfig>,
16
17    /// In-memory simulated transport instances.
18    #[cfg(feature = "sim-transport")]
19    #[serde(default, skip_serializing_if = "is_transport_empty")]
20    pub sim: TransportInstances<SimTransportConfig>,
21
22    /// Ethernet transport instances.
23    #[serde(default, skip_serializing_if = "is_transport_empty")]
24    pub ethernet: TransportInstances<EthernetConfig>,
25
26    /// TCP transport instances.
27    #[serde(default, skip_serializing_if = "is_transport_empty")]
28    pub tcp: TransportInstances<TcpConfig>,
29
30    /// WebSocket physical transport instances.
31    #[serde(default, skip_serializing_if = "is_transport_empty")]
32    pub websocket: TransportInstances<WebSocketConfig>,
33
34    /// Tor transport instances.
35    #[serde(default, skip_serializing_if = "is_transport_empty")]
36    pub tor: TransportInstances<TorConfig>,
37
38    /// WebRTC transport instances.
39    #[serde(default, skip_serializing_if = "is_transport_empty")]
40    pub webrtc: TransportInstances<WebRtcConfig>,
41
42    /// BLE transport instances.
43    #[serde(default, skip_serializing_if = "is_transport_empty")]
44    pub ble: TransportInstances<BleConfig>,
45}
46
47/// Helper for skip_serializing_if on TransportInstances.
48fn is_transport_empty<T>(instances: &TransportInstances<T>) -> bool {
49    instances.is_empty()
50}
51
52impl TransportsConfig {
53    /// Check if any transports are configured.
54    pub fn is_empty(&self) -> bool {
55        self.udp.is_empty()
56            && {
57                #[cfg(feature = "sim-transport")]
58                {
59                    self.sim.is_empty()
60                }
61                #[cfg(not(feature = "sim-transport"))]
62                {
63                    true
64                }
65            }
66            && self.ethernet.is_empty()
67            && self.tcp.is_empty()
68            && self.websocket.is_empty()
69            && self.tor.is_empty()
70            && self.webrtc.is_empty()
71            && self.ble.is_empty()
72    }
73
74    /// Merge another TransportsConfig into this one.
75    ///
76    /// Non-empty transport sections from `other` replace those in `self`.
77    pub fn merge(&mut self, other: TransportsConfig) {
78        if !other.udp.is_empty() {
79            self.udp = other.udp;
80        }
81        #[cfg(feature = "sim-transport")]
82        if !other.sim.is_empty() {
83            self.sim = other.sim;
84        }
85        if !other.ethernet.is_empty() {
86            self.ethernet = other.ethernet;
87        }
88        if !other.tcp.is_empty() {
89            self.tcp = other.tcp;
90        }
91        if !other.websocket.is_empty() {
92            self.websocket = other.websocket;
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}