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

Method handle_request

nodedb/src/control/server/native/session.rs:239–457  ·  view source on GitHub ↗

Route a decoded request to the appropriate handler.

(
        &mut self,
        req: nodedb_types::protocol::NativeRequest,
    )

Source from the content-addressed store, hash-verified

237
238 /// Route a decoded request to the appropriate handler.
239 async fn handle_request(
240 &mut self,
241 req: nodedb_types::protocol::NativeRequest,
242 ) -> NativeResponse {
243 let seq = req.seq;
244 let op = req.op;
245
246 // Auth handling.
247 if op == OpCode::Auth {
248 return self.handle_auth(seq, &req.fields).await;
249 }
250
251 // Ping requires no auth.
252 if op == OpCode::Ping {
253 return dispatch::handle_ping(seq);
254 }
255
256 // Status requires no auth — returns current startup phase.
257 if op == OpCode::Status {
258 let health = crate::control::startup::health::observe(&self.state.startup);
259 let native_status = crate::control::startup::health::to_native_status(&health);
260 return NativeResponse::status_row(seq, native_status.to_string());
261 }
262
263 // All other ops require authentication.
264 if self.identity.is_none() {
265 if self.auth_mode == AuthMode::Trust {
266 let trust_id = super::super::session_auth::trust_identity(&self.state, "anonymous");
267 self.auth_context = Some(super::super::session_auth::build_auth_context(&trust_id));
268 self.identity = Some(trust_id);
269 } else {
270 return NativeResponse::error(
271 seq,
272 "28000",
273 "not authenticated. Send Auth request first.",
274 );
275 }
276 }
277
278 let identity = match self.identity.as_ref() {
279 Some(id) => id,
280 None => {
281 return NativeResponse::error(seq, "28000", "not authenticated");
282 }
283 };
284
285 // Build a default AuthContext if not yet set (shouldn't happen but be safe).
286 let default_auth_ctx;
287 let auth_ctx = match self.auth_context.as_ref() {
288 Some(ctx) => ctx,
289 None => {
290 default_auth_ctx = super::super::session_auth::build_auth_context(identity);
291 &default_auth_ctx
292 }
293 };
294
295 let ctx = DispatchCtx {
296 state: &self.state,

Callers 1

runMethod · 0.80

Calls 15

observeFunction · 0.85
to_native_statusFunction · 0.85
trust_identityFunction · 0.85
build_auth_contextFunction · 0.85
handle_sqlFunction · 0.85
handle_showFunction · 0.85
handle_resetFunction · 0.85
handle_beginFunction · 0.85
handle_commitFunction · 0.85
handle_rollbackFunction · 0.85
handle_direct_opFunction · 0.85
handle_authMethod · 0.80

Tested by

no test coverage detected