Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
refactor: fix clippy errors with version 1.50.0 of rust
Browse files Browse the repository at this point in the history
BREAKING CHANGE: this changes the return type of State::new
  • Loading branch information
lionel-faber committed Feb 15, 2021
1 parent 92856cd commit b6b385a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 22 deletions.
20 changes: 10 additions & 10 deletions src/routing/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) async fn initial(

let span = trace_span!("bootstrap::initial", name = %node.name());

let state = State::new(node, send_tx, recv_rx)?;
let state = State::new(node, send_tx, recv_rx);

future::join(
state.run(vec![bootstrap_addr], None),
Expand Down Expand Up @@ -82,7 +82,7 @@ pub(crate) async fn relocate(

let span = trace_span!("bootstrap::relocate", name = %node.name());

let state = State::new(node, send_tx, recv_rx)?;
let state = State::new(node, send_tx, recv_rx);

future::join(
state.run(bootstrap_addrs, Some(relocate_details)),
Expand All @@ -108,13 +108,13 @@ impl<'a> State<'a> {
node: Node,
send_tx: mpsc::Sender<(MessageType, Vec<SocketAddr>)>,
recv_rx: MessageReceiver<'a>,
) -> Result<Self> {
Ok(Self {
) -> Self {
Self {
send_tx,
recv_rx,
node,
backlog: VecDeque::with_capacity(BACKLOG_CAPACITY),
})
}
}

async fn run(
Expand Down Expand Up @@ -587,7 +587,7 @@ mod tests {

let node = Node::new(crypto::gen_keypair(), gen_addr());
let peer = node.peer();
let state = State::new(node, send_tx, recv_rx)?;
let state = State::new(node, send_tx, recv_rx);

// Create the bootstrap task, but don't run it yet.
let bootstrap = async move {
Expand Down Expand Up @@ -673,7 +673,7 @@ mod tests {
let bootstrap_node = Node::new(crypto::gen_keypair(), gen_addr());

let node = Node::new(crypto::gen_keypair(), gen_addr());
let mut state = State::new(node, send_tx, recv_rx)?;
let mut state = State::new(node, send_tx, recv_rx);

let bootstrap_task = state.bootstrap(vec![bootstrap_node.addr], None);
let test_task = async {
Expand Down Expand Up @@ -730,7 +730,7 @@ mod tests {
let bootstrap_node = Node::new(crypto::gen_keypair(), gen_addr());

let node = Node::new(crypto::gen_keypair(), gen_addr());
let mut state = State::new(node, send_tx, recv_rx)?;
let mut state = State::new(node, send_tx, recv_rx);

let bootstrap_task = state.bootstrap(vec![bootstrap_node.addr], None);
let test_task = async {
Expand Down Expand Up @@ -798,7 +798,7 @@ mod tests {
}
};

let mut state = State::new(node, send_tx, recv_rx)?;
let mut state = State::new(node, send_tx, recv_rx);

let bootstrap_task = state.bootstrap(vec![bootstrap_node.addr], None);

Expand Down Expand Up @@ -869,7 +869,7 @@ mod tests {
}
};

let state = State::new(node, send_tx, recv_rx)?;
let state = State::new(node, send_tx, recv_rx);

let section_key = bls::SecretKey::random().public_key();
let elders = (0..ELDER_SIZE)
Expand Down
17 changes: 12 additions & 5 deletions src/routing/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ impl Comm {
) -> Result<Self> {
let quic_p2p = QuicP2p::with_config(Some(transport_config), Default::default(), true)?;

// Don't bootstrap, just create an endpoint where to listen to
// Don't bootstrap, just create an endpoint to listen to
// the incoming messages from other nodes.
let (endpoint, _, incoming_messages, disconnections) = quic_p2p.new_endpoint().await?;
// This also returns the a channel where we can listen for
// disconnection events.
let (endpoint, _incoming_connections, incoming_messages, disconnections) =
quic_p2p.new_endpoint().await?;

let _ = task::spawn(handle_incoming_messages(
incoming_messages,
Expand All @@ -65,7 +68,8 @@ impl Comm {
let quic_p2p = QuicP2p::with_config(Some(transport_config), Default::default(), true)?;

// Bootstrap to the network returning the connection to a node.
let (endpoint, _, incoming_messages, disconnections, bootstrap_addr) =
// We can use the returned channels to listen for incoming messages and disconnection events
let (endpoint, _incoming_connections, incoming_messages, disconnections, bootstrap_addr) =
quic_p2p.bootstrap().await?;

let _ = task::spawn(handle_incoming_messages(
Expand Down Expand Up @@ -111,7 +115,10 @@ impl Comm {
self.endpoint
.send_message(msg, recipient)
.await
.map_err(|_| SendError)
.map_err(|err| {
error!("{}", err);
SendError
})
}

/// Sends a message to multiple recipients. Attempts to send to `delivery_group_size`
Expand Down Expand Up @@ -197,7 +204,7 @@ impl Comm {

// Low-level send
async fn send_to(&self, recipient: &SocketAddr, msg: Bytes) -> Result<(), qp2p::Error> {
// This will attempt to used a cached connection
// This will attempt to use a cached connection
if self
.endpoint
.send_message(msg.clone(), recipient)
Expand Down
32 changes: 28 additions & 4 deletions tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ async fn test_genesis_node() -> Result<()> {

assert_eq!(pub_key, node.public_key().await);

assert_next_event!(event_stream, Event::EldersChanged { self_status_change: NodeElderChange::Promoted, .. });
assert_next_event!(
event_stream,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
);

assert!(node.is_elder().await);

Expand All @@ -46,7 +52,13 @@ async fn test_node_bootstrapping() -> Result<()> {

// spawn genesis node events listener
let genesis_handler = tokio::spawn(async move {
assert_next_event!(event_stream, Event::EldersChanged { self_status_change: NodeElderChange::Promoted, .. });
assert_next_event!(
event_stream,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
);
assert_next_event!(event_stream, Event::MemberJoined { .. });
// TODO: we should expect `EldersChanged` too.
// assert_next_event!(event_stream, Event::EldersChanged { self_status_change: NodeElderChange::Promoted, .. });
Expand Down Expand Up @@ -81,7 +93,13 @@ async fn test_startup_section_bootstrapping() -> Result<()> {
let genesis_contact = genesis_node.our_connection_info();
let nodes_joining_tasks = (0..other_node_count).map(|_| async {
let (node, mut event_stream) = create_node(config_with_contact(genesis_contact)).await?;
assert_event!(event_stream, Event::EldersChanged { self_status_change: NodeElderChange::Promoted, .. });
assert_event!(
event_stream,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
);
Ok::<_, Error>(node)
});
let other_nodes = future::try_join_all(nodes_joining_tasks).await?;
Expand Down Expand Up @@ -121,7 +139,13 @@ async fn test_startup_elders() -> Result<()> {
return;
}

assert_event!(stream, Event::EldersChanged { self_status_change: NodeElderChange::Promoted, .. })
assert_event!(
stream,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
)
}))
.await;

Expand Down
8 changes: 7 additions & 1 deletion tests/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ async fn test_node_drop() -> Result<()> {
let mut nodes = create_connected_nodes(3).await?;

for (_, events) in &mut nodes[1..] {
assert_event!(events, Event::EldersChanged { self_status_change: NodeElderChange::Promoted, .. });
assert_event!(
events,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
);
}

// Wait for the DKG(s) to complete, to make sure there are no more messages being exchanged
Expand Down
8 changes: 7 additions & 1 deletion tests/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ async fn test_messages_between_nodes() -> Result<()> {
// start a second node which sends a message to the first node
let (node2, mut event_stream) = create_node(config_with_contact(node1_contact)).await?;

assert_event!(event_stream, Event::EldersChanged { self_status_change: NodeElderChange::Promoted, .. });
assert_event!(
event_stream,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
);

let node2_name = node2.name().await;

Expand Down
8 changes: 7 additions & 1 deletion tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ pub async fn create_connected_nodes(count: usize) -> Result<Vec<(Routing, EventS
..Default::default()
})
.await?;
assert_next_event!(event_stream, Event::EldersChanged { self_status_change: NodeElderChange::Promoted, .. });
assert_next_event!(
event_stream,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
);

let bootstrap_contact = node.our_connection_info();

Expand Down

0 comments on commit b6b385a

Please sign in to comment.