Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions iroh/bench/src/iroh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,20 @@ pub async fn connect_client(
pub fn transport_config(max_streams: usize, initial_mtu: u16) -> QuicTransportConfig {
// High stream windows are chosen because the amount of concurrent streams
// is configurable as a parameter.
let mut config = QuicTransportConfig::default();
config.max_concurrent_uni_streams(max_streams.try_into().unwrap());
config.initial_mtu(initial_mtu);
let mut builder = QuicTransportConfig::builder()
.max_concurrent_uni_streams(max_streams.try_into().unwrap())
.initial_mtu(initial_mtu);

let mut acks = quinn::AckFrequencyConfig::default();
acks.ack_eliciting_threshold(10u32.into());
config.ack_frequency_config(Some(acks));
builder = builder.ack_frequency_config(Some(acks));

#[cfg(feature = "qlog")]
config.qlog_from_env("bench-iroh");
{
builder = builder.qlog_from_env("bench-iroh");
}

config
builder.build()
}

async fn drain_stream(
Expand Down
7 changes: 5 additions & 2 deletions iroh/examples/0rtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ use std::{env, str::FromStr, time::Instant};

use clap::Parser;
use data_encoding::HEXLOWER;
use iroh::{EndpointId, SecretKey, discovery::Discovery, endpoint::ZeroRttStatus};
use iroh::{
EndpointId, SecretKey,
discovery::Discovery,
endpoint::{RecvStream, SendStream, ZeroRttStatus},
};
use n0_error::{Result, StackResultExt, StdResultExt};
use n0_future::StreamExt;
use quinn::{RecvStream, SendStream};
use tracing::{info, trace};

const PINGPONG_ALPN: &[u8] = b"0rtt-pingpong";
Expand Down
5 changes: 3 additions & 2 deletions iroh/examples/auth-hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ mod auth {

use iroh::{
Endpoint, EndpointAddr, EndpointId,
endpoint::{AfterHandshakeOutcome, BeforeConnectOutcome, Connection, EndpointHooks},
endpoint::{
AfterHandshakeOutcome, BeforeConnectOutcome, Connection, ConnectionError, EndpointHooks,
},
protocol::{AcceptError, ProtocolHandler},
};
use n0_error::{AnyError, Result, StackResultExt, StdResultExt, anyerr};
use n0_future::task::AbortOnDropHandle;
use quinn::ConnectionError;
use tokio::{
sync::{mpsc, oneshot},
task::JoinSet,
Expand Down
7 changes: 4 additions & 3 deletions iroh/examples/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ impl EndpointArgs {

#[cfg(feature = "qlog")]
{
let mut transport_config = iroh::endpoint::QuicTransportConfig::default();
transport_config.qlog_from_env("transfer");
builder = builder.transport_config(transport_config)
let cfg = iroh::endpoint::QuicTransportConfig::builder()
.qlog_from_env("transfer")
.build();
builder = builder.transport_config(cfg)
}

let endpoint = builder.alpns(vec![TRANSFER_ALPN.to_vec()]).bind().await?;
Expand Down
9 changes: 5 additions & 4 deletions iroh/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,11 @@ mod tests {
.await;

// 10x faster test via a 3s idle timeout instead of the 30s default
let mut config = QuicTransportConfig::default();
config.keep_alive_interval(Duration::from_secs(1));
config.max_idle_timeout(Some(IdleTimeout::try_from(Duration::from_secs(3)).unwrap()));
let opts = ConnectOptions::new().with_transport_config(config);
let cfg = QuicTransportConfig::builder()
.keep_alive_interval(Duration::from_secs(1))
.max_idle_timeout(Some(IdleTimeout::try_from(Duration::from_secs(3)).unwrap()))
.build();
let opts = ConnectOptions::new().with_transport_config(cfg);

let res = ep2
.connect_with_opts(ep1.id(), TEST_ALPN, opts)
Expand Down
79 changes: 44 additions & 35 deletions iroh/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
mod connection;
pub(crate) mod hooks;
pub mod presets;
mod quic;
pub(crate) mod quic;

pub use hooks::{AfterHandshakeOutcome, BeforeConnectOutcome, EndpointHooks};

Expand All @@ -55,17 +55,20 @@ pub use self::{
Accept, Accepting, AlpnError, AuthenticationError, Connecting, ConnectingError, Connection,
ConnectionInfo, ConnectionState, HandshakeCompleted, Incoming, IncomingZeroRtt,
IncomingZeroRttConnection, OutgoingZeroRtt, OutgoingZeroRttConnection,
RemoteEndpointIdError, ZeroRttStatus,
RemoteEndpointIdError, RetryError, ZeroRttStatus,
},
quic::{
AcceptBi, AcceptUni, AckFrequencyConfig, AeadKey, ApplicationClose, Chunk, ClosedStream,
ConnectionClose, ConnectionError, ConnectionStats, Controller, ControllerFactory,
CryptoError, CryptoServerConfig, ExportKeyingMaterialError, FrameStats, HandshakeTokenKey,
IdleTimeout, MtuDiscoveryConfig, OpenBi, OpenUni, PathStats, QuicTransportConfig,
ReadDatagram, ReadError, ReadExactError, ReadToEndError, RecvStream, ResetError,
RetryError, SendDatagramError, SendStream, ServerConfig, Side, StoppedError, StreamId,
TransportError, TransportErrorCode, UdpStats, UnsupportedVersion, VarInt,
VarIntBoundsExceeded, WeakConnectionHandle, WriteError, Written,
Codec, ConnectionClose, ConnectionError, ConnectionStats, Controller, ControllerFactory,
ControllerMetrics, CryptoError, Dir, ExportKeyingMaterialError, FrameStats, FrameType,
HandshakeTokenKey, HeaderKey, IdleTimeout, Keys, MtuDiscoveryConfig, OpenBi, OpenUni,
PacketKey, PathId, PathStats, QuicConnectError, QuicTransportConfig,
QuicTransportConfigBuilder, ReadDatagram, ReadError, ReadExactError, ReadToEndError,
RecvStream, ResetError, RttEstimator, SendDatagram, SendDatagramError, SendStream,
ServerConfig, ServerConfigBuilder, Side, StoppedError, StreamId, TimeSource, TokenLog,
TokenReuseError, TransportError, TransportErrorCode, TransportParameters, UdpStats,
UnorderedRecvStream, UnsupportedVersion, ValidationTokenConfig, VarInt,
VarIntBoundsExceeded, WriteError, Written,
},
};
pub use crate::magicsock::transports::TransportConfig;
Expand Down Expand Up @@ -468,15 +471,14 @@ struct StaticConfig {
}

impl StaticConfig {
/// Create a [`quinn::ServerConfig`] with the specified ALPN protocols.
fn create_server_config(&self, alpn_protocols: Vec<Vec<u8>>) -> ServerConfig {
/// Create a [`ServerConfig`] with the specified ALPN protocols.
fn create_server_config(&self, alpn_protocols: Vec<Vec<u8>>) -> quinn_proto::ServerConfig {
let quic_server_config = self
.tls_config
.make_server_config(alpn_protocols, self.keylog);
let mut server_config = ServerConfig::with_crypto(Arc::new(quic_server_config));
server_config.transport_config(self.transport_config.to_arc());

server_config
let mut inner = quinn::ServerConfig::with_crypto(Arc::new(quic_server_config));
inner.transport_config(self.transport_config.to_inner_arc());
inner
}
}

Expand Down Expand Up @@ -525,7 +527,7 @@ pub enum ConnectWithOptsError {
#[error("Unable to connect to remote")]
Quinn {
#[error(std_err)]
source: quinn_proto::ConnectError,
source: QuicConnectError,
},
#[error("Internal consistency error")]
InternalConsistencyError {
Expand Down Expand Up @@ -715,8 +717,8 @@ impl Endpoint {

let transport_config = options
.transport_config
.map(|cfg| cfg.to_arc())
.unwrap_or(self.static_config.transport_config.to_arc());
.map(|cfg| cfg.to_inner_arc())
.unwrap_or(self.static_config.transport_config.to_inner_arc());

// Start connecting via quinn. This will time out after 10 seconds if no reachable
// address is available.
Expand Down Expand Up @@ -1144,6 +1146,15 @@ impl Endpoint {
self.msock.is_closed()
}

/// Create a [`ServerConfigBuilder`] for this endpoint that includes the given alpns.
///
/// Use the [`ServerConfigBuilder`] to customize the [`ServerConfig`] connection configuration
/// for a connection accepted using the [`Incoming::accept_with`] method.
pub fn create_server_config_builder(&self, alpns: Vec<Vec<u8>>) -> ServerConfigBuilder {
let inner = self.static_config.create_server_config(alpns);
ServerConfigBuilder::new(inner, self.static_config.transport_config.clone())
}

// # Remaining private methods

#[cfg(test)]
Expand Down Expand Up @@ -1313,7 +1324,6 @@ mod tests {
use n0_future::{BufferedStreamExt, StreamExt, stream, time};
use n0_tracing_test::traced_test;
use n0_watcher::Watcher;
use quinn::ConnectionError;
use rand::SeedableRng;
use tokio::sync::oneshot;
use tracing::{Instrument, debug_span, info, info_span, instrument};
Expand All @@ -1322,7 +1332,7 @@ mod tests {
use crate::{
RelayMap, RelayMode,
discovery::static_provider::StaticProvider,
endpoint::{ConnectOptions, Connection},
endpoint::{ApplicationClose, ConnectOptions, Connection, ConnectionError},
protocol::{AcceptError, ProtocolHandler, Router},
test_utils::{QlogFileGroup, run_relay_server, run_relay_server_with},
};
Expand Down Expand Up @@ -1380,13 +1390,13 @@ mod tests {
conn.close(7u8.into(), b"bye");

let res = conn.accept_uni().await;
assert_eq!(res.unwrap_err(), quinn::ConnectionError::LocallyClosed);
assert_eq!(res.unwrap_err(), ConnectionError::LocallyClosed);

let res = stream.read_to_end(10).await;
assert_eq!(
res.unwrap_err(),
quinn::ReadToEndError::Read(quinn::ReadError::ConnectionLost(
quinn::ConnectionError::LocallyClosed
ConnectionError::LocallyClosed
))
);
info!("server test completed");
Expand Down Expand Up @@ -1417,11 +1427,10 @@ mod tests {
info!("waiting for closed");
// Remote now closes the connection, we should see an error sometime soon.
let err = conn.closed().await;
let expected_err =
quinn::ConnectionError::ApplicationClosed(quinn::ApplicationClose {
error_code: 7u8.into(),
reason: b"bye".to_vec().into(),
});
let expected_err = ConnectionError::ApplicationClosed(ApplicationClose {
error_code: 7u8.into(),
reason: b"bye".to_vec().into(),
});
assert_eq!(err, expected_err);

info!("opening new - expect it to fail");
Expand Down Expand Up @@ -1631,7 +1640,7 @@ mod tests {
let ep1_nodeaddr = ep1.addr();

#[instrument(name = "client", skip_all)]
async fn connect(ep: Endpoint, dst: EndpointAddr) -> Result<quinn::ConnectionError> {
async fn connect(ep: Endpoint, dst: EndpointAddr) -> Result<ConnectionError> {
info!(me = %ep.id().fmt_short(), "client starting");
let conn = ep.connect(dst, TEST_ALPN).await?;
let mut send = conn.open_uni().await.anyerr()?;
Expand Down Expand Up @@ -1660,7 +1669,7 @@ mod tests {
let conn_closed = dbg!(ep2_connect.await.anyerr()??);
assert!(matches!(
conn_closed,
ConnectionError::ApplicationClosed(quinn::ApplicationClose { .. })
ConnectionError::ApplicationClosed(ApplicationClose { .. })
));

Ok(())
Expand All @@ -1680,7 +1689,7 @@ mod tests {
relay_map: RelayMap,
node_addr_rx: oneshot::Receiver<EndpointAddr>,
qlog: Arc<QlogFileGroup>,
) -> Result<quinn::ConnectionError> {
) -> Result<ConnectionError> {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0u64);
let secret = SecretKey::generate(&mut rng);
let ep = Endpoint::builder()
Expand Down Expand Up @@ -1756,7 +1765,7 @@ mod tests {
let conn_closed = dbg!(client_task.await.anyerr()??);
assert!(matches!(
conn_closed,
ConnectionError::ApplicationClosed(quinn::ApplicationClose { .. })
ConnectionError::ApplicationClosed(ApplicationClose { .. })
));

Ok(())
Expand All @@ -1774,7 +1783,7 @@ mod tests {
async fn connect(
relay_map: RelayMap,
node_addr_rx: oneshot::Receiver<EndpointAddr>,
) -> Result<quinn::ConnectionError> {
) -> Result<ConnectionError> {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0u64);
let secret = SecretKey::generate(&mut rng);
let ep = Endpoint::builder()
Expand Down Expand Up @@ -1853,7 +1862,7 @@ mod tests {
let conn_closed = dbg!(client_task.await.anyerr()??);
assert!(matches!(
conn_closed,
ConnectionError::ApplicationClosed(quinn::ApplicationClose { .. })
ConnectionError::ApplicationClosed(ApplicationClose { .. })
));

Ok(())
Expand Down Expand Up @@ -1920,7 +1929,7 @@ mod tests {
async fn accept(
relay_map: RelayMap,
node_addr_tx: oneshot::Sender<EndpointAddr>,
) -> Result<quinn::ConnectionError> {
) -> Result<ConnectionError> {
let secret = SecretKey::from([1u8; 32]);
let ep = Endpoint::builder()
.secret_key(secret)
Expand Down Expand Up @@ -1968,7 +1977,7 @@ mod tests {
let conn_closed = dbg!(server_task.await.anyerr()??);
assert!(matches!(
conn_closed,
ConnectionError::ApplicationClosed(quinn::ApplicationClose { .. })
ConnectionError::ApplicationClosed(ApplicationClose { .. })
));

Ok(())
Expand Down
Loading
Loading