Skip to main content

rtci_sctp/
shared.rs

1use crate::Payload;
2use ::shared::TransportMessage;
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(TransportMessage<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 peer restarted the association (RFC 9260 5.2.4 action A): it has new tags, which
50    /// the endpoint routes by from now on.
51    Retagged {
52        old_local: AssociationId,
53        new_local: AssociationId,
54        old_peer: AssociationId,
55        new_peer: AssociationId,
56    },
57    /*// The association needs association identifiers
58    NeedIdentifiers(Instant, u64),
59    /// Stop routing Association ID for this sequence number to the Association
60    /// When `bool == true`, a new Association ID will be issued to peer
61    RetireAssociationId(Instant, u64, bool),*/
62}
63
64/// Protocol-level identifier for an Association.
65///
66/// Mainly useful for identifying this Association's packets on the wire with tools like Wireshark.
67pub type AssociationId = u32;
68
69#[derive(Debug, Copy, Clone)]
70pub struct IssuedAid {
71    pub sequence: u64,
72    pub id: AssociationId,
73}