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
7 changes: 4 additions & 3 deletions Cargo.lock

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

13 changes: 7 additions & 6 deletions iroh/bench/src/iroh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub fn transport_config(max_streams: usize, initial_mtu: u16) -> QuicTransportCo
}

async fn drain_stream(
stream: &mut RecvStream,
mut stream: RecvStream,
read_unordered: bool,
) -> Result<(usize, Duration, u64)> {
let mut read = 0;
Expand All @@ -152,7 +152,8 @@ async fn drain_stream(
let mut num_chunks: u64 = 0;

if read_unordered {
while let Some(chunk) = stream.read_chunk(usize::MAX, false).await.anyerr()? {
let mut stream = stream.into_unordered();
while let Some(chunk) = stream.read_chunk(usize::MAX).await.anyerr()? {
if first_byte {
ttfb = download_start.elapsed();
first_byte = false;
Expand Down Expand Up @@ -224,7 +225,7 @@ pub async fn handle_client_stream(
) -> Result<(TransferResult, TransferResult)> {
let start = Instant::now();

let (mut send_stream, mut recv_stream) = connection
let (mut send_stream, recv_stream) = connection
.open_bi()
.await
.std_context("failed to open stream")?;
Expand All @@ -234,7 +235,7 @@ pub async fn handle_client_stream(
let upload_result = TransferResult::new(start.elapsed(), upload_size, Duration::default(), 0);

let start = Instant::now();
let (size, ttfb, num_chunks) = drain_stream(&mut recv_stream, read_unordered).await?;
let (size, ttfb, num_chunks) = drain_stream(recv_stream, read_unordered).await?;
let download_result = TransferResult::new(start.elapsed(), size as u64, ttfb, num_chunks);

Ok((upload_result, download_result))
Expand All @@ -260,7 +261,7 @@ pub async fn server(endpoint: Endpoint, opt: Opt) -> Result<()> {

server_tasks.push(tokio::spawn(async move {
loop {
let (mut send_stream, mut recv_stream) = match connection.accept_bi().await {
let (mut send_stream, recv_stream) = match connection.accept_bi().await {
Err(ConnectionError::ApplicationClosed(_)) => break,
Err(e) => {
eprintln!("accepting stream failed: {e:?}");
Expand All @@ -271,7 +272,7 @@ pub async fn server(endpoint: Endpoint, opt: Opt) -> Result<()> {
trace!("stream established");

tokio::spawn(async move {
drain_stream(&mut recv_stream, opt.read_unordered).await?;
drain_stream(recv_stream, opt.read_unordered).await?;
send_data_on_stream(&mut send_stream, opt.download_size).await?;
n0_error::Ok(())
});
Expand Down
13 changes: 7 additions & 6 deletions iroh/bench/src/quinn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub fn transport_config(max_streams: usize, initial_mtu: u16) -> TransportConfig
}

async fn drain_stream(
stream: &mut RecvStream,
mut stream: RecvStream,
read_unordered: bool,
) -> Result<(usize, Duration, u64)> {
let mut read = 0;
Expand All @@ -135,7 +135,8 @@ async fn drain_stream(
let mut num_chunks: u64 = 0;

if read_unordered {
while let Some(chunk) = stream.read_chunk(usize::MAX, false).await.anyerr()? {
let mut stream = stream.into_unordered();
while let Some(chunk) = stream.read_chunk(usize::MAX).await.anyerr()? {
if first_byte {
ttfb = download_start.elapsed();
first_byte = false;
Expand Down Expand Up @@ -207,7 +208,7 @@ pub async fn handle_client_stream(
) -> Result<(TransferResult, TransferResult)> {
let start = Instant::now();

let (mut send_stream, mut recv_stream) = connection
let (mut send_stream, recv_stream) = connection
.open_bi()
.await
.std_context("failed to open stream")?;
Expand All @@ -217,7 +218,7 @@ pub async fn handle_client_stream(
let upload_result = TransferResult::new(start.elapsed(), upload_size, Duration::default(), 0);

let start = Instant::now();
let (size, ttfb, num_chunks) = drain_stream(&mut recv_stream, read_unordered).await?;
let (size, ttfb, num_chunks) = drain_stream(recv_stream, read_unordered).await?;
let download_result = TransferResult::new(start.elapsed(), size as u64, ttfb, num_chunks);

Ok((upload_result, download_result))
Expand All @@ -243,7 +244,7 @@ pub async fn server(endpoint: Endpoint, opt: Opt) -> Result<()> {

server_tasks.push(tokio::spawn(async move {
loop {
let (mut send_stream, mut recv_stream) = match connection.accept_bi().await {
let (mut send_stream, recv_stream) = match connection.accept_bi().await {
Err(::quinn::ConnectionError::ApplicationClosed(_)) => break,
Err(e) => {
eprintln!("accepting stream failed: {e:?}");
Expand All @@ -254,7 +255,7 @@ pub async fn server(endpoint: Endpoint, opt: Opt) -> Result<()> {
trace!("stream established");

tokio::spawn(async move {
drain_stream(&mut recv_stream, opt.read_unordered).await?;
drain_stream(recv_stream, opt.read_unordered).await?;
send_data_on_stream(&mut send_stream, opt.download_size).await?;
n0_error::Ok(())
});
Expand Down
9 changes: 5 additions & 4 deletions iroh/examples/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,15 @@ async fn fetch(endpoint: Endpoint, remote_addr: EndpointAddr) -> Result<()> {
let _guard = watch_conn_type(conn.remote_id(), conn.paths());

// Use the Quinn API to send and recv content.
let (mut send, mut recv) = conn.open_bi().await.anyerr()?;
let (mut send, recv) = conn.open_bi().await.anyerr()?;

let message = format!("{me} is saying hello!");
send.write_all(message.as_bytes()).await.anyerr()?;
// Call `finish` to signal no more data will be sent on this stream.
send.finish().anyerr()?;
println!("Sent: \"{message}\"");

let (len, time_to_first_byte, chnk) = drain_stream(&mut recv, false).await?;
let (len, time_to_first_byte, chnk) = drain_stream(recv, false).await?;

// We received the last message: close all connections and allow for the close
// message to be sent.
Expand All @@ -439,7 +439,7 @@ async fn fetch(endpoint: Endpoint, remote_addr: EndpointAddr) -> Result<()> {
}

async fn drain_stream(
stream: &mut iroh::endpoint::RecvStream,
mut stream: iroh::endpoint::RecvStream,
read_unordered: bool,
) -> Result<(usize, Duration, u64)> {
let mut read = 0;
Expand All @@ -451,7 +451,8 @@ async fn drain_stream(
let mut num_chunks: u64 = 0;

if read_unordered {
while let Some(chunk) = stream.read_chunk(usize::MAX, false).await.anyerr()? {
let mut stream = stream.into_unordered();
while let Some(chunk) = stream.read_chunk(usize::MAX).await.anyerr()? {
if first_byte {
time_to_first_byte = download_start.elapsed();
first_byte = false;
Expand Down
2 changes: 1 addition & 1 deletion iroh/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn simple_endpoint_id_based_connection_transfer() -> Result {

let (mut send, mut recv) = conn.accept_bi().await.anyerr()?;
let mut bytes_sent = 0;
while let Some(chunk) = recv.read_chunk(10_000, true).await.anyerr()? {
while let Some(chunk) = recv.read_chunk(10_000).await.anyerr()? {
bytes_sent += chunk.bytes.len();
send.write_chunk(chunk.bytes).await.anyerr()?;
}
Expand Down
Loading