Skip to content
Closed
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
3,429 changes: 1,693 additions & 1,736 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ rust-version = "1.81"

[dependencies]
anyhow = "1.0.98"
iroh = { version = "0.35", default-features = false }
iroh-quinn-proto = "0.13.0"
n0-future = "0.1.3"
rtp = "0.13"
iroh = { version = "1.0.0", default-features = false, features = ["tls-ring"] }
noq-proto = "1.0.0"
n0-future = "0.3.2"
rtp = "0.17.1"
tokio = { version = "1.45.1", features = ["sync"] }
tokio-util = "0.7.15"
tracing = "0.1.41"
webrtc-util = { version = "0.11", default-features = false, features = [
webrtc-util = { version = "0.17.1", default-features = false, features = [
"marshal",
] }

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ pub use self::{
/// The ALPN used.
pub const ALPN: &[u8] = b"/iroh/roq/1";

pub use iroh_quinn_proto::VarInt;
pub use rtp::{self, packet::Packet as RtpPacket};
2 changes: 1 addition & 1 deletion src/receive_flow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{ensure, Result};
use iroh_quinn_proto::VarInt;
use noq_proto::VarInt;
use rtp::packet::Packet as RtpPacket;
use tokio::sync::mpsc;
use tokio_util::{bytes::Bytes, sync::CancellationToken};
Expand Down
4 changes: 2 additions & 2 deletions src/send_flow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{ensure, Result};
use iroh::endpoint::Connection;
use iroh_quinn_proto::{coding::Codec, VarInt};
use iroh::endpoint::{Connection, VarInt};
use noq_proto::coding::Encodable;
use rtp::packet::Packet as RtpPacket;
use tokio_util::{bytes::BytesMut, sync::CancellationToken};
use tracing::debug;
Expand Down
3 changes: 2 additions & 1 deletion src/send_stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{ensure, Result};
use iroh_quinn_proto::{coding::Codec, VarInt};
use iroh::endpoint::VarInt;
use noq_proto::coding::Encodable;
use rtp::packet::Packet as RtpPacket;
use tokio_util::{bytes::BytesMut, sync::CancellationToken};
use tracing::debug;
Expand Down
27 changes: 14 additions & 13 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{collections::HashMap, sync::Arc};

use anyhow::{bail, Result};
use iroh::endpoint::{Connection, VarInt};
use iroh_quinn_proto::coding::Codec;
use n0_future::task::{self, AbortOnDropHandle, JoinSet};
use noq_proto::coding::Decodable;
use tokio::{
io::{AsyncRead, AsyncReadExt},
sync::{mpsc, Mutex},
Expand Down Expand Up @@ -280,32 +280,33 @@ async fn read_varint<R: AsyncRead + Unpin>(conn: &mut R) -> Result<VarInt> {
#[cfg(test)]
mod tests {
use iroh::Endpoint;
use iroh::endpoint::presets;
use rtp::packet::Packet as RtpPacket;

use super::*;
use crate::ALPN;

#[tokio::test]
async fn test_datagram_flow() -> Result<()> {
let ep1 = Endpoint::builder()
.bind_addr_v4("127.0.0.1:0".parse().unwrap())
let ep1 = Endpoint::builder(presets::Minimal)
.bind_addr("127.0.0.1:0")?
.alpns(vec![ALPN.to_vec()])
.bind()
.await?;
let ep2 = Endpoint::builder()
.bind_addr_v4("127.0.0.1:0".parse().unwrap())
let ep2 = Endpoint::builder(presets::Minimal)
.bind_addr("127.0.0.1:0")?
.alpns(vec![ALPN.to_vec()])
.bind()
.await?;

let flow_id = VarInt::from_u32(0);

let ep2_addr = ep2.node_addr().await?;
let ep2_addr = ep2.addr();

let _handle = task::spawn(async move {
while let Some(incoming) = ep2.accept().await {
if let Ok(connection) = incoming.await {
assert_eq!(connection.alpn().unwrap(), ALPN, "invalid ALPN");
assert_eq!(connection.alpn(), ALPN, "invalid ALPN");

let session = Session::new(connection);
let send_flow = session.new_send_flow(flow_id).await.unwrap();
Expand Down Expand Up @@ -341,25 +342,25 @@ mod tests {

#[tokio::test]
async fn test_session_flow() -> Result<()> {
let ep1 = Endpoint::builder()
.bind_addr_v4("127.0.0.1:0".parse().unwrap())
let ep1 = Endpoint::builder(presets::Minimal)
.bind_addr("127.0.0.1:0")?
.alpns(vec![ALPN.to_vec()])
.bind()
.await?;
let ep2 = Endpoint::builder()
.bind_addr_v4("127.0.0.1:0".parse().unwrap())
let ep2 = Endpoint::builder(presets::Minimal)
.bind_addr("127.0.0.1:0")?
.alpns(vec![ALPN.to_vec()])
.bind()
.await?;

let flow_id = VarInt::from_u32(0);

let ep2_addr = ep2.node_addr().await?;
let ep2_addr = ep2.addr();

let _handle = task::spawn(async move {
while let Some(incoming) = ep2.accept().await {
if let Ok(connection) = incoming.await {
assert_eq!(connection.alpn().unwrap(), ALPN, "invalid ALPN");
assert_eq!(connection.alpn(), ALPN, "invalid ALPN");

let session = Session::new(connection);
let send_flow = session.new_send_flow(flow_id).await.unwrap();
Expand Down
34 changes: 17 additions & 17 deletions tests/opus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::Result;
use iroh::Endpoint;
use iroh_roq::{Session, VarInt, ALPN};
use iroh::endpoint::presets;
use noq_proto::VarInt;
use iroh_roq::{Session, ALPN};
use rtp::packet::Packet as RtpPacket;
use tokio_util::bytes::BytesMut;

Expand All @@ -11,48 +13,47 @@ const MONO_20MS: usize = 48000 * 20 / 1000;
#[test]
fn test_opus_decode_encode() -> Result<()> {
let mut opus_encoder =
opus::Encoder::new(48000, opus::Channels::Stereo, opus::Application::Voip).unwrap();
let mut opus_decoder = opus::Decoder::new(48000, opus::Channels::Stereo).unwrap();
opus::Encoder::new(48000, opus::Channels::Stereo, opus::Application::Voip)?;
let mut opus_decoder = opus::Decoder::new(48000, opus::Channels::Stereo)?;
let mut pcm_raw_data = vec![17_i16; MONO_20MS * 2];
pcm_raw_data[1] = 1;

let mut encoded_opus = vec![0; 1500];
let size = opus_encoder
.encode(&pcm_raw_data, &mut encoded_opus)
.unwrap();
.encode(&pcm_raw_data, &mut encoded_opus)?;
let packet = &encoded_opus[..size];

let mut output = vec![0i16; MONO_20MS * 2];
// decode() returns the number of samples per channel.
assert_eq!(
MONO_20MS,
opus_decoder.decode(packet, &mut output, false).unwrap()
opus_decoder.decode(packet, &mut output, false)?
);

Ok(())
}

#[tokio::test]
async fn test_stream_opus_packets() -> Result<()> {
let ep1 = Endpoint::builder()
.bind_addr_v4("127.0.0.1:0".parse().unwrap())
let ep1 = Endpoint::builder(presets::Minimal)
.bind_addr("127.0.0.1:0")?
.alpns(vec![ALPN.to_vec()])
.bind()
.await?;
let ep2 = Endpoint::builder()
.bind_addr_v4("127.0.0.1:0".parse().unwrap())
let ep2 = Endpoint::builder(presets::Minimal)
.bind_addr("127.0.0.1:0")?
.alpns(vec![ALPN.to_vec()])
.bind()
.await?;

let flow_id = VarInt::from_u32(0);

let ep2_addr = ep2.node_addr().await?;
let ep2_addr = ep2.addr();

let _handle = tokio::task::spawn(async move {
while let Some(incoming) = ep2.accept().await {
if let Ok(connection) = incoming.await {
assert_eq!(connection.alpn().unwrap(), ALPN, "invalid ALPN");
assert_eq!(connection.alpn(), ALPN, "invalid ALPN");

let session = Session::new(connection);
let send_flow = session.new_send_flow(flow_id).await.unwrap();
Expand Down Expand Up @@ -81,11 +82,11 @@ async fn test_stream_opus_packets() -> Result<()> {
let conn = ep1.connect(ep2_addr, ALPN).await?;

let session = Session::new(conn.clone());
let send_flow = session.new_send_flow(flow_id).await.unwrap();
let mut recv_flow = session.new_receive_flow(flow_id).await.unwrap();
let send_flow = session.new_send_flow(flow_id).await?;
let mut recv_flow = session.new_receive_flow(flow_id).await?;

let mut opus_encoder =
opus::Encoder::new(48000, opus::Channels::Stereo, opus::Application::Voip).unwrap();
opus::Encoder::new(48000, opus::Channels::Stereo, opus::Application::Voip)?;

let num_chunks = 8;

Expand All @@ -100,8 +101,7 @@ async fn test_stream_opus_packets() -> Result<()> {
let end = start + chunk_size;
pcm_raw_data[start + 1] = 1;
let size = opus_encoder
.encode(&pcm_raw_data[start..end], &mut payload[..])
.unwrap();
.encode(&pcm_raw_data[start..end], &mut payload[..])?;

payload.truncate(size);

Expand Down
Loading