18#ifndef A11_NET_WEBRTC_WIRE_STREAM_H_
19#define A11_NET_WEBRTC_WIRE_STREAM_H_
31#include <absl/status/status.h>
32#include <absl/status/statusor.h>
58 static absl::StatusOr<TurnServer>
FromString(std::string_view value);
88 std::optional<std::string>
112 struct ConstructorToken {};
126 static absl::StatusOr<std::shared_ptr<WebRtcWireStream>>
CreateClient(
128 std::shared_ptr<SignallingService> signalling,
144 static absl::StatusOr<std::shared_ptr<WebRtcWireStream>>
CreateClient(
146 std::shared_ptr<SignallingTransport> signalling,
164 static absl::StatusOr<std::shared_ptr<WebRtcWireStream>>
Create(
166 std::shared_ptr<rtc::PeerConnection>
connection,
169 OpenOperation open_operation = {},
size_t split_size = 48 * 1024);
180 std::shared_ptr<internal::BinaryChannel> channel,
182 std::shared_ptr<rtc::PeerConnection>
connection,
185 OpenOperation open_operation = {},
size_t split_size = 48 * 1024);
200 std::shared_ptr<rtc::PeerConnection>
connection,
208 std::shared_ptr<rtc::DataChannel> data_channel_;
209 std::shared_ptr<rtc::PeerConnection> connection_;
210 std::shared_ptr<SignallingTransport> signalling_endpoint_;
215 std::function<
a11::Task(std::shared_ptr<WebRtcWireStream>)>;
236 static absl::StatusOr<std::shared_ptr<WebRtcWireServer>>
Create(
237 std::string
identity, std::shared_ptr<SignallingService> signalling,
258 : state_(std::move(state)) {}
260 static a11::Task OnSignal(
const std::shared_ptr<State>& state,
262 static absl::Status HandleOffer(
const std::shared_ptr<State>& state,
264 static absl::Status HandleCandidate(
const std::shared_ptr<State>& state,
266 static void ReportPeerError(
const std::shared_ptr<State>& state,
269 std::shared_ptr<State> state_;
Shared WireStream lifecycle and framing for binary channels.
Definition channel_wire_stream.h:55
std::function< absl::Status()> OpenOperation
Transport-specific operation that initiates or accepts the channel.
Definition channel_wire_stream.h:58
Accepts incoming WebRTC peer connections under a fixed identity.
Definition webrtc_wire_stream.h:224
~WebRtcWireServer()
Definition webrtc_wire_stream.cc:695
size_t pending_peer_count() const
Definition webrtc_wire_stream.cc:1060
std::shared_ptr< SignallingEndpoint > signalling_endpoint() const
Definition webrtc_wire_stream.cc:1065
static absl::StatusOr< std::shared_ptr< WebRtcWireServer > > Create(std::string identity, 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:645
std::string identity() const
Definition webrtc_wire_stream.cc:1050
absl::Status Stop()
Stops the server and stops accepting new peer connections.
Definition webrtc_wire_stream.cc:1016
bool running() const
Definition webrtc_wire_stream.cc:1055
A WireStream that carries A11 traffic over a WebRTC data channel.
Definition webrtc_wire_stream.h:110
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)
Definition webrtc_wire_stream.h:198
std::shared_ptr< rtc::DataChannel > data_channel() const
Definition webrtc_wire_stream.cc:581
~WebRtcWireStream() override
Definition webrtc_wire_stream.cc:572
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)
Adopts an already-built binary channel (possibly multiplexed).
Definition webrtc_wire_stream.cc:320
std::shared_ptr< SignallingTransport > signalling_endpoint() const
Definition webrtc_wire_stream.cc:589
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:346
std::shared_ptr< rtc::PeerConnection > peer_connection() const
Definition webrtc_wire_stream.cc:585
static absl::StatusOr< std::shared_ptr< WebRtcWireStream > > CreateClient(std::string identity, std::string peer_identity, std::shared_ptr< SignallingService > signalling, WebRtcConfiguration configuration={}, WireStreamOptions options={})
Dials a peer over a shared in-process signalling service.
Definition webrtc_wire_stream.cc:386
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:215
TurnRelayType
Transport used to reach a TURN relay server.
Definition webrtc_wire_stream.h:47
ChannelEndpointRole
Handshake role a binary channel endpoint is permitted to assume.
Definition channel_wire_stream.h:29
Future< Unit > Task
Asynchronous operation whose only successful result is completion itself.
Definition future.h:403
Future< T > SubmitWithCancellationHook(absl::AnyInvocable< absl::StatusOr< T >() && > work, std::function< void()> cancellation_hook, thread::TreeOptions tree_options)
Run work on A11's fiber pool with application-specific cancellation.
Definition executor.h:30
Definition webrtc_wire_stream.h:39
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:48
Address and credentials for a TURN relay used during ICE.
Definition webrtc_wire_stream.h:55
std::string password
Relay credential password.
Definition webrtc_wire_stream.h:63
std::string username
Relay credential username.
Definition webrtc_wire_stream.h:62
friend bool operator==(const TurnServer &, const TurnServer &)=default
std::string hostname
TURN host name or address.
Definition webrtc_wire_stream.h:60
static absl::StatusOr< TurnServer > FromString(std::string_view value)
Parses a TURN server from a URL-like string.
Definition webrtc_wire_stream.cc:179
std::uint16_t port
TURN service port.
Definition webrtc_wire_stream.h:61
TurnRelayType relay_type
Transport to the relay.
Definition webrtc_wire_stream.h:64
ICE, fragmentation, and binding settings for a WebRTC connection.
Definition webrtc_wire_stream.h:75
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:87
absl::Status Validate() const
Definition webrtc_wire_stream.cc:243
std::optional< std::string > bind_address
Optional local candidate address.
Definition webrtc_wire_stream.h:89
std::vector< std::string > stun_servers
STUN URLs used for NAT discovery.
Definition webrtc_wire_stream.h:84
std::optional< size_t > max_message_size
Advertised channel ceiling.
Definition webrtc_wire_stream.h:78
size_t channel_split_size
A11 packet size below SCTP limits.
Definition webrtc_wire_stream.h:80
bool enable_ice_udp_mux
Reuse one UDP socket for ICE candidates.
Definition webrtc_wire_stream.h:82
size_t desired_channels
Data channels a client opens and replenishes.
Definition webrtc_wire_stream.h:95
std::vector< TurnServer > turn_servers
Fallback relay servers.
Definition webrtc_wire_stream.h:85
size_t max_channels
Data channels a server admits per peer.
Definition webrtc_wire_stream.h:96
Definition webrtc_wire_stream.cc:622
Buffering, sizing, and deadline limits for a WireStream endpoint.
Definition wire_stream.h:44
const std::string identity
Definition webrtc_wire_stream.cc:90
const std::string peer_identity
Definition webrtc_wire_stream.cc:91
const std::shared_ptr< rtc::PeerConnection > connection
Definition webrtc_wire_stream.cc:93
A11's transport abstraction: the bidirectional WireStream channel and the options/callbacks that driv...