pub struct Association { /* private fields */ }Expand description
Association represents an SCTP association
Implementations§
Source§impl Association
impl Association
Sourcepub fn message_interleaving(&self) -> bool
pub fn message_interleaving(&self) -> bool
Whether user message interleaving (RFC 8260) is in use: both sides announced the
I-DATA chunk. false while the association is being set up.
Source§impl Association
impl Association
Sourcepub fn peer_supports_reconfig(&self) -> bool
pub fn peer_supports_reconfig(&self) -> bool
Whether the peer announced the stream re-configuration extension (RFC 6525 5.1.1). Without it no stream can be reset, which closing a WebRTC data channel needs.
Sourcepub fn request_incoming_stream_reset(
&mut self,
streams: &[StreamId],
) -> Result<()>
pub fn request_incoming_stream_reset( &mut self, streams: &[StreamId], ) -> Result<()>
Asks the peer to reset some of its outgoing streams, this side’s incoming ones (RFC
6525 5.1.3); no stream listed asks for all of them. The peer answers by resetting
them, which arrives as a reset of each stream, or by refusing
(ReconfigEvent::IncomingStreamsResetNotPerformed).
Sourcepub fn request_ssn_tsn_reset(&mut self, now: Instant) -> Result<()>
pub fn request_ssn_tsn_reset(&mut self, now: Instant) -> Result<()>
Asks for the TSNs of both directions and the Stream Sequence Numbers of every stream
to start over (RFC 6525 5.1.4). Nothing new is sent from now until the peer has
answered (ReconfigEvent::AssociationReset or
ReconfigEvent::AssociationResetFailed); what is written meanwhile is queued. The
request goes out once everything sent so far is acknowledged.
Refused within 30 seconds of the last such request.
Sourcepub fn add_outgoing_streams(&mut self, count: u16) -> Result<()>
pub fn add_outgoing_streams(&mut self, count: u16) -> Result<()>
Asks for count more outgoing streams (RFC 6525 5.1.5). They may be used once the
peer has accepted (ReconfigEvent::StreamsAdded), and not before.
Sourcepub fn add_incoming_streams(&mut self, count: u16) -> Result<()>
pub fn add_incoming_streams(&mut self, count: u16) -> Result<()>
Asks the peer to add count outgoing streams of its own, this side’s incoming ones
(RFC 6525 5.1.6). A peer that agrees adds them with a request of its own; asking
raises this side’s inbound limit (set_stream_limits) to
make room for them.
Sourcepub fn set_stream_limits(&mut self, max_inbound: u16, max_outbound: u16)
pub fn set_stream_limits(&mut self, max_inbound: u16, max_outbound: u16)
Sets how many streams this association may grow to when the peer asks for more (RFC
6525 5.2.5, 5.2.6: “a limit that should be configurable by the application”): a
request that would take the inbound or the outbound count past its limit is denied.
The limits start as the counts the association was configured with
(TransportConfig::with_max_num_inbound_streams,
TransportConfig::with_max_num_outbound_streams). Streams the association already
has are not taken away.
Source§impl Association
impl Association
Sourcepub fn congestion_window(&self) -> u32
pub fn congestion_window(&self) -> u32
The congestion window, in bytes of user data.
Sourcepub fn set_max_send_rate(&mut self, bits_per_second: Option<f64>)
pub fn set_max_send_rate(&mut self, bits_per_second: Option<f64>)
Bounds the rate new DATA is sent at to bits_per_second (DATA chunks on the wire), or
lifts the bound with None (the default). The association’s own congestion control
runs as ever (RFC 9260 7.2) and new DATA goes when both it and the bound let it: a
token bucket that fills at the rate, holds at most [SEND_RATE_BURST] of it (and two
PMDCS at least), and lets the chunk out that takes it below empty, the last. A window
held under cwnd by the bound is not in full use, so cwnd does not grow meanwhile (7.2.1,
7.2.2). Retransmissions are not held. The caller wakes the association
(handle_timeout, poll_transmit) while DATA waits on the bound: it sets no timer.
For an application that shares one congestion controller’s estimate among several flows over one path (RFC 8836 section 2, requirement 6a; RFC 8699): the data channels of a WebRTC peer connection take their share of the media’s estimate this way.
Sourcepub fn max_send_rate(&self) -> Option<f64>
pub fn max_send_rate(&self) -> Option<f64>
The bound set_max_send_rate set, bits per second.
Sourcepub fn slow_start_threshold(&self) -> u32
pub fn slow_start_threshold(&self) -> u32
The slow start threshold, in bytes of user data.
Sourcepub fn peer_receive_window(&self) -> u32
pub fn peer_receive_window(&self) -> u32
The peer’s receive window as this side tracks it (RFC 9260 6.2.1: the last a_rwnd less the bytes sent since and not acknowledged), in bytes of user data.
Sourcepub fn status(&self) -> AssociationStatus
pub fn status(&self) -> AssociationStatus
RFC 9260 11.1.8 Status: the association’s state in one call (single-homed, RFC 8261 6.1, so one destination: no address list or primary path).
Sourcepub fn on_path_change(&mut self, now: Instant)
pub fn on_path_change(&mut self, now: Instant)
Tells the association that its packets take another path from now on: the transport underneath switched (for WebRTC, ICE selected another candidate pair).
RFC 9260 7.2.5: what was learned about the old path says nothing about the new one, so the congestion control state and the RTO start again from their initial values. DATA outstanding stays outstanding, and its retransmission timer runs on with the initial RTO.
Sourcepub fn path_mtu(&self) -> u32
pub fn path_mtu(&self) -> u32
The largest SCTP packet (common header and chunks) the association sends: the path MTU as it knows it.
Sourcepub fn set_path_mtu(&mut self, mtu: u32)
pub fn set_path_mtu(&mut self, mtu: u32)
Tells the association the largest SCTP packet the path below carries, in bytes: the path MTU less what lies beneath SCTP (for WebRTC: the DTLS record overhead, the UDP and IP headers, and TURN framing where a relay is used). The entry point for whatever learns the path MTU: the transport’s initial value for a path, the application’s own discovery, or an ICMP “Packet Too Big” it has validated (RFC 9260 section 7.3, RFC 8261 section 4).
With path MTU discovery on (TransportConfig::with_path_mtu_discovery) the value
is BASE_PLPMTU (RFC 8899 section 5.1.2): the association uses it, confirms it with a
probe once established and searches above it; a new value starts the discovery over.
Setting the value in use again changes nothing.
From now on packets are bundled up to the packet size, the Path Maximum DATA Chunk
Size of the congestion control rules follows it, and messages written from now on are
fragmented to fit. A message already fragmented keeps its fragments: after a reduction
they are sent as they are, each alone in a packet larger than the new MTU, and the
layer below has to fragment or the caller to accept the loss (RFC 9260 section 6.9:
SCTP does not re-fragment). A value below
MIN_DATA_PACKET_MTU is raised to it.
Sourcepub fn handle_packet_too_big(&mut self, ptb_size: u32) -> bool
pub fn handle_packet_too_big(&mut self, ptb_size: u32) -> bool
The layer below reported, from a Packet Too Big it validated (RFC 8899 section
4.6.1), that the path carries SCTP packets of ptb_size bytes (PL_PTB_SIZE: the
headers below SCTP taken off). Returns whether the packet size went down.
With path MTU discovery the report is one of its inputs, never the size itself (RFC
8899 section 4.6.2; see PathMtuDiscovery::on_packet_too_big): a size below the
PLPMTU and not below BASE_PLPMTU takes the PLPMTU back to BASE_PLPMTU and the search
starts again. Without discovery the packet size comes down to the size reported (RFC
9260 section 10, ICMP7: for an ICMPv6 Packet Too Big or ICMPv4 Fragmentation Needed
“an implementation SHOULD process this information as defined for PMTU discovery”;
RFC 8201 section 4), never below
MIN_DATA_PACKET_MTU and never up. A report never
raises the congestion window, and SCTP does not rely on reports: discovery goes on
without them (RFC 8261 section 6.1, RFC 8831 section 5).
Sourcepub fn set_max_path_mtu(&mut self, max: u32)
pub fn set_max_path_mtu(&mut self, max: u32)
MAX_PLPMTU of the path MTU discovery (RFC 8899 section 5.1.2): the largest SCTP packet the search tries, the local interface MTU less what lies under SCTP. Nothing without discovery.
Sourcepub fn path_mtu_state(&self) -> Option<PathMtuState>
pub fn path_mtu_state(&self) -> Option<PathMtuState>
Where the path MTU discovery is (RFC 8899 section 5.2); None without discovery.
Sourcepub fn poll(&mut self) -> Option<Event>
pub fn poll(&mut self) -> Option<Event>
Returns application-facing event
Associations should be polled for events after:
- a call was made to
handle_event - a call was made to
handle_timeout
Sourcepub fn poll_endpoint_event(&mut self) -> Option<EndpointEvent>
pub fn poll_endpoint_event(&mut self) -> Option<EndpointEvent>
Return endpoint-facing event
Sourcepub fn poll_timeout(&self) -> Option<Instant>
pub fn poll_timeout(&self) -> Option<Instant>
Returns the next time at which handle_timeout should be called
The value returned may change after:
- the application performed some I/O on the association
- a call was made to
handle_transmit - a call to
poll_transmitreturnedSome - a call was made to
handle_timeout
Sourcepub fn poll_transmit(
&mut self,
now: Instant,
) -> Option<TransportMessage<Payload>>
pub fn poll_transmit( &mut self, now: Instant, ) -> Option<TransportMessage<Payload>>
Returns packets to transmit
Associations should be polled for transmit after:
- the application performed some I/O on the Association
- a call was made to
handle_event - a call was made to
handle_timeout
Sourcepub fn handle_timeout(&mut self, now: Instant)
pub fn handle_timeout(&mut self, now: Instant)
Process timer expirations
Executes protocol logic, potentially preparing signals (including application Events,
EndpointEvents and outgoing datagrams) that should be extracted through the relevant
methods.
It is most efficient to call this immediately after the system clock reaches the latest
Instant that was output by poll_timeout; however spurious extra calls will simply
no-op and therefore are safe.
Sourcepub fn handle_event(&mut self, event: AssociationEvent)
pub fn handle_event(&mut self, event: AssociationEvent)
Process AssociationEvents generated by the associated Endpoint
Will execute protocol logic upon receipt of an association event, in turn preparing signals
(including application Events, EndpointEvents and outgoing datagrams) that should be
extracted through the relevant methods.
Sourcepub fn partial_reliability(&self) -> bool
pub fn partial_reliability(&self) -> bool
Whether PR-SCTP (RFC 3758) is in use: both sides announced it. false while the
association is being set up, and for good when the peer does not support it, in which
case every message is sent reliably whatever its stream’s reliability parameters say.
Sourcepub fn stats(&self) -> AssociationStats
pub fn stats(&self) -> AssociationStats
Returns Association statistics
Sourcepub fn is_handshaking(&self) -> bool
pub fn is_handshaking(&self) -> bool
Whether the Association is in the process of being established
If this returns false, the Association may be either established or closed, signaled by the
emission of a Connected or AssociationLost message respectively.
Sourcepub fn negotiated_max_streams(&self) -> Option<u16>
pub fn negotiated_max_streams(&self) -> Option<u16>
The number of streams negotiated for this association: the smaller of the inbound and outbound counts the two endpoints agreed on in INIT/INIT ACK.
None while the association is still handshaking. Before the peer’s INIT (or INIT ACK) has
been processed, the two counts still hold this endpoint’s configured limits rather than
anything agreed, so reporting them would overstate what the association can carry.
This is what RFC 8831 data channels are limited by, and what W3C
RTCSctpTransport.maxChannels reports.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Whether the Association is closed
Closed Associations cannot transport any further data. An association becomes closed when either peer application intentionally closes it, or when either transport layer detects an error such as a time-out or certificate validation failure.
A AssociationLost event is emitted with details when the association becomes closed.
Sourcepub fn is_ended(&self) -> bool
pub fn is_ended(&self) -> bool
Whether the association is over: closed by either side, by an error, or by a handshake that failed.
Unlike is_closed, false for an association still handshaking in
SCTP’s initial CLOSED state (RFC 9260 section 4), which has not ended.
Sourcepub fn is_drained(&self) -> bool
pub fn is_drained(&self) -> bool
Whether there is no longer any need to keep the association around
Closed associations become drained after a brief timeout to absorb any remaining in-flight packets from the peer. All drained associations have been closed.
Sourcepub fn verification_tag(&self) -> u32
pub fn verification_tag(&self) -> u32
The Verification Tag this association expects in the packets it receives (RFC 9260 section 8.5): its own Initiate Tag.
Sourcepub fn remote_addr(&self) -> SocketAddr
pub fn remote_addr(&self) -> SocketAddr
The latest socket address for this Association’s peer
Sourcepub fn rtt(&self) -> Duration
pub fn rtt(&self) -> Duration
Smoothed round-trip time, or zero before the first RTT measurement. Retransmission timeout backoff does not change this estimate.
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
The local IP address which was used when the peer established the association
This can be different from the address the endpoint is bound to, in case
the endpoint is bound to a wildcard address like 0.0.0.0 or ::.
This will return None for clients.
Retrieving the local IP address is currently supported on the following platforms:
- Linux
On all non-supported platforms the local IP address will not be available,
and the method will return None.
Sourcepub fn shutdown(&mut self) -> Result<()>
pub fn shutdown(&mut self) -> Result<()>
Shutdown initiates the shutdown sequence. The method blocks until the shutdown sequence is completed and the association is closed, or until the passed context is done, in which case the context’s error is returned.
Sourcepub fn abort(&mut self) -> Result<()>
pub fn abort(&mut self) -> Result<()>
Aborts the association (RFC 9260 §9.1): queues an ABORT chunk and closes the association.
Unlike shutdown this needs no round trip, which is what closing a
WebRTC peer connection calls for: W3C close() tears the association down “by sending an
SCTP ABORT chunk”. The ABORT carries a “User-Initiated Abort” error cause (RFC 9260
§3.3.10.12), which a peer takes as an intentional close rather than an error.
The ABORT is sent by the next poll_transmit. Anything not handed to
poll_transmit before this call is discarded, so drain it first if it should still go out.
A no-op on a closed association.
Sourcepub fn abort_cause_code(&self) -> Option<u16>
pub fn abort_cause_code(&self) -> Option<u16>
The cause code (RFC 9260 section 3.3.10) of the ABORT that ended the association: the
first error cause of the one received, or of the one this side sent. None when no
ABORT ended it, or the ABORT carried no cause. What W3C webrtc-pc reports as an
RTCError’s sctpCauseCode.
Sourcepub fn peer_abort_reason(&self) -> Option<&[u8]>
pub fn peer_abort_reason(&self) -> Option<&[u8]>
The Upper Layer Abort Reason the peer gave when it aborted the association (RFC 9260
sections 3.3.10.12 and 9.1: “the Upper Layer Abort Reason … SHOULD be made available
to the upper layer”). None when the association did not end by the peer’s
User-Initiated Abort; empty when that carried no reason.
Sourcepub fn abort_with_reason(&mut self, reason: &[u8]) -> Result<()>
pub fn abort_with_reason(&mut self, reason: &[u8]) -> Result<()>
As abort, with an Upper Layer Abort Reason in the User-Initiated
Abort error cause (RFC 9260 section 3.3.10.12) for the peer’s application.
Sourcepub fn close(&mut self, reason: AssociationError) -> Result<()>
pub fn close(&mut self, reason: AssociationError) -> Result<()>
Close ends the SCTP Association and cleans up any state
Sourcepub fn open_stream(
&mut self,
stream_identifier: StreamId,
default_payload_type: PayloadProtocolIdentifier,
) -> Result<Stream<'_>>
pub fn open_stream( &mut self, stream_identifier: StreamId, default_payload_type: PayloadProtocolIdentifier, ) -> Result<Stream<'_>>
open_stream opens a stream
Sourcepub fn accept_stream(&mut self) -> Option<Stream<'_>>
pub fn accept_stream(&mut self) -> Option<Stream<'_>>
accept_stream accepts a stream
Sourcepub fn stream(&mut self, stream_identifier: StreamId) -> Result<Stream<'_>>
pub fn stream(&mut self, stream_identifier: StreamId) -> Result<Stream<'_>>
stream returns a stream
Sourcepub fn stream_ids(&self) -> Vec<StreamId>
pub fn stream_ids(&self) -> Vec<StreamId>
The identifiers of every stream currently open on this association.
Sourcepub fn bytes_sent(&self) -> usize
pub fn bytes_sent(&self) -> usize
The bytes of every SCTP packet handed out by poll_transmit, common headers included.
Sourcepub fn set_max_message_size(&mut self, max_message_size: u32)
pub fn set_max_message_size(&mut self, max_message_size: u32)
Sets the maximum message size this side may send: what a later offer/answer exchange negotiated (W3C webrtc 4.4.1.4 “update the data max message size”, RFC 8841 section 6.1).
Sourcepub fn take_undelivered_messages(&mut self) -> Vec<UndeliveredMessage>
pub fn take_undelivered_messages(&mut self) -> Vec<UndeliveredMessage>
The user messages this association did not deliver, once it ended (RFC 9260 11.1.14
Receive Unsent Message, 11.1.15 Receive Unacknowledged Message): each message that
was never sent and each one sent and not completely acknowledged, in the order sent
then written, as Event::SendFailure counted them. Taken once; empty while the
association runs. A graceful shutdown ends only when everything was acknowledged, so
it leaves none.
Sourcepub fn zero_checksum(&self) -> bool
pub fn zero_checksum(&self) -> bool
Whether packets are sent with a zero checksum (RFC 9653): both sides announced that they take one over DTLS.
Sourcepub fn request_heartbeat(&mut self, now: Instant) -> bool
pub fn request_heartbeat(&mut self, now: Instant) -> bool
RFC 9260 11.1.10 Request Heartbeat: “Instructs the local endpoint to perform a
heartbeat on the specified destination transport address”. Sends a HEARTBEAT now,
whether or not heartbeats are enabled (TransportConfig::with_heartbeat_interval),
unless one is waiting for its HEARTBEAT ACK already (its answer serves). Its HEARTBEAT
ACK measures the round trip (Self::rtt); left unanswered for an RTO it counts as an
error of the path, as a periodic one does (8.3). Returns whether a HEARTBEAT was
queued: false outside ESTABLISHED, SHUTDOWN-PENDING and SHUTDOWN-RECEIVED, or with
one outstanding. The association is single-homed (RFC 8261 6.1), so there is no
address to name.
Sourcepub fn set_heartbeat_interval(
&mut self,
interval: Option<Duration>,
now: Instant,
)
pub fn set_heartbeat_interval( &mut self, interval: Option<Duration>, now: Instant, )
Sets HB.interval for this association (RFC 9260 11.1.9, “Change Heartbeat”). None
stops the HEARTBEATs.
Sourcepub fn stream_bytes_dequeued(&self, stream_identifier: StreamId) -> u64
pub fn stream_bytes_dequeued(&self, stream_identifier: StreamId) -> u64
Application bytes of stream_identifier that have left the send queue (see
Stream::bytes_dequeued). For a stream that was closed (reset, or lost with the
association), the count it had when it was closed, until a stream with the same
identifier is opened; 0 for a stream this association never held.
Sourcepub fn streams_lost_in_restart(&self) -> &[(StreamId, u64)]
pub fn streams_lost_in_restart(&self) -> &[(StreamId, u64)]
The streams of the association before the peer’s last restart (Event::Restarted),
each with the application bytes that had left its send queue: what was sent on it
before it went with the restart.