use std::path::PathBuf;
pub const SESSION_HEADER: &str = "x-node-device-session";
pub const PATH_HEADER: &str = "x-node-device-session-path";
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SessionPath {
Relay,
WebRtc,
}
impl SessionPath {
pub fn as_str(self) -> &'static str {
match self {
Self::Relay => "relay",
Self::WebRtc => "webrtc",
}
}
}
#[derive(Clone, Debug, Default)]
pub struct IngressSocket {
pub path: Option<PathBuf>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Session {
pub device_id: String,
pub device_did: String,
pub scopes: Vec<String>,
pub expires_at: String,
pub credential: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Refusal {
pub code: String,
pub message: String,
}
impl Refusal {
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
Self {
code: code.into(),
message: message.into(),
}
}
pub fn wire(&self) -> String {
format!("{}: {}", self.code, self.message)
}
}
#[derive(Debug, thiserror::Error)]
pub enum SessionEnd {
#[error("session closed")]
Closed,
#[error("session not opened: {0}")]
NotOpened(String),
#[error("open timed out")]
OpenTimeout,
#[error("transport: {0}")]
Transport(#[from] std::io::Error),
}