liminal-server 0.25.4

Standalone server for the liminal messaging bus
Documentation
//! Registration proves serve on the routed subject before any declared namespace.

use super::{
    ConnectionProcessState, ConnectionRuntime, FrameAction, HotAction, MembershipAction,
    WorkerRegistration, lys_decision, lys_refusal, membership_refusal, worker_register_rejected,
};
use liminal::protocol::{Frame, WorkerRegisterOutcome};

pub(super) fn decide(
    runtime: &ConnectionRuntime,
    state: &ConnectionProcessState,
    registration: &WorkerRegistration,
) -> Option<FrameAction> {
    // The directory routes only the task queue. Decide it exactly as its
    // reply will be decided, before a namespace can hide that refusal.
    if let Some(reason) = lys_refusal(runtime, state, &registration.task_queue, HotAction::Serve)
        .or_else(|| membership_refusal(state, &registration.task_queue, MembershipAction::Post))
    {
        return Some(worker_register_rejected(reason));
    }
    for namespace in &registration.namespaces {
        if let Some(refused) = lys_decision(runtime, state, namespace, HotAction::Serve, |reason| {
            Frame::WorkerRegisterAck {
                flags: 0,
                outcome: WorkerRegisterOutcome::Rejected { reason },
            }
        }) {
            return Some(refused);
        }
    }
    None
}