From fb20fcc6d1036fe6de86f2b4388fb55951d9c6ac Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 20:53:22 +0100 Subject: libp2p: add prefer option --- src/transport/libp2p/config.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/transport/libp2p/config.rs') diff --git a/src/transport/libp2p/config.rs b/src/transport/libp2p/config.rs index 719f2e8..8b172ba 100644 --- a/src/transport/libp2p/config.rs +++ b/src/transport/libp2p/config.rs @@ -23,6 +23,8 @@ pub(crate) struct Libp2pConfig { pub(crate) upnp: bool, /// Address ranges neither published nor dialled, nor connected over (`Ignoring`). pub(crate) ignore: Vec, + /// Address ranges that matter most, best first (`Book::preference`). + pub(crate) prefer: Vec, /// Use public infrastructure: the IPFS DHT, public relays. pub(crate) public: bool, /// libp2p's in-memory transport instead of TCP and QUIC: for tests. @@ -41,11 +43,11 @@ pub(super) fn parse_addresses(option: &str, addresses: &[String]) -> Result Result> { +/// The ranges of option `option`. +pub(super) fn parse_ranges(option: &str, ranges: &[String]) -> Result> { ranges .iter() - .map(|range| range.parse().context("libp2p-ignore")) + .map(|range| range.parse().with_context(|| option.to_owned())) .collect() } @@ -57,7 +59,8 @@ pub(crate) fn check(settings: &crate::config::Settings) -> Result<()> { parse_addresses("libp2p-listen", &settings.libp2p_listen)?; parse_addresses("libp2p-announce", &settings.libp2p_announce)?; parse_addresses("libp2p-relays", &settings.libp2p_relays)?; - parse_ranges(&settings.libp2p_ignore)?; + parse_ranges("libp2p-ignore", &settings.libp2p_ignore)?; + parse_ranges("libp2p-prefer", &settings.libp2p_prefer)?; if settings.relay_only { if settings.libp2p_listen.is_empty() { bail!("relay-only needs libp2p-listen: where nodes reach the relay"); @@ -88,7 +91,8 @@ impl Libp2pConfig { continuum: !relay_only, mdns: settings.libp2p_mdns, upnp: settings.libp2p_upnp, - ignore: parse_ranges(&settings.libp2p_ignore)?, + ignore: parse_ranges("libp2p-ignore", &settings.libp2p_ignore)?, + prefer: parse_ranges("libp2p-prefer", &settings.libp2p_prefer)?, public: settings.libp2p_public, memory: false, }) -- cgit v1.3.1