Add `Sync` req. on boxed rngs.

This commit is contained in:
c0gent 2018-10-04 10:08:52 -07:00
parent 4b00bda555
commit d7e87e4601
No known key found for this signature in database
GPG Key ID: 9CC25E71A743E892
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> impl<N, T> DistAlgorithm for Coin<N, T>
where where
N: NodeIdT, N: NodeIdT,
T: Clone + AsRef<[u8]> + Send, T: Clone + AsRef<[u8]> + Send + Sync,
{ {
type NodeId = N; type NodeId = N;
type Input = (); type Input = ();
@ -123,7 +123,7 @@ where
impl<N, T> Coin<N, T> impl<N, T> Coin<N, T>
where where
N: NodeIdT, N: NodeIdT,
T: Clone + AsRef<[u8]> + Send, T: Clone + AsRef<[u8]> + Send + Sync,
{ {
pub fn new(netinfo: Arc<NetworkInfo<N>>, nonce: T) -> Self { pub fn new(netinfo: Arc<NetworkInfo<N>>, nonce: T) -> Self {
Coin { Coin {

View File

@ -39,7 +39,7 @@ pub struct DynamicHoneyBadger<C, N: Rand> {
pub(super) incoming_queue: Vec<(N, Message<N>)>, pub(super) incoming_queue: Vec<(N, Message<N>)>,
/// A random number generator used for secret key generation. /// A random number generator used for secret key generation.
// Boxed to avoid overloading the algorithm's type with more generics. // Boxed to avoid overloading the algorithm's type with more generics.
pub(super) rng: Box<dyn rand::Rng + Send>, pub(super) rng: Box<dyn rand::Rng + Send + Sync>,
} }
impl<C, N> fmt::Debug for DynamicHoneyBadger<C, N> 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>, pub(super) remote_epochs: BTreeMap<N, u64>,
/// A random number generator used for secret key generation. /// A random number generator used for secret key generation.
// Boxed to avoid overloading the algorithm's type with more generics. // Boxed to avoid overloading the algorithm's type with more generics.
pub(super) rng: Box<dyn Rng + Send>, pub(super) rng: Box<dyn Rng + Send + Sync>,
/// Represents the optimization strategy to use for output of the `Subset` algorithm. /// Represents the optimization strategy to use for output of the `Subset` algorithm.
pub(super) subset_handling_strategy: SubsetHandlingStrategy, 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. /// A distributed algorithm that defines a message flow.
pub trait DistAlgorithm: Send { pub trait DistAlgorithm: Send + Sync {
/// Unique node identifier. /// Unique node identifier.
type NodeId: NodeIdT; type NodeId: NodeIdT;
/// The input provided by the user. /// The input provided by the user.

View File

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