Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

SecretStore: exclusive sessions #6624

Merged
merged 5 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ impl Cluster for SessionKeyGenerationTransport {
debug_assert!(self.other_nodes_ids.contains(to));
self.cluster.send(to, self.map_message(message)?)
}

fn is_connected(&self, node: &NodeId) -> bool {
self.cluster.is_connected(node)
}

fn nodes(&self) -> BTreeSet<NodeId> {
self.cluster.nodes()
}
}

impl SessionCore {
Expand Down
33 changes: 23 additions & 10 deletions secret_store/src/key_server_cluster/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ pub trait Cluster: Send + Sync {
fn broadcast(&self, message: Message) -> Result<(), Error>;
/// Send message to given node.
fn send(&self, to: &NodeId, message: Message) -> Result<(), Error>;
/// Is connected to given node?
fn is_connected(&self, node: &NodeId) -> bool;
/// Get a set of connected nodes.
fn nodes(&self) -> BTreeSet<NodeId>;
}

/// Cluster initialization parameters.
Expand Down Expand Up @@ -1287,14 +1291,6 @@ impl ClusterView {
})),
}
}

pub fn is_connected(&self, node: &NodeId) -> bool {
self.core.lock().nodes.contains(node)
}

pub fn nodes(&self) -> BTreeSet<NodeId> {
self.core.lock().nodes.clone()
}
}

impl Cluster for ClusterView {
Expand All @@ -1315,6 +1311,14 @@ impl Cluster for ClusterView {
core.cluster.spawn(connection.send_message(message));
Ok(())
}

fn is_connected(&self, node: &NodeId) -> bool {
self.core.lock().nodes.contains(node)
}

fn nodes(&self) -> BTreeSet<NodeId> {
self.core.lock().nodes.clone()
}
}

impl ClusterClientImpl {
Expand Down Expand Up @@ -1460,7 +1464,7 @@ fn make_socket_address(address: &str, port: u16) -> Result<SocketAddr, Error> {
pub mod tests {
use std::sync::Arc;
use std::time;
use std::collections::VecDeque;
use std::collections::{BTreeSet, VecDeque};
use parking_lot::Mutex;
use tokio_core::reactor::Core;
use ethkey::{Random, Generator, Public};
Expand Down Expand Up @@ -1517,6 +1521,15 @@ pub mod tests {
self.data.lock().messages.push_back((to.clone(), message));
Ok(())
}

fn is_connected(&self, node: &NodeId) -> bool {
let data = self.data.lock();
&self.id == node || data.nodes.contains(node)
}

fn nodes(&self) -> BTreeSet<NodeId> {
self.data.lock().nodes.iter().cloned().collect()
}
}

pub fn loop_until<F>(core: &mut Core, timeout: time::Duration, predicate: F) where F: Fn() -> bool {
Expand Down Expand Up @@ -1621,7 +1634,7 @@ pub mod tests {
fn generation_session_completion_signalled_if_failed_on_master() {
//::logger::init_log();
let mut core = Core::new().unwrap();
let clusters = make_clusters(&core, 6023, 3);
let clusters = make_clusters(&core, 6025, 3);
run_clusters(&clusters);
loop_until(&mut core, time::Duration::from_millis(300), || clusters.iter().all(all_connections_established));

Expand Down
Loading