Skip to content

Commit

Permalink
feat: sending file working (and wip UI)
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <m@rtin.fyi>
  • Loading branch information
Martichou committed Feb 28, 2024
1 parent 56e32c1 commit 53890f0
Show file tree
Hide file tree
Showing 38 changed files with 919 additions and 130 deletions.
49 changes: 45 additions & 4 deletions core_lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ts-rs = { version = "7.1", features = ["serde-compat", "uuid-impl", "chrono-impl
uuid = "1.7.0"
serde = { version = "1.0", features = ["derive"] }
mime_guess = "2.0.4"
get_if_addrs = "0.5.3"

[build-dependencies]
prost-build = "0.12"
3 changes: 2 additions & 1 deletion core_lib/bindings/ChannelMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import type { ChannelAction } from "./ChannelAction";
import type { ChannelDirection } from "./ChannelDirection";
import type { State } from "./State";
import type { TransferMetadata } from "./TransferMetadata";
import type { TransferType } from "./TransferType";

export interface ChannelMessage { id: string, direction: ChannelDirection, action: ChannelAction | null, state: State | null, meta: TransferMetadata | null, }
export interface ChannelMessage { id: string, direction: ChannelDirection, action: ChannelAction | null, rtype: TransferType | null, state: State | null, meta: TransferMetadata | null, }
4 changes: 4 additions & 0 deletions core_lib/bindings/EndpointInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { DeviceType } from "./DeviceType";

export interface EndpointInfo { id: string, name: string | null, ip: string | null, port: string | null, rtype: DeviceType | null, present: boolean | null, }
3 changes: 3 additions & 0 deletions core_lib/bindings/OutboundPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type OutboundPayload = { "Files": Array<string> };
4 changes: 4 additions & 0 deletions core_lib/bindings/SendInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { OutboundPayload } from "./OutboundPayload";

export interface SendInfo { id: string, name: string, addr: string, ob: OutboundPayload, }
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" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "Disconnected" | "Finished";
export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "SentUkeyClientInit" | "SentUkeyClientFinish" | "SentPairedKeyEncryption" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "SentIntroduction" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "SendingFiles" | "Disconnected" | "Finished";
3 changes: 3 additions & 0 deletions core_lib/bindings/TransferType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type TransferType = "Inbound" | "Outbound";
6 changes: 5 additions & 1 deletion core_lib/bindings/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export * from "./ChannelDirection"
export * from "./DeviceType"
export * from "./ChannelMessage"
export * from "./TransferType"
export * from "./OutboundPayload"
export * from "./TransferMetadata"
export * from "./EndpointInfo"
export * from "./ChannelAction"
export * from "./RemoteDeviceInfo"
export * from "./State"
export * from "./State"
export * from "./SendInfo"
2 changes: 2 additions & 0 deletions core_lib/dist/ChannelMessage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import type { ChannelAction } from "./ChannelAction";
import type { ChannelDirection } from "./ChannelDirection";
import type { State } from "./State";
import type { TransferMetadata } from "./TransferMetadata";
import type { TransferType } from "./TransferType";
export interface ChannelMessage {
id: string;
direction: ChannelDirection;
action: ChannelAction | null;
rtype: TransferType | null;
state: State | null;
meta: TransferMetadata | null;
}
9 changes: 9 additions & 0 deletions core_lib/dist/EndpointInfo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { DeviceType } from "./DeviceType";
export interface EndpointInfo {
id: string;
name: string | null;
ip: string | null;
port: string | null;
rtype: DeviceType | null;
present: boolean | null;
}
2 changes: 2 additions & 0 deletions core_lib/dist/EndpointInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 1 addition & 1 deletion core_lib/dist/State.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "Disconnected" | "Finished";
export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "SentUkeyClientInit" | "SentUkeyClientFinish" | "SentPairedKeyEncryption" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "SentIntroduction" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "SendingFiles" | "Disconnected" | "Finished";
1 change: 1 addition & 0 deletions core_lib/dist/TransferType.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type TransferType = "Inbound" | "Outbound";
3 changes: 3 additions & 0 deletions core_lib/dist/TransferType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions core_lib/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export * from "./ChannelDirection";
export * from "./DeviceType";
export * from "./ChannelMessage";
export * from "./TransferType";
export * from "./TransferMetadata";
export * from "./EndpointInfo";
export * from "./ChannelAction";
export * from "./RemoteDeviceInfo";
export * from "./State";
2 changes: 2 additions & 0 deletions core_lib/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./ChannelDirection"), exports);
__exportStar(require("./DeviceType"), exports);
__exportStar(require("./ChannelMessage"), exports);
__exportStar(require("./TransferType"), exports);
__exportStar(require("./TransferMetadata"), exports);
__exportStar(require("./EndpointInfo"), exports);
__exportStar(require("./ChannelAction"), exports);
__exportStar(require("./RemoteDeviceInfo"), exports);
__exportStar(require("./State"), exports);
2 changes: 2 additions & 0 deletions core_lib/esm/ChannelMessage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import type { ChannelAction } from "./ChannelAction";
import type { ChannelDirection } from "./ChannelDirection";
import type { State } from "./State";
import type { TransferMetadata } from "./TransferMetadata";
import type { TransferType } from "./TransferType";
export interface ChannelMessage {
id: string;
direction: ChannelDirection;
action: ChannelAction | null;
rtype: TransferType | null;
state: State | null;
meta: TransferMetadata | null;
}
9 changes: 9 additions & 0 deletions core_lib/esm/EndpointInfo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { DeviceType } from "./DeviceType";
export interface EndpointInfo {
id: string;
name: string | null;
ip: string | null;
port: string | null;
rtype: DeviceType | null;
present: boolean | null;
}
2 changes: 2 additions & 0 deletions core_lib/esm/EndpointInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 1 addition & 1 deletion core_lib/esm/State.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "Disconnected" | "Finished";
export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "SentUkeyClientInit" | "SentUkeyClientFinish" | "SentPairedKeyEncryption" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "SentIntroduction" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "SendingFiles" | "Disconnected" | "Finished";
1 change: 1 addition & 0 deletions core_lib/esm/TransferType.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type TransferType = "Inbound" | "Outbound";
3 changes: 3 additions & 0 deletions core_lib/esm/TransferType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions core_lib/esm/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export * from "./ChannelDirection";
export * from "./DeviceType";
export * from "./ChannelMessage";
export * from "./TransferType";
export * from "./TransferMetadata";
export * from "./EndpointInfo";
export * from "./ChannelAction";
export * from "./RemoteDeviceInfo";
export * from "./State";
2 changes: 2 additions & 0 deletions core_lib/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./ChannelDirection"), exports);
__exportStar(require("./DeviceType"), exports);
__exportStar(require("./ChannelMessage"), exports);
__exportStar(require("./TransferType"), exports);
__exportStar(require("./TransferMetadata"), exports);
__exportStar(require("./EndpointInfo"), exports);
__exportStar(require("./ChannelAction"), exports);
__exportStar(require("./RemoteDeviceInfo"), exports);
__exportStar(require("./State"), exports);
7 changes: 6 additions & 1 deletion core_lib/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extern crate log;

use rquickshare::RQS;
use tokio::sync::mpsc;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
Expand All @@ -17,9 +18,13 @@ async fn main() -> Result<(), anyhow::Error> {
tracing_subscriber::fmt::init();

// Start the RQuickShare service
let rqs = RQS::default();
let mut rqs = RQS::default();
rqs.run().await?;

let discovery_channel = mpsc::channel(10);

rqs.discovery(discovery_channel.0)?;

// Wait for CTRL+C and then stop RQS
let _ = tokio::signal::ctrl_c().await;
info!("Stopping service.");
Expand Down
8 changes: 8 additions & 0 deletions core_lib/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ pub enum ChannelAction {
CancelTransfer,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, TS)]
#[ts(export)]
pub enum TransferType {
Inbound,
Outbound,
}

#[derive(Debug, Clone, Default, Deserialize, Serialize, TS)]
#[ts(export)]
pub struct ChannelMessage {
Expand All @@ -30,6 +37,7 @@ pub struct ChannelMessage {
pub action: Option<ChannelAction>,

// Only present when channelDirection is libToFront
pub rtype: Option<TransferType>,
pub state: Option<State>,
pub meta: Option<TransferMetadata>,
}
13 changes: 7 additions & 6 deletions core_lib/src/hdl/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const SANE_FRAME_LENGTH: i32 = 5 * 1024 * 1024;
#[derive(Debug)]
pub struct InboundRequest {
socket: TcpStream,
state: InnerState,
pub state: InnerState,
sender: Sender<ChannelMessage>,
receiver: Receiver<ChannelMessage>,
}
Expand Down Expand Up @@ -572,9 +572,9 @@ impl InboundRequest {
current_offset
));
}
if current_offset + chunk.body().len() as i64 > file_internal.meta.size() {
if current_offset + chunk.body().len() as i64 > file_internal.total_size {
return Err(anyhow!(
"Transferred file size exceeds previously specified value"
"Transferred file size exceeds previously specified value: {} vs {}", current_offset + chunk.body().len() as i64, file_internal.total_size
));
}

Expand Down Expand Up @@ -753,10 +753,10 @@ impl InboundRequest {
}

let info = InternalFileInfo {
meta: file.clone(),
payload_id: file.payload_id(),
destination_url: dest,
file_url: dest,
bytes_transferred: 0,
total_size: file.size(),
file: None,
};
self.state.transferred_files.insert(file.payload_id(), info);
Expand Down Expand Up @@ -864,7 +864,7 @@ impl InboundRequest {
for id in ids {
let mfi = self.state.transferred_files.get_mut(&id).unwrap();

let file = File::create(&mfi.destination_url)?;
let file = File::create(&mfi.file_url)?;
info!("Created file: {:?}", &file);
mfi.file = Some(file);
}
Expand Down Expand Up @@ -1190,6 +1190,7 @@ impl InboundRequest {
let _ = self.sender.send(ChannelMessage {
id: self.state.id.clone(),
direction: ChannelDirection::LibToFront,
rtype: Some(crate::channel::TransferType::Inbound),
state: Some(self.state.state.clone()),
meta: self.state.transfer_metadata.clone(),
..Default::default()
Expand Down
Loading

0 comments on commit 53890f0

Please sign in to comment.