ferogram-session
Session persistence types and pluggable storage backends for ferogram.
Session persistence for ferogram. Extracted in v0.3.7 so you can swap, extend, or use session storage without pulling in the full client.
ferogram re-exports everything from here, so existing code needs no changes.
Installation
[]
= "0.3.8"
What it stores
- DC address table with per-DC auth keys, salts, and capability flags
- MTProto update counters: pts, qts, seq, date, and per-channel pts
- Peer access-hash cache for users, channels, and groups
- Min-user message contexts for
InputPeerUserFromMessage
The binary format is versioned. load() handles all previous versions without error. save() always writes the current version. Saves are atomic: written to a .tmp file first, then renamed into place.
Session Types
PersistedSession
The main serializable struct. Holds the full DC table, update state, and peer cache.
use PersistedSession;
use Path;
let session = load?;
session.save?;
// String (base64) round-trip
let s = session.to_string;
let session2 = from_string?;
DcEntry and DcFlags
use ;
let entry = from_parts;
let ipv6 = from_parts;
Backends
BinaryFileBackend
Default backend. Saves the session as a binary file on disk.
use BinaryFileBackend;
let backend = new;
InMemoryBackend
No persistence, lives only for the process lifetime. Good for tests or quick scripts.
use InMemoryBackend;
let backend = new;
StringSessionBackend
Stores the session as a base64 string. Handy when you can't write to disk, like reading the session from an environment variable in a serverless setup.
use StringSessionBackend;
let backend = new;
SqliteBackend (feature: sqlite-session)
= { = "0.3.8", = ["sqlite-session"] }
use SqliteBackend;
let backend = open?;
LibSqlBackend (feature: libsql-session)
= { = "0.3.8", = ["libsql-session"] }
use LibSqlBackend;
let backend = open_local?;
Custom Backends
Implement SessionBackend to add your own storage:
use ;
use io;
Feature flags
| Flag | What it enables |
|---|---|
sqlite-session |
SqliteBackend via rusqlite |
libsql-session |
LibSqlBackend via libsql |
serde |
Serialize/Deserialize on session types |
Stack position
ferogram
└ ferogram-session <-- here
License
MIT or Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.
Ankit Chaubey - github.com/ankit-chaubey