pub type AssociationId = i32;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BindxFlags {
Add,
Remove,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SocketToAssociation {
OneToOne,
OneToMany,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NotificationOrData {
Notification(Notification),
Data(ReceivedData),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ReceivedData {
pub payload: Vec<u8>,
pub rcv_info: Option<RcvInfo>,
pub nxt_info: Option<NxtInfo>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SendData {
pub payload: Vec<u8>,
pub snd_info: Option<SendInfo>,
}
#[repr(C)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct SendInfo {
pub sid: u16,
pub flags: u16,
pub ppid: u32,
pub context: u32,
pub assoc_id: AssociationId,
}
#[repr(C)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct RcvInfo {
pub sid: u16,
pub ssn: u16,
pub flags: u16,
pub ppid: u32,
pub tsn: u32,
pub cumtsn: u32,
pub context: u32,
pub assoc_id: AssociationId,
}
#[repr(C)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct NxtInfo {
pub sid: u16,
pub flags: u16,
pub ppid: u32,
pub length: u32,
pub assoc_id: AssociationId,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Notification {
AssociationChange(AssociationChange),
Shutdown(Shutdown),
Unsupported,
}
#[repr(C)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AssociationChange {
pub ev_type: Event,
pub flags: u16,
pub length: u32,
pub state: AssocChangeState,
pub error: u16,
pub ob_streams: u16,
pub ib_streams: u16,
pub assoc_id: AssociationId,
pub info: Vec<u8>,
}
#[repr(C)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Shutdown {
pub ev_type: Event,
pub flags: u16,
pub length: u32,
pub assoc_id: AssociationId,
}
#[repr(u16)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
DataIo = (1 << 15),
Association,
Address,
SendFailure,
PeerError,
Shutdown,
PartialDelivery,
AdaptationLayer,
Authentication,
SenderDry,
StreamReset,
AssociationReset,
StreamChange,
SendFailureEvent,
Unknown,
}
impl Event {
pub(crate) fn from_u16(val: u16) -> Self {
match val {
0x8000 => Event::DataIo,
0x8001 => Event::Association,
0x8002 => Event::Address,
0x8003 => Event::SendFailure,
0x8004 => Event::PeerError,
0x8005 => Event::Shutdown,
0x8006 => Event::PartialDelivery,
0x8007 => Event::AdaptationLayer,
0x8008 => Event::Authentication,
0x8009 => Event::SenderDry,
0x800A => Event::StreamReset,
0x800B => Event::AssociationReset,
0x800C => Event::StreamChange,
0x800D => Event::SendFailureEvent,
_ => Event::Unknown,
}
}
}
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SubscribeEventAssocId {
Future,
Current,
All,
Value(AssociationId),
}
impl From<SubscribeEventAssocId> for AssociationId {
fn from(value: SubscribeEventAssocId) -> Self {
match value {
SubscribeEventAssocId::Future => 0 as Self,
SubscribeEventAssocId::Current => 1 as Self,
SubscribeEventAssocId::All => 2 as Self,
SubscribeEventAssocId::Value(v) => v,
}
}
}
#[repr(u16)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AssocChangeState {
CommUp = 0,
CommLost,
Restart,
ShutdownComplete,
CannotStartAssoc,
Unknown,
}
impl AssocChangeState {
pub(crate) fn from_u16(val: u16) -> Self {
match val {
0 => AssocChangeState::CommUp,
1 => AssocChangeState::CommLost,
2 => AssocChangeState::Restart,
3 => AssocChangeState::ShutdownComplete,
4 => AssocChangeState::CannotStartAssoc,
_ => AssocChangeState::Unknown,
}
}
}
#[repr(i32)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CmsgType {
Init = 0,
SndRcv,
SndInfo,
RcvInfo,
NxtInfo,
PrInfo,
AuthInfo,
DstAddrV4,
DstAddrV6,
}
#[repr(i32)]
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum ConnState {
#[default]
Empty = 0,
Closed,
CookieWait,
CookieEchoed,
Established,
ShutdownPending,
ShutdownSent,
ShutdownReceived,
ShutdownAckSent,
Unknown, }
impl ConnState {
fn from_i32(val: i32) -> Self {
match val {
0 => Self::Empty,
1 => Self::Closed,
2 => Self::CookieWait,
3 => Self::CookieEchoed,
4 => Self::Established,
5 => Self::ShutdownPending,
6 => Self::ShutdownSent,
7 => Self::ShutdownReceived,
8 => Self::ShutdownAckSent,
_ => Self::Unknown,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PeerAddress {
pub assoc_id: AssociationId,
pub address: std::net::SocketAddr,
pub state: i32,
pub cwnd: u32,
pub srtt: u32,
pub rto: u32,
pub mtu: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConnStatus {
pub assoc_id: AssociationId,
pub state: ConnState,
pub rwnd: u32,
pub unacked_data: u16,
pub pending_data: u16,
pub instreams: u16,
pub outstreams: u16,
pub fragmentation_pt: u32,
pub peer_primary: PeerAddress,
}
pub(crate) mod internal;