Skip to main content

TokenStore

Struct TokenStore 

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

The access tokens a paired node holds, newest first, and the rules that govern them.

This is the piece that makes the pairing survivable. Storing a list rather than one token is why a dropped reply is a retry instead of a service call — and the list is what S2C §Recovery asks for: “It now has (at least) two accessTokens in its list, and does not know for certain which one is active at the communication server. It should try all the accessTokens sequentially.”

Each entry remembers whether it is already in force or is a grant still waiting to be confirmed, because only the second kind expires — after PENDING_TOKEN_LIFETIME, which is what stops a confirmation that arrives an hour late from retiring a token that still works.

Implementations§

Source§

impl TokenStore

Source

pub const MAX: usize = 4

How many tokens are kept before the oldest is dropped.

Each failed round trip adds one. Four is well past the two the protocol produces in the worst ordinary case, and bounds what a peer can make us store.

Source

pub fn new(current: AccessToken) -> Self

A store holding the token pairing produced.

Source

pub fn accepts(&self, presented: &AccessToken) -> bool

Whether a presented token opens the door.

Any token in the list is accepted, because the client may hold any of them and the alternative to accepting it is a dead pairing.

Source

pub fn add(&mut self, token: AccessToken, now: Timestamp)

Record a replacement granted at now and not yet confirmed.

It joins the list rather than replacing it, because until the client proves it has stored the new token both must open the door (S2C §Recovery). What now buys is the other half of the rule: confirm will not activate a grant the client sat on for more than PENDING_TOKEN_LIFETIME.

Source

pub fn adopt(&mut self, token: AccessToken)

Record a token that is already in force, such as the one pairing produced.

Source

pub fn confirm( &mut self, token: &AccessToken, now: Timestamp, ) -> Result<(), ConnectError>

Activate a granted token and retire every other, as confirmAccessToken does.

Called when the client proves it holds one — by presenting it as the bearer of confirmAccessToken — which is what makes retiring the others safe.

§Errors

ConnectError::NotPaired when the token is not one this store holds; ConnectError::Expired when it was granted more than PENDING_TOKEN_LIFETIME ago and so is no longer confirmable. An expired grant leaves the store untouched, so whatever the client held before still works.

Source

pub fn is_pending(&self, presented: &AccessToken) -> bool

Whether a presented token is a grant this store issued and has not yet seen confirmed.

confirmAccessToken must be authenticated with the replacement, not with any token the store happens to accept: presenting the replacement is the proof the client stored it, and that proof is the only reason retiring the others is safe.

Source

pub fn current(&self) -> Option<&AccessToken>

The token to present next: the newest.

Source

pub fn candidates(&self) -> impl Iterator<Item = &AccessToken>

Every token to try, newest first.

A client that got a 401 works down this list before concluding it is unpaired.

Source

pub fn len(&self) -> usize

How many are held.

Source

pub fn is_empty(&self) -> bool

Whether the pairing has no token at all, which means it is gone.

Source

pub fn clear(&mut self)

Forget everything. What a NoLongerPaired means.

Trait Implementations§

Source§

impl Clone for TokenStore

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TokenStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TokenStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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