Skip to content

Commit

Permalink
fix: don't continue if there is an error or false return.
Browse files Browse the repository at this point in the history
  • Loading branch information
dd-dreams committed Mar 8, 2024
1 parent a49223b commit b373bc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 6 additions & 3 deletions aft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,12 @@ async fn main() {
};
let mut c = Sender::new(&format!("{}:{}", &addr, cliargs.port), create_128_encryptor);

if let Err(e) = c.init(cliargs.filename, config.get_identifier().expect("Identifier isn't present"),
cliargs.identifier, pass,) {
error!("\n{e}");
let init = c.init(cliargs.filename, config.get_identifier().expect("Identifier isn't present"),
cliargs.identifier, pass);

match init {
Ok(b) => if !b {return;},
Err(e) => {error!("\n{e}"); return;}
}
if let Err(e) = c.send_chunks() {
error!("Connection error: {}", e);
Expand Down
15 changes: 5 additions & 10 deletions aft/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ where
/// When there is a connection error.
///
/// Returns false when the identifier is too long.
fn if_relay(&mut self, rece_ident: &str, sen_ident: &str) -> io::Result<bool> {
fn if_relay(&mut self, rece_ident: &str, sen_ident: &str) -> Result<bool, Errors> {
// Notify the relay that this client is a sender
self.writer.0.write_all(&[CLIENT_SEND])?;

Expand All @@ -128,14 +128,8 @@ where

match self.read_signal_relay()? {
Signals::OK => Ok(true),
Signals::Error => {
error!("Receiver is not online.");
Ok(false)
}
s => {
error!("Unexepected signal: {}", s);
Ok(false)
}
Signals::Error => Ok(false),
_ => Err(Errors::InvalidSignal)
}
}

Expand Down Expand Up @@ -208,7 +202,8 @@ where
debug!("Connected to a relay");
if let Some(ident) = receiver_identifier {
if !self.if_relay(ident, sen_ident)? {
return Err(Errors::NotRelay);
error!("{ident} not online");
return Ok(false);
}
} else {
return Err(Errors::NoReceiverIdentifier);
Expand Down

0 comments on commit b373bc7

Please sign in to comment.