sctp_proto/
shared.rs

1use crate::Transmit;
2
3/// Events sent from an Endpoint to an Association
4#[derive(Debug)]
5pub struct AssociationEvent(pub(crate) AssociationEventInner);
6
7#[derive(Debug)]
8pub(crate) enum AssociationEventInner {
9    /// A datagram has been received for the Association
10    Datagram(Transmit),
11    // New Association identifiers have been issued for the Association
12    //NewIdentifiers(Vec<IssuedAid>, Instant),
13}
14
15/// Events sent from an Association to an Endpoint
16#[derive(Debug)]
17pub struct EndpointEvent(pub(crate) EndpointEventInner);
18
19impl EndpointEvent {
20    /// Construct an event that indicating that a `Association` will no longer emit events
21    ///
22    /// Useful for notifying an `Endpoint` that a `Association` has been destroyed outside of the
23    /// usual state machine flow, e.g. when being dropped by the user.
24    pub fn drained() -> Self {
25        Self(EndpointEventInner::Drained)
26    }
27
28    /// Determine whether this is the last event a `Association` will emit
29    ///
30    /// Useful for determining when association-related event loop state can be freed.
31    pub fn is_drained(&self) -> bool {
32        self.0 == EndpointEventInner::Drained
33    }
34}
35
36#[derive(Clone, Debug, Eq, PartialEq)]
37pub(crate) enum EndpointEventInner {
38    /// The association has been drained
39    Drained,
40    /*// The association needs association identifiers
41    NeedIdentifiers(Instant, u64),
42    /// Stop routing Association ID for this sequence number to the Association
43    /// When `bool == true`, a new Association ID will be issued to peer
44    RetireAssociationId(Instant, u64, bool),*/
45}
46
47/// Protocol-level identifier for an Association.
48///
49/// Mainly useful for identifying this Association's packets on the wire with tools like Wireshark.
50pub type AssociationId = u32;
51
52/// Explicit congestion notification codepoint
53#[repr(u8)]
54#[derive(Debug, Copy, Clone, Eq, PartialEq)]
55pub enum EcnCodepoint {
56    #[doc(hidden)]
57    Ect0 = 0b10,
58    #[doc(hidden)]
59    Ect1 = 0b01,
60    #[doc(hidden)]
61    Ce = 0b11,
62}
63
64impl EcnCodepoint {
65    /// Create new object from the given bits
66    pub fn from_bits(x: u8) -> Option<Self> {
67        use self::EcnCodepoint::*;
68        Some(match x & 0b11 {
69            0b10 => Ect0,
70            0b01 => Ect1,
71            0b11 => Ce,
72            _ => {
73                return None;
74            }
75        })
76    }
77}
78
79#[derive(Debug, Copy, Clone)]
80pub struct IssuedAid {
81    pub sequence: u64,
82    pub id: AssociationId,
83}