Skip to content

Commit

Permalink
feat: update quinn to use Endpoint::accept
Browse files Browse the repository at this point in the history
  • Loading branch information
b-zee authored and bochaco committed Dec 12, 2022
1 parent 891b45e commit bb6e610
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
17 changes: 8 additions & 9 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,18 +623,17 @@ mod tests {
use bytes::Bytes;
use color_eyre::eyre::{bail, Result};
use futures::future::OptionFuture;
use quinn::Endpoint as QuinnEndpoint;
use std::time::Duration;

#[tokio::test]
#[tracing_test::traced_test]
async fn basic_usage() -> Result<()> {
let config = InternalConfig::try_from_config(Default::default())?;

let mut peer1 = QuinnEndpoint::server(config.server.clone(), local_addr())?;
let mut peer1 = quinn::Endpoint::server(config.server.clone(), local_addr())?;
peer1.set_default_client_config(config.client);

let peer2 = QuinnEndpoint::server(config.server.clone(), local_addr())?;
let peer2 = quinn::Endpoint::server(config.server.clone(), local_addr())?;

{
let (p1_tx, mut p1_rx) = Connection::new(
Expand Down Expand Up @@ -692,10 +691,10 @@ mod tests {
..Default::default()
})?;

let mut peer1 = QuinnEndpoint::server(config.server.clone(), local_addr())?;
let mut peer1 = quinn::Endpoint::server(config.server.clone(), local_addr())?;
peer1.set_default_client_config(config.client);

let peer2 = QuinnEndpoint::server(config.server.clone(), local_addr())?;
let peer2 = quinn::Endpoint::server(config.server.clone(), local_addr())?;

// open a connection between the two peers
let (p1_tx, _) = Connection::new(
Expand Down Expand Up @@ -738,10 +737,10 @@ mod tests {
async fn test_endpoint_echo() -> Result<()> {
let config = InternalConfig::try_from_config(Config::default())?;

let mut peer1 = QuinnEndpoint::server(config.server.clone(), local_addr())?;
let mut peer1 = quinn::Endpoint::server(config.server.clone(), local_addr())?;
peer1.set_default_client_config(config.client);

let peer2 = QuinnEndpoint::server(config.server.clone(), local_addr())?;
let peer2 = quinn::Endpoint::server(config.server.clone(), local_addr())?;

{
let (p1_tx, _) = Connection::new(
Expand Down Expand Up @@ -789,10 +788,10 @@ mod tests {
async fn endpoint_verification() -> Result<()> {
let config = InternalConfig::try_from_config(Default::default())?;

let mut peer1 = QuinnEndpoint::server(config.server.clone(), local_addr())?;
let mut peer1 = quinn::Endpoint::server(config.server.clone(), local_addr())?;
peer1.set_default_client_config(config.client.clone());

let mut peer2 = QuinnEndpoint::server(config.server.clone(), local_addr())?;
let mut peer2 = quinn::Endpoint::server(config.server.clone(), local_addr())?;
peer2.set_default_client_config(config.client);

{
Expand Down
14 changes: 4 additions & 10 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ impl Endpoint {

let (termination_tx, termination_rx) = broadcast::channel(1);

let (mut quinn_endpoint, quinn_incoming) =
QuinnEndpoint::server(config.server.clone(), local_addr.into())?;
let mut quinn_endpoint = quinn::Endpoint::server(config.server.clone(), local_addr.into())?;

// set client config used for any outgoing connections
quinn_endpoint.set_default_client_config(config.client);
Expand Down Expand Up @@ -129,11 +128,7 @@ impl Endpoint {

let (connection_tx, connection_rx) = mpsc::channel(STANDARD_CHANNEL_SIZE);

listen_for_incoming_connections(
quinn_incoming,
connection_tx,
endpoint.quinn_endpoint.clone(),
);
listen_for_incoming_connections(endpoint.quinn_endpoint.clone(), connection_tx);

if let Some((contact, _)) = contact.as_ref() {
let valid = endpoint
Expand Down Expand Up @@ -420,13 +415,12 @@ impl Endpoint {
}

pub(super) fn listen_for_incoming_connections(
mut quinn_incoming: quinn::Incoming,
connection_tx: mpsc::Sender<(Connection, ConnectionIncoming)>,
quinn_endpoint: quinn::Endpoint,
connection_tx: mpsc::Sender<(Connection, ConnectionIncoming)>,
) {
let _ = tokio::spawn(async move {
loop {
match quinn_incoming.next().await {
match quinn_endpoint.accept().await {
Some(quinn_conn) => match quinn_conn.await {
Ok(connection) => {
let (connection, connection_incoming) =
Expand Down

0 comments on commit bb6e610

Please sign in to comment.