Skip to content

Commit

Permalink
feat: update transfer_metadata for future use
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <[email protected]>
  • Loading branch information
Martichou committed Feb 14, 2024
1 parent 99fa239 commit cde67c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
33 changes: 11 additions & 22 deletions src/backend/inbound.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::fs::File;
use std::os::unix::fs::FileExt;

Expand Down Expand Up @@ -56,21 +55,8 @@ impl InboundRequest {
client_seq: 0,
state: State::Initial,
encryption_done: true,
remote_device_info: None,
cipher_commitment: None,
private_key: None,
public_key: None,
server_init_data: None,
client_init_msg_data: None,
decrypt_key: None,
recv_hmac_key: None,
encrypt_key: None,
send_hmac_key: None,
pin_code: None,
payload_buffers: HashMap::default(),
text_payload_id: -1,
transfer_metadata: None,
transferred_files: HashMap::default(),
..Default::default()
},
}
}
Expand Down Expand Up @@ -689,10 +675,13 @@ impl InboundRequest {
pin_code: self.state.pin_code.clone(),
text_description: None,
};
// TODO - Ask for user consent
info!("Asking for user consent: {:?}", metadata);

// TODO - Currently always accept file transfer
info!("Asking for user consent: {:?}", metadata);
self.update_state(|e| {
e.transfer_metadata = Some(metadata);
});
// TODO - Ask for user consent
// Currently always accept file transfer
self.accept_transfer().await?;
} else if introduction.text_metadata.len() == 1 {
trace!("process_introduction: handling text_metadata");
Expand All @@ -704,14 +693,14 @@ impl InboundRequest {
pin_code: self.state.pin_code.clone(),
text_description: meta.text_title.clone(),
};

info!("Asking for user consent: {:?}", metadata);
self.update_state(|e| {
e.text_payload_id = meta.payload_id();
e.transfer_metadata = Some(metadata);
});

// TODO - Ask for user consent
info!("Asking for user consent: {:?}", metadata);

// TODO - Currently always accept file transfer
// Currently always accept file transfer
self.accept_transfer().await?;
} else {
// TODO - Reject transfer
Expand Down
18 changes: 12 additions & 6 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ mod mdns;
pub use mdns::*;

#[allow(dead_code)]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub enum State {
#[default]
Initial,
ReceivedConnectionRequest,
SentUkeyServerInit,
Expand All @@ -29,14 +30,21 @@ pub enum State {
Disconnected,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct InnerState {
pub id: String,
pub server_seq: i32,
pub client_seq: i32,
pub state: State,
pub encryption_done: bool,

// Subject to be used-facing for progress, ...
pub state: State,
pub remote_device_info: Option<RemoteDeviceInfo>,
pub pin_code: Option<String>,
pub transfer_metadata: Option<TransferMetadata>,
pub transferred_files: HashMap<i64, InternalFileInfo>,

// Everything needed for encryption/decryption/verif
pub cipher_commitment: Option<CipherCommitment>,
pub private_key: Option<SecretKey>,
pub public_key: Option<PublicKey>,
Expand All @@ -46,10 +54,8 @@ pub struct InnerState {
pub recv_hmac_key: Option<Vec<u8>>,
pub encrypt_key: Option<Vec<u8>>,
pub send_hmac_key: Option<Vec<u8>>,
pub pin_code: Option<String>,

// Used to handle/track ingress transfer
pub text_payload_id: i64,
pub payload_buffers: HashMap<i64, Vec<u8>>,
pub transfer_metadata: Option<TransferMetadata>,
pub transferred_files: HashMap<i64, InternalFileInfo>,
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
extern crate log;

use manager::TcpServer;
use tokio::{net::TcpListener, sync::broadcast};
use tokio::net::TcpListener;
use tokio::sync::broadcast;
use tokio_util::sync::CancellationToken;
use tokio_util::task::TaskTracker;
use utils::DeviceType;
Expand Down

0 comments on commit cde67c0

Please sign in to comment.