Skip to content

Commit

Permalink
refactor!: Make Endpoint::disconnect_from infallible
Browse files Browse the repository at this point in the history
This function can never return an error.

BREAKING CHANGE: `Endpoint::disconnect_from` now returns `()`.
  • Loading branch information
Chris Connelly authored and connec committed Aug 27, 2021
1 parent 2386486 commit 9eb947f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,14 @@ impl<I: ConnId> Endpoint<I> {
}

/// Removes all existing connections to a given peer
pub async fn disconnect_from(&self, peer_addr: &SocketAddr) -> Result<()> {
pub async fn disconnect_from(&self, peer_addr: &SocketAddr) {
self.connection_pool
.remove(peer_addr)
.await
.iter()
.for_each(|conn| {
conn.close(0u8.into(), b"");
});
Ok(())
}

/// Connects to another peer, retries for `config.retry_duration_msec` if the connection fails.
Expand Down
4 changes: 2 additions & 2 deletions src/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async fn disconnection() -> Result<()> {
}

// After Alice disconnects from Bob both peers should receive the disconnected event.
alice.disconnect_from(&bob_addr).await?;
alice.disconnect_from(&bob_addr).await;

if let Some(disconnected_peer) = alice_disconnections.next().await {
assert_eq!(disconnected_peer, bob_addr);
Expand Down Expand Up @@ -271,7 +271,7 @@ async fn simultaneous_incoming_and_outgoing_connections() -> Result<()> {
}

// Drop the connection initiated by Bob.
bob.disconnect_from(&alice_addr).await?;
bob.disconnect_from(&alice_addr).await;

// It should be closed on Alice's side too.
if let Some(disconnected_peer) = alice_disconnections.next().await {
Expand Down

0 comments on commit 9eb947f

Please sign in to comment.