Skip to content

Commit

Permalink
feat: get peer's cached connection
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Jan 20, 2021
1 parent 2ab7d42 commit 1d8f4ab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ impl Endpoint {
}
}

/// Get an existing connection for the peer address.
pub fn get_connection(&self, peer_addr: &SocketAddr) -> Option<Connection> {
if let Some((conn, guard)) = self.connection_pool.get(peer_addr) {
trace!("Using cached connection to peer: {}", peer_addr);
Some(Connection::new(conn, guard))
} else {
None
}
}

/// Connects to another peer.
///
/// Returns `Connection` which is a handle for sending messages to the peer and
Expand Down

0 comments on commit 1d8f4ab

Please sign in to comment.