Skip to main content

DecisionStore

Trait DecisionStore 

Source
pub trait DecisionStore: Send + Sync {
Show 17 methods // Required methods fn put(&self, record: DecisionRecord) -> Result<Stored, DecisionRefused>; fn check_room(&self) -> Result<(), DecisionRefused>; fn get(&self, request_uri: &str) -> Option<DecisionRecord>; fn by_token(&self, token: &str) -> Option<DecisionRecord>; fn pending_for( &self, account: &str, cursor: Option<&str>, ) -> (Vec<DecisionRecord>, String); fn settle( &self, request_uri: &str, state: DecisionState, ) -> Option<DecisionRecord>; fn approve( &self, request_uri: &str, redirect: Option<String>, ) -> Option<DecisionRecord>; fn holds(&self, request_uri: &str) -> bool; fn collect(&self, request_uri: &str) -> Option<String>; fn sweep(&self, now: OffsetDateTime); fn arrivals(&self) -> Arc<Notify> ⓘ; fn epoch(&self) -> String; fn remember( &self, account: &str, client_key: &ClientKey, client_id: &str, granted: ScopeSet, now: OffsetDateTime, ); fn remembered( &self, account: &str, client_key: &ClientKey, now: OffsetDateTime, ) -> Option<Remembered>; fn forget_client(&self, client_id: &str, account: Option<&str>) -> usize; fn forget_account(&self, account: &str); fn forget_all(&self);
}
Expand description

Where decision records live between PAR and an answer.

Required Methods§

Source

fn put(&self, record: DecisionRecord) -> Result<Stored, DecisionRefused>

Stores a freshly minted record, assigning its sequence and its first_time, and hands back what was stored.

Sweeps expired records first, so a bound is measured against what is actually still answerable rather than against everything ever minted.

An account at its own bound displaces, it does not refuse. PAR is unauthenticated and login_hint names whoever the caller likes, so a bound that dropped the newest push let a stranger keep an account from signing in at all: fill its eight slots every two minutes and the account’s own sign-ins never reach it. Displacing the oldest undecided record instead keeps the bound — the account still holds no more than it may — while leaving an account’s freshest attempt always answerable, which is the one an agent is actually waiting on. What that costs is in Displaced, for the caller to undo.

The server-wide bound still refuses a push that would grow this store; see DecisionRefused. A displacing push does not grow it, and is not measured against it: an account’s own room is its own, so a full store cannot take an account’s freshest attempt away from it.

The account’s bound counts its undecided records, and only one of those is ever displaced. An answer, and the redirect an approval holds, stay until the pushed request expires; the server-wide bound counts them.

Source

fn check_room(&self) -> Result<(), DecisionRefused>

Whether the server-wide bound has room right now, without writing anything and without checking any account’s own bound — there is no account to check one against here.

oauth::par::push_for_unresolved_hint calls this so a login_hint naming nobody answers exactly the 403 a real account’s push would when this server itself is out of room — a fact about server load, which is fine to say identically to everyone — without that push ever costing the slot it checked for, since nothing is stored under it either way.

Source

fn get(&self, request_uri: &str) -> Option<DecisionRecord>

One record by the pushed request it decides, whatever state it is in.

Source

fn by_token(&self, token: &str) -> Option<DecisionRecord>

One record by the token that approves it, if that token is still the token of a live record.

Source

fn pending_for( &self, account: &str, cursor: Option<&str>, ) -> (Vec<DecisionRecord>, String)

This account’s live records that arrived after cursor, oldest first, and the cursor a caller should send next.

The cursor advances past records for other accounts too, so a poll that returns nothing still makes progress. A cursor this store did not mint — see Cursor — is read as the beginning of its order, so a client that outlived a restart is handed everything rather than nothing.

Source

fn settle( &self, request_uri: &str, state: DecisionState, ) -> Option<DecisionRecord>

Moves a live record out of DecisionState::Pending, returning it as it was just before. None if it is unknown, expired or already settled — which is what makes an approval single-use even before the consent reference is consumed.

An approval is what makes the client key no longer the account’s first_time.

Source

fn approve( &self, request_uri: &str, redirect: Option<String>, ) -> Option<DecisionRecord>

DecisionStore::settles a live record as DecisionState::Approved and holds redirect for a browser signed in as the account, in one step, so no load of the page finds the approval without it.

Source

fn holds(&self, request_uri: &str) -> bool

Whether an approval holds a redirect for a browser.

Source

fn collect(&self, request_uri: &str) -> Option<String>

Hands over the redirect an approval held for a browser, once.

Source

fn sweep(&self, now: OffsetDateTime)

Drops every record whose pushed request has expired, answered or not, and the redirect it held.

Source

fn arrivals(&self) -> Arc<Notify> ⓘ

Woken every time a record arrives, so a long poll does not have to spin.

Source

fn epoch(&self) -> String

This store’s arrival-order epoch; see Cursor.

Source

fn remember( &self, account: &str, client_key: &ClientKey, client_id: &str, granted: ScopeSet, now: OffsetDateTime, )

Remembers the account’s approval of client_key at granted, until REMEMBERED_TTL from now. Replaces the one it had, rather than merging scopes into it.

Source

fn remembered( &self, account: &str, client_key: &ClientKey, now: OffsetDateTime, ) -> Option<Remembered>

The account’s live remembered approval of client_key, if any.

Source

fn forget_client(&self, client_id: &str, account: Option<&str>) -> usize

Forgets the remembered approvals of client_id, on account or on every account, and says how many it forgot.

Source

fn forget_account(&self, account: &str)

Forgets every remembered approval the account made.

Source

fn forget_all(&self)

Forgets every remembered approval.

Implementors§