Improve example logging, add BinaryPath.

This commit is contained in:
Andreas Fackler 2018-05-09 13:38:41 +02:00
parent b98bbe9dcd
commit c790a1feba
3 changed files with 31 additions and 8 deletions

View File

@ -39,7 +39,7 @@ use std::collections::HashSet;
use std::fmt::Debug;
use std::marker::{Send, Sync};
use std::net::SocketAddr;
use std::{io, iter, process};
use std::{io, iter, process, thread, time};
use hbbft::broadcast;
use network::commst;
@ -131,8 +131,9 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
).run()
{
Ok(t) => {
debug!(
"Broadcast succeeded: {}",
println!(
"Broadcast succeeded! Node {} output: {}",
our_id,
String::from_utf8(T::into(t)).unwrap()
);
}
@ -167,6 +168,9 @@ impl<T: Clone + Debug + AsRef<[u8]> + PartialEq + Send + Sync + From<Vec<u8>> +
// messaging task.
broadcast_handle.join();
// Wait another second so that pending messages get sent out.
thread::sleep(time::Duration::from_secs(1));
// Stop the messaging task.
stop_tx
.send(())

View File

@ -1,5 +1,7 @@
#! /bin/bash
export RUST_LOG=hbbft=debug
cargo build --example consensus-node
cargo run --example consensus-node -- --bind-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5002 --remote-address=127.0.0.1:5003 --value=Foo &
sleep 1
@ -8,3 +10,4 @@ sleep 1
cargo run --example consensus-node -- --bind-address=127.0.0.1:5002 --remote-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5003 &
sleep 1
cargo run --example consensus-node -- --bind-address=127.0.0.1:5003 --remote-address=127.0.0.1:5000 --remote-address=127.0.0.1:5001 --remote-address=127.0.0.1:5002 &
wait

View File

@ -299,18 +299,34 @@ impl LemmaProto {
}
}
/// The path of a lemma in a Merkle tree
struct BinaryPath(Vec<bool>);
/// The path of the lemma, as a binary string
fn path_of_lemma(mut lemma: &Lemma) -> String {
let mut result = String::new();
fn path_of_lemma(mut lemma: &Lemma) -> BinaryPath {
let mut result = Vec::new();
loop {
match lemma.sibling_hash {
None => (),
Some(Positioned::Left(_)) => result.push('1'),
Some(Positioned::Right(_)) => result.push('0'),
Some(Positioned::Left(_)) => result.push(true),
Some(Positioned::Right(_)) => result.push(false),
}
lemma = match lemma.sub_lemma.as_ref() {
Some(lemma) => lemma,
None => return result,
None => return BinaryPath(result),
}
}
}
impl fmt::Display for BinaryPath {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for b in &self.0 {
if *b {
write!(f, "1")?;
} else {
write!(f, "0")?;
}
}
Ok(())
}
}