aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/libp2p/config.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-31 20:53:22 +0100
committertv <tv@krebsco.de>2026-10-31 20:53:22 +0100
commit9fa1c4601f3c62555903e549e976915169602b26 (patch)
treec005ac09f07f2959f69bae56f9343f9d8ffde6b5 /src/transport/libp2p/config.rs
parenta08c430100edfba7b924c957f98294fd79de0e1b (diff)
libp2p: add prefer option
Diffstat (limited to 'src/transport/libp2p/config.rs')
-rw-r--r--src/transport/libp2p/config.rs14
1 files changed, 9 insertions, 5 deletions
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<IpRange>,
+ /// Address ranges that matter most, best first (`Book::preference`).
+ pub(crate) prefer: Vec<IpRange>,
/// 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<Vec<
.collect()
}
-/// The ranges of `libp2p-ignore`.
-pub(super) fn parse_ranges(ranges: &[String]) -> Result<Vec<IpRange>> {
+/// The ranges of option `option`.
+pub(super) fn parse_ranges(option: &str, ranges: &[String]) -> Result<Vec<IpRange>> {
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,
})