Skip to main content

ServiceContext

Struct ServiceContext 

Source
pub struct ServiceContext { /* private fields */ }
Expand description

Context for service creation.

Contains all shared resources needed by services during initialization. Passed to factory functions registered via #[service_factory].

Implementations§

Source§

impl ServiceContext

Source

pub fn moql_admission_proof( &self, service_name: &str, ) -> Result<Option<MoqlAdmissionProof>>

Return an accepted-state-bound admission proof for a service that was checkpoint-authorized for native network startup.

Source

pub fn native_iroh_announcement_callback( &self, service_name: &str, ) -> Result<NativeIrohAnnouncementCallback>

Publication callback for a MoQ-only service which has no RPC loop.

Source

pub fn new( signing_key: SigningKey, verifying_key: VerifyingKey, ipc: bool, models_dir: PathBuf, ) -> Self

Create a new service context.

Source

pub fn with_dedicated_process_service(self, service: String) -> Self

The launcher may set this only after enforcing one service per process. It authorizes that service to terminate the process on an unjoinable worker.

Source

pub fn is_dedicated_process_for(&self, service: &str) -> bool

Source

pub fn with_secrets_dir(self, dir: PathBuf) -> Self

Carry the explicitly resolved credentials directory into factories.

Startup resolves [secrets].path from the loaded config and reads the retained signing key and service JWT from that directory; factory-time helpers (key registration, JWT renewal) have no config handle of their own and must not re-resolve from env/defaults, or a custom --config [secrets].path deployment would work at startup and then renew against the wrong directory.

Source

pub fn secrets_dir(&self) -> Option<&Path>

The explicitly resolved credentials directory, when the constructing process carried one.

Source

pub fn set_ml_dsa_verifying_keys( &mut self, keys: Arc<RwLock<Vec<MlDsaVerifyingKey>>>, )

Set the shared ML-DSA-65 verifying keys for PQ-hybrid JWT verification.

Source

pub fn ml_dsa_verifying_keys_arc(&self) -> Arc<RwLock<Vec<MlDsaVerifyingKey>>> ⓘ

Get a clone of the shared ML-DSA verifying keys Arc.

Source

pub fn with_service_key( self, service_name: &str, signing_key: SigningKey, ) -> Self

Add a per-service independent signing key.

In single-process mode, these are generated in memory at startup. In multi-process mode, these are loaded from per-service credential files.

Source

pub fn with_native_announcement( self, service_name: impl Into<String>, announcement: NativeServiceAnnouncement, ) -> Self

Source

pub fn with_service_keys<I>(self, keys: I) -> Self
where I: IntoIterator<Item = (String, SigningKey)>,

Bulk-register service keys from an iterator.

Source

pub fn with_ca_verifying_key(self, key: VerifyingKey) -> Self

Set the CA verifying key (trust anchor for verifying service JWTs).

Source

pub fn with_ca_ml_dsa_verifying_key(self, key: MlDsaVerifyingKey) -> Self

Set the CA’s derived ML-DSA-65 verifying key (the post-quantum half of the CA JWT composite pair used for hybrid service JWTs).

Source

pub fn swap_signing_key(self, new_key: SigningKey) -> Self

Swap the signing key to an independent per-service key.

Used in IPC mode for non-policy services: replaces the root/CA key with the service’s own independent Ed25519 key. The CA key is no longer accessible via signing_key() after this call.

Source

pub fn generate_independent_service_keys(self, service_names: &[String]) -> Self

Generate independent Ed25519 keypairs for all listed services and issue CA-signed service JWTs in memory.

Used by single-process mode where all services run in one process. The root signing key serves as the CA key — PolicyService will use it directly (it IS the CA), while all other services get independent keys.

Populates service_keys, ca_verifying_key, and the global trust store from the generated materials.

Source

pub fn with_quic(self, config: QuicSharedConfig) -> Self

Set the shared QUIC/WebTransport configuration.

Per-service ports are resolved via into_spawnable_quic().

Source

pub fn quic_shared(&self) -> Option<&QuicSharedConfig>

Get the shared QUIC config (if enabled).

Source

pub fn has_quic(&self) -> bool

Check if QUIC/WebTransport is enabled.

Source

pub fn iroh_required(&self) -> bool

Source

pub fn with_oauth_issuer(self, url: String) -> Self

Set the OAuth issuer URL for RFC 9728 metadata.

Source

pub fn oauth_issuer_url(&self) -> Option<&str>

Get the OAuth issuer URL (if configured).

Source

pub fn federation_key_source(&self) -> Option<Arc<dyn FederationKeySource>>

Get the federation key source (if configured).

Source

pub fn with_federation_key_source( self, src: Arc<dyn FederationKeySource>, ) -> Self

Set the shared federation key source for multi-issuer ZMQ token acceptance.

Source

pub fn signing_key(&self) -> &SigningKey

Get the root signing key.

Only PolicyService (the CA) should call this. All other services must use service_signing_key("name") for per-service key derivation. The root key is needed by PolicyService to issue service JWTs and by node-level operations (main.rs) for QuicSharedConfig construction.

If you’re writing a factory function and the service name is not “policy”, use service_signing_key(service_name) instead.

Source

pub fn service_signing_key(&self, service_name: &str) -> SigningKey

Get the signing key for a specific service.

Lookup order:

  1. service_keys registry (independent keypair per service)
  2. PolicyService special case (returns root key — it IS the CA)
  3. “multi” fallback (multi-service IPC mode shares one key for all services)

Panics if no key is registered. Ensure generate_independent_service_keys() was called (inproc) or the service’s own key was loaded from credentials (IPC).

Source

pub fn ca_verifying_key(&self) -> Option<VerifyingKey>

Get the CA verifying key (trust anchor).

Source

pub fn verifying_key(&self) -> VerifyingKey

Get the verifying key.

Source

pub fn jwt_verifying_key(&self) -> VerifyingKey

Get the JWT verifying key (CA verifying key — trust anchor).

This is the key that verifies all service JWTs. Published as x_root_pubkey in RFC 9728 metadata. Services use this to verify service JWTs from peers.

Source

pub fn cluster_key_source(&self) -> Arc<dyn JwtKeySource> ⓘ

Create a key source for regular services.

When a JWKS fetcher is configured, returns JwksKeySource(Mode::Isolated) with kid-based resolution. Otherwise falls back to ClusterKeySource (single hardcoded CA key).

§Panics

Panics if ca_verifying_key is not set.

Source

pub fn set_jwks_fetcher(&mut self, fetcher: JwksFetcher)

Set the JWKS fetcher for JWKS-backed key resolution.

When set, cluster_key_source() returns JwksKeySource(Mode::Isolated) instead of ClusterKeySource, enabling kid-based key selection from the local /oauth/jwks endpoint.

Source

pub fn identity_provider(&self) -> &Arc<NodeIdentityProvider> ⓘ

Get the identity provider for purpose-keyed signing.

Source

pub fn is_ipc(&self) -> bool

Check if running in IPC mode.

Source

pub fn models_dir(&self) -> &Path

Get models directory path.

Source

pub fn deployment_data_dir(&self) -> Result<PathBuf>

Canonical service-owned deployment directory.

This deliberately ignores the caller-provided models_dir: public ServiceContext::new creates local/factory context only and cannot select the production Discovery authority root.

Source

pub fn endpoint(&self, service: &str, kind: SocketKind) -> TransportConfig

Get transport config for a service endpoint from the registry.

This looks up the endpoint from the global EndpointRegistry.

Source

pub fn transport(&self, service: &str, kind: SocketKind) -> TransportConfig

Get unified transport config for a service.

In IPC mode, returns a Unix socket path in the runtime directory. In inproc mode, returns the endpoint from the global registry.

This unifies the transport resolution logic that was previously duplicated across factory functions.

Source

pub fn into_spawnable_quic<S: RequestService + Send + Sync + 'static>( &self, service: S, quic_port: Option<u16>, ) -> Box<dyn Spawnable>

Wrap a RequestService for spawning with a per-service QUIC port.

  • quic_port: None → use ephemeral port (0) when QUIC is globally enabled
  • quic_port: Some(0) → ephemeral (OS-assigned) port
  • quic_port: Some(N) → explicit port N

When [quic] enabled = true in config, all services get QUIC on auto-assigned ephemeral ports by default. Set an explicit port to control which port a service uses.

Source

pub fn into_spawnable_quic_with_publisher<S: RequestService + Send + Sync + 'static>( &self, service: S, quic_port: Option<u16>, publisher: Option<NativeAnnouncementPublisher>, ) -> Box<dyn Spawnable>

Supply an owned publication path for a service that cannot RPC itself before readiness. Binding/cancellation still belong to the spawner.

Source

pub fn into_spawnable<S: RequestService + Send + Sync + 'static>( &self, service: S, ) -> Box<dyn Spawnable>

Wrap a RequestService for spawning, enabling QUIC when globally configured.

Uses ephemeral port (0) for QUIC when [quic] enabled = true.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> MaybeSync for T
where T: Sync,