Skip to main content

Association

Struct Association 

Source
pub struct Association { /* private fields */ }
Expand description

Association represents an SCTP association

Implementations§

Source§

impl Association

Source

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

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn congestion_window(&self) -> u32

The congestion window, in bytes of user data.

Source

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.

Source

pub fn max_send_rate(&self) -> Option<f64>

The bound set_max_send_rate set, bits per second.

Source

pub fn slow_start_threshold(&self) -> u32

The slow start threshold, in bytes of user data.

Source

pub fn rto(&self) -> Duration

The current retransmission timeout.

Source

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.

Source

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).

Source

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.

Source

pub fn path_mtu(&self) -> u32

The largest SCTP packet (common header and chunks) the association sends: the path MTU as it knows it.

Source

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.

Source

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).

Source

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.

Source

pub fn path_mtu_state(&self) -> Option<PathMtuState>

Where the path MTU discovery is (RFC 8899 section 5.2); None without discovery.

Source

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
Source

pub fn poll_endpoint_event(&mut self) -> Option<EndpointEvent>

Return endpoint-facing event

Source

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_transmit returned Some
  • a call was made to handle_timeout
Source

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
Source

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.

Source

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.

Source

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.

Source

pub fn stats(&self) -> AssociationStats

Returns Association statistics

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn side(&self) -> Side

Look up whether we’re the client or server of this Association

Source

pub fn remote_addr(&self) -> SocketAddr

The latest socket address for this Association’s peer

Source

pub fn rtt(&self) -> Duration

Smoothed round-trip time, or zero before the first RTT measurement. Retransmission timeout backoff does not change this estimate.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn close(&mut self, reason: AssociationError) -> Result<()>

Close ends the SCTP Association and cleans up any state

Source

pub fn open_stream( &mut self, stream_identifier: StreamId, default_payload_type: PayloadProtocolIdentifier, ) -> Result<Stream<'_>>

open_stream opens a stream

Source

pub fn accept_stream(&mut self) -> Option<Stream<'_>>

accept_stream accepts a stream

Source

pub fn stream(&mut self, stream_identifier: StreamId) -> Result<Stream<'_>>

stream returns a stream

Source

pub fn stream_ids(&self) -> Vec<StreamId>

The identifiers of every stream currently open on this association.

Source

pub fn bytes_sent(&self) -> usize

The bytes of every SCTP packet handed out by poll_transmit, common headers included.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for Association

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for Association

§

impl !RefUnwindSafe for Association

§

impl !UnwindSafe for Association

§

impl Forget for Association

§

impl Move for Association

§

impl Send for Association
where RawTable<(u32, ChunkReconfig)>: Send, RawVecInner: Send, RawTable<(u32, ParamOutgoingResetRequest)>: Send, BoxRaw<dyn Param>: Send, RawTable<(u32, IncomingResetWaiting)>: Send, Bytes: Send, NonZero<u64>: Send, Arc<CookieSigner>: Send, Arc<TransportConfig>: Send, Arc<dyn RTCCryptoProvider>: Send, RawTable<(u32, ChunkPayloadData)>: Send, RawTable<(MessageId, MessageTsns)>: Send, RawTable<(u16, StreamQueue)>: Send, RawTable<(u16, u16)>: Send, NodeRef<Owned, ((u128, u64), u16), SetValZST, LeafOrInternal>: Send, BoxRaw<(((u128, u64), u16), SetValZST)>: Send, NodeRef<Owned, (u64, u16), SetValZST, LeafOrInternal>: Send, BoxRaw<((u64, u16), SetValZST)>: Send, RawTable<(u16, ())>: Send, BoxRaw<dyn Chunk>: Send, RawTable<((u16, bool), u32)>: Send, RawTable<(u16, StreamState)>: Send, RawTable<(u16, u64)>: Send, Arc<Atomic<bool>>: Send,

§

impl Sync for Association
where RawTable<(u32, ChunkReconfig)>: Sync, RawVecInner: Sync, RawTable<(u32, ParamOutgoingResetRequest)>: Sync, BoxRaw<dyn Param>: Sync, RawTable<(u32, IncomingResetWaiting)>: Sync, Bytes: Sync, NonZero<u64>: Sync, Arc<CookieSigner>: Sync, Arc<TransportConfig>: Sync, Arc<dyn RTCCryptoProvider>: Sync, RawTable<(u32, ChunkPayloadData)>: Sync, RawTable<(MessageId, MessageTsns)>: Sync, RawTable<(u16, StreamQueue)>: Sync, RawTable<(u16, u16)>: Sync, NodeRef<Owned, ((u128, u64), u16), SetValZST, LeafOrInternal>: Sync, BoxRaw<(((u128, u64), u16), SetValZST)>: Sync, NodeRef<Owned, (u64, u16), SetValZST, LeafOrInternal>: Sync, BoxRaw<((u64, u16), SetValZST)>: Sync, RawTable<(u16, ())>: Sync, BoxRaw<dyn Chunk>: Sync, RawTable<((u16, bool), u32)>: Sync, RawTable<(u16, StreamState)>: Sync, RawTable<(u16, u64)>: Sync, Arc<Atomic<bool>>: Sync,

§

impl Unpin for Association
where *const u8 is !null: Unpin, Box<dyn Param>: Unpin, *const u8: Unpin, Align8<*mut ()>: Unpin, &'static Vtable: Unpin, NonZero<u64>: Unpin, Arc<CookieSigner>: Unpin, Arc<TransportConfig>: Unpin, Arc<dyn RTCCryptoProvider>: Unpin, *const LeafNode<((u128, u64), u16), SetValZST> is !null: Unpin, Box<(((u128, u64), u16), SetValZST)>: Unpin, *const LeafNode<(u64, u16), SetValZST> is !null: Unpin, Box<((u64, u16), SetValZST)>: Unpin, Box<dyn Chunk>: Unpin, Arc<Atomic<bool>>: Unpin,

§

impl UnsafeUnpin for Association
where *const u8 is !null: UnsafeUnpin, PhantomData<(u32, ChunkReconfig)>: UnsafeUnpin, PhantomData<(u16, Option<u64>)>: UnsafeUnpin, PhantomData<u16>: UnsafeUnpin, PhantomData<OwnRequest>: UnsafeUnpin, PhantomData<(u32, ParamOutgoingResetRequest)>: UnsafeUnpin, PhantomData<(u32, IncomingResetWaiting)>: UnsafeUnpin, PhantomData<ChunkPayloadData>: UnsafeUnpin, *const u8: UnsafeUnpin, Align8<*mut ()>: UnsafeUnpin, &'static Vtable: UnsafeUnpin, *const ArcInner<CookieSigner> is !null: UnsafeUnpin, PhantomData<ArcInner<CookieSigner>>: UnsafeUnpin, *const ArcInner<TransportConfig> is !null: UnsafeUnpin, PhantomData<ArcInner<TransportConfig>>: UnsafeUnpin, *const ArcInner<dyn RTCCryptoProvider> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn RTCCryptoProvider>>: UnsafeUnpin, PhantomData<u32>: UnsafeUnpin, PhantomData<(u32, u32)>: UnsafeUnpin, PhantomData<GapAckBlock>: UnsafeUnpin, PhantomData<(u32, ChunkPayloadData)>: UnsafeUnpin, PhantomData<(MessageId, MessageTsns)>: UnsafeUnpin, PhantomData<(u16, StreamQueue)>: UnsafeUnpin, PhantomData<(u16, u16)>: UnsafeUnpin, *const LeafNode<((u128, u64), u16), SetValZST> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(((u128, u64), u16), SetValZST)>>: UnsafeUnpin, *const LeafNode<(u64, u16), SetValZST> is !null: UnsafeUnpin, PhantomData<Box<((u64, u16), SetValZST)>>: UnsafeUnpin, PhantomData<(u16, ())>: UnsafeUnpin, PhantomData<Packet>: UnsafeUnpin, PhantomData<((u16, bool), u32)>: UnsafeUnpin, PhantomData<Box<dyn Param>>: UnsafeUnpin, PhantomData<(u16, StreamState)>: UnsafeUnpin, PhantomData<(u16, u64)>: UnsafeUnpin, PhantomData<Event>: UnsafeUnpin, PhantomData<EndpointEventInner>: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<Atomic<bool>> is !null: UnsafeUnpin, PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin, PhantomData<ErrorCause>: UnsafeUnpin, PhantomData<UndeliveredMessage>: UnsafeUnpin, PhantomData<Vec<ChunkPayloadData>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.