diff options
Diffstat (limited to 'src/transport/libp2p/config.rs')
| -rw-r--r-- | src/transport/libp2p/config.rs | 14 |
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, }) |
