Periodic websocket sends are now working
This commit is contained in:
@@ -7,5 +7,14 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
tokio = "*"
|
||||
tokio = { version = "1.37.0", features = ["time"] }
|
||||
websockets = "0.3.0"
|
||||
bft-json-crdt = { path = "../../bft-json-crdt" }
|
||||
bft-crdt-derive = { path = "../../bft-json-crdt/bft-crdt-derive" }
|
||||
|
||||
[features]
|
||||
default = ["bft", "logging-list", "logging-json"]
|
||||
logging-list = ["logging-base"]
|
||||
logging-json = ["logging-base"]
|
||||
logging-base = []
|
||||
bft = []
|
||||
|
||||
0
side-node/src/crypto/mod.rs
Normal file
0
side-node/src/crypto/mod.rs
Normal file
@@ -1,3 +1,4 @@
|
||||
use bft_json_crdt::keypair::make_keypair;
|
||||
use cli::{parse_args, Commands};
|
||||
|
||||
pub(crate) mod cli;
|
||||
@@ -13,7 +14,8 @@ async fn main() {
|
||||
init::init();
|
||||
}
|
||||
Some(Commands::Run {}) => {
|
||||
websocket::start().await.unwrap();
|
||||
let keys = make_keypair();
|
||||
websocket::start(keys).await.unwrap();
|
||||
}
|
||||
None => println!("No command provided. Exiting. See --help for more information."),
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
use bft_json_crdt::keypair::Ed25519KeyPair;
|
||||
use tokio::time::{self};
|
||||
use websockets::WebSocket;
|
||||
|
||||
pub(crate) async fn start() -> Result<(), websockets::WebSocketError> {
|
||||
/// Starts a websocket and periodically sends a BFT-CRDT message to the websocket server
|
||||
pub(crate) async fn start(keys: Ed25519KeyPair) -> Result<(), websockets::WebSocketError> {
|
||||
let mut ws = WebSocket::connect("ws://localhost:8080/").await?;
|
||||
|
||||
ws.send_text("foo".to_string()).await?;
|
||||
// ws.receive().await?;
|
||||
// ws.close(None).await?;
|
||||
let mut interval = time::interval(time::Duration::from_secs(2));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
println!("Sending: period");
|
||||
ws.send_text("period".to_string()).await?;
|
||||
let msg = ws.receive().await?;
|
||||
|
||||
println!("Received: {:?}", msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user