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

chore: tidy peer management for join command #21

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
service-manager = "0.5.1"
sn_node_rpc_client = "0.2.4"
sn_peers_acquisition = "0.2.1"
sn_peers_acquisition = "0.2.2"
sn_protocol = "0.10.8"
sn-releases = "0.1.6"
sysinfo = "0.29.10"
Expand Down
34 changes: 10 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ use crate::service::{NodeServiceManager, ServiceControl};
use clap::{Parser, Subcommand};
use color_eyre::{eyre::eyre, Help, Result};
use colored::Colorize;
use libp2p::Multiaddr;
use libp2p_identity::PeerId;
use semver::Version;
use sn_node_rpc_client::RpcClient;
use sn_peers_acquisition::{get_peers_from_args, parse_peer_addr, PeersArgs};
use sn_peers_acquisition::{get_peers_from_args, PeersArgs};
use sn_protocol::node_registry::{get_local_node_registry_path, NodeRegistry};
use sn_releases::{ReleaseType, SafeReleaseRepositoryInterface};
use std::path::PathBuf;
Expand Down Expand Up @@ -151,7 +150,7 @@ pub enum SubCmd {
#[clap(long)]
node_version: Option<String>,
#[command(flatten)]
peers: Option<PeersArgs>,
peers: PeersArgs,
/// Set to skip the network validation process
#[clap(long)]
skip_validation: bool,
Expand Down Expand Up @@ -359,28 +358,15 @@ async fn main() -> Result<()> {
)
.await?;

// Unfortunately because the peers argument is an option, clap does not handle parsing
// `SAFE_PEERS`.
//
// It needs to be an option, otherwise we wouldn't be able to use the `join` command
// without peers to automatically add new nodes to an existing local network.
let peers = match std::env::var("SAFE_PEERS") {
Ok(var) => {
let peers = var
.split(',')
.map(|addr| parse_peer_addr(addr.trim()).unwrap())
.collect::<Vec<Multiaddr>>();
Some(peers)
}
Err(_) => {
if let Some(peers) = peers {
Some(get_peers_from_args(peers).await?)
} else {
None
}
}
// If no peers are obtained we will attempt to join the existing local network, if one
// is running.
let peers = match get_peers_from_args(peers).await {
Ok(peers) => Some(peers),
Err(e) => match e {
sn_peers_acquisition::error::Error::PeersNotObtained => None,
_ => return Err(e.into()),
},
};

let options = LocalNetworkOptions {
faucet_bin_path: faucet_path,
join: true,
Expand Down
Loading