Skip to main content

Session

Trait Session 

Source
pub trait Session: Send + Sync {
    // Required methods
    fn home_dc_id(&self) -> i32;
    fn set_home_dc_id(&self, dc_id: i32) -> BoxFuture<'_, ()>;
    fn dc_option(&self, dc_id: i32) -> Option<DcOption>;
    fn set_dc_option(&self, dc_option: &DcOption) -> BoxFuture<'_, ()>;
    fn peer(&self, peer: PeerId) -> BoxFuture<'_, Option<PeerInfo>>;
    fn cache_peer(&self, peer: &PeerInfo) -> BoxFuture<'_, ()>;
    fn updates_state(&self) -> BoxFuture<'_, UpdatesState>;
    fn set_update_state(&self, update: UpdateState) -> BoxFuture<'_, ()>;

    // Provided method
    fn peer_ref(&self, peer: PeerId) -> BoxFuture<'_, Option<PeerRef>> { ... }
}
Expand description

The main interface to interact with the different crate::storages.

All methods are synchronous and currently infallible because clients are not equipped to deal with the arbitrary errors that a dynamic Session could produce. This may change in the future.

A newly-created storage should return the same values that crate::SessionData::default would produce.

Required Methods§

Source

fn home_dc_id(&self) -> i32

Datacenter that is “home” to the user authorized by this session.

If not known, the ID of the closest datacenter should be returned instead. Note that incorrect guesses are allowed, and the user may need to migrate.

This method should be implemented as an infallible memory read, because it is used on every request and thus should be cheap to call.

Source

fn set_home_dc_id(&self, dc_id: i32) -> BoxFuture<'_, ()>

Changes the Session::home_dc_id after finding out the actual datacenter to which main queries should be executed against.

This must update the value in the cache layer used by home_dc_id.

Source

fn dc_option(&self, dc_id: i32) -> Option<DcOption>

Query a single datacenter option.

If no up-to-date option has been Session::set_dc_option yet, a statically-known option must be returned.

None may only be returned on invalid DC IDs or DCs that are not yet known.

This method should be implemented as an infallible memory read, because it is used on every request and thus should be cheap to call.

Source

fn set_dc_option(&self, dc_option: &DcOption) -> BoxFuture<'_, ()>

Update the previously-known Session::dc_option with new values.

Should also be used after generating permanent authentication keys to a datacenter.

This must update the value in the cache layer used by dc_option.

Source

fn peer(&self, peer: PeerId) -> BoxFuture<'_, Option<PeerInfo>>

Query a peer by its identity.

Querying for PeerId::self_user can be used as a way to determine whether the authentication key has a logged-in user bound (i.e. signed in).

Source

fn cache_peer(&self, peer: &PeerInfo) -> BoxFuture<'_, ()>

Cache a peer’s basic information for Session::peer to be able to query them later.

This method may not necessarily remember the peers forever, except for users where PeerInfo::User::is_self is Some(true).

Source

fn updates_state(&self) -> BoxFuture<'_, UpdatesState>

Loads the entire updates state.

Source

fn set_update_state(&self, update: UpdateState) -> BoxFuture<'_, ()>

Update the state for one or all updates.

Provided Methods§

Source

fn peer_ref(&self, peer: PeerId) -> BoxFuture<'_, Option<PeerRef>>

Query the full peer reference from its identity.

By default, this uses Session::peer to retrieve the PeerAuth.

Implementors§