Skip to content

Commit

Permalink
feat(improve): stabilise UI & communication
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <[email protected]>
  • Loading branch information
Martichou committed Feb 28, 2024
1 parent acbb5aa commit 7120162
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 261 deletions.
2 changes: 1 addition & 1 deletion core_lib/bindings/State.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "SentUkeyClientInit" | "SentUkeyClientFinish" | "SentPairedKeyEncryption" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "SentIntroduction" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "SendingFiles" | "Disconnected" | "Finished";
export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "SentUkeyClientInit" | "SentUkeyClientFinish" | "SentPairedKeyEncryption" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "SentIntroduction" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "SendingFiles" | "Disconnected" | "Cancelled" | "Finished";
18 changes: 16 additions & 2 deletions core_lib/src/hdl/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ impl InboundRequest {
)).await?;
},
Some(ChannelAction::CancelTransfer) => {
todo!()
self.update_state(
|e| {
e.state = State::Cancelled;
},
true,
);
self.disconnection().await?;
return Err(anyhow!(crate::errors::AppError::NotAnError));
},
None => {
trace!("inbound: nothing to do")
Expand Down Expand Up @@ -634,7 +641,14 @@ impl InboundRequest {

if v1_frame.r#type() == sharing_nearby::v1_frame::FrameType::Cancel {
info!("Transfer canceled");
return self.disconnection().await;
self.update_state(
|e| {
e.state = State::Disconnected;
},
true,
);
self.disconnection().await?;
return Err(anyhow!(crate::errors::AppError::NotAnError));
}

match self.state.state {
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/hdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub enum State {
ReceivingFiles,
SendingFiles,
Disconnected,
Cancelled,
Finished,
}

Expand Down
35 changes: 31 additions & 4 deletions core_lib/src/hdl/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ impl OutboundRequest {
return Ok(());
}

debug!("inbound: got: {:?}", channel_msg);
debug!("outbound: got: {:?}", channel_msg);
match channel_msg.action {
Some(ChannelAction::CancelTransfer) => {
todo!()
self.update_state(
|e| {
e.state = State::Cancelled;
},
true,
);
self.disconnection().await?;
return Err(anyhow!(crate::errors::AppError::NotAnError));
},
None => {
trace!("inbound: nothing to do")
Expand Down Expand Up @@ -551,7 +558,14 @@ impl OutboundRequest {

if v1_frame.r#type() == sharing_nearby::v1_frame::FrameType::Cancel {
info!("Transfer canceled");
return self.disconnection().await;
self.update_state(
|e| {
e.state = State::Disconnected;
},
true,
);
self.disconnection().await?;
return Err(anyhow!(crate::errors::AppError::NotAnError));
}

match self.state.state {
Expand Down Expand Up @@ -750,13 +764,14 @@ impl OutboundRequest {
Some(i) => i,
None => {
info!("All files have been transferred");
self.disconnection().await?;
self.update_state(
|e| {
e.state = State::Finished;
},
true,
);
self.disconnection().await?;
// Breaking instead of NotAnError to allow peacefull termination
break;
}
};
Expand Down Expand Up @@ -892,11 +907,23 @@ impl OutboundRequest {
"Cannot process: consent denied: {:?}",
v1_frame.connection_response.as_ref().unwrap().status()
);
self.update_state(
|e| {
e.state = State::Disconnected;
},
true,
);
self.disconnection().await?;
return Err(anyhow!(crate::errors::AppError::NotAnError));
}
sharing_nearby::connection_response_frame::Status::Unknown => {
error!("Unknown consent type: aborting");
self.update_state(
|e| {
e.state = State::Disconnected;
},
true,
);
self.disconnection().await?;
return Err(anyhow!(crate::errors::AppError::NotAnError));
}
Expand Down
2 changes: 1 addition & 1 deletion core_lib/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl TcpServer {
break;
}

if or.state.state != State::Finished {
if or.state.state != State::Finished && or.state.state != State::Cancelled {
let _ = self.sender.clone().send(ChannelMessage {
id: si.addr,
direction: ChannelDirection::LibToFront,
Expand Down
Loading

0 comments on commit 7120162

Please sign in to comment.