Simplifying
This commit is contained in:
@@ -39,8 +39,29 @@ async fn setup(name: &String) -> SideNode {
|
|||||||
let keys = keys::load_from_file(side_dir);
|
let keys = keys::load_from_file(side_dir);
|
||||||
let (incoming_sender, incoming_receiver) = mpsc::channel::<SignedOp>(32);
|
let (incoming_sender, incoming_receiver) = mpsc::channel::<SignedOp>(32);
|
||||||
let crdt = BaseCrdt::<TransactionList>::new(&keys);
|
let crdt = BaseCrdt::<TransactionList>::new(&keys);
|
||||||
let mut node = SideNode::new(crdt, keys, incoming_receiver);
|
let node = SideNode::new(crdt, keys, incoming_receiver);
|
||||||
|
WebSocketClient::start(incoming_sender).await;
|
||||||
println!("Node setup complete.");
|
println!("Node setup complete.");
|
||||||
WebSocketClient::start(&mut node, incoming_sender).await;
|
|
||||||
node
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async fn maybe_autosend(
|
||||||
|
// autosend: bool,
|
||||||
|
// handle: ezsockets::Client<websocket::WebSocketClient>,
|
||||||
|
// mut node: SideNode,
|
||||||
|
// ) {
|
||||||
|
// if autosend {
|
||||||
|
// let forever = task::spawn(async {
|
||||||
|
// let mut interval = time::interval(Duration::from_millis(10));
|
||||||
|
|
||||||
|
// loop {
|
||||||
|
// interval.tick().await;
|
||||||
|
// let fake = utils::fake_transaction("foo123".to_string());
|
||||||
|
// let signed_op = node.add_transaction_local(fake);
|
||||||
|
// let json = serde_json::to_string(&signed_op).unwrap();
|
||||||
|
// handle.text(json).unwrap();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// forever.await.unwrap();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ impl SideNode {
|
|||||||
self.crdt.apply(incoming.clone());
|
self.crdt.apply(incoming.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn add_transaction_local(
|
pub(crate) fn _add_transaction_local(
|
||||||
&mut self,
|
&mut self,
|
||||||
transaction: serde_json::Value,
|
transaction: serde_json::Value,
|
||||||
) -> bft_json_crdt::json_crdt::SignedOp {
|
) -> bft_json_crdt::json_crdt::SignedOp {
|
||||||
@@ -59,7 +59,7 @@ impl SideNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Print the current state of the CRDT, can be used to debug
|
/// Print the current state of the CRDT, can be used to debug
|
||||||
pub(crate) fn trace_crdt(&self) {
|
pub(crate) fn _trace_crdt(&self) {
|
||||||
println!("{:?}", self.crdt.doc.list);
|
println!("{:?}", self.crdt.doc.list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,18 @@ use ezsockets::ClientConfig;
|
|||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::{node::SideNode, utils};
|
use crate::utils;
|
||||||
|
|
||||||
pub(crate) struct WebSocketClient {
|
pub(crate) struct WebSocketClient {
|
||||||
incoming_sender: mpsc::Sender<SignedOp>,
|
incoming_sender: mpsc::Sender<SignedOp>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebSocketClient {
|
impl WebSocketClient {
|
||||||
pub(crate) fn new(incoming_sender: mpsc::Sender<SignedOp>) -> Self {
|
|
||||||
Self { incoming_sender }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start the websocket client
|
/// Start the websocket client
|
||||||
pub(crate) async fn start(node: &mut SideNode, incoming_sender: mpsc::Sender<SignedOp>) {
|
pub(crate) async fn start(
|
||||||
|
incoming_sender: mpsc::Sender<SignedOp>,
|
||||||
|
// stdin_sender: mpsc::Sender<String>,
|
||||||
|
) -> tokio::task::JoinHandle<()> {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
let config = ClientConfig::new("ws://localhost:8080/websocket");
|
let config = ClientConfig::new("ws://localhost:8080/websocket");
|
||||||
let (handle, future) =
|
let (handle, future) =
|
||||||
@@ -24,24 +23,27 @@ impl WebSocketClient {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
future.await.unwrap();
|
future.await.unwrap();
|
||||||
});
|
});
|
||||||
let stdin = std::io::stdin();
|
tokio::spawn(async move {
|
||||||
let lines = stdin.lock().lines();
|
let stdin = std::io::stdin();
|
||||||
for line in lines {
|
let lines = stdin.lock().lines();
|
||||||
println!("We don't get here until we send a message");
|
for line in lines {
|
||||||
let line = line.unwrap();
|
println!("We don't get here until we send a message");
|
||||||
let signed_op = if let "exit" = line.as_str() {
|
let line = line.unwrap();
|
||||||
break;
|
let signed_op = if let "exit" = line.as_str() {
|
||||||
} else if let "trace" = line.as_str() {
|
break;
|
||||||
node.trace_crdt();
|
// } else if let "trace" = line.as_str() {
|
||||||
continue;
|
// node.trace_crdt();
|
||||||
} else {
|
// continue;
|
||||||
let fake = utils::fake_transaction("foo123".to_string());
|
} else {
|
||||||
node.add_transaction_local(fake)
|
let fake = utils::fake_transaction("foo123".to_string());
|
||||||
};
|
// stdin_sender.send(fake).await.unwrap();
|
||||||
tracing::info!("sending {:?}", signed_op);
|
fake
|
||||||
let json = serde_json::to_string(&signed_op).unwrap();
|
};
|
||||||
handle.text(json).unwrap();
|
tracing::info!("sending {:?}", signed_op);
|
||||||
}
|
let json = serde_json::to_string(&signed_op).unwrap();
|
||||||
|
handle.text(json).unwrap();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user