package session
Import Path
github.com/gotd/td/session (on go.dev)
Dependency Relation
imports 15 packages, and imported by one package
Involved Source Files
Package session implements session storage.
storage_file.go
storage_mem.go
tdesktop.go
telethon.go
Package-Level Type Names (total 8, in which 7 are exported)
Config is subset of tg.Config.
Indicates that telegram is probably censored by governments/ISPs in the current region
DC IP list
Domain name for fetching encrypted DC list from DNS TXT record
Current date at the server
Expiration date of this config: when it expires it'll have to be refetched using help
getConfig¹
Links:
1) https://core.telegram.org/method/help.getConfig
Whether to forcefully try connecting using IPv6 dcOptions¹
Links:
1) https://core.telegram.org/type/DcOption
Whether we're connected to the test DCs
ID of the DC that returned the reply
Temporary passport¹ sessions
Links:
1) https://core.telegram.org/passport
Use SetTmpSessions and GetTmpSessions helpers.
DC ID to use to download webfiles¹
Links:
1) https://core.telegram.org/api/files#downloading-webfiles
TG returns tg.Config from Config.
Note that config is the subset of tg.Config, so some fields will be unset.
func ConfigFromTG(c tg.Config) Config
func mapConfig(mainDC int, cfg tdesktop.MTPConfig) Config
Data of session.
Format (JSON, {"Version":1,"Data":{...}}). All fields after Salt are
optional additions to version 1: older gotd versions ignore them and
files written by older versions load with them unset.
Addr string
AuthKey []byte
AuthKeyCreatedAt is the creation time of AuthKey (the permanent key in
PFS mode), Unix seconds; zero if unknown (e.g. created by an older
version).
AuthKeyID []byte
Bot reports whether UserID is a bot.
Config Config
DC int
DCs holds auth keys of the other DCs, by DC ID, so that they survive
restarts without a new key exchange and authorization transfer.
Salt int64
ServerTimeOffset is the difference between server and local time, if
known. The telegram client saves the observed offset and seeds the
next run with it (unless Options.ServerTimeOffset is set).
UserID is the ID of the authorized user or bot, if known.
func TDesktopSession(account tdesktop.Account) (*Data, error)
func TelethonSession(hx string) (*Data, error)
func (*Loader).Load(ctx context.Context) (*Data, error)
func decodeStringSession(data []byte) (*Data, error)
func (*Loader).Save(ctx context.Context, data *Data) error
func github.com/gotd/td/telegram.(*Client).fillDCKeys(data *Data)
func github.com/gotd/td/telegram.(*Client).restoreDCKeys(ctx context.Context, data *Data)
DCKey is the auth key of a non-home DC.
AuthKey []byte
AuthKeyID []byte
Authorized reports whether the authorization was transferred to the
key (auth.importAuthorization), so it can be used without a transfer.
CreatedAt is the key creation time, Unix seconds; zero if unknown.
Salt int64
FileStorage implements SessionStorage for file system as file
stored in Path.
Path string
mux sync.Mutex
LoadSession loads session from file.
StoreSession stores session to file.
*FileStorage : Storage
Loader wraps Storage implementing Data (un-)marshaling.
Storage Storage
Load loads Data from Storage.
Save saves Data to Storage.
*Loader : github.com/gotd/td/telegram.clientStorage
Storage is secure persistent storage for client session.
NB: Implementation security is important, attacker can abuse it not only for
connecting as authenticated user or bot, but even decrypting previous
messages in some situations.
( Storage) LoadSession(ctx context.Context) ([]byte, error)
( Storage) StoreSession(ctx context.Context, data []byte) error
*FileStorage
*StorageMemory
StorageMemory implements in-memory session storage.
Goroutine-safe.
data []byte
mux sync.RWMutex
Bytes appends raw session data to the given slice.
Returns ErrNotFound if storage is nil or if underlying session is empty.
Clone creates a clone of existing StorageMemory,
Dump dumps raw session data to the given writer.
Returns ErrNotFound if storage is nil or if underlying session is empty.
LoadSession loads session from memory.
StoreSession stores session to memory.
WriteFile dumps raw session data to the named file, creating it if necessary.
Returns ErrNotFound if storage is nil or if underlying session is empty.
*StorageMemory : Storage
func (*StorageMemory).Clone() *StorageMemory
Package-Level Functions (total 6, in which 3 are exported)
ConfigFromTG converts tg.Config to Config.
Note that Config is the subset of tg.Config, so data loss is possible.
TDesktopSession converts TDesktop's Account to Data.
TelethonSession decodes Telethon's StringSession string to the Data.
Notice that Telethon does not save tg.Config and server salt.
See https://docs.telethon.dev/en/latest/modules/sessions.html#telethon.sessions.string.StringSession.
See https://github.com/LonamiWebs/Telethon/blob/master/telethon/sessions/string.py#L29-L46.
Package-Level Variables (total 2, both are exported)
ErrNotFound means that session is not found in storage.
ErrVersionUnsupported means that session was written by a newer version of
the format: it is not ErrNotFound, so a client does not start a new login
over a valid key.
Package-Level Constants (total 2, neither is exported)
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |