Skip to content

Commit

Permalink
refactor!: Use ConnectionError when possible
Browse files Browse the repository at this point in the history
This changes the public `Endpoint` methods `connect_to` and
`open_bidirectional_stream` to use `ConnectionError` for errors. This
reduces the scope of errors for callers to handle, and sets us up for
further reductions with other methods.

BREAKING CHANGE: `Endpoint::connect_to` and
`Endpoint::open_bidirectional_stream` now use `ConnectionError`, rather
than `Error`, for error results.
  • Loading branch information
Chris Connelly authored and connec committed Aug 27, 2021
1 parent be8874f commit db74509
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::Endpoint;

use super::{
connection_pool::{ConnId, ConnectionPool, ConnectionRemover},
error::{Error, Result},
error::{ConnectionError, Error, Result},
wire_msg::WireMsg,
};
use bytes::Bytes;
Expand Down Expand Up @@ -45,7 +45,10 @@ impl<I: ConnId> Connection<I> {
}

/// Priority default is 0. Both lower and higher can be passed in.
pub(crate) async fn open_bi(&self, priority: i32) -> Result<(SendStream, RecvStream)> {
pub(crate) async fn open_bi(
&self,
priority: i32,
) -> Result<(SendStream, RecvStream), ConnectionError> {
let (send_stream, recv_stream) = self.handle_error(self.quic_conn.open_bi().await).await?;
let send_stream = SendStream::new(send_stream);
send_stream.set_priority(priority);
Expand Down
4 changes: 2 additions & 2 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl<I: ConnId> Endpoint<I> {
/// When sending a message on `Connection` fails, the connection is also automatically removed
/// from the pool and the subsequent call to `connect_to` is guaranteed to reopen new connection
/// too.
pub async fn connect_to(&self, node_addr: &SocketAddr) -> Result<()> {
pub async fn connect_to(&self, node_addr: &SocketAddr) -> Result<(), ConnectionError> {
let _ = self.get_or_connect_to(node_addr).await?;
Ok(())
}
Expand Down Expand Up @@ -468,7 +468,7 @@ impl<I: ConnId> Endpoint<I> {
&self,
peer_addr: &SocketAddr,
priority: i32,
) -> Result<(SendStream, RecvStream)> {
) -> Result<(SendStream, RecvStream), ConnectionError> {
let connection = self.get_or_connect_to(peer_addr).await?;
connection.open_bi(priority).await
}
Expand Down

0 comments on commit db74509

Please sign in to comment.