From 04b7365ed97fccbf425ffa3f2f7c36a8757fc374 Mon Sep 17 00:00:00 2001 From: Vladimir Komendantskiy Date: Wed, 13 Jun 2018 10:47:33 +0100 Subject: [PATCH] updated the examples with the keys --- examples/consensus-node.rs | 2 ++ examples/network/node.rs | 15 ++++++++++++++- examples/simulation.rs | 12 +++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/examples/consensus-node.rs b/examples/consensus-node.rs index 22317fd..7ba12db 100644 --- a/examples/consensus-node.rs +++ b/examples/consensus-node.rs @@ -8,7 +8,9 @@ extern crate env_logger; extern crate hbbft; #[macro_use] extern crate log; +extern crate pairing; extern crate protobuf; +extern crate rand; mod network; diff --git a/examples/network/node.rs b/examples/network/node.rs index bc9034e..f4238ac 100644 --- a/examples/network/node.rs +++ b/examples/network/node.rs @@ -42,7 +42,11 @@ use std::net::SocketAddr; use std::rc::Rc; use std::{io, iter, process, thread, time}; +use pairing::bls12_381::Bls12; +use rand; + use hbbft::broadcast::{Broadcast, BroadcastMessage}; +use hbbft::crypto::SecretKeySet; use hbbft::messaging::{DistAlgorithm, NetworkInfo, SourcedMessage}; use hbbft::proto::message::BroadcastProto; use network::commst; @@ -124,7 +128,16 @@ impl + PartialEq + Send + Sync + From> + // corresponding to this instance, and no dedicated comms task. The // node index is 0. let broadcast_handle = scope.spawn(move || { - let netinfo = Rc::new(NetworkInfo::new(our_id, (0..num_nodes).collect())); + let all_ids = (0..num_nodes).collect(); + let sk_set = + SecretKeySet::::new((num_nodes - 1) / 3, &mut rand::thread_rng()); + let pk_set = sk_set.public_keys(); + let netinfo = Rc::new(NetworkInfo::new( + our_id, + all_ids, + sk_set.secret_key_share(our_id as u64), + pk_set.clone(), + )); let mut broadcast = Broadcast::new(netinfo, proposer_id).expect("failed to instantiate broadcast"); diff --git a/examples/simulation.rs b/examples/simulation.rs index 86f4974..56fd110 100644 --- a/examples/simulation.rs +++ b/examples/simulation.rs @@ -4,6 +4,7 @@ extern crate docopt; extern crate env_logger; extern crate hbbft; extern crate itertools; +extern crate pairing; extern crate rand; extern crate serde; #[macro_use(Deserialize, Serialize)] @@ -18,11 +19,13 @@ use std::{cmp, u64}; use colored::*; use docopt::Docopt; use itertools::Itertools; +use pairing::bls12_381::Bls12; use rand::Rng; use serde::de::DeserializeOwned; use serde::Serialize; use signifix::{metric, TryFrom}; +use hbbft::crypto::SecretKeySet; use hbbft::honey_badger::{Batch, HoneyBadger}; use hbbft::messaging::{DistAlgorithm, NetworkInfo, Target}; @@ -425,8 +428,15 @@ fn main() { println!(); let num_good_nodes = args.flag_n - args.flag_f; let txs = (0..args.flag_txs).map(|_| Transaction::new(args.flag_tx_size)); + let sk_set = SecretKeySet::::new(args.flag_f, &mut rand::thread_rng()); + let pk_set = sk_set.public_keys(); let new_honey_badger = |id: NodeUid, all_ids: BTreeSet| { - let netinfo = Rc::new(NetworkInfo::new(id, all_ids)); + let netinfo = Rc::new(NetworkInfo::new( + id, + all_ids, + sk_set.secret_key_share(id.0 as u64), + pk_set.clone(), + )); HoneyBadger::new(netinfo, args.flag_b, txs.clone()).expect("Instantiate honey_badger") }; let hw_quality = HwQuality {