Skip to main content

SessionBackend

Trait SessionBackend 

Source
pub trait SessionBackend: Send + Sync {
    // Required methods
    fn save(&self, session: &PersistedSession) -> Result<()>;
    fn load(&self) -> Result<Option<PersistedSession>>;
    fn delete(&self) -> Result<()>;
    fn name(&self) -> &str;

    // Provided methods
    fn update_dc(&self, entry: &DcEntry) -> Result<()> { ... }
    fn set_home_dc(&self, dc_id: i32) -> Result<()> { ... }
    fn apply_update_state(&self, update: UpdateStateChange) -> Result<()> { ... }
    fn cache_peer(&self, peer: &CachedPeer) -> Result<()> { ... }
}
Expand description

Synchronous snapshot backend: saves and loads the full session at once.

All built-in backends implement this. Higher-level code should prefer the extension methods below (update_dc, set_home_dc, update_state) which avoid unnecessary full-snapshot writes.

Required Methods§

Source

fn save(&self, session: &PersistedSession) -> Result<()>

Source

fn load(&self) -> Result<Option<PersistedSession>>

Source

fn delete(&self) -> Result<()>

Source

fn name(&self) -> &str

Human-readable name for logging/debug output.

Provided Methods§

Source

fn update_dc(&self, entry: &DcEntry) -> Result<()>

Update a single DC entry without rewriting the entire session.

Typically called after:

  • completing a DH handshake on a new DC (to persist its auth key)
  • receiving updated DC addresses from help.getConfig

Ported from Session::set_dc_option.

Source

fn set_home_dc(&self, dc_id: i32) -> Result<()>

Change the home DC without touching any other session data.

Called after a successful *_MIGRATE redirect: the user’s account now lives on a different DC.

Ported from Session::set_home_dc_id.

Source

fn apply_update_state(&self, update: UpdateStateChange) -> Result<()>

Apply a single update-sequence change without a full save/load.

Ported from Session::set_update_state(UpdateState).

update is the new partial or full state to merge in.

Source

fn cache_peer(&self, peer: &CachedPeer) -> Result<()>

Cache a peer access hash without a full session save.

This is lossy-on-default (full round-trip) but correct. Override in SQL backends to issue a single INSERT OR REPLACE.

Ported from Session::cache_peer.

Implementors§