Make `DistAlgorithm` require `Send`.

Using `hbbft` in other software that is based on frameworks like [tokio](https://tokio.rs), being `Send` is often a requirement on shared data structures.
This commit is contained in:
Marc Brinkmann 2018-10-04 15:21:40 +02:00 committed by Andreas Fackler
parent 6f0b53436f
commit 4b00bda555
5 changed files with 7 additions and 7 deletions

View File

@ -78,7 +78,7 @@ pub type Step<N, T> = messaging::Step<Coin<N, T>>;
impl<N, T> DistAlgorithm for Coin<N, T>
where
N: NodeIdT,
T: Clone + AsRef<[u8]>,
T: Clone + AsRef<[u8]> + Send,
{
type NodeId = N;
type Input = ();
@ -123,7 +123,7 @@ where
impl<N, T> Coin<N, T>
where
N: NodeIdT,
T: Clone + AsRef<[u8]>,
T: Clone + AsRef<[u8]> + Send,
{
pub fn new(netinfo: Arc<NetworkInfo<N>>, nonce: T) -> Self {
Coin {

View File

@ -39,7 +39,7 @@ pub struct DynamicHoneyBadger<C, N: Rand> {
pub(super) incoming_queue: Vec<(N, Message<N>)>,
/// A random number generator used for secret key generation.
// Boxed to avoid overloading the algorithm's type with more generics.
pub(super) rng: Box<dyn rand::Rng>,
pub(super) rng: Box<dyn rand::Rng + Send>,
}
impl<C, N> fmt::Debug for DynamicHoneyBadger<C, N>

View File

@ -32,7 +32,7 @@ pub struct HoneyBadger<C, N: Rand> {
pub(super) remote_epochs: BTreeMap<N, u64>,
/// A random number generator used for secret key generation.
// Boxed to avoid overloading the algorithm's type with more generics.
pub(super) rng: Box<dyn Rng>,
pub(super) rng: Box<dyn Rng + Send>,
/// Represents the optimization strategy to use for output of the `Subset` algorithm.
pub(super) subset_handling_strategy: SubsetHandlingStrategy,
}

View File

@ -185,7 +185,7 @@ impl<D: DistAlgorithm> From<TargetedMessage<D::Message, D::NodeId>> for Step<D>
}
/// A distributed algorithm that defines a message flow.
pub trait DistAlgorithm {
pub trait DistAlgorithm: Send {
/// Unique node identifier.
type NodeId: NodeIdT;
/// The input provided by the user.

View File

@ -7,14 +7,14 @@ use rand;
/// Workaround trait for creating new random number generators
pub trait SubRng {
fn sub_rng(&mut self) -> Box<dyn rand::Rng>;
fn sub_rng(&mut self) -> Box<dyn rand::Rng + Send>;
}
impl<R> SubRng for R
where
R: rand::Rng,
{
fn sub_rng(&mut self) -> Box<dyn rand::Rng> {
fn sub_rng(&mut self) -> Box<dyn rand::Rng + Send> {
// Currently hard-coded to be an `Isaac64Rng`, until better options emerge. This is either
// dependant on `rand` 0.5 support or an API re-design of parts of `threshold_crypto` and
// `hbbft`.