arg groups & formatting
This commit is contained in:
parent
60abc00526
commit
6b3f466b3c
0
src/cli.rs
Normal file
0
src/cli.rs
Normal file
@ -1,7 +1,7 @@
|
|||||||
use crate::crypto;
|
use std::{collections::HashMap, error::Error, net::SocketAddr, path::PathBuf};
|
||||||
|
|
||||||
use aes_gcm::{aead::consts::U12, aes::Aes256, AesGcm};
|
use aes_gcm::{aead::consts::U12, aes::Aes256, AesGcm};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use std::{collections::HashMap, error::Error, net::SocketAddr, path::PathBuf};
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{BufReader, BufWriter},
|
io::{BufReader, BufWriter},
|
||||||
net::{
|
net::{
|
||||||
@ -10,6 +10,8 @@ use tokio::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::crypto;
|
||||||
|
|
||||||
const PUBLIC_IPV4: &str = "https://ipinfo.io/ip";
|
const PUBLIC_IPV4: &str = "https://ipinfo.io/ip";
|
||||||
const PUBLIC_IPV6: &str = "https://ipv6.icanhazip.com";
|
const PUBLIC_IPV6: &str = "https://ipv6.icanhazip.com";
|
||||||
|
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
use crate::crypto;
|
use std::error::Error;
|
||||||
|
|
||||||
use aes_gcm::{aead::consts::U12, aes::Aes256, AesGcm};
|
use aes_gcm::{aead::consts::U12, aes::Aes256, AesGcm};
|
||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{engine::general_purpose, Engine};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use std::error::Error;
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter},
|
io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter},
|
||||||
net::tcp::{ReadHalf, WriteHalf},
|
net::tcp::{ReadHalf, WriteHalf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::crypto;
|
||||||
|
|
||||||
pub async fn send(
|
pub async fn send(
|
||||||
writer: &mut BufWriter<WriteHalf<'_>>,
|
writer: &mut BufWriter<WriteHalf<'_>>,
|
||||||
cipher: Option<&mut AesGcm<Aes256, U12>>,
|
cipher: Option<&mut AesGcm<Aes256, U12>>,
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
use crate::{
|
|
||||||
common::{Connection, Message},
|
|
||||||
comms, crypto,
|
|
||||||
};
|
|
||||||
use std::{collections::HashMap, error::Error, net::SocketAddr, path::PathBuf};
|
use std::{collections::HashMap, error::Error, net::SocketAddr, path::PathBuf};
|
||||||
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{AsyncWriteExt, BufWriter},
|
io::{AsyncWriteExt, BufWriter},
|
||||||
@ -10,6 +7,11 @@ use tokio::{
|
|||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
common::{Connection, Message},
|
||||||
|
comms, crypto,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
use super::comms;
|
use std::{error::Error, path::Path};
|
||||||
|
|
||||||
use aes_gcm::{
|
use aes_gcm::{
|
||||||
aead::{consts::U12, AeadMut},
|
aead::{consts::U12, Aead},
|
||||||
aes::Aes256,
|
aes::Aes256,
|
||||||
Aes256Gcm, AesGcm, KeyInit, Nonce,
|
Aes256Gcm, AesGcm, KeyInit, Nonce,
|
||||||
};
|
};
|
||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, rngs::OsRng, Rng, RngCore};
|
||||||
use rand::{rngs::OsRng, RngCore};
|
|
||||||
use std::{error::Error, path::Path};
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{BufReader, BufWriter},
|
io::{BufReader, BufWriter},
|
||||||
net::tcp::{ReadHalf, WriteHalf},
|
net::tcp::{ReadHalf, WriteHalf},
|
||||||
};
|
};
|
||||||
use x25519_dalek::{EphemeralSecret, PublicKey, SharedSecret};
|
use x25519_dalek::{EphemeralSecret, PublicKey, SharedSecret};
|
||||||
|
|
||||||
|
use crate::comms;
|
||||||
|
|
||||||
const AES_NONCE_SIZE: usize = 12;
|
const AES_NONCE_SIZE: usize = 12;
|
||||||
const DH_PBK_SIZE: usize = 32;
|
const DH_PBK_SIZE: usize = 32;
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
pub mod cli;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod comms;
|
pub mod comms;
|
||||||
pub mod connector;
|
pub mod connector;
|
||||||
pub mod crypto;
|
pub mod crypto;
|
||||||
pub mod listener;
|
pub mod listener;
|
||||||
pub mod parsers;
|
pub mod parsers;
|
||||||
pub mod ui;
|
pub mod util;
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
use crate::{
|
|
||||||
common::{Connection, Message},
|
|
||||||
comms, crypto,
|
|
||||||
};
|
|
||||||
use std::{collections::HashMap, error::Error, net::SocketAddr, path::PathBuf, sync::Arc};
|
use std::{collections::HashMap, error::Error, net::SocketAddr, path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::AsyncReadExt,
|
io::AsyncReadExt,
|
||||||
@ -10,6 +7,11 @@ use tokio::{
|
|||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
common::{Connection, Message},
|
||||||
|
comms, crypto,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Listener {
|
pub struct Listener {
|
||||||
host_addr: SocketAddr,
|
host_addr: SocketAddr,
|
||||||
|
39
src/main.rs
39
src/main.rs
@ -1,7 +1,9 @@
|
|||||||
use clap::{Parser, Subcommand};
|
|
||||||
use contego::parsers::{addr_parser, dirpath_parser, filepath_parser};
|
|
||||||
use std::{error::Error, net::SocketAddr, path::PathBuf};
|
use std::{error::Error, net::SocketAddr, path::PathBuf};
|
||||||
|
|
||||||
|
use clap::{command, ArgGroup, Parser, Subcommand};
|
||||||
|
|
||||||
|
use contego::parsers::{addr_parser, dirpath_parser, filepath_parser};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(about, version)]
|
#[command(about, version)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
@ -15,25 +17,35 @@ struct Cli {
|
|||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// Host fileserver instance by providing JSON file with paths or list of paths
|
/// Host fileserver instance by providing JSON file with paths or list of paths
|
||||||
|
#[clap(group(ArgGroup::new("input").required(true).args(&["infile", "files"])))]
|
||||||
Host {
|
Host {
|
||||||
|
/// Host port
|
||||||
|
#[clap(short = 'p', long, default_value_t = 8080)]
|
||||||
|
port: u16,
|
||||||
/// Use IPv6 instead of IPv4
|
/// Use IPv6 instead of IPv4
|
||||||
#[clap(short = '6', long, default_value_t = false)]
|
#[clap(short = '6', long, default_value_t = false)]
|
||||||
ipv6: bool,
|
ipv6: bool,
|
||||||
/// Path to the inputfile
|
/// Path to the inputfile
|
||||||
#[clap(short = 'i', long, value_parser = filepath_parser)]
|
#[clap(short = 'i', long, value_parser = filepath_parser, conflicts_with = "files", group = "input")]
|
||||||
infile: Option<PathBuf>,
|
infile: Option<PathBuf>,
|
||||||
/// Paths to the files (comma separated)
|
/// Paths to the files
|
||||||
#[clap(short = 'f', long, num_args = 1.., value_parser = filepath_parser)]
|
#[clap(short = 'f', long, num_args = 1.., value_parser = filepath_parser, conflicts_with = "infile", group = "input")]
|
||||||
files: Option<Vec<PathBuf>>,
|
files: Option<Vec<PathBuf>>,
|
||||||
|
/// Outgoing traffic chunksize in bytes
|
||||||
|
#[clap(short = 'c', long, default_value_t = 8192)]
|
||||||
|
chunksize: usize,
|
||||||
|
/// Host the files locally
|
||||||
|
#[clap(short = 'l', long, default_value_t = false)]
|
||||||
|
local: bool,
|
||||||
},
|
},
|
||||||
/// Connect to hosted server by providing address, output folder and access key
|
/// Connect to hosted server by providing address, output folder and access key
|
||||||
Connect {
|
Connect {
|
||||||
/// IP address of the server (IPv4 or IPv6)
|
/// IP address of the server (IPv4 or IPv6)
|
||||||
#[clap(short = 'a', long, value_parser = addr_parser)]
|
#[clap(short = 'a', long, value_parser = addr_parser)]
|
||||||
address: SocketAddr,
|
addr: SocketAddr,
|
||||||
/// Path to the output folder
|
/// Path to the output folder
|
||||||
#[clap(short = 'o', long, value_parser = dirpath_parser)]
|
#[clap(short = 'o', long, value_parser = dirpath_parser)]
|
||||||
outdir: PathBuf,
|
out: PathBuf,
|
||||||
/// Access key for the fileserver
|
/// Access key for the fileserver
|
||||||
#[clap(short = 'k', long)]
|
#[clap(short = 'k', long)]
|
||||||
key: String,
|
key: String,
|
||||||
@ -43,7 +55,18 @@ enum Commands {
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
println!("{:?}", cli);
|
|
||||||
|
match cli.command {
|
||||||
|
Commands::Host {
|
||||||
|
port,
|
||||||
|
ipv6,
|
||||||
|
infile,
|
||||||
|
files,
|
||||||
|
chunksize,
|
||||||
|
local,
|
||||||
|
} => {}
|
||||||
|
Commands::Connect { addr, out, key } => {}
|
||||||
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
17
src/ui.rs
17
src/ui.rs
@ -1,17 +0,0 @@
|
|||||||
/*
|
|
||||||
TODO:
|
|
||||||
|
|
||||||
- suspend everything except errors and critical exceptions that lead to panic or abort
|
|
||||||
|
|
||||||
server:
|
|
||||||
- ip & access key on display
|
|
||||||
- commands to copy ip/key to clipboard
|
|
||||||
- updating list/log of connecting/disconnecting clients (?)
|
|
||||||
|
|
||||||
client:
|
|
||||||
- connection ip on display
|
|
||||||
- comamnds to download one or more files
|
|
||||||
- updating list of available/downloading/downloaded files (?)
|
|
||||||
|
|
||||||
* (?): maybe requires a separate UI thread for updates
|
|
||||||
*/
|
|
23
src/util.rs
Normal file
23
src/util.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use std::{error::Error, fs, path::PathBuf};
|
||||||
|
|
||||||
|
fn get_filepaths(
|
||||||
|
infile: Option<PathBuf>,
|
||||||
|
files: Option<Vec<PathBuf>>,
|
||||||
|
) -> Result<Vec<PathBuf>, Box<dyn Error>> {
|
||||||
|
let mut filepaths = Vec::new();
|
||||||
|
|
||||||
|
if let Some(infile) = infile {
|
||||||
|
let paths = fs::read_to_string(infile)?;
|
||||||
|
for path in paths.lines() {
|
||||||
|
filepaths.push(PathBuf::from(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(files) = files {
|
||||||
|
for file in files {
|
||||||
|
filepaths.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(filepaths)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user