MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / register

Method register

nodedb/src/control/security/sessions/registry.rs:124–160  ·  view source on GitHub ↗

Register a new session. Returns a kill-signal receiver the session loop must check at each request boundary. Returns [`SessionCapExceeded`] when the registry is full.

(
        &self,
        session_id: &str,
        params: &SessionParams,
    )

Source from the content-addressed store, hash-verified

122 /// request boundary. Returns [`SessionCapExceeded`] when the registry
123 /// is full.
124 pub fn register(
125 &self,
126 session_id: &str,
127 params: &SessionParams,
128 ) -> Result<watch::Receiver<KillReason>, SessionCapExceeded> {
129 let now = now_secs();
130 let (kill_tx, kill_rx) = watch::channel(KillReason::Alive);
131 let current_database_u64 = params.current_database.map(|d| d.as_u64()).unwrap_or(0);
132 let token_expiry = params.token_expiry_ms.unwrap_or(0);
133 let entry = RegisteredSession {
134 user_id: params.user_id,
135 db_user: params.db_user.clone(),
136 peer_addr: params.peer_addr.clone(),
137 protocol: params.protocol.clone(),
138 auth_method: params.auth_method.clone(),
139 tenant_id: params.tenant_id,
140 connected_at: now,
141 last_active: AtomicU64::new(now),
142 kill_tx,
143 credential_version: params.credential_version,
144 current_database: AtomicU64::new(current_database_u64),
145 idle_timeout_secs: AtomicU64::new(0),
146 token_expiry_ms: AtomicU64::new(token_expiry),
147 bytes_in: AtomicU64::new(0),
148 bytes_out: AtomicU64::new(0),
149 current_statement_digest: RwLock::new(None),
150 };
151
152 let mut sessions = self.sessions.write().unwrap_or_else(|p| p.into_inner());
153 if self.max_sessions > 0 && sessions.len() >= self.max_sessions {
154 return Err(SessionCapExceeded {
155 cap: self.max_sessions,
156 });
157 }
158 sessions.insert(session_id.to_string(), entry);
159 Ok(kill_rx)
160 }
161
162 /// Unregister a session on disconnect.
163 pub fn unregister(&self, session_id: &str) {

Calls 7

to_stringMethod · 0.80
now_secsFunction · 0.50
as_u64Method · 0.45
cloneMethod · 0.45
writeMethod · 0.45
lenMethod · 0.45
insertMethod · 0.45