diff --git a/core_lib/bindings/State.ts b/core_lib/bindings/State.ts index 6ad3ef0..64bc894 100644 --- a/core_lib/bindings/State.ts +++ b/core_lib/bindings/State.ts @@ -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"; \ No newline at end of file +export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "SentUkeyClientInit" | "SentUkeyClientFinish" | "SentPairedKeyEncryption" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "SentIntroduction" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "SendingFiles" | "Disconnected" | "Cancelled" | "Finished"; \ No newline at end of file diff --git a/core_lib/src/hdl/inbound.rs b/core_lib/src/hdl/inbound.rs index 9e712e8..eb2b8ab 100644 --- a/core_lib/src/hdl/inbound.rs +++ b/core_lib/src/hdl/inbound.rs @@ -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") @@ -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 { diff --git a/core_lib/src/hdl/mod.rs b/core_lib/src/hdl/mod.rs index 144cbaa..d17c99b 100644 --- a/core_lib/src/hdl/mod.rs +++ b/core_lib/src/hdl/mod.rs @@ -38,6 +38,7 @@ pub enum State { ReceivingFiles, SendingFiles, Disconnected, + Cancelled, Finished, } diff --git a/core_lib/src/hdl/outbound.rs b/core_lib/src/hdl/outbound.rs index 46157e3..043e22b 100644 --- a/core_lib/src/hdl/outbound.rs +++ b/core_lib/src/hdl/outbound.rs @@ -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") @@ -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 { @@ -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; } }; @@ -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)); } diff --git a/core_lib/src/manager.rs b/core_lib/src/manager.rs index 49faa59..463fc3a 100644 --- a/core_lib/src/manager.rs +++ b/core_lib/src/manager.rs @@ -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, diff --git a/frontend/src/components/HomePage.vue b/frontend/src/components/HomePage.vue index 045d90e..995b2ad 100644 --- a/frontend/src/components/HomePage.vue +++ b/frontend/src/components/HomePage.vue @@ -1,177 +1,3 @@ - - + + \ No newline at end of file diff --git a/frontend/src/utils.ts b/frontend/src/utils.ts new file mode 100644 index 0000000..4c3a7df --- /dev/null +++ b/frontend/src/utils.ts @@ -0,0 +1,3 @@ +export function opt(v?: T) { + return v ?? null; +} \ No newline at end of file