Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit 6b42af5

Browse files
committed
chore: tidy peer management for join command
The `peers` argument is no longer declared with an `Option` and the manual parsing of `SAFE_PEERS` is removed. If the user doesn't specify any peers using `--peer` or `SAFE_PEERS`, the `get_peers_from_args` function will return a particular type of error. In this case, we can just assume the user wants the nodes to join an existing local network.
1 parent 7368f30 commit 6b42af5

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ serde = { version = "1.0", features = ["derive"] }
2424
serde_json = "1.0"
2525
service-manager = "0.5.1"
2626
sn_node_rpc_client = "0.2.4"
27-
sn_peers_acquisition = "0.2.1"
27+
sn_peers_acquisition = "0.2.2"
2828
sn_protocol = "0.10.8"
2929
sn-releases = "0.1.6"
3030
sysinfo = "0.29.10"

src/main.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ use crate::service::{NodeServiceManager, ServiceControl};
2222
use clap::{Parser, Subcommand};
2323
use color_eyre::{eyre::eyre, Help, Result};
2424
use colored::Colorize;
25-
use libp2p::Multiaddr;
2625
use libp2p_identity::PeerId;
2726
use semver::Version;
2827
use sn_node_rpc_client::RpcClient;
29-
use sn_peers_acquisition::{get_peers_from_args, parse_peer_addr, PeersArgs};
28+
use sn_peers_acquisition::{get_peers_from_args, PeersArgs};
3029
use sn_protocol::node_registry::{get_local_node_registry_path, NodeRegistry};
3130
use sn_releases::{ReleaseType, SafeReleaseRepositoryInterface};
3231
use std::path::PathBuf;
@@ -151,7 +150,7 @@ pub enum SubCmd {
151150
#[clap(long)]
152151
node_version: Option<String>,
153152
#[command(flatten)]
154-
peers: Option<PeersArgs>,
153+
peers: PeersArgs,
155154
/// Set to skip the network validation process
156155
#[clap(long)]
157156
skip_validation: bool,
@@ -359,28 +358,15 @@ async fn main() -> Result<()> {
359358
)
360359
.await?;
361360

362-
// Unfortunately because the peers argument is an option, clap does not handle parsing
363-
// `SAFE_PEERS`.
364-
//
365-
// It needs to be an option, otherwise we wouldn't be able to use the `join` command
366-
// without peers to automatically add new nodes to an existing local network.
367-
let peers = match std::env::var("SAFE_PEERS") {
368-
Ok(var) => {
369-
let peers = var
370-
.split(',')
371-
.map(|addr| parse_peer_addr(addr.trim()).unwrap())
372-
.collect::<Vec<Multiaddr>>();
373-
Some(peers)
374-
}
375-
Err(_) => {
376-
if let Some(peers) = peers {
377-
Some(get_peers_from_args(peers).await?)
378-
} else {
379-
None
380-
}
381-
}
361+
// If no peers are obtained we will attempt to join the existing local network, if one
362+
// is running.
363+
let peers = match get_peers_from_args(peers).await {
364+
Ok(peers) => Some(peers),
365+
Err(e) => match e {
366+
sn_peers_acquisition::error::Error::PeersNotObtained => None,
367+
_ => return Err(e.into()),
368+
},
382369
};
383-
384370
let options = LocalNetworkOptions {
385371
faucet_bin_path: faucet_path,
386372
join: true,

0 commit comments

Comments
 (0)