summaryrefslogtreecommitdiffstats
path: root/src/config/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/mod.rs')
-rw-r--r--src/config/mod.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 811ad57..21a8733 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -236,6 +236,13 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[
"Chunk size when serving large transfers to other nodes (e.g. an epoch's snapshot to a rejoining node), 1KiB to 4MiB.",
),
option(
+ "transports",
+ Kind::List,
+ "NAME,[NAME...]",
+ Some("mycelium"),
+ "The transports this node uses, in order of preference: mycelium, libp2p (in builds with the libp2p feature). A peer is reached on the first one both have; nodes on several carry the traffic between nodes that share none.",
+ ),
+ option(
"mycelium-rest-url",
Kind::Text,
"SCHEME://HOSTNAME:PORT",
@@ -342,6 +349,8 @@ pub(crate) struct Settings {
/// In bytes.
#[serde(default = "default_blob_chunk", with = "crate::units::size_option")]
pub(crate) blob_chunk: u64,
+ #[serde(default = "default_transports")]
+ pub(crate) transports: Vec<String>,
pub(crate) mycelium_rest_url: Option<String>,
pub(crate) mycelium_key_file: Option<PathBuf>,
pub(crate) mycelium_network_key_file: Option<PathBuf>,
@@ -373,6 +382,12 @@ fn default_electorate_window() -> Duration {
fn default_blob_chunk() -> u64 {
64 * 1024
}
+fn default_transports() -> Vec<String> {
+ vec!["mycelium".to_owned()]
+}
+/// The transports `transports` may name, and whether this build has each.
+pub(crate) const TRANSPORTS: &[(&str, bool)] =
+ &[("mycelium", true), ("libp2p", cfg!(feature = "libp2p"))];
fn default_mycelium_peers() -> Vec<String> {
vec!["tls://127.0.0.1:9651".to_owned()]
}
@@ -434,6 +449,28 @@ impl Settings {
if self.genesis && self.recover_from.is_some() {
bail!("recover-from starts the swarm from a backup; it can't be combined with genesis");
}
+ if self.transports.is_empty() {
+ bail!("transports: a node needs at least one");
+ }
+ for (index, name) in self.transports.iter().enumerate() {
+ match TRANSPORTS.iter().find(|(known, _)| known == name) {
+ None => bail!(
+ "transports: unknown transport {name:?} (known: {})",
+ TRANSPORTS
+ .iter()
+ .map(|(known, _)| *known)
+ .collect::<Vec<_>>()
+ .join(", ")
+ ),
+ Some((_, false)) => {
+ bail!("transports: this build has no {name} (built without the {name} feature)")
+ }
+ Some(_) if self.transports[..index].contains(name) => {
+ bail!("transports: {name} is named twice")
+ }
+ Some(_) => {}
+ }
+ }
if self.debug_epoch.is_some() && !self.debug_api {
bail!("debug-epoch needs debug-api");
}
@@ -1354,6 +1391,20 @@ mod tests {
)
.is_err()
);
+ let transports = |names: JsonValue| {
+ resolve(
+ layer(json!({ "htpasswd": "u", "node-key-file": "node.key", "transports": names })),
+ Vec::new(),
+ )
+ };
+ assert!(transports(json!([])).is_err());
+ assert!(transports(json!(["pigeon"])).is_err());
+ assert!(transports(json!(["mycelium", "mycelium"])).is_err());
+ assert!(transports(json!(["mycelium"])).is_ok());
+ assert_eq!(
+ transports(json!(["libp2p", "mycelium"])).is_ok(),
+ cfg!(feature = "libp2p")
+ );
}
#[test]