rtc_sctp/
lib.rs

1//! Low-level protocol logic for the SCTP protocol
2//!
3//! sctp-proto contains a fully deterministic implementation of SCTP protocol logic. It contains
4//! no networking code and does not get any relevant timestamps from the operating system. Most
5//! users may want to use the futures-based sctp-async API instead.
6//!
7//! The sctp-proto API might be of interest if you want to use it from a C or C++ project
8//! through C bindings or if you want to use a different event loop than the one tokio provides.
9//!
10//! The most important types are `Endpoint`, which conceptually represents the protocol state for
11//! a single socket and mostly manages configuration and dispatches incoming datagrams to the
12//! related `Association`. `Association` types contain the bulk of the protocol logic related to
13//! managing a single association and all the related state (such as streams).
14
15#![warn(rust_2018_idioms)]
16#![allow(dead_code)]
17#![allow(clippy::bool_to_int_with_if)]
18
19use bytes::Bytes;
20use std::{fmt, ops};
21
22mod association;
23pub use crate::association::{
24    stats::AssociationStats,
25    stream::{ReliabilityType, Stream, StreamEvent, StreamId, StreamState},
26    timer::TimerConfig,
27    Association, AssociationError, Event,
28};
29
30pub(crate) mod chunk;
31pub use crate::chunk::{
32    chunk_payload_data::{ChunkPayloadData, PayloadProtocolIdentifier},
33    ErrorCauseCode,
34};
35
36mod config;
37pub use crate::config::{ClientConfig, EndpointConfig, ServerConfig, TransportConfig};
38
39mod endpoint;
40pub use crate::endpoint::{AssociationHandle, ConnectError, DatagramEvent, Endpoint};
41
42mod packet;
43
44mod shared;
45pub use crate::shared::{AssociationEvent, AssociationId, EndpointEvent};
46
47pub(crate) mod param;
48
49pub(crate) mod queue;
50pub use crate::queue::reassembly_queue::{Chunk, Chunks};
51
52pub(crate) mod util;
53
54/// Whether an endpoint was the initiator of an association
55#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
56pub enum Side {
57    /// The initiator of an association
58    #[default]
59    Client = 0,
60    /// The acceptor of an association
61    Server = 1,
62}
63
64impl fmt::Display for Side {
65    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66        let s = match *self {
67            Side::Client => "Client",
68            Side::Server => "Server",
69        };
70        write!(f, "{}", s)
71    }
72}
73
74impl Side {
75    #[inline]
76    /// Shorthand for `self == Side::Client`
77    pub fn is_client(self) -> bool {
78        self == Side::Client
79    }
80
81    #[inline]
82    /// Shorthand for `self == Side::Server`
83    pub fn is_server(self) -> bool {
84        self == Side::Server
85    }
86}
87
88impl ops::Not for Side {
89    type Output = Side;
90    fn not(self) -> Side {
91        match self {
92            Side::Client => Side::Server,
93            Side::Server => Side::Client,
94        }
95    }
96}
97
98use crate::packet::PartialDecode;
99
100/// Payload in Incoming/outgoing Transmit
101#[derive(Debug)]
102pub enum Payload {
103    PartialDecode(PartialDecode),
104    RawEncode(Vec<Bytes>),
105}