From 54a8d7b3409f6a5857b6fc9a964a36b66c28ae25 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 30 Oct 2026 15:36:47 +0100 Subject: refactor transports to start themselves --- src/transport/libp2p.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/transport/libp2p.rs') diff --git a/src/transport/libp2p.rs b/src/transport/libp2p.rs index 610b94e..2d67d2c 100644 --- a/src/transport/libp2p.rs +++ b/src/transport/libp2p.rs @@ -205,6 +205,41 @@ pub(crate) struct Libp2pConfig { } impl Libp2pConfig { + /// The configuration `settings` give; `relay_only`: a relay that is no node + /// (`--relay-only`). + pub(crate) fn from_settings( + settings: &crate::config::Settings, + relay_only: bool, + ) -> Result { + let parse = |option: &str, addresses: &[String]| { + addresses + .iter() + .map(|address| { + address + .parse::() + .with_context(|| format!("{option} {address:?}")) + }) + .collect::>>() + }; + Ok(Self { + key: Self::load_key(settings.libp2p_key_file.as_deref())?, + listen: parse("libp2p-listen", &settings.libp2p_listen)?, + announce: parse("libp2p-announce", &settings.libp2p_announce)?, + relays: parse("libp2p-relays", &settings.libp2p_relays)?, + relay: settings.libp2p_relay || relay_only, + continuum: !relay_only, + mdns: settings.libp2p_mdns, + upnp: settings.libp2p_upnp, + ignore: settings + .libp2p_ignore + .iter() + .map(|range| range.parse().context("libp2p-ignore")) + .collect::>>()?, + public: settings.libp2p_public, + memory: false, + }) + } + /// The key in `path` (32 raw bytes, an Ed25519 secret key), or a new one each start /// without a file: the peer ID only says where a node is, so a new one costs nothing /// but the WHO that finds it again (`transport::identity`). -- cgit v1.3.1