ruck/src/client.rs

56 lines
1.5 KiB
Rust
Raw Normal View History

2022-02-10 19:52:28 +00:00
use crate::crypto::handshake;
use crate::message::{Message, MessageStream};
2022-02-06 19:04:36 +00:00
2022-02-10 19:52:28 +00:00
use anyhow::Result;
use bytes::{BufMut, Bytes, BytesMut};
2022-02-06 19:04:36 +00:00
use futures::prelude::*;
2022-02-07 00:54:36 +00:00
use std::path::PathBuf;
2022-02-06 19:04:36 +00:00
use tokio::net::TcpStream;
2022-02-10 19:52:28 +00:00
pub async fn send(file_paths: &Vec<PathBuf>, password: &String) -> Result<()> {
let socket = TcpStream::connect("127.0.0.1:8080").await?;
let mut stream = Message::to_stream(socket);
let (stream, key) = handshake(
&mut stream,
Bytes::from(password.to_string()),
Bytes::from("id123"),
)
.await?;
return upload_encrypted_files(stream, file_paths, key).await;
2022-02-06 19:04:36 +00:00
// Send the value
2022-02-10 19:52:28 +00:00
// for path in paths.iter() {
// let b = path.to_str().unwrap().as_bytes();
// let mut buf = BytesMut::with_capacity(1024);
// buf.put(&b[..]);
// let body = buf.freeze();
// let m = Message {
// key: "abc".to_string(),
// from_sender: true,
// body: body,
// };
// stream.send(m).await.unwrap();
// }
}
pub async fn receive(password: &String) -> Result<()> {
let socket = TcpStream::connect("127.0.0.1:8080").await?;
let mut stream = Message::to_stream(socket);
let (stream, key) = handshake(
&mut stream,
Bytes::from(password.to_string()),
Bytes::from("id123"),
)
.await?;
return Ok(());
}
pub async fn upload_encrypted_files(
stream: &mut MessageStream,
file_paths: &Vec<PathBuf>,
key: Bytes,
) -> Result<()> {
return Ok(());
2022-02-06 19:04:36 +00:00
}