rtc_sctp/shared.rs
1use crate::Payload;
2use ::shared::Transmit;
3use std::fmt::{Debug, Formatter};
4
5/// Events sent from an Endpoint to an Association
6#[derive(Debug)]
7pub struct AssociationEvent(pub(crate) AssociationEventInner);
8
9pub(crate) enum AssociationEventInner {
10 /// A datagram has been received for the Association
11 Datagram(Transmit<Payload>),
12 // New Association identifiers have been issued for the Association
13 //NewIdentifiers(Vec<IssuedAid>, Instant),
14}
15
16impl Debug for AssociationEventInner {
17 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18 f.debug_struct("AssociationEventInner")
19 .field("Datagram", &self)
20 .finish()
21 }
22}
23
24/// Events sent from an Association to an Endpoint
25#[derive(Debug)]
26pub struct EndpointEvent(pub(crate) EndpointEventInner);
27
28impl EndpointEvent {
29 /// Construct an event that indicating that a `Association` will no longer emit events
30 ///
31 /// Useful for notifying an `Endpoint` that a `Association` has been destroyed outside of the
32 /// usual state machine flow, e.g. when being dropped by the user.
33 pub fn drained() -> Self {
34 Self(EndpointEventInner::Drained)
35 }
36
37 /// Determine whether this is the last event a `Association` will emit
38 ///
39 /// Useful for determining when association-related event loop state can be freed.
40 pub fn is_drained(&self) -> bool {
41 self.0 == EndpointEventInner::Drained
42 }
43}
44
45#[derive(Clone, Debug, Eq, PartialEq)]
46pub(crate) enum EndpointEventInner {
47 /// The association has been drained
48 Drained,
49 /*// The association needs association identifiers
50 NeedIdentifiers(Instant, u64),
51 /// Stop routing Association ID for this sequence number to the Association
52 /// When `bool == true`, a new Association ID will be issued to peer
53 RetireAssociationId(Instant, u64, bool),*/
54}
55
56/// Protocol-level identifier for an Association.
57///
58/// Mainly useful for identifying this Association's packets on the wire with tools like Wireshark.
59pub type AssociationId = u32;
60
61#[derive(Debug, Copy, Clone)]
62pub struct IssuedAid {
63 pub sequence: u64,
64 pub id: AssociationId,
65}