openrtc 2.9.8

OpenRTC: a Rust-first P2P runtime for device discovery, signaling, and iroh/QUIC networking.
Documentation
//! Private carrier identities used below the Iroh endpoint.

/// Experimental IDs are intentionally not advertised as public interoperability
/// identifiers until Iroh's transport registry assigns stable values.
pub const EXPERIMENTAL_WEBRTC_TRANSPORT_ID: u64 = 0x4f_52_54_57;
pub const EXPERIMENTAL_MOQ_TRANSPORT_ID: u64 = 0x4f_52_4d_51;

/// Returns whether `transport_id` belongs to an OpenRTC-owned custom carrier.
///
/// Accept loops use this narrow allowlist to distinguish a carrier candidate,
/// whose coordination authorization may still be in flight, from an ordinary
/// Iroh connection that must continue through normal admission immediately.
#[cfg(any(
    not(target_arch = "wasm32"),
    feature = "transport-webrtc",
    feature = "transport-moq",
    test
))]
pub(crate) fn is_openrtc_carrier_transport_id(transport_id: u64) -> bool {
    matches!(
        transport_id,
        EXPERIMENTAL_WEBRTC_TRANSPORT_ID | EXPERIMENTAL_MOQ_TRANSPORT_ID
    )
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IrohCarrierKind {
    WebRtc,
    Moq,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn only_openrtc_carrier_transport_ids_receive_candidate_grace() {
        assert!(is_openrtc_carrier_transport_id(
            EXPERIMENTAL_WEBRTC_TRANSPORT_ID
        ));
        assert!(is_openrtc_carrier_transport_id(
            EXPERIMENTAL_MOQ_TRANSPORT_ID
        ));
        assert!(!is_openrtc_carrier_transport_id(0));
        assert!(!is_openrtc_carrier_transport_id(0x4f_52_54_58));
    }
}

/// Local completed MoQ object work, including readiness/control/repeated objects.
/// Not QUIC/WebTransport wire bytes, remote delivery, provider cost, or payer proof.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MoqObjectQuantities {
    pub accepted_write_objects: u64,
    pub accepted_write_bytes: u64,
    pub completed_received_objects: u64,
    pub completed_received_bytes: u64,
}

impl MoqObjectQuantities {
    pub fn is_safe(&self) -> bool {
        [self.accepted_write_objects, self.accepted_write_bytes,
         self.completed_received_objects, self.completed_received_bytes]
            .into_iter().all(|value| value <= 9_007_199_254_740_991)
    }
}