Let's start afresh
This commit is contained in:
parent
12339aad90
commit
cf3d3355ca
10 changed files with 0 additions and 236 deletions
22
Cargo.toml
22
Cargo.toml
|
@ -1,22 +0,0 @@
|
|||
[package]
|
||||
name = "systemquery"
|
||||
version = "0.1.0"
|
||||
authors = ["Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>"]
|
||||
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
|
|
@ -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<PeerConnection>
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
use tokio::net::TcpStream;
|
||||
use tokio::io::Interest;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
pub struct PeerConnection {
|
||||
send: oneshot::Sender<String>,
|
||||
receive: oneshot::Receiver<String>
|
||||
}
|
||||
|
||||
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<String>,
|
||||
stream_out: oneshot::Sender<String>) {
|
||||
let ready = stream.ready(Interest::READABLE | Interest::WRITABLE).await?;
|
||||
|
||||
if ready.is_readable() {
|
||||
let mut data =
|
||||
}
|
||||
}
|
||||
}
|
59
src/main.rs
59
src/main.rs
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
|
||||
pub struct JoinRequest {
|
||||
hostname: String,
|
||||
datetime: Date
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
pub mod messages;
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
use tokio::sync::oneshot::{ Sender, Receiver };
|
||||
|
||||
struct SingleChannel<T> {
|
||||
tx: Sender<T>,
|
||||
rx: Receiver<T>
|
||||
}
|
||||
|
||||
impl Default for SingleChannel {
|
||||
fn default() -> SingleChannel {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
SingleChannel { tx, rx }
|
||||
}
|
||||
}
|
||||
|
||||
struct DualChannel<T> {
|
||||
left: SingleChannel<T>,
|
||||
right: SingleChannel<T>
|
||||
}
|
||||
|
||||
impl Default for DualChannel {
|
||||
fn default() -> DualChannel {
|
||||
DualChannel { left: SingleChannel::default(), right: SingleChannel::default() };
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
|
Loading…
Reference in a new issue