Files
bft-crdt-experiment/side-node/src/main.rs

80 lines
2.1 KiB
Rust
Raw Normal View History

2024-06-06 19:25:54 +01:00
/** use cli::{parse_args, Commands};
2024-05-29 12:44:52 +01:00
2024-05-29 13:17:16 +01:00
pub(crate) mod cli;
2024-05-29 16:47:35 +01:00
pub(crate) mod init;
pub(crate) mod keys;
pub(crate) mod list_transaction_crdt;
pub(crate) mod utils;
pub(crate) mod websocket;
2024-05-29 13:17:16 +01:00
2024-05-29 12:44:52 +01:00
#[tokio::main]
async fn main() {
let args = parse_args();
2024-05-29 12:44:52 +01:00
match &args.command {
Some(Commands::Init { name }) => {
2024-06-06 15:54:33 +01:00
let config = init::config::SideNodeConfig {
name: name.to_string(),
2024-06-06 15:54:33 +01:00
};
let _ = init::init(home(name), config);
}
Some(Commands::Run { name }) => {
let side_dir = home(name);
let (mut bft_crdt, keys) = list_transaction_crdt::new(side_dir);
2024-06-05 19:42:41 +01:00
websocket::start(keys, &mut bft_crdt).await.unwrap();
}
2024-05-29 16:47:35 +01:00
None => println!("No command provided. Exiting. See --help for more information."),
2024-05-29 12:44:52 +01:00
}
2024-05-29 08:32:40 +01:00
}
fn home(name: &String) -> std::path::PathBuf {
let mut path = dirs::home_dir().unwrap();
path.push(".side");
path.push(name);
path
}
2024-06-06 19:25:54 +01:00
**/
use async_trait::async_trait;
use ezsockets::ClientConfig;
use std::io::BufRead;
struct Client {}
#[async_trait]
impl ezsockets::ClientExt for Client {
type Call = ();
async fn on_text(&mut self, text: String) -> Result<(), ezsockets::Error> {
tracing::info!("received message: {text}");
Ok(())
}
async fn on_binary(&mut self, bytes: Vec<u8>) -> Result<(), ezsockets::Error> {
tracing::info!("received bytes: {bytes:?}");
Ok(())
}
async fn on_call(&mut self, call: Self::Call) -> Result<(), ezsockets::Error> {
let () = call;
Ok(())
}
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let config = ClientConfig::new("ws://localhost:8080/websocket");
let (handle, future) = ezsockets::connect(|_client| Client {}, config).await;
tokio::spawn(async move {
future.await.unwrap();
});
let stdin = std::io::stdin();
let lines = stdin.lock().lines();
for line in lines {
let line = line.unwrap();
tracing::info!("sending {line}");
handle.text(line).unwrap();
}
}