node_device_session/
types.rs1use std::path::PathBuf;
4
5pub const SESSION_HEADER: &str = "x-node-device-session";
7pub const PATH_HEADER: &str = "x-node-device-session-path";
9
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
12pub enum SessionPath {
13 Relay,
15 WebRtc,
17}
18
19impl SessionPath {
20 pub fn as_str(self) -> &'static str {
22 match self {
23 Self::Relay => "relay",
24 Self::WebRtc => "webrtc",
25 }
26 }
27}
28
29#[derive(Clone, Debug, Default)]
31pub struct IngressSocket {
32 pub path: Option<PathBuf>,
34}
35
36#[derive(Clone, Debug, PartialEq, Eq)]
38pub struct Session {
39 pub device_id: String,
41 pub device_did: String,
43 pub scopes: Vec<String>,
45 pub expires_at: String,
47 pub credential: Option<String>,
49}
50
51#[derive(Clone, Debug, PartialEq, Eq)]
53pub struct Refusal {
54 pub code: String,
56 pub message: String,
58}
59
60impl Refusal {
61 pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
63 Self {
64 code: code.into(),
65 message: message.into(),
66 }
67 }
68
69 pub fn wire(&self) -> String {
71 format!("{}: {}", self.code, self.message)
72 }
73}
74
75#[derive(Debug, thiserror::Error)]
77pub enum SessionEnd {
78 #[error("session closed")]
80 Closed,
81 #[error("session not opened: {0}")]
83 NotOpened(String),
84 #[error("open timed out")]
86 OpenTimeout,
87 #[error("transport: {0}")]
89 Transport(#[from] std::io::Error),
90}