Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fb83cc8
feat(iroh): add initial scaffolding for WebRTC support
anchalshivank Aug 18, 2025
908eef3
feat(iroh): add basic webrtc implementation
anchalshivank Aug 19, 2025
676a6b3
Merge branch 'main' into feature/webrtc-wasm-support
anchalshivank Aug 19, 2025
54e9423
feat(webrtc): implement actor and sender
anchalshivank Aug 27, 2025
257bdb5
feat(webrtc): add webrtc poll_recv, webrtc transport and webrtc sender
anchalshivank Sep 2, 2025
3496a19
feat(webrtc): add various builder for different transports
anchalshivank Sep 3, 2025
a559b35
Merge branch 'main' into feature/webrtc-wasm-support
anchalshivank Sep 3, 2025
219915a
fix(webrtc): fix compile errors
anchalshivank Sep 4, 2025
d4ce636
feat(webrtc): add webrtc initiation in ping action for disco
anchalshivank Sep 8, 2025
4a358f2
feat(webrtc): exchange offer via disco
anchalshivank Sep 8, 2025
b87d3f8
chore(webrtc): remove repomix.xml
anchalshivank Sep 10, 2025
7d4cfbd
feat(webrtc): add offer and answer exchange struct
anchalshivank Sep 11, 2025
dd02f37
feat(webrtc): send answer after receiving offer
anchalshivank Sep 12, 2025
b054362
feat(webrtc): add ice exchange
anchalshivank Sep 13, 2025
829a419
feat(webrtc): send ice-candidates
anchalshivank Sep 13, 2025
f446b67
feat(webrtc): exchange ice candidates
anchalshivank Sep 15, 2025
70aed13
feat(webrtc): send data via webrtc p2p
anchalshivank Sep 15, 2025
42264d9
feat(webrtc): refactor code
anchalshivank Sep 16, 2025
5aaf775
feat(webrtc): refactor code
anchalshivank Sep 16, 2025
d5c14a5
Merge branch 'main' into feature/webrtc-wasm-support
anchalshivank Sep 16, 2025
b00e5ac
feat(webrtc): fix compilation errors
anchalshivank Sep 16, 2025
4540a68
chore(webrtc): remove unneccesary code
anchalshivank Sep 16, 2025
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
6 changes: 5 additions & 1 deletion iroh/src/disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ use std::{
};

use data_encoding::HEXLOWER;
use iroh_base::{PublicKey, RelayUrl};
use iroh_base::{NodeId, PublicKey, RelayUrl};
use nested_enum_utils::common_fields;
use serde::{Deserialize, Serialize};
use snafu::{Snafu, ensure};
use url::Url;

use crate::magicsock::transports;
use crate::magicsock::transports::Addr;

// TODO: custom magicn
/// The 6 byte header of all discovery messages.
Expand Down Expand Up @@ -143,6 +144,8 @@ pub enum SendAddr {
Udp(SocketAddr),
/// Relay Url.
Relay(RelayUrl),
/// Node Id
NodeId(NodeId)
}

impl SendAddr {
Expand All @@ -165,6 +168,7 @@ impl From<transports::Addr> for SendAddr {
match addr {
transports::Addr::Ip(addr) => SendAddr::Udp(addr),
transports::Addr::Relay(url, _) => SendAddr::Relay(url),
Addr::WebRtc(relay_url, dest_id, channel_id) => SendAddr::
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions iroh/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,12 @@ impl MagicSock {
.recv_data_relay
.inc_by(datagram.len() as _);
}
transports::Addr::WebRtc(..) => {
self.metrics
.magicsock
.recv_data_webrtc
.inc_by(datagram.len() as _);
}
}

quic_datagram_count += 1;
Expand Down Expand Up @@ -719,6 +725,11 @@ impl MagicSock {
let quic_mapped_addr = self.node_map.receive_relay(src_url, *src_node);
quinn_meta.addr = quic_mapped_addr.private_socket_addr();
}
transports::Addr::WebRtc(relay_url, node_id, channel_id) => {

todo!("implemnet webrtc processing")

}
}
} else {
// If all datagrams in this buf are DISCO, set len to zero to make
Expand Down
46 changes: 45 additions & 1 deletion iroh/src/magicsock/transports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
task::{Context, Poll},
};

use crate::magicsock::transports::webrtc::WebRtcTransport;
use crate::magicsock::transports::webrtc::{WebRtcSender, WebRtcTransport};
use iroh_base::{NodeId, RelayUrl};
use n0_watcher::Watcher;
use relay::{RelayNetworkChangeSender, RelaySender};
Expand Down Expand Up @@ -235,13 +235,15 @@ impl Transports {
#[cfg(not(wasm_browser))]
let ip = self.ip.iter().map(|t| t.create_sender()).collect();
let relay = self.relay.iter().map(|t| t.create_sender()).collect();
let webrtc = self.web_rtc.iter().map(|t| t.create_sender()).collect();
let max_transmit_segments = self.max_transmit_segments();

UdpSender {
#[cfg(not(wasm_browser))]
ip,
msock,
relay,
webrtc,
max_transmit_segments,
}
}
Expand Down Expand Up @@ -317,8 +319,12 @@ pub(crate) struct Transmit<'a> {
pub(crate) enum Addr {
Ip(SocketAddr),
Relay(RelayUrl, NodeId),
WebRtc(RelayUrl, NodeId, ChannelId),
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ChannelId(Option<u16>);

impl Default for Addr {
fn default() -> Self {
Self::Ip(SocketAddr::V6(SocketAddrV6::new(
Expand Down Expand Up @@ -352,6 +358,7 @@ impl Addr {
match self {
Self::Ip(ip) => Some(ip),
Self::Relay(..) => None,
Self::WebRtc(relay_url, node_id, channel_id) => None,
}
}
}
Expand All @@ -362,6 +369,7 @@ pub(crate) struct UdpSender {
#[cfg(not(wasm_browser))]
ip: Vec<IpSender>,
relay: Vec<RelaySender>,
webrtc: Vec<WebRtcSender>,
max_transmit_segments: usize,
}

Expand Down Expand Up @@ -409,6 +417,19 @@ impl UdpSender {
}
}
}
Addr::WebRtc(relay_url, node_id, channel_id) => {

for sender in &self.webrtc {
match sender.send(*node_id,transmit, channel_id).await{
Ok(()) => {
return Ok(());
}
Err(err) => {
warn!("webrtc failed to send: {:?}", err);
}
}
}
}
}
if any_match {
Err(io::Error::other("all available transports failed"))
Expand Down Expand Up @@ -452,6 +473,17 @@ impl UdpSender {
}
}
}
Addr::WebRtc(relay_url, node_id, channel_id) => {

for sender in &mut self.webrtc {
match sender.poll_send(cx, *node_id, transmit, channel_id){
Poll::Ready(res) => { return Poll::Ready(res) },
Poll::Pending => {}
}
}

}

}
Poll::Pending
}
Expand Down Expand Up @@ -493,6 +525,18 @@ impl UdpSender {
}
}
}
Addr::WebRtc(relay_url, node_id, channel_id) => {
for transport in &self.webrtc {

match transport.try_send(*node_id, transmit, channel_id) {
Ok(()) => return Ok(()),
Err(_err) => {
continue;
}
}

}
}
}
Err(io::Error::new(
io::ErrorKind::WouldBlock,
Expand Down
Loading