From 1ef607dc33e0c1204ac6d9509a074e88d692aa86 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 20 Dec 2021 09:55:45 +0100 Subject: Let client connect to multiple other clients Signed-off-by: Matthias Beyer --- cli/src/cli.rs | 1 + cli/src/profile.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index ee8d608..4b0b0f5 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -46,6 +46,7 @@ pub fn app<'a>() -> App<'a> { .long("connect") .required(false) .takes_value(true) + .multiple(true) .value_name("MULTIADDR") .about("Connect to MULTIADDR as well") ) diff --git a/cli/src/profile.rs b/cli/src/profile.rs index 87b1e54..c239bc5 100644 --- a/cli/src/profile.rs +++ b/cli/src/profile.rs @@ -36,10 +36,14 @@ async fn profile_serve(matches: &ArgMatches) -> Result<()> { use ipfs::MultiaddrWithPeerId; let name = matches.value_of("name").map(String::from).unwrap(); // required - let connect_peer = matches.value_of("connect").map(|s| { - s.parse::() - .map_err(anyhow::Error::from) - }).transpose()?; + let connect_peer = matches.values_of("connect") + .map(|v| { + v.map(|s| { + s.parse::().map_err(anyhow::Error::from) + }) + .collect::>>() + }) + .transpose()?; let state_dir = Profile::state_dir_path(&name)?; @@ -51,8 +55,10 @@ async fn profile_serve(matches: &ArgMatches) -> Result<()> { } if let Some(connect_to) = connect_peer { - log::info!("Connecting to {:?}", connect_to); - profile.connect(connect_to).await?; + for c in connect_to { + log::info!("Connecting to {:?}", c); + profile.connect(c).await?; + } } let running = Arc::new(AtomicBool::new(true)); -- cgit v1.2.3