Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6840253
minor: simplify naming, add docs
dmitry-markin Aug 10, 2026
fc2de85
Use `AddressPair` to identify WebRTC sessions everywhere
dmitry-markin Aug 10, 2026
3040120
Switch to `quinn-udp` sockets
dmitry-markin Aug 10, 2026
b9ec8fc
Use dst packet address & allow wildcard listeners
dmitry-markin Aug 10, 2026
2a02c23
Get rid of socket map
dmitry-markin Aug 10, 2026
b1f1778
Extract `build_listen_addresses`
dmitry-markin Aug 10, 2026
96d8014
Set source address when sending packets
dmitry-markin Aug 10, 2026
878e4da
`WebRtcSocket` unit tests
dmitry-markin Aug 11, 2026
9e91556
`WebRtcListener` tests
dmitry-markin Aug 11, 2026
f69d96a
minor: fix `Config::listen_addresses` doc
dmitry-markin Aug 11, 2026
fad4c90
minor: unify access level & fix buffer capacity doc
dmitry-markin Aug 11, 2026
1a7741a
Support custom number of GRO segments
dmitry-markin Aug 11, 2026
98649d3
Warn instead of failure on interface enumeration error
dmitry-markin Aug 11, 2026
5c488fe
Downgrade `WouldBlock` to `trace!`
dmitry-markin Aug 11, 2026
ceabaf8
WebRTC listen addresses integartion test
dmitry-markin Aug 11, 2026
56927c3
minor: listener license plate
dmitry-markin Aug 11, 2026
8cb20d6
Merge remote-tracking branch 'origin/master' into dm-webrtc-wildcard
dmitry-markin Aug 11, 2026
4f5dde2
minor: `WebRtcSocket` doc
dmitry-markin Aug 12, 2026
e9b5a37
Expose `DtlsCertificate::certhash_b64`
dmitry-markin Aug 13, 2026
5abaf8a
minor: fix compilation
dmitry-markin Aug 13, 2026
7648eba
Downgrade 'start webrtc' log to debug
dmitry-markin Aug 13, 2026
f38c201
Merge remote-tracking branch 'origin/master' into dm-webrtc-wildcard
dmitry-markin Aug 14, 2026
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
15 changes: 15 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ip_network = "0.4"
libc = "0.2.158"
mockall = "0.13.1"
multiaddr = "0.18.2"
multibase = "0.9.2"
multihash = { version = "0.19.4", default-features = false, features = ["std"] }
multihash-codetable = { version = "0.2.1", default-features = false, features = [
"sha2",
Expand Down Expand Up @@ -90,6 +91,7 @@ rcgen = { version = "0.14.5", optional = true }

# WebRTC related dependencies. WebRTC is an experimental feature flag. The dependencies must be updated.
str0m = { version = "0.22.0", default-features = false, features = ["openssl", "vendored"], optional = true }
quinn-udp = { version = "0.6.1", default-features = false, features = ["tracing"], optional = true }
# End of WebRTC related dependencies.

# Fuzzing related dependencies.
Expand Down Expand Up @@ -134,7 +136,7 @@ fuzz = [
# Unstable / experimental feature flags. These features are not guaranteed to be stable and may change in the future.
# They are not yet suitable for production use-cases and should be used with caution.
quic = ["dep:webpki", "dep:quinn", "dep:rustls", "dep:ring", "dep:rcgen"]
webrtc = ["dep:str0m"]
webrtc = ["dep:str0m", "dep:quinn-udp"]
rsa = ["dep:ring"]

[profile.release]
Expand Down
15 changes: 15 additions & 0 deletions src/transport/webrtc/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
//!
//! litep2p does not persist the certificate itself, persistence is left to the caller.

use crate::types::multihash::Multihash;
use multihash_codetable::MultihashDigest as _;
use str0m::{config::DtlsCert, crypto::CryptoError, error::DtlsError, RtcError};

/// Local certificate & key used for DTLS connections.
#[derive(Debug)]
pub struct DtlsCertificate {
/// Certificate as X.509 DER.
certificate: Vec<u8>,
/// Matching private key as PKCS#8 DER.
private_key: Vec<u8>,
}

Expand Down Expand Up @@ -40,6 +45,16 @@ impl DtlsCertificate {
})
}

/// Get the certificate certhash for WebRTC multiaddress.
pub fn certhash(&self) -> Multihash<64> {
multihash_codetable::Code::Sha2_256.digest(&self.certificate)
}

/// Certhash string representation as in multiaddress.
pub fn certhash_b64(&self) -> String {
multibase::encode(multibase::Base::Base64Url, self.certhash().to_bytes())
}

/// Returns the raw certificate and private-key bytes.
pub fn as_parts(&self) -> (&Vec<u8>, &Vec<u8>) {
(&self.certificate, &self.private_key)
Expand Down
4 changes: 2 additions & 2 deletions src/transport/webrtc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use crate::transport::webrtc::certificate::DtlsCertificate;
/// otherwise, the WebRTC transport is not initialized.
#[derive(Debug)]
pub struct Config {
/// WebRTC listening address.
/// WebRTC listen addresses.
///
/// Unspecified addresses (`0.0.0.0` / `[::]`) are not supported.
/// Wildcard addresses are expanded to specific interface addresses when advertised.
pub listen_addresses: Vec<Multiaddr>,

/// Connection datagram buffer size.
Expand Down
30 changes: 14 additions & 16 deletions src/transport/webrtc/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ use crate::{
transport::{
webrtc::{
schema::webrtc::message::Flag,
socket::WebRtcSocket,
substream::{Message, Substream as WebRtcSubstream, SubstreamHandle},
util::{extract_framed_message, WebRtcMessage},
AddressPair,
},
Endpoint, SUBSTREAM_OPEN_TIMEOUT,
},
Expand All @@ -46,11 +48,10 @@ use str0m::{
net::{Protocol as Str0mProtocol, Receive},
Event, IceConnectionState, Input, Output, Rtc,
};
use tokio::{net::UdpSocket, sync::mpsc::Receiver};
use tokio::sync::mpsc::Receiver;

use std::{
collections::{HashMap, HashSet, VecDeque},
net::SocketAddr,
pin::Pin,
sync::Arc,
task::{Context, Poll},
Expand Down Expand Up @@ -244,14 +245,11 @@ pub struct WebRtcConnection {
/// Endpoint.
endpoint: Endpoint,

/// Peer address
peer_address: SocketAddr,

/// Local address.
local_address: SocketAddr,
/// Addresses of the session.
addrs: AddressPair,

/// Transport socket.
socket: Arc<UdpSocket>,
socket: Arc<WebRtcSocket>,

/// RX channel for receiving datagrams from the transport.
dgram_rx: Receiver<Vec<u8>>,
Expand Down Expand Up @@ -296,9 +294,8 @@ impl WebRtcConnection {
pub fn new(
rtc: Rtc,
peer: PeerId,
peer_address: SocketAddr,
local_address: SocketAddr,
socket: Arc<UdpSocket>,
addrs: AddressPair,
socket: Arc<WebRtcSocket>,
protocol_set: ProtocolSet,
endpoint: Endpoint,
dgram_rx: Receiver<Vec<u8>>,
Expand All @@ -307,8 +304,7 @@ impl WebRtcConnection {
rtc,
protocol_set,
peer,
peer_address,
local_address,
addrs,
socket,
endpoint,
dgram_rx,
Expand Down Expand Up @@ -1134,7 +1130,9 @@ impl WebRtcConnection {
"transmit data",
);

if let Err(error) = self.socket.try_send_to(&v.contents, v.destination) {
if let Err(error) =
self.socket.try_send_to(&v.contents, v.destination, self.addrs.local.ip())
{
if error.kind() == std::io::ErrorKind::WouldBlock {
tracing::trace!(
target: LOG_TARGET,
Expand Down Expand Up @@ -1266,8 +1264,8 @@ impl WebRtcConnection {
Instant::now(),
Receive {
proto: Str0mProtocol::Udp,
source: self.peer_address,
destination: self.local_address,
source: self.addrs.remote,
destination: self.addrs.local,
contents,
},
);
Expand Down
Loading
Loading