Source File
session_state.go
Belonging Package
github.com/gotd/td/mtproto
package mtprotoimport// SessionState is the server session of a connection slot: session_id and// the number of content messages sent in it (for seqno). Connections that// share a SessionState one at a time continue the same server session after// a reconnect with the same auth key, so the server keeps its queued answers// and updates and does not send new_session_created, like TDLib and Telegram// Desktop do. A new session is started when the key changes.//// A SessionState must be used by one connection at a time: acquire it with// TryAcquire before passing it in Options; the connection releases it when// Run returns.type SessionState struct {mux sync.MutexkeyID [8]byteid int64contentMessages int32inUse bool// lastBindAt is the time of the last successful auth.bindTempAuthKey// of the slot, Unix seconds (PFS key recovery policy).lastBindAt int64}// NewSessionState returns an empty SessionState.func () *SessionState {return &SessionState{}}// TryAcquire marks the state as used by a connection. It reports false if// another connection uses it.func ( *SessionState) () bool {.mux.Lock()defer .mux.Unlock()if .inUse {return false}.inUse = truereturn true}// load returns the session of key keyID, if any.func ( *SessionState) ( [8]byte) ( int64, int32, bool) {.mux.Lock()defer .mux.Unlock()if .id == 0 || .keyID != {return 0, 0, false}return .id, .contentMessages, true}// release saves the session of the connection and frees the state. A zero id// forgets the session.func ( *SessionState) ( [8]byte, int64, int32) {.mux.Lock()defer .mux.Unlock().keyID =.id =.contentMessages =.inUse = false}func ( *SessionState) ( int64) {.mux.Lock().lastBindAt =.mux.Unlock()}func ( *SessionState) () int64 {.mux.Lock()defer .mux.Unlock()return .lastBindAt}
![]() |
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. |