emissary_core/config.rs
1// Permission is hereby granted, free of charge, to any person obtaining a
2// copy of this software and associated documentation files (the "Software"),
3// to deal in the Software without restriction, including without limitation
4// the rights to use, copy, modify, merge, publish, distribute, sublicense,
5// and/or sell copies of the Software, and to permit persons to whom the
6// Software is furnished to do so, subject to the following conditions:
7//
8// The above copyright notice and this permission notice shall be included in
9// all copies or substantial portions of the Software.
10//
11// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
16// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19use core::net::Ipv4Addr;
20
21use crate::{primitives::Str, profile::Profile, tunnel::TunnelPoolConfig};
22
23use alloc::{string::String, vec::Vec};
24
25/// Exploratory tunnel pool config.
26#[derive(Clone, PartialEq, Eq)]
27pub struct ExploratoryConfig {
28 /// Length of an inbound exploratory tunnel.
29 pub inbound_len: Option<usize>,
30
31 /// Number of inbound exploratory tunnels.
32 pub inbound_count: Option<usize>,
33
34 /// Length of an outbound exploratory tunnel.
35 pub outbound_len: Option<usize>,
36
37 /// Number of outbound exploratory tunnels.
38 pub outbound_count: Option<usize>,
39}
40
41impl From<Option<ExploratoryConfig>> for TunnelPoolConfig {
42 fn from(value: Option<ExploratoryConfig>) -> Self {
43 let default_config = TunnelPoolConfig::default();
44
45 match value {
46 None => default_config,
47 Some(config) => TunnelPoolConfig {
48 name: Str::from("exploratory"),
49 num_inbound: config.inbound_count.unwrap_or(default_config.num_inbound),
50 num_inbound_hops: config.inbound_len.unwrap_or(default_config.num_inbound_hops),
51 num_outbound: config.outbound_count.unwrap_or(default_config.num_outbound),
52 num_outbound_hops: config.outbound_len.unwrap_or(default_config.num_outbound_hops),
53 },
54 }
55 }
56}
57
58/// NTCP2 configuration.
59#[derive(Clone, PartialEq, Eq)]
60pub struct Ntcp2Config {
61 /// NTCP2 port.
62 pub port: u16,
63
64 /// NTCP2 listen address.
65 pub host: Option<Ipv4Addr>,
66
67 /// Should NTCP2 be published in router info.
68 pub publish: bool,
69
70 /// NTCP2 key.
71 pub key: [u8; 32],
72
73 /// NTCP2 IV.
74 pub iv: [u8; 16],
75}
76
77/// SSU2 configuration.
78#[derive(Clone, PartialEq, Eq)]
79pub struct Ssu2Config {
80 /// SSU2 port.
81 pub port: u16,
82
83 /// SSU2 listen address.
84 pub host: Option<Ipv4Addr>,
85
86 /// Should SSU2 be published in router info.
87 pub publish: bool,
88
89 /// SSU2 static key.
90 pub static_key: [u8; 32],
91
92 /// SSU2 introduction key.
93 pub intro_key: [u8; 32],
94}
95
96/// I2CP configuration.
97#[derive(Debug, Clone)]
98pub struct I2cpConfig {
99 /// I2CP server listen port.
100 pub port: u16,
101
102 /// Host where the I2CP server shoud be bound to.
103 pub host: String,
104}
105
106/// SAMv3 configuration.
107#[derive(Debug, Clone)]
108pub struct SamConfig {
109 /// SAMv3 TCP server listen port.
110 pub tcp_port: u16,
111
112 /// SAMv3 UDP server listen port.
113 pub udp_port: u16,
114
115 /// Host where the SAM server shoud be bound to.
116 pub host: String,
117}
118
119/// Metrics configuration.
120#[derive(Default, Debug, Clone)]
121pub struct MetricsConfig {
122 /// Port where the metrics server should be bound to.
123 pub port: u16,
124}
125
126/// Metrics configuration.
127#[derive(Default, Debug, Clone)]
128pub struct TransitConfig {
129 /// Maximum number of transit tunnels.
130 ///
131 /// If `None`, there are no limit on transit tunnels.
132 pub max_tunnels: Option<usize>,
133}
134
135/// Router configuration.
136#[derive(Default)]
137pub struct Config {
138 /// Allow local addresses.
139 pub allow_local: bool,
140
141 /// Router capabilities.
142 pub caps: Option<String>,
143
144 /// Event refresh interval in seconds.
145 pub refresh_interval: Option<usize>,
146
147 /// Exploratory tunnel pool config.
148 pub exploratory: Option<ExploratoryConfig>,
149
150 /// Should the node be run as a floodfill router.
151 pub floodfill: bool,
152
153 /// I2CP configuration.
154 ///
155 /// `None` if I2CP is disabled.
156 pub i2cp_config: Option<I2cpConfig>,
157
158 /// Are tunnels allowed to be insecure.
159 pub insecure_tunnels: bool,
160
161 /// Metrics configuration.
162 pub metrics: Option<MetricsConfig>,
163
164 /// Network ID.
165 pub net_id: Option<u8>,
166
167 /// NTCP2 configuration.
168 pub ntcp2: Option<Ntcp2Config>,
169
170 /// SSU2 configuration.
171 pub ssu2: Option<Ssu2Config>,
172
173 /// Known router profiles.
174 pub profiles: Vec<(String, Profile)>,
175
176 /// Router Info, if it exists.
177 pub router_info: Option<Vec<u8>>,
178
179 /// Known routers.
180 pub routers: Vec<Vec<u8>>,
181
182 /// SAMv3 configuration.
183 ///
184 /// `None` if SAMv3 is disabled.
185 pub samv3_config: Option<SamConfig>,
186
187 /// Transit tunnel configuration.
188 ///
189 /// `None` if transit tunnels are disabled.
190 pub transit: Option<TransitConfig>,
191
192 /// Router signing key.
193 pub signing_key: Option<[u8; 32]>,
194
195 /// Router static key.
196 pub static_key: Option<[u8; 32]>,
197}