821537186e
- Reorganized import statements in adapter tests for better readability - Replaced or_insert_with(Vec::new) with or_default() in test closures - Updated Cargo.lock with new dependency versions and checksums - Added TLS features to tonic dependency configuration - Included sqlx, chrono, and uuid dependencies with specific features - Added jsonwebtoken and arc-swap as project dependencies - Reformatted assertion statements to comply with line length limits - Adjusted base64 import order in engine codec module - Updated protobuf include statement formatting
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use crate::engine::packet::Packet;
|
|
use crate::engine::session::{SessionState, SessionStore, TransportType};
|
|
|
|
pub async fn handle_upgrade_probe(store: &SessionStore, sid: &str) -> Result<Packet, UpgradeError> {
|
|
let session = store.get(sid).ok_or(UpgradeError::SessionNotFound)?;
|
|
let mut session = session.write().await;
|
|
|
|
if session.state == SessionState::Closed {
|
|
return Err(UpgradeError::SessionClosed);
|
|
}
|
|
|
|
session.set_state(SessionState::Upgrading);
|
|
Ok(Packet::pong("probe"))
|
|
}
|
|
|
|
pub async fn handle_upgrade_complete(
|
|
store: &SessionStore,
|
|
sid: &str,
|
|
new_transport: TransportType,
|
|
) -> Result<(), UpgradeError> {
|
|
let session = store.get(sid).ok_or(UpgradeError::SessionNotFound)?;
|
|
let mut session = session.write().await;
|
|
|
|
session.set_transport(new_transport);
|
|
session.set_state(SessionState::Open);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn send_noop_to_pending_polling(
|
|
store: &SessionStore,
|
|
sid: &str,
|
|
) -> Result<(), UpgradeError> {
|
|
let session = store.get(sid).ok_or(UpgradeError::SessionNotFound)?;
|
|
let mut session = session.write().await;
|
|
|
|
session.buffer_packet(Packet::noop());
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum UpgradeError {
|
|
#[error("session not found")]
|
|
SessionNotFound,
|
|
#[error("session closed")]
|
|
SessionClosed,
|
|
#[error("invalid state for upgrade")]
|
|
InvalidState,
|
|
}
|