Skip to content

Commit

Permalink
Merge 447d5f2 into 7736504
Browse files Browse the repository at this point in the history
  • Loading branch information
connec committed Sep 17, 2021
2 parents 7736504 + 447d5f2 commit 2055fd6
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 124 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ on: [pull_request]

jobs:
lint:
if: github.repository_owner == 'maidsafe'
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@f114310111fdbd07e99f47f9ca13d62b3ec98372
- uses: wagoid/commitlint-github-action@59203cb6ee1ce85035e6fe7b3aa878cf80653739
7 changes: 4 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,17 @@ jobs:
!startsWith(github.event.pull_request.title, 'Automated version bump')
name: Unused dependency check
runs-on: ubuntu-latest
env:
CARGO_HTTP_MULTIPLEXING: 'false'
RUSTFLAGS: ''
steps:
- uses: actions/checkout@v2
# Install Rust and required components
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true

- name: Run cargo-udeps
uses: aig787/cargo-udeps-action@v1
uses: aig787/cargo-udeps-action@1cd634a329e14ccfbccfe7c96497d14dac24a743
with:
version: 'latest'
args: '--all-targets'
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub const DEFAULT_INITIAL_RETRY_INTERVAL: Duration = Duration::from_millis(500);
/// gives 5-6 retries in ~30 s total retry time.
pub const DEFAULT_MAX_RETRY_INTERVAL: Duration = Duration::from_secs(15);

/// Default for [`RetryConfig::retry_interval_multiplier`] (x1.5).
/// Default for [`RetryConfig::retry_delay_multiplier`] (x1.5).
///
/// Together with the default max and initial,
/// gives 5-6 retries in ~30 s total retry time.
Expand Down
5 changes: 2 additions & 3 deletions src/connection_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,11 @@ struct Store<I: ConnId> {
id_gen: IdGen,
}

/// Unique key identifying a connection. Two connections will always have distict keys even if they
/// have the same socket address.
/// An application-defined identifier for a connection.
pub trait ConnId:
Clone + Copy + Eq + PartialEq + Ord + PartialOrd + Default + Send + Sync + 'static
{
/// Generate
/// Generate an ID for the given `SocketAddr`.
fn generate(socket_addr: &SocketAddr) -> Self;
}

Expand Down
27 changes: 21 additions & 6 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ use tokio::sync::mpsc::{Receiver, Sender};
use tokio::time::{timeout, Duration};
use tracing::{trace, warn};

/// Connection instance to a node which can be used to send messages to it
/// A connection between two [`Endpoint`]s.
///
/// This is backed by an `Arc` and a small amount of metadata, so cloning is fairly cheap. The
/// connection is also pooled, meaning the same underlying connection will be used when connecting
/// multiple times to the same peer. If an error occurs on the connection, it will be removed from
/// the pool. See the documentation of [`Endpoint::connect_to`] for more details about connection
/// pooling.
///
/// [`Endpoint`]: crate::Endpoint
/// [`Endpoint::connect_to`]: crate::Endpoint::connect_to
#[derive(Clone)]
pub(crate) struct Connection<I: ConnId> {
pub struct Connection<I: ConnId> {
quic_conn: quinn::Connection,
remover: ConnectionRemover<I>,
}
Expand All @@ -45,6 +54,16 @@ impl<I: ConnId> Connection<I> {
Self { quic_conn, remover }
}

/// Get the ID under which the connection is stored in the pool.
pub fn id(&self) -> I {
self.remover.id()
}

/// Get the address of the connected peer.
pub fn remote_address(&self) -> SocketAddr {
self.quic_conn.remote_address()
}

/// Priority default is 0. Both lower and higher can be passed in.
pub(crate) async fn open_bi(
&self,
Expand Down Expand Up @@ -81,10 +100,6 @@ impl<I: ConnId> Connection<I> {
}
}

pub(crate) fn remote_address(&self) -> SocketAddr {
self.quic_conn.remote_address()
}

async fn handle_error<T, E>(&self, result: Result<T, E>) -> Result<T, E> {
if result.is_err() {
self.remover.remove().await
Expand Down
Loading

0 comments on commit 2055fd6

Please sign in to comment.