pub struct Gateway { /* private fields */ }Expand description
Gateway state shared by the HTTP handler and the Station channel.
Implementations§
Source§impl Gateway
impl Gateway
Sourcepub fn with_browser_links(
self,
path: &Path,
webtransport: bool,
) -> Result<Self, Error>
pub fn with_browser_links( self, path: &Path, webtransport: bool, ) -> Result<Self, Error>
Enables the browser link routes with a persistent Noise identity.
§Errors
The key cannot be read or created, or it is of another method.
Sourcepub fn start_browser_webtransport(
&self,
address: SocketAddr,
tls: Arc<ServerConfig>,
) -> Result<BrowserWebTransport>
pub fn start_browser_webtransport( &self, address: SocketAddr, tls: Arc<ServerConfig>, ) -> Result<BrowserWebTransport>
Starts the opt-in UDP listener. Drop the returned guard to stop accepting links.
§Errors
WebTransport is off, TLS or the UDP listener could not start, or no Tokio runtime is active.
Source§impl Gateway
impl Gateway
Sourcepub fn with_station_auth(
self,
shared: SharedStationToken,
replay_entries: usize,
) -> Self
pub fn with_station_auth( self, shared: SharedStationToken, replay_entries: usize, ) -> Self
How the gateway treats the shared Station token, and how many proof nonces it keeps (each
for twice the clock skew; a proof is refused when they are all in use). The default is
SharedStationToken::Auto and DEFAULT_REPLAY_ENTRIES.
Whether the shared Station token is accepted now.
Sourcepub fn station_auth_weakenings(&self) -> Vec<String>
pub fn station_auth_weakenings(&self) -> Vec<String>
What keeps the Stations’ credentials from being what they should be, one line each, for the log and for a person who reads the Stations: the shared token being accepted, and a gateway that cannot tell Stations apart.
Source§impl Gateway
impl Gateway
Sourcepub async fn serve_tls<F>(
self,
listener: TcpListener,
config: Arc<ServerConfig>,
shutdown: F,
) -> Result<()>
pub async fn serve_tls<F>( self, listener: TcpListener, config: Arc<ServerConfig>, shutdown: F, ) -> Result<()>
Serves the gateway on listener over TLS with config (see tls_server_config) until
shutdown: each request carries the client’s address and the certificates it proved.
§Errors
The listener fails to accept.
Source§impl Gateway
impl Gateway
Sourcepub fn set_login_limits(&self, limits: &LoginLimits)
pub fn set_login_limits(&self, limits: &LoginLimits)
Makes the login and resume routes count tries by limits from now on. The counts held
so far start over, so an address or name that was being held off is let through once.
Sourcepub fn new(config: GatewayConfig) -> Self
pub fn new(config: GatewayConfig) -> Self
Creates the bounded gateway state and the one authenticated Station input queue.
Sourcepub fn with_secret_requester(self, signer: Signer, lifetime: f64) -> Self
pub fn with_secret_requester(self, signer: Signer, lifetime: f64) -> Self
Signs the secret requests this gateway leaves with signer, each valid for lifetime
seconds. Without one they are unsigned, and only a Station told to accept that acts on them.
Sourcepub fn with_secret_trust(self, trust: Trust) -> Self
pub fn with_secret_trust(self, trust: Trust) -> Self
Verifies the scope-key records it plans from, the Station certificates it seals to and the
answers it reports against trust. The default pins no root, so every secret request is
refused until one is set.
Sourcepub fn with_registry(
config: GatewayConfig,
registry: Arc<dyn RegistryBackend>,
) -> Self
pub fn with_registry( config: GatewayConfig, registry: Arc<dyn RegistryBackend>, ) -> Self
Creates a gateway backed by the shared Registry for user access tokens.
Sourcepub fn with_access(
config: GatewayConfig,
registry: Arc<dyn RegistryBackend>,
access: AccessProviders,
) -> Self
pub fn with_access( config: GatewayConfig, registry: Arc<dyn RegistryBackend>, access: AccessProviders, ) -> Self
Creates a gateway backed by the shared Registry and configured user access providers.
Sourcepub fn with_liaison(self, config: LiaisonConfig) -> Self
pub fn with_liaison(self, config: LiaisonConfig) -> Self
Serves A2A to config’s peers: on the HTTP JSON-RPC binding at /v1/a2a to a person
signed in as a peer’s principal, and on links through Gateway::liaison and a
liaison::LinkListener. Without it /v1/a2a answers 404.
Sourcepub fn with_agent_links(
self,
identity: impl AsRef<Path>,
) -> Result<Self, GatewayError>
pub fn with_agent_links( self, identity: impl AsRef<Path>, ) -> Result<Self, GatewayError>
Serves the links to people’s own agents: the WebSocket a relay dials at
/v1/assistant/agent-link and the routes that ask for its codes and list and revoke its
links, proving the gateway by the key kept at identity (made the first time, by Noise).
§Errors
GatewayError::InvalidConfiguration when the key cannot be read or made.
Sourcepub fn liaison(&self) -> Option<Liaison>
pub fn liaison(&self) -> Option<Liaison>
Liaison’s A2A agent over this gateway, when Gateway::with_liaison set one up.
Sourcepub fn with_roster(self, source: Arc<dyn ConfigProvider>) -> Self
pub fn with_roster(self, source: Arc<dyn ConfigProvider>) -> Self
Serves roster administration (/v1/user/roster/...) from source, the roster every
Station reads. Edits need a source that takes changes, such as a SQL roster; without a
source those routes answer 503.
Sourcepub fn with_source_facts(self, facts: SourceFactsFn) -> Self
pub fn with_source_facts(self, facts: SourceFactsFn) -> Self
Reads what is known of a Source instance (its web page, intake labels) through facts;
published_source_facts reads what the Stations publish at check-in, since this gateway
loads no Source provider. An instance facts knows nothing of lists no page, and takes
intake labels from its own labels.
Sourcepub fn with_access_admin(self, access: Arc<LiveAccess>) -> Self
pub fn with_access_admin(self, access: Arc<LiveAccess>) -> Self
Serves the access administration routes (/v1/user/access, an Operation’s access) over
access, the policy in force.
Sourcepub fn with_own_providers(self, providers: Vec<ProviderEntry>) -> Self
pub fn with_own_providers(self, providers: Vec<ProviderEntry>) -> Self
Reports the providers this gateway has loaded (its sign-in, directory and authorizer
providers) under the host name gateway.
Sourcepub fn with_degraded(self, degraded: Vec<Degradation>) -> Self
pub fn with_degraded(self, degraded: Vec<Degradation>) -> Self
Reports what keeps this gateway from being whole, on /v1/stations to a person who reads a
Station.
Sourcepub fn with_accounts(self, accounts: Arc<dyn Accounts>) -> Self
pub fn with_accounts(self, accounts: Arc<dyn Accounts>) -> Self
Serves the account routes (/v1/user/accounts) over accounts, the provider that keeps
the accounts people sign in with.
Sourcepub fn assistant_agent(&self) -> Option<String>
pub fn assistant_agent(&self) -> Option<String>
The roster Agent that is Moneypenny while she is on, as a conversation or turn that starts now would find her.
Sourcepub fn set_assistant(&self, enabled: bool, config: Option<AssistantConfig>)
pub fn set_assistant(&self, enabled: bool, config: Option<AssistantConfig>)
Turns Moneypenny on or off and gives the conversations and turns that start from now on
config (when there is one to give); a turn already running finishes as it began. A
gateway built without Gateway::with_assistant has no one to change.
Sourcepub fn config(&self) -> &Arc<GatewayConfig> ⓘ
pub fn config(&self) -> &Arc<GatewayConfig> ⓘ
The limits and trusted origin this gateway runs by.
Sourcepub fn with_assistant(self, config: AssistantConfig) -> Self
pub fn with_assistant(self, config: AssistantConfig) -> Self
Serves Moneypenny, the operator’s assistant: the app’s conversation socket, her tools’ MCP endpoint and the Stations’ assistant routes. Her model runs on a Station as the roster Agent the config names. Without it the socket answers 503.
Sourcepub fn with_job_poll_max_wait(self, max_wait: Duration) -> Self
pub fn with_job_poll_max_wait(self, max_wait: Duration) -> Self
How long a Station’s assistant job poll is held while Moneypenny is not served
([assistant.gateway] max_wait); once she is, her config decides.
Sourcepub fn with_pages(self, config: PagesConfig) -> Result<Self, GatewayError>
pub fn with_pages(self, config: PagesConfig) -> Result<Self, GatewayError>
Keeps the pages Moneypenny publishes in config.dir and serves them: under /pages/ on
the API’s own origin, or, with config.origin, only on the pages’ own listener
(Gateway::pages_router). Needs Gateway::with_assistant to publish anything.
§Errors
The directory cannot be made or read, or the origin is not an origin.
Sourcepub fn pages_router(&self) -> Option<Router>
pub fn pages_router(&self) -> Option<Router>
The router of the pages’ own listener: page routes only, no /v1. None unless
Gateway::with_pages gave an origin.
Sourcepub async fn serve_pages<F>(
self,
address: SocketAddr,
shutdown: F,
) -> Result<(), Error>
pub async fn serve_pages<F>( self, address: SocketAddr, shutdown: F, ) -> Result<(), Error>
Serves the pages’ own listener on address until shutdown.
§Errors
The address cannot be bound, or there is no pages origin.
Sourcepub fn authenticate_station(&self, presented: &str) -> Result<(), GatewayError>
pub fn authenticate_station(&self, presented: &str) -> Result<(), GatewayError>
Checks whether a presented secret is the configured Station channel credential.
Sourcepub async fn register_run(
&self,
station_token: &str,
operation_id: OperationId,
mission_id: MissionId,
run_id: RunId,
) -> Result<(), GatewayError>
pub async fn register_run( &self, station_token: &str, operation_id: OperationId, mission_id: MissionId, run_id: RunId, ) -> Result<(), GatewayError>
Registers one active Run after authenticating the Station.
Sourcepub async fn next_sequence(
&self,
station_token: &str,
run_id: &RunId,
) -> Result<u64, GatewayError>
pub async fn next_sequence( &self, station_token: &str, run_id: &RunId, ) -> Result<u64, GatewayError>
Returns the next event cursor for an authenticated registered Run.
Sourcepub async fn board_runs(&self) -> Vec<BoardRun>
pub async fn board_runs(&self) -> Vec<BoardRun>
Returns the Runs, their latest lifecycle states and the Agent of each one’s Mission.
The Registry’s Run records say what ended or is waiting to be checked, which no
Station sends again after the gateway restarts; the lifecycle frames received since say
what is happening now and win while their sequence is above zero, unless the record has
closed. Records past [gateway] board_runs, the least recently updated, are left out.
Sourcepub async fn board_missions(&self) -> Vec<BoardMission>
pub async fn board_missions(&self) -> Vec<BoardMission>
Returns registered Missions grouped by Station with their Runs.
Sourcepub async fn publish_lifecycle(
&self,
station_token: &str,
event: LifecycleEvent,
) -> Result<(), GatewayError>
pub async fn publish_lifecycle( &self, station_token: &str, event: LifecycleEvent, ) -> Result<(), GatewayError>
Encodes and publishes one lifecycle event for a registered Run.
Sourcepub async fn publish_terminal_output(
&self,
station_token: &str,
run_id: RunId,
sequence: u64,
bytes: Vec<u8>,
) -> Result<(), GatewayError>
pub async fn publish_terminal_output( &self, station_token: &str, run_id: RunId, sequence: u64, bytes: Vec<u8>, ) -> Result<(), GatewayError>
Encodes and publishes raw terminal output without requiring the Station to encode guatiao.
Sourcepub fn terminal_bytes(&self, run_id: &RunId) -> usize
pub fn terminal_bytes(&self, run_id: &RunId) -> usize
The most terminal output that fits one frame of run_id at any sequence, and that the
wire contract allows: what a Station is told, so that it splits longer output itself.
Sourcepub async fn issue_attach_token(
&self,
station_token: &str,
grant: AttachGrant,
) -> Result<String, GatewayError>
pub async fn issue_attach_token( &self, station_token: &str, grant: AttachGrant, ) -> Result<String, GatewayError>
Mints an opaque, short-lived, single-use token for an existing Run.
Sourcepub async fn exchange_attach_token(
&self,
token: &str,
) -> Result<String, GatewayError>
pub async fn exchange_attach_token( &self, token: &str, ) -> Result<String, GatewayError>
Exchanges an attach token for a cookie-only, one-connection ticket.
Sourcepub async fn attach(
&self,
run_id: &RunId,
ticket: &str,
after_sequence: u64,
) -> Result<Attachment, GatewayError>
pub async fn attach( &self, run_id: &RunId, ticket: &str, after_sequence: u64, ) -> Result<Attachment, GatewayError>
Consumes a connection ticket and grants one bounded viewer slot.
The returned replay starts with the latest schema announcement for each
channel, followed by scrollback newer than after_sequence. Where that scrollback starts
later than after_sequence or skips a sequence, a TerminalGap
says so, ahead of the frame after it.
Sourcepub async fn ingest(
&self,
station_token: &str,
run_id: &RunId,
sequence: u64,
frame: Vec<u8>,
) -> Result<(), GatewayError>
pub async fn ingest( &self, station_token: &str, run_id: &RunId, sequence: u64, frame: Vec<u8>, ) -> Result<(), GatewayError>
Validates and records a Station-originated guatiao frame, then fans it out.
Sourcepub async fn submit_input(
&self,
run_id: &RunId,
connection_id: &str,
frame: Vec<u8>,
) -> Result<(), GatewayError>
pub async fn submit_input( &self, run_id: &RunId, connection_id: &str, frame: Vec<u8>, ) -> Result<(), GatewayError>
Queues one browser frame for the Station after confirming an active write lease.
Sourcepub async fn disconnect(&self, attachment: Attachment)
pub async fn disconnect(&self, attachment: Attachment)
Releases a viewer slot and its write lease when a socket closes.
Sourcepub async fn disconnect_connection(&self, run_id: &RunId, connection_id: &str)
pub async fn disconnect_connection(&self, run_id: &RunId, connection_id: &str)
Releases an active connection by its non-secret internal handle.
Sourcepub async fn receive_agent_input(&self) -> Option<AgentInput>
pub async fn receive_agent_input(&self) -> Option<AgentInput>
Waits for the next terminal input from an authenticated Station connection.
Sourcepub async fn receive_agent_input_within(
&self,
wait: Duration,
) -> Option<AgentInput>
pub async fn receive_agent_input_within( &self, wait: Duration, ) -> Option<AgentInput>
Waits at most wait for the next input; None when none came.
Sourcepub fn public_origin(&self) -> &str
pub fn public_origin(&self) -> &str
Returns the configured public HTTPS origin for same-origin checks.
Sourcepub fn router(self) -> Router
pub fn router(self) -> Router
Returns the Axum service for the Station channel, browser attach and terminal sockets.
Sourcepub async fn serve_loopback<F>(
self,
port: u16,
shutdown: F,
) -> Result<(), Error>
pub async fn serve_loopback<F>( self, port: u16, shutdown: F, ) -> Result<(), Error>
Serves the gateway on loopback so browsers reach it only through the
configured HTTPS reverse proxy. Once shutdown resolves and the open requests end, it
waits up to [assistant.gateway] log_flush_timeout for Moneypenny’s conversation log.