diff --git a/cli/src/main.rs b/cli/src/main.rs index b5740c3d..94b7d6f4 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -8,18 +8,15 @@ use clap::{Args, CommandFactory, Parser, Subcommand}; use cli_clipboard::{ClipboardContext, ClipboardProvider}; use color_eyre::{eyre, eyre::Context}; use console::{style, Term}; -use dialoguer::{Input}; +use dialoguer::Input; use futures::{future::Either, Future, FutureExt}; use indicatif::{MultiProgress, ProgressBar}; use magic_wormhole::PgpWordList; -use magic_wormhole::{forwarding, transfer, transit, Wormhole}; use std::{ io::Write, - path::{Path, PathBuf}, + path::{PathBuf}, }; -use std::{io::Write, path::PathBuf}; - use magic_wormhole::{ dilated_transfer, forwarding, transfer, transit, MailboxConnection, Wormhole, }; @@ -428,7 +425,7 @@ async fn main() -> eyre::Result<()> { } }; - if with_dilation && peer_allows_dilation(&wormhole.peer_version()) { + if with_dilation && peer_allows_dilation(wormhole.peer_version()) { log::debug!("dilate wormhole"); let mut dilated_wormhole = wormhole.dilate()?; // need to pass transit relay URL dilated_wormhole.run().await; @@ -1069,15 +1066,14 @@ async fn receive_inner_v1( .truncate(true) .open(&file_path) .await?; - req - .accept( - &transit::log_transit_connection, - &mut file, - create_progress_handler(pb), - ctrl_c(), - ) - .await - .context("Receive process failed") + req.accept( + &transit::log_transit_connection, + &mut file, + create_progress_handler(pb), + ctrl_c(), + ) + .await + .context("Receive process failed") } async fn receive_inner_v2( @@ -1117,7 +1113,7 @@ async fn receive_inner_v2( /* Create a temporary directory for receiving */ use rand::Rng; - let tmp_dir = target_dir.join(&format!( + let tmp_dir = target_dir.join(format!( "wormhole-tmp-{:06}", rand::thread_rng().gen_range(0..1_000_000) )); diff --git a/src/core.rs b/src/core.rs index 7b50900a..66d37273 100644 --- a/src/core.rs +++ b/src/core.rs @@ -4,7 +4,7 @@ use crate::core::protocol::{WormholeProtocol, WormholeProtocolDefault}; #[cfg(feature = "dilation")] use crate::dilation::DilatedWormhole; use log::*; -use serde; + use serde_derive::{Deserialize, Serialize}; use serde_json::Value; use xsalsa20poly1305 as secretbox; @@ -18,7 +18,7 @@ pub mod rendezvous; mod server_messages; #[cfg(test)] pub(crate) mod test; -mod wordlist; +pub mod wordlist; #[derive(Debug, thiserror::Error)] #[non_exhaustive] @@ -161,7 +161,7 @@ impl MailboxConnection { let (mut server, welcome) = RendezvousServer::connect(&config.id, &config.rendezvous_url).await?; let (nameplate, mailbox) = server.allocate_claim_open().await?; - let code = Code::new(&nameplate, &password); + let code = Code::new(&nameplate, password); Ok(MailboxConnection { config, @@ -303,13 +303,13 @@ impl Wormhole { ) -> Result<(WormholeWelcome, Self), WormholeError> { let mailbox_connection = MailboxConnection::connect(config, code.clone(), !expect_claimed_nameplate).await?; - return Ok(( + Ok(( WormholeWelcome { welcome: mailbox_connection.welcome.clone(), - code: code, + code, }, Self::connect(mailbox_connection).await?, - )); + )) } /// Set up a Wormhole which is the client-client part of the connection setup @@ -469,7 +469,7 @@ impl Wormhole { } pub fn our_version(&self) -> &Box { - &self.protocol.our_version() + self.protocol.our_version() } } @@ -643,7 +643,7 @@ impl> From for EitherSide { impl From for TheirSide { fn from(side: MySide) -> TheirSide { - TheirSide(side.0.into()) + TheirSide(side.0) } } @@ -660,7 +660,7 @@ impl Phase { } pub fn dilation(phase: u64) -> Self { - Phase(format!("dilate-{}", phase.to_string()).to_string().into()) + Phase(format!("dilate-{}", phase).into()) } pub fn is_version(&self) -> bool { diff --git a/src/core/wordlist.rs b/src/core/wordlist.rs index 2a7531ab..d6d546e2 100644 --- a/src/core/wordlist.rs +++ b/src/core/wordlist.rs @@ -1,6 +1,6 @@ use rand::{rngs::OsRng, seq::SliceRandom}; -use serde_json::{self, Value}; -use std::fmt; +use serde_json::{self}; + use dialoguer::Completion; use std::collections::HashMap; diff --git a/src/dilation/manager.rs b/src/dilation/manager.rs index e3a5cbee..c2ee7b2d 100644 --- a/src/dilation/manager.rs +++ b/src/dilation/manager.rs @@ -38,12 +38,12 @@ pub struct ManagerMachine { #[cfg_attr(test, automock)] impl ManagerMachine { pub fn new(side: MySide) -> Self { - let machine = ManagerMachine { + + ManagerMachine { side, role: Role::Follower, state: Some(State::Wanting), - }; - machine + } } pub fn current_state(&self) -> Option { @@ -96,7 +96,7 @@ impl ManagerMachine { command = Some(ManagerCommand::from(ProtocolCommand::SendPlease { side: side.clone(), })); - let role = self.choose_role(&their_side.clone()); + let role = self.choose_role(&their_side); log::debug!( "role: {}", if role == Role::Leader { @@ -184,7 +184,7 @@ impl ManagerMachine { "processing event finished: state={}, command={}", self.state.unwrap(), command - .clone() + .map(|cmd| cmd.to_string()) .unwrap_or("n/a".to_string()) ); diff --git a/src/dilation/mod.rs b/src/dilation/mod.rs index c96763e8..5563bc41 100644 --- a/src/dilation/mod.rs +++ b/src/dilation/mod.rs @@ -66,7 +66,7 @@ impl DilatedWormhole { DilatedWormhole { wormhole: WormholeConnection::new(wormhole), side: side.clone(), - manager: ManagerMachine::new(side.clone()), + manager: ManagerMachine::new(side), } } diff --git a/src/transfer.rs b/src/transfer.rs index 39c38514..dc1a11f1 100644 --- a/src/transfer.rs +++ b/src/transfer.rs @@ -457,13 +457,11 @@ impl Offer { "{name} and {} other files or directories", self.content.len() - 1 ) + } else if self.is_directory() { + let count = entry.iter_files().count(); + format!("{name} with {count} files inside") } else { - if self.is_directory() { - let count = entry.iter_files().count(); - format!("{name} with {count} files inside") - } else { - name.clone() - } + name.clone() } } @@ -731,11 +729,11 @@ impl OfferEntry { match self { OfferEntry::RegularFile { size, .. } => OfferEntry::RegularFile { size: *size, - content: f(&base_path), + content: f(base_path), }, OfferEntry::Directory { content } => OfferEntry::Directory { content: content - .into_iter() + .iter() .map(|(k, v)| { base_path.push(k.clone()); let v = v.set_content(base_path, f); diff --git a/src/transfer/v1.rs b/src/transfer/v1.rs index e7035811..075ff156 100644 --- a/src/transfer/v1.rs +++ b/src/transfer/v1.rs @@ -299,7 +299,7 @@ pub async fn send_folder( }, OfferSendEntry::RegularFile { size, content } => { log::debug!("Adding file {path:?}; {size} bytes"); - let header = tar_helper::create_header_file(&path, size)?; + let header = tar_helper::create_header_file(path, size)?; let padding = tar_helper::padding(size); *total_size += header.len() as u64; *total_size += padding.len() as u64; @@ -773,7 +773,7 @@ mod tar_helper { // long name extension by emitting an entry which indicates that it's the // filename. if let Err(e) = header.set_path(path) { - let data = path2bytes(&path); + let data = path2bytes(path); let max = header.as_old().name.len(); // Since `e` isn't specific enough to let us know the path is indeed too // long, verify it first before using the extension. diff --git a/src/transfer/v2.rs b/src/transfer/v2.rs index 7ecaa5b1..88a73dae 100644 --- a/src/transfer/v2.rs +++ b/src/transfer/v2.rs @@ -109,7 +109,7 @@ async fn make_transit( /* Send our transit hints */ wormhole .send_json(&PeerMessage::transit_v2( - (**connector.our_hints()).clone().into(), + (**connector.our_hints()).clone(), )) .await?; @@ -118,7 +118,7 @@ async fn make_transit( match wormhole.receive_json::().await??.check_err()? { PeerMessage::TransitV2(transit) => { debug!("received transit message: {:?}", transit); - transit.hints_v2.into() + transit.hints_v2 }, other => { let error = TransferError::unexpected_message("transit-v2", other); @@ -210,8 +210,8 @@ async fn send_inner( ) -> Result<(), TransferError> { transit.send_record(&{ /* This must be split into two statements to appease the borrow checker (unfortunate side effect of borrow-through) */ - let message = PeerMessageV2::Offer((&offer).into()).ser_msgpack(); - message + + PeerMessageV2::Offer((&offer).into()).ser_msgpack() }).await?; let files = match PeerMessageV2::de_msgpack(&transit.receive_record().await?)?.check_err()? { @@ -246,7 +246,7 @@ async fn send_inner( { let offset = *offset; /* This must be split into two statements to appease the borrow checker (unfortunate side effect of borrow-through) */ - let content = (offer.get_file(&file).unwrap().0)(); + let content = (offer.get_file(file).unwrap().0)(); let mut content = content.await?; let file = file.clone(); @@ -591,7 +591,7 @@ async fn receive_inner( PeerMessageV2::TransferAck(transfer_ack) => transfer_ack, PeerMessageV2::FileStart(_) => { bail!(TransferError::Protocol( - format!("Unexpected message: got 'file-start' but did not expect any more files") + "Unexpected message: got 'file-start' but did not expect any more files".to_string() .into_boxed_str() )) },