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
impl ServiceContext
Sourcepub fn moql_admission_proof(
&self,
service_name: &str,
) -> Result<Option<MoqlAdmissionProof>>
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.
Sourcepub fn native_iroh_announcement_callback(
&self,
service_name: &str,
) -> Result<NativeIrohAnnouncementCallback>
pub fn native_iroh_announcement_callback( &self, service_name: &str, ) -> Result<NativeIrohAnnouncementCallback>
Publication callback for a MoQ-only service which has no RPC loop.
Sourcepub fn new(
signing_key: SigningKey,
verifying_key: VerifyingKey,
ipc: bool,
models_dir: PathBuf,
) -> Self
pub fn new( signing_key: SigningKey, verifying_key: VerifyingKey, ipc: bool, models_dir: PathBuf, ) -> Self
Create a new service context.
Sourcepub fn with_dedicated_process_service(self, service: String) -> Self
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.
pub fn is_dedicated_process_for(&self, service: &str) -> bool
Sourcepub fn with_secrets_dir(self, dir: PathBuf) -> Self
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.
Sourcepub fn secrets_dir(&self) -> Option<&Path>
pub fn secrets_dir(&self) -> Option<&Path>
The explicitly resolved credentials directory, when the constructing process carried one.
Sourcepub fn set_ml_dsa_verifying_keys(
&mut self,
keys: Arc<RwLock<Vec<MlDsaVerifyingKey>>>,
)
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.
Sourcepub fn ml_dsa_verifying_keys_arc(&self) -> Arc<RwLock<Vec<MlDsaVerifyingKey>>> ⓘ
pub fn ml_dsa_verifying_keys_arc(&self) -> Arc<RwLock<Vec<MlDsaVerifyingKey>>> ⓘ
Get a clone of the shared ML-DSA verifying keys Arc.
Sourcepub fn with_service_key(
self,
service_name: &str,
signing_key: SigningKey,
) -> Self
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.
pub fn with_native_announcement( self, service_name: impl Into<String>, announcement: NativeServiceAnnouncement, ) -> Self
Sourcepub fn with_service_keys<I>(self, keys: I) -> Selfwhere
I: IntoIterator<Item = (String, SigningKey)>,
pub fn with_service_keys<I>(self, keys: I) -> Selfwhere
I: IntoIterator<Item = (String, SigningKey)>,
Bulk-register service keys from an iterator.
Sourcepub fn with_ca_verifying_key(self, key: VerifyingKey) -> Self
pub fn with_ca_verifying_key(self, key: VerifyingKey) -> Self
Set the CA verifying key (trust anchor for verifying service JWTs).
Sourcepub fn with_ca_ml_dsa_verifying_key(self, key: MlDsaVerifyingKey) -> Self
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).
Sourcepub fn swap_signing_key(self, new_key: SigningKey) -> Self
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.
Sourcepub fn generate_independent_service_keys(self, service_names: &[String]) -> Self
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.
Sourcepub fn with_quic(self, config: QuicSharedConfig) -> Self
pub fn with_quic(self, config: QuicSharedConfig) -> Self
Set the shared QUIC/WebTransport configuration.
Per-service ports are resolved via into_spawnable_quic().
Get the shared QUIC config (if enabled).
pub fn iroh_required(&self) -> bool
Sourcepub fn with_oauth_issuer(self, url: String) -> Self
pub fn with_oauth_issuer(self, url: String) -> Self
Set the OAuth issuer URL for RFC 9728 metadata.
Sourcepub fn oauth_issuer_url(&self) -> Option<&str>
pub fn oauth_issuer_url(&self) -> Option<&str>
Get the OAuth issuer URL (if configured).
Sourcepub fn federation_key_source(&self) -> Option<Arc<dyn FederationKeySource>>
pub fn federation_key_source(&self) -> Option<Arc<dyn FederationKeySource>>
Get the federation key source (if configured).
Sourcepub fn with_federation_key_source(
self,
src: Arc<dyn FederationKeySource>,
) -> Self
pub fn with_federation_key_source( self, src: Arc<dyn FederationKeySource>, ) -> Self
Set the shared federation key source for multi-issuer ZMQ token acceptance.
Sourcepub fn signing_key(&self) -> &SigningKey
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.
Sourcepub fn service_signing_key(&self, service_name: &str) -> SigningKey
pub fn service_signing_key(&self, service_name: &str) -> SigningKey
Get the signing key for a specific service.
Lookup order:
service_keysregistry (independent keypair per service)- PolicyService special case (returns root key — it IS the CA)
- “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).
Sourcepub fn ca_verifying_key(&self) -> Option<VerifyingKey>
pub fn ca_verifying_key(&self) -> Option<VerifyingKey>
Get the CA verifying key (trust anchor).
Sourcepub fn verifying_key(&self) -> VerifyingKey
pub fn verifying_key(&self) -> VerifyingKey
Get the verifying key.
Sourcepub fn jwt_verifying_key(&self) -> VerifyingKey
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.
Sourcepub fn cluster_key_source(&self) -> Arc<dyn JwtKeySource> ⓘ
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.
Sourcepub fn set_jwks_fetcher(&mut self, fetcher: JwksFetcher)
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.
Sourcepub fn identity_provider(&self) -> &Arc<NodeIdentityProvider> ⓘ
pub fn identity_provider(&self) -> &Arc<NodeIdentityProvider> ⓘ
Get the identity provider for purpose-keyed signing.
Sourcepub fn models_dir(&self) -> &Path
pub fn models_dir(&self) -> &Path
Get models directory path.
Sourcepub fn deployment_data_dir(&self) -> Result<PathBuf>
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.
Sourcepub fn endpoint(&self, service: &str, kind: SocketKind) -> TransportConfig
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.
Sourcepub fn transport(&self, service: &str, kind: SocketKind) -> TransportConfig
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.
Sourcepub fn into_spawnable_quic<S: RequestService + Send + Sync + 'static>(
&self,
service: S,
quic_port: Option<u16>,
) -> Box<dyn Spawnable>
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 enabledquic_port: Some(0)→ ephemeral (OS-assigned) portquic_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.
Sourcepub fn into_spawnable_quic_with_publisher<S: RequestService + Send + Sync + 'static>(
&self,
service: S,
quic_port: Option<u16>,
publisher: Option<NativeAnnouncementPublisher>,
) -> Box<dyn Spawnable>
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.
Auto Trait Implementations§
impl Freeze for ServiceContext
impl !RefUnwindSafe for ServiceContext
impl Send for ServiceContext
impl Sync for ServiceContext
impl Unpin for ServiceContext
impl UnsafeUnpin for ServiceContext
impl !UnwindSafe for ServiceContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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