mirror of
https://github.com/CompeyDev/ruck.git
synced 2025-01-07 11:29:10 +00:00
Reduce print statements; stub dockerfile
This commit is contained in:
parent
d29015f085
commit
d6e299b031
12 changed files with 58 additions and 33 deletions
32
Dockerfile
Normal file
32
Dockerfile
Normal file
|
@ -0,0 +1,32 @@
|
|||
FROM rust:1.58 as build
|
||||
|
||||
# create a new empty shell project
|
||||
RUN USER=root cargo new --bin ruck
|
||||
WORKDIR /ruck
|
||||
|
||||
# copy over your manifests
|
||||
COPY ./Cargo.lock ./Cargo.lock
|
||||
COPY ./Cargo.toml ./Cargo.toml
|
||||
|
||||
# this build step will cache your dependencies
|
||||
RUN cargo build --release
|
||||
|
||||
# copy your source tree
|
||||
RUN rm src/*.rs
|
||||
COPY ./src ./src
|
||||
|
||||
# build for release
|
||||
RUN rm ./target/release/deps/ruck*
|
||||
RUN cargo build --release
|
||||
|
||||
# Copy the binary into a new container for a smaller docker image
|
||||
FROM debian:buster-slim
|
||||
|
||||
COPY --from=build ./target/release/ruck /
|
||||
USER root
|
||||
|
||||
ENV RUST_LOG=info
|
||||
ENV RUST_BACKTRACE=full
|
||||
|
||||
CMD ["/ruck", "relay"]
|
||||
|
|
@ -20,4 +20,11 @@
|
|||
- https://pdos.csail.mit.edu/papers/chord:sigcomm01/chord_sigcomm.pdf
|
||||
- https://pdos.csail.mit.edu/6.824/schedule.html
|
||||
- https://flylib.com/books/en/2.292.1.105/1/
|
||||
- https://en.wikipedia.org/wiki/Two_Generals%27_Problem
|
||||
- https://en.wikipedia.org/wiki/Two_Generals%27_Problem
|
||||
|
||||
## Todo
|
||||
|
||||
- [ ] Use tracing
|
||||
- [ ] Add progress bars
|
||||
- [ ] Exit happily when transfer is complete
|
||||
- [ ] Compress files
|
1
scripts/build.sh
Executable file
1
scripts/build.sh
Executable file
|
@ -0,0 +1 @@
|
|||
docker build -t ruck ..
|
1
scripts/run.sh
Executable file
1
scripts/run.sh
Executable file
|
@ -0,0 +1 @@
|
|||
$ docker run -p 8080:3030 --rm --name ruck1 ruck
|
|
@ -1,3 +1,4 @@
|
|||
use crate::conf::BUFFER_SIZE;
|
||||
use crate::crypto::handshake;
|
||||
use crate::file::{to_size_string, FileHandle, FileInfo};
|
||||
use crate::message::{
|
||||
|
@ -10,8 +11,6 @@ use blake2::{Blake2s256, Digest};
|
|||
use bytes::{Bytes, BytesMut};
|
||||
use futures::future::try_join_all;
|
||||
use futures::prelude::*;
|
||||
use futures::stream::FuturesUnordered;
|
||||
use futures::StreamExt;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::PathBuf;
|
||||
|
@ -112,7 +111,7 @@ pub async fn negotiate_files_up(
|
|||
pub async fn negotiate_files_down(
|
||||
stream: &mut MessageStream,
|
||||
cipher: &Aes256Gcm,
|
||||
) -> Result<(Vec<FileInfo>)> {
|
||||
) -> Result<Vec<FileInfo>> {
|
||||
let file_offer = match stream.next().await {
|
||||
Some(Ok(msg)) => match msg {
|
||||
Message::EncryptedMessage(response) => response,
|
||||
|
@ -163,7 +162,7 @@ pub async fn upload_encrypted_files(
|
|||
loop {
|
||||
tokio::select! {
|
||||
Some(msg) = rx.recv() => {
|
||||
println!("message received to client.rx {:?}", msg);
|
||||
// println!("message received to client.rx {:?}", msg);
|
||||
let x = msg.to_encrypted_message(cipher)?;
|
||||
stream.send(x).await?
|
||||
}
|
||||
|
@ -175,7 +174,7 @@ pub async fn upload_encrypted_files(
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
const BUFFER_SIZE: usize = 1024 * 64;
|
||||
|
||||
pub async fn enqueue_file_chunks(
|
||||
fh: &mut FileHandle,
|
||||
tx: mpsc::UnboundedSender<EncryptedMessage>,
|
||||
|
@ -185,7 +184,7 @@ pub async fn enqueue_file_chunks(
|
|||
while bytes_read != 0 {
|
||||
let mut buf = BytesMut::with_capacity(BUFFER_SIZE);
|
||||
bytes_read = fh.file.read_buf(&mut buf).await?;
|
||||
println!("Bytes_read: {:?}, The bytes: {:?}", bytes_read, &buf[..]);
|
||||
// println!("Bytes_read: {:?}, The bytes: {:?}", bytes_read, &buf[..]);
|
||||
if bytes_read != 0 {
|
||||
let chunk = buf.freeze();
|
||||
let file_info = fh.to_file_info();
|
||||
|
@ -220,7 +219,7 @@ pub async fn download_files(
|
|||
result = stream.next() => match result {
|
||||
Some(Ok(Message::EncryptedMessage(payload))) => {
|
||||
let ec = EncryptedMessage::from_encrypted_message(cipher, &payload)?;
|
||||
println!("encrypted message received! {:?}", ec);
|
||||
// println!("encrypted message received! {:?}", ec);
|
||||
match ec {
|
||||
EncryptedMessage::FileTransferMessage(payload) => {
|
||||
println!("matched file transfer message");
|
||||
|
@ -264,8 +263,8 @@ pub async fn download_file(
|
|||
println!("trying to create file...filename={:?}", filename);
|
||||
let mut file = File::create(filename).await?;
|
||||
println!("file created ok! filename={:?}", filename);
|
||||
while let Some((chunk_num, chunk)) = rx.recv().await {
|
||||
println!("rx got message! chunk={:?}", chunk);
|
||||
while let Some((_chunk_num, chunk)) = rx.recv().await {
|
||||
// println!("rx got message! chunk={:?}", chunk);
|
||||
file.write_all(&chunk).await?;
|
||||
}
|
||||
println!("done receiving messages");
|
||||
|
|
1
src/conf.rs
Normal file
1
src/conf.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub const BUFFER_SIZE: usize = 1024 * 1024;
|
|
@ -20,7 +20,7 @@ pub async fn handshake(
|
|||
id,
|
||||
msg: Bytes::from(outbound_msg),
|
||||
});
|
||||
println!("client - handshake msg, {:?}", handshake_msg);
|
||||
// println!("client - handshake msg, {:?}", handshake_msg);
|
||||
stream.send(handshake_msg).await?;
|
||||
let first_message = match stream.next().await {
|
||||
Some(Ok(msg)) => match msg {
|
||||
|
@ -36,7 +36,7 @@ pub async fn handshake(
|
|||
Ok(key_bytes) => key_bytes,
|
||||
Err(e) => return Err(anyhow!(e.to_string())),
|
||||
};
|
||||
println!("Handshake successful. Key is {:?}", key);
|
||||
// println!("Handshake successful. Key is {:?}", key);
|
||||
return Ok((stream, new_cipher(&key)));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
use crate::message::FileTransferPayload;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::Metadata;
|
||||
use std::path::PathBuf;
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
mod cli;
|
||||
mod client;
|
||||
mod conf;
|
||||
mod crypto;
|
||||
mod file;
|
||||
mod message;
|
||||
mod server;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use clap::Parser;
|
||||
use cli::{Cli, Commands};
|
||||
use client::{receive, send};
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::file::FileInfo;
|
|||
|
||||
use aes_gcm::Aes256Gcm; // Or `Aes128Gcm`
|
||||
use anyhow::{anyhow, Result};
|
||||
use bincode::config;
|
||||
use bytes::Bytes;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::error::Error;
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::collections::HashMap;
|
|||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::sync::{mpsc, oneshot, Mutex};
|
||||
use tokio::sync::{mpsc, Mutex};
|
||||
|
||||
type Tx = mpsc::UnboundedSender<Message>;
|
||||
type Rx = mpsc::UnboundedReceiver<Message>;
|
||||
|
@ -121,13 +121,13 @@ pub async fn handle_connection(
|
|||
return Ok(());
|
||||
}
|
||||
};
|
||||
println!("server - received msg from {:?}", addr);
|
||||
// println!("server - received msg from {:?}", addr);
|
||||
let client = Client::new(handshake_payload.id.clone(), state.clone(), stream).await?;
|
||||
let mut client = Client::upgrade(client, state.clone(), handshake_payload).await?;
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(msg) = client.rx.recv() => {
|
||||
println!("message received to client.rx {:?}", msg);
|
||||
// println!("message received to client.rx {:?}", msg);
|
||||
client.messages.send(msg).await?
|
||||
}
|
||||
result = client.messages.next() => match result {
|
||||
|
|
11
src/tests.rs
11
src/tests.rs
|
@ -1,11 +0,0 @@
|
|||
use crate::crypto::new_cipher;
|
||||
use crate::file::FileHandle;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_file_handle_nonexistent_file() {
|
||||
let pb = PathBuf::new();
|
||||
let fh = FileHandle::new(pb).await;
|
||||
assert!(fh.is_err());
|
||||
}
|
Loading…
Reference in a new issue