32#ifndef A11_NET_WEBRTC_WIRE_STREAM_H_
33#define A11_NET_WEBRTC_WIRE_STREAM_H_
45#include <absl/base/thread_annotations.h>
46#include <absl/status/status.h>
47#include <absl/status/statusor.h>
48#include <absl/time/time.h>
54#include "thread/boost_primitives.h"
64class MultiplexedBinaryChannel;
65class PathMtuDiscovery;
122 std::optional<size_t>
mtu;
129 std::optional<std::string>
170 struct ConstructorToken {};
184 static absl::StatusOr<std::shared_ptr<WebRtcWireStream>>
CreateClient(
186 const std::shared_ptr<SignallingService>& signalling,
203 static absl::StatusOr<std::shared_ptr<WebRtcWireStream>>
CreateClient(
205 const std::shared_ptr<SignallingTransport>& signalling,
224 static absl::StatusOr<std::shared_ptr<WebRtcWireStream>>
Create(
226 std::shared_ptr<rtc::PeerConnection>
connection,
229 OpenOperation open_operation = {},
size_t split_size = 48 * 1024);
239 static absl::StatusOr<std::shared_ptr<WebRtcWireStream>>
241 std::shared_ptr<internal::BinaryChannel> channel,
242 std::shared_ptr<rtc::DataChannel> primary_channel,
243 std::shared_ptr<rtc::PeerConnection>
connection,
246 OpenOperation open_operation = {},
size_t split_size = 48 * 1024,
252 [[nodiscard]] std::shared_ptr<rtc::DataChannel>
data_channel()
const;
255 [[nodiscard]] std::shared_ptr<rtc::PeerConnection>
peer_connection()
const;
295 const std::shared_ptr<internal::MultiplexedBinaryChannel>& stream_data);
303 std::shared_ptr<rtc::PeerConnection>
connection,
305 size_t configured_mtu)
310 path_mtu_(configured_mtu) {}
313 std::shared_ptr<rtc::DataChannel> data_channel_;
314 std::shared_ptr<rtc::PeerConnection> connection_;
315 std::shared_ptr<SignallingTransport> signalling_endpoint_;
316 mutable thread::Mutex path_mtu_mu_;
317 size_t path_mtu_ ABSL_GUARDED_BY(path_mtu_mu_);
318 std::shared_ptr<internal::PathMtuDiscovery> discovery_
319 ABSL_GUARDED_BY(path_mtu_mu_);
324 std::function<
a11::Task(std::shared_ptr<WebRtcWireStream>)>;
349 static absl::StatusOr<std::shared_ptr<WebRtcWireServer>>
Create(
351 const std::shared_ptr<SignallingService>& signalling,
376 static absl::StatusOr<std::shared_ptr<WebRtcWireServer>>
Create(
377 const std::shared_ptr<SignallingTransport>& signalling,
386 [[nodiscard]] std::string
identity()
const;
388 [[nodiscard]]
bool running()
const;
399 : state_(std::move(state)) {}
401 static a11::Task OnSignal(
const std::shared_ptr<State>& state,
403 static absl::Status HandleOffer(
const std::shared_ptr<State>& state,
405 static absl::Status HandleCandidate(
const std::shared_ptr<State>& state,
407 static void ReportPeerError(
const std::shared_ptr<State>& state,
410 std::shared_ptr<State> state_;
Shared WireStream lifecycle and framing for binary channels.
Definition channel_wire_stream.h:69
std::function< absl::Status()> OpenOperation
Transport-specific operation that initiates or accepts the channel.
Definition channel_wire_stream.h:72
Accepts incoming WebRTC peer connections under a fixed identity.
Definition webrtc_wire_stream.h:333
~WebRtcWireServer()
Definition webrtc_wire_stream.cc:937
size_t pending_peer_count() const
Definition webrtc_wire_stream.cc:1327
std::shared_ptr< SignallingTransport > signalling_endpoint() const
Definition webrtc_wire_stream.cc:1332
std::string identity() const
Definition webrtc_wire_stream.cc:1317
absl::Status Stop()
Stops the server and stops accepting new peer connections.
Definition webrtc_wire_stream.cc:1280
bool running() const
Definition webrtc_wire_stream.cc:1322
static absl::StatusOr< std::shared_ptr< WebRtcWireServer > > Create(std::string identity, const std::shared_ptr< SignallingService > &signalling, OnWebRtcStream on_stream, WebRtcConfiguration configuration={}, WireStreamOptions stream_options={})
Creates a WebRTC server that accepts peer connections.
Definition webrtc_wire_stream.cc:870
A WireStream that carries A11 traffic over a WebRTC data channel.
Definition webrtc_wire_stream.h:168
size_t discovered_path_mtu() const
Definition webrtc_wire_stream.cc:804
void StartPathMtuDiscovery(const WebRtcConfiguration &configuration, const std::shared_ptr< internal::MultiplexedBinaryChannel > &stream_data)
Starts path MTU discovery on this stream.
Definition webrtc_wire_stream.cc:707
std::shared_ptr< rtc::DataChannel > data_channel() const
Definition webrtc_wire_stream.cc:657
~WebRtcWireStream() override
Definition webrtc_wire_stream.cc:648
static absl::StatusOr< std::shared_ptr< WebRtcWireStream > > BuildMultiplexedStream(std::shared_ptr< internal::BinaryChannel > channel, std::shared_ptr< rtc::DataChannel > primary_channel, std::shared_ptr< rtc::PeerConnection > connection, std::shared_ptr< SignallingTransport > signalling_endpoint, std::string id, ChannelEndpointRole role, WireStreamOptions options={}, OpenOperation open_operation={}, size_t split_size=48 *1024, size_t configured_mtu=kWebRtcBaseMtu)
Adopts an already-built binary channel (possibly multiplexed).
Definition webrtc_wire_stream.cc:379
std::shared_ptr< SignallingTransport > signalling_endpoint() const
Definition webrtc_wire_stream.cc:665
static absl::StatusOr< std::shared_ptr< WebRtcWireStream > > CreateClient(std::string identity, std::string peer_identity, const std::shared_ptr< SignallingService > &signalling, const WebRtcConfiguration &configuration={}, WireStreamOptions options={})
Dials a peer over a shared in-process signalling service.
Definition webrtc_wire_stream.cc:443
static absl::StatusOr< std::shared_ptr< WebRtcWireStream > > Create(std::shared_ptr< rtc::DataChannel > data_channel, std::shared_ptr< rtc::PeerConnection > connection, std::shared_ptr< SignallingTransport > signalling_endpoint, ChannelEndpointRole role, WireStreamOptions options={}, OpenOperation open_operation={}, size_t split_size=48 *1024)
Adopts an already-established data channel as a WireStream.
Definition webrtc_wire_stream.cc:406
size_t current_path_mtu() const
Definition webrtc_wire_stream.cc:813
std::shared_ptr< rtc::PeerConnection > peer_connection() const
Definition webrtc_wire_stream.cc:661
absl::Status SetPathMtu(size_t mtu)
Sets the SCTP path MTU on this already-connected association.
Definition webrtc_wire_stream.cc:676
WebRtcWireStream(ConstructorToken, std::shared_ptr< State > state, std::shared_ptr< rtc::DataChannel > data_channel, std::shared_ptr< rtc::PeerConnection > connection, std::shared_ptr< SignallingTransport > signalling_endpoint, size_t configured_mtu)
Definition webrtc_wire_stream.h:301
std::string value
Definition discover.cc:114
Completion values used by every asynchronous A11 operation.
std::function< a11::Task(std::shared_ptr< WebRtcWireStream >)> OnWebRtcStream
Callback invoked with each newly negotiated peer WireStream.
Definition webrtc_wire_stream.h:324
TurnRelayType
Transport used to reach a TURN relay server.
Definition webrtc_wire_stream.h:69
constexpr size_t kWebRtcBaseMtu
The MTU a WebRTC association uses until something better is confirmed.
Definition webrtc_wire_stream.h:77
constexpr size_t kWebRtcMinMtu
Smallest MTU usrsctp will accept (SCTP_SMALLEST_PMTU).
Definition webrtc_wire_stream.h:80
ChannelEndpointRole
Handshake role a binary channel endpoint is permitted to assume.
Definition channel_wire_stream.h:43
Future< Unit > Task
Asynchronous operation whose only successful result is completion itself.
Definition future.h:411
Definition webrtc_wire_stream.h:56
Out-of-band signalling used to negotiate WebRTC peer connections.
One signalling payload: an SDP description, an ICE candidate, or an error.
Definition signalling.h:62
Address and credentials for a TURN relay used during ICE.
Definition webrtc_wire_stream.h:88
std::string password
Relay credential password.
Definition webrtc_wire_stream.h:96
std::string username
Relay credential username.
Definition webrtc_wire_stream.h:95
friend bool operator==(const TurnServer &, const TurnServer &)=default
std::string hostname
TURN host name or address.
Definition webrtc_wire_stream.h:93
static absl::StatusOr< TurnServer > FromString(std::string_view value)
Parses a TURN server from a URL-like string.
Definition webrtc_wire_stream.cc:211
std::uint16_t port
TURN service port.
Definition webrtc_wire_stream.h:94
TurnRelayType relay_type
Transport to the relay.
Definition webrtc_wire_stream.h:97
ICE, fragmentation, and binding settings for a WebRTC connection.
Definition webrtc_wire_stream.h:108
size_t max_discovered_mtu
Bounds and timers for the search.
Definition webrtc_wire_stream.h:148
std::optional< std::pair< std::uint16_t, std::uint16_t > > preferred_port_range
Optional inclusive local UDP port range for ICE.
Definition webrtc_wire_stream.h:128
std::optional< size_t > mtu
Network MTU SCTP builds packets to, in bytes.
Definition webrtc_wire_stream.h:122
absl::Status Validate() const
Definition webrtc_wire_stream.cc:275
std::optional< std::string > bind_address
Optional local candidate address.
Definition webrtc_wire_stream.h:130
std::vector< std::string > stun_servers
STUN URLs used for NAT discovery.
Definition webrtc_wire_stream.h:125
std::optional< size_t > max_message_size
Advertised channel ceiling.
Definition webrtc_wire_stream.h:111
size_t channel_split_size
A11 packet size below SCTP limits.
Definition webrtc_wire_stream.h:113
bool enable_ice_udp_mux
Reuse one UDP socket for ICE candidates.
Definition webrtc_wire_stream.h:123
bool path_mtu_discovery
Discover the path MTU by probing, instead of assuming mtu.
Definition webrtc_wire_stream.h:146
absl::Duration path_mtu_raise_interval
Delay before searching upward again after convergence.
Definition webrtc_wire_stream.h:152
size_t desired_channels
Data channels a client opens and replenishes.
Definition webrtc_wire_stream.h:134
absl::Duration path_mtu_startup_retry
Delay before retrying while the SCTP association is unavailable.
Definition webrtc_wire_stream.h:154
std::vector< TurnServer > turn_servers
Fallback relay servers.
Definition webrtc_wire_stream.h:126
absl::Duration probe_timeout
How long one probe has to be acknowledged before it counts as lost.
Definition webrtc_wire_stream.h:150
size_t max_channels
Data channels a server admits per peer.
Definition webrtc_wire_stream.h:136
Definition webrtc_wire_stream.cc:847
Buffering, sizing, and deadline limits for a WireStream endpoint.
Definition wire_stream.h:58
const std::string identity
Definition webrtc_wire_stream.cc:107
const std::string peer_identity
Definition webrtc_wire_stream.cc:108
const std::shared_ptr< rtc::PeerConnection > connection
Definition webrtc_wire_stream.cc:110
WebRtcConfiguration configuration
Definition webrtc_wire_stream.cc:120
A11's transport abstraction: the bidirectional WireStream channel and the options/callbacks that driv...