Minor cleanup
This commit is contained in:
@@ -11,29 +11,36 @@ use websockets::WebSocket;
|
|||||||
|
|
||||||
/// Starts a websocket and periodically sends a BFT-CRDT message to the websocket server
|
/// Starts a websocket and periodically sends a BFT-CRDT message to the websocket server
|
||||||
pub(crate) async fn start() -> Result<(), websockets::WebSocketError> {
|
pub(crate) async fn start() -> Result<(), websockets::WebSocketError> {
|
||||||
|
println!("connecting to websocket at ws://localhost:8080/");
|
||||||
let mut ws = WebSocket::connect("ws://localhost:8080/").await?;
|
let mut ws = WebSocket::connect("ws://localhost:8080/").await?;
|
||||||
|
|
||||||
let mut interval = time::interval(time::Duration::from_secs(2));
|
// generate a placeholder transaction
|
||||||
|
|
||||||
let json = generate_transaction().unwrap();
|
let json = generate_transaction().unwrap();
|
||||||
|
|
||||||
|
// set up a new BFT-CRDT
|
||||||
let keys = make_keypair();
|
let keys = make_keypair();
|
||||||
let mut bft_crdt = BaseCrdt::<ListExample>::new(&keys);
|
let mut bft_crdt = BaseCrdt::<ListExample>::new(&keys);
|
||||||
|
|
||||||
// next job is to keep adding to this guy
|
// next job is to keep adding to this guy
|
||||||
let _a = bft_crdt.doc.list.insert(ROOT_ID, 'a').sign(&keys);
|
let _a = bft_crdt.doc.list.insert(ROOT_ID, 'a').sign(&keys);
|
||||||
|
|
||||||
|
let mut interval = every_two_seconds();
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
println!("Sending: {}", json);
|
println!("Sending: {}", json);
|
||||||
ws.send_text(json.clone()).await?;
|
ws.send_text(json.clone()).await?;
|
||||||
|
|
||||||
// TODO: apply changes in here when we receive socket input from other nodes
|
// TODO: bft_crdt.apply() changes in here when we receive socket input from other nodes
|
||||||
|
|
||||||
let msg = ws.receive().await?;
|
let msg = ws.receive().await?;
|
||||||
println!("Received: {:?}", msg);
|
println!("Received: {:?}", msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn every_two_seconds() -> time::Interval {
|
||||||
|
time::interval(time::Duration::from_secs(2))
|
||||||
|
}
|
||||||
|
|
||||||
#[add_crdt_fields]
|
#[add_crdt_fields]
|
||||||
#[derive(Clone, CrdtNode)]
|
#[derive(Clone, CrdtNode)]
|
||||||
struct ListExample {
|
struct ListExample {
|
||||||
|
|||||||
Reference in New Issue
Block a user