From cf3d3355ca820435230afd1a1beca33f1ad26fa6 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 30 Sep 2021 21:31:38 +0100 Subject: [PATCH] Let's start afresh --- Cargo.toml | 22 -------------- src/agent/mod.rs | 36 ---------------------- src/agent/peer_connection.rs | 34 --------------------- src/main.rs | 59 ------------------------------------ src/protocol/messages.rs | 6 ---- src/protocol/mod.rs | 1 - src/settings/definitions.rs | 20 ------------ src/settings/mod.rs | 32 ------------------- src/utils/dual_channel.rs | 25 --------------- src/utils/mod.rs | 1 - 10 files changed, 236 deletions(-) delete mode 100644 Cargo.toml delete mode 100644 src/agent/mod.rs delete mode 100644 src/agent/peer_connection.rs delete mode 100644 src/main.rs delete mode 100644 src/protocol/messages.rs delete mode 100644 src/protocol/mod.rs delete mode 100644 src/settings/definitions.rs delete mode 100644 src/settings/mod.rs delete mode 100644 src/utils/dual_channel.rs delete mode 100644 src/utils/mod.rs diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 1af9d59..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "systemquery" -version = "0.1.0" -authors = ["Starbeamrainbowlabs "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -log = "0.4" # Apparently Rust has an entire logging setup - this is the base crate -pretty_env_logger = "0.4" # The logging implementation we've chosen for the above - -clap = "2" # CLI argument parser - -serde = { version = "1.0", features = ["derive"] } # Serialisation -serde_derive = "1.0" # Serialisation helper -toml = "0.5" # TOML serialisation module - -tokio = { version = "1", features = ["full"] } # Async runtime - - -psk-client = { version = "0.1", features = ["vendored-openssl"] } # Pre-shared key TLS support diff --git a/src/agent/mod.rs b/src/agent/mod.rs deleted file mode 100644 index b1a568c..0000000 --- a/src/agent/mod.rs +++ /dev/null @@ -1,36 +0,0 @@ -use tokio::net::{ TcpListener, TcpStream }; - -use crate::settings::Settings; - -mod peer_connection; - -use peer_connection::PeerConnection; - -pub struct Agent { - settings: Settings, - listener: TcpListener, - peers: Vec -} - -impl Agent { - pub async fn new(settings: Settings) { - let bind_address = settings.bind_address.clone(); - let mut agent = Agent { - settings, - listener: match TcpListener::bind(bind_address.clone()).await { - Ok(listener) => listener, - Err(error) => panic!("Error: Failed to open socket using the address '{}': {}", bind_address, error) - }, - peers: Vec::new() - }; - - loop { - let (client, _) = agent.listener.accept().await.unwrap(); - let peer = PeerConnection::new(client); - - agent.peers.push(peer); - - } - - } -} diff --git a/src/agent/peer_connection.rs b/src/agent/peer_connection.rs deleted file mode 100644 index cfa2ffc..0000000 --- a/src/agent/peer_connection.rs +++ /dev/null @@ -1,34 +0,0 @@ -use tokio::net::TcpStream; -use tokio::io::Interest; -use tokio::sync::oneshot; - -pub struct PeerConnection { - send: oneshot::Sender, - receive: oneshot::Receiver -} - -impl PeerConnection { - pub fn new(stream: TcpStream) -> PeerConnection { - let (in_tx1, in_rx1) = oneshot::channel(); - let (out_tx2, out_rx2) = oneshot::channel(); - - let peer = PeerConnection { send: in_tx1, receive: out_rx2 }; - - tokio::spawn(async { - peer.handle(stream, in_rx1, out_tx2); - }); - - return peer; - } - - pub async fn handle(&self, - stream: TcpStream, - stream_in: oneshot::Receiver, - stream_out: oneshot::Sender) { - let ready = stream.ready(Interest::READABLE | Interest::WRITABLE).await?; - - if ready.is_readable() { - let mut data = - } - } -} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 63b0dce..0000000 --- a/src/main.rs +++ /dev/null @@ -1,59 +0,0 @@ -#[macro_use] -extern crate clap; -extern crate pretty_env_logger; - -use std::process; - -use clap::{ App, AppSettings, Arg, SubCommand }; - - - -mod settings; -mod agent; - -fn main() { - // Initialise the logging system - pretty_env_logger::init(); - - let mut cli = App::new("systemquery") - .version(crate_version!()) - .author("Starbeamrainbowlabs") - .about("Distributed system information query tool") - .global_settings(&[ AppSettings::ColoredHelp ]) - .subcommand(SubCommand::with_name("agent") - .about("Starts the systemquery agent") - .arg(Arg::with_name("config") - .short("c").long("config") - .value_name("path/to/config.toml") - .help("Specifies the config file location") - .takes_value(true) - .default_value("/etc/systemquery/systemquery.toml"))) - .subcommand(SubCommand::with_name("query") - .about("Query the cluster [requires agent to be running on this host]") - .arg(Arg::with_name("address") - .short("a").long("address") - .takes_value(true) - .help("Address of the agent to connect to") - .takes_value(true) - .default_value("unix-abstract:systemquery"))); - let args = cli.clone().get_matches(); - - - match args.subcommand_name() { - Some("agent") => { - println!("Coming soon :-)"); - }, - Some("query") => { - println!("Coming soon :-)"); - }, - None => { - cli.print_help().ok(); - println!("\n"); - process::exit(0); - }, - _ => { - println!("Error: Unknown subcommand {}", args.subcommand_name().unwrap()); - process::exit(1); - } - } -} diff --git a/src/protocol/messages.rs b/src/protocol/messages.rs deleted file mode 100644 index 71f261c..0000000 --- a/src/protocol/messages.rs +++ /dev/null @@ -1,6 +0,0 @@ - - -pub struct JoinRequest { - hostname: String, - datetime: Date -} diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs deleted file mode 100644 index ba63992..0000000 --- a/src/protocol/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod messages; diff --git a/src/settings/definitions.rs b/src/settings/definitions.rs deleted file mode 100644 index 358aed7..0000000 --- a/src/settings/definitions.rs +++ /dev/null @@ -1,20 +0,0 @@ - -use serde::{ Serialize, Deserialize }; - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Settings { - pub bind_address : String, - pub port : i16, - pub secret_join : String, - pub secret_query : String -} -impl Default for Settings { - fn default() -> Settings { - Settings { - bind_address: "127.0.0.1".to_string(), - port: 3015, - secret_join: "CHANGE_ME".to_string(), - secret_query: "CHANGE_ME".to_string() - } - } -} diff --git a/src/settings/mod.rs b/src/settings/mod.rs deleted file mode 100644 index f58aa7c..0000000 --- a/src/settings/mod.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::fs; - -// for toml::toml!, which are aren't currently using -// #[macro_use] -// use toml; - - -mod definitions; -pub use definitions::Settings; - - -impl Settings { - pub fn new() -> Settings { - Settings::default() - } - - /// Creates a new Settings object from the contents of a given (TOML) file. - pub fn from_file(filename : String) -> Settings { - let config_str = match fs::read_to_string(&filename) { - Ok(str) => str, - Err(error) => { - // println!("{}", error); - panic!("{}", error); // Oops, something went wrong while reading the config file - } - }; - - let config_obj : Settings = toml::from_str(&config_str).unwrap(); - // info!("{:?}", config_obj); - return config_obj; - } - -} diff --git a/src/utils/dual_channel.rs b/src/utils/dual_channel.rs deleted file mode 100644 index d4606b8..0000000 --- a/src/utils/dual_channel.rs +++ /dev/null @@ -1,25 +0,0 @@ -use tokio::sync::oneshot::{ Sender, Receiver }; - -struct SingleChannel { - tx: Sender, - rx: Receiver -} - -impl Default for SingleChannel { - fn default() -> SingleChannel { - let (tx, rx) = oneshot::channel(); - - SingleChannel { tx, rx } - } -} - -struct DualChannel { - left: SingleChannel, - right: SingleChannel -} - -impl Default for DualChannel { - fn default() -> DualChannel { - DualChannel { left: SingleChannel::default(), right: SingleChannel::default() }; - } -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/utils/mod.rs +++ /dev/null @@ -1 +0,0 @@ -