pub mod features;
pub mod limits;
pub mod messages;
pub mod negotiate;
pub mod role;
pub use features::FeatureFlags;
pub use limits::{
DEFAULT_MAX_INFLIGHT_FRAMES, DEFAULT_MAX_ROUTES, DEFAULT_MAX_SUBSCRIPTIONS, NegotiatedLimits,
};
pub use messages::{Hello, RefusalReason, Refused, Welcome};
pub use negotiate::{
Acceptor, HandshakeError, HandshakeOutcome, MIN_USABLE_PAYLOAD_BYTES, NegotiatedSession,
SessionAssignment, accept_welcome, negotiate,
};
pub use role::{Role, RoleSet};
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use super::*;
use crate::auth::AuthToken;
use crate::ids::SessionId;
#[test]
fn every_leg_completes_the_same_handshake() {
let token = AuthToken::from_bytes([3; 32]);
for (index, &role) in Role::ALL.iter().enumerate() {
let hello = Hello::new(role, token.clone())
.with_features(FeatureFlags::TRACING)
.with_label(role.as_str());
let acceptor = Acceptor::new(token.clone())
.with_accepted_roles(RoleSet::only(role))
.with_features(FeatureFlags::TRACING | FeatureFlags::QUIC);
let session_id = SessionId::from_u128(index as u128 + 1);
let outcome = negotiate(&hello, &acceptor, SessionAssignment::Fresh(session_id));
let welcome = outcome.welcome().cloned().expect("accepted");
let session = accept_welcome(&hello, &welcome).unwrap();
assert_eq!(session.role, role);
assert_eq!(session.session_id, session_id);
assert_eq!(session.features, FeatureFlags::TRACING);
assert!(!session.resumed);
}
}
#[test]
fn the_module_re_exports_the_whole_surface() {
fn assert_exists<T>() {}
assert_exists::<Hello>();
assert_exists::<Welcome>();
assert_exists::<Refused>();
assert_exists::<RefusalReason>();
assert_exists::<Role>();
assert_exists::<RoleSet>();
assert_exists::<FeatureFlags>();
assert_exists::<NegotiatedLimits>();
assert_exists::<Acceptor>();
assert_exists::<NegotiatedSession>();
assert_exists::<HandshakeOutcome>();
assert_exists::<HandshakeError>();
assert_exists::<SessionAssignment>();
const {
assert!(MIN_USABLE_PAYLOAD_BYTES > 0);
assert!(DEFAULT_MAX_ROUTES > 0);
assert!(DEFAULT_MAX_INFLIGHT_FRAMES > 0);
assert!(DEFAULT_MAX_SUBSCRIPTIONS > 0);
}
}
}