Documentation ¶
Overview ¶
Package updates provides a Telegram's state synchronization engine.
It guarantees that all state-sensitive updates will be performed in correct order.
Limitations:
Engine cannot verify stateless types of updates (tg.UpdatesClass without Seq, or tg.UpdateClass without Pts or Qts).
Due to the fact that updates.getDifference and updates.getChannelDifference do not return event sequences, the engine cannot guarantee the correctness of these operations. We rely on the server here.
Engine cannot recover the channel gap if there is a ChannelDifferenceTooLong error. Restoring the state in such situation is not the prerogative of this engine. See: https://core.telegram.org/constructor/updates.channelDifferenceTooLong
TODO: Write implementation details.
Index ¶
- Variables
- type AccessHasher
- type Config
- type DiffUpdate
- type Engine
- type Entities
- type Handler
- type MemStorage
- func (s *MemStorage) Channels(f func(channelID, pts int)) error
- func (s *MemStorage) ForgetAll() error
- func (s *MemStorage) GetState() (State, error)
- func (s *MemStorage) SetChannelPts(channelID, pts int) error
- func (s *MemStorage) SetDate(date int) error
- func (s *MemStorage) SetPts(pts int) error
- func (s *MemStorage) SetQts(qts int) error
- func (s *MemStorage) SetSeq(seq int) error
- func (s *MemStorage) SetState(state State) error
- type RawClient
- type State
- type Storage
Constants ¶
This section is empty.
Variables ¶
var ErrStateNotFound = errors.New("state not found")
ErrStateNotFound means that state is not found in storage.
Functions ¶
This section is empty.
Types ¶
type AccessHasher ¶
type AccessHasher interface { GetChannelHash(channelID int) (hash int64, found bool, err error) SetChannelHash(channelID int, accessHash int64) error }
AccessHasher stores channel access hashes.
type Config ¶
type Config struct { RawClient RawClient Handler Handler Storage Storage AccessHasher AccessHasher SelfID int IsBot bool Forget bool Logger *zap.Logger }
Config of the engine.
type DiffUpdate ¶
type DiffUpdate struct { NewMessages []tg.MessageClass NewEncryptedMessages []tg.EncryptedMessageClass Users []tg.UserClass Chats []tg.ChatClass }
DiffUpdate struct.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine deals with gaps.
func (*Engine) HandleUpdates ¶
func (e *Engine) HandleUpdates(u tg.UpdatesClass) error
HandleUpdates handles updates.
type Entities ¶
type Entities struct { Users map[int]*tg.User Chats map[int]*tg.Chat Channels map[int]*tg.Channel ChannelsForbidden map[int]*tg.ChannelForbidden }
Entities contains update entities.
type Handler ¶
type Handler interface { HandleDiff(DiffUpdate) error HandleUpdates(*Entities, []tg.UpdateClass) error ChannelTooLong(channelID int) }
Handler interface.
type MemStorage ¶
type MemStorage struct {
// contains filtered or unexported fields
}
MemStorage is a in-memory sequence storage.
func (*MemStorage) Channels ¶
func (s *MemStorage) Channels(f func(channelID, pts int)) error
Channels iterates through channels.
func (*MemStorage) ForgetAll ¶
func (s *MemStorage) ForgetAll() error
ForgetAll clears all sequence info.
func (*MemStorage) GetState ¶
func (s *MemStorage) GetState() (State, error)
GetState returns the state.
func (*MemStorage) SetChannelPts ¶
func (s *MemStorage) SetChannelPts(channelID, pts int) error
SetChannelPts sets channel pts.
func (*MemStorage) SetState ¶
func (s *MemStorage) SetState(state State) error
SetState sets the state.
type RawClient ¶
type RawClient interface { UpdatesGetState(ctx context.Context) (*tg.UpdatesState, error) UpdatesGetDifference(ctx context.Context, request *tg.UpdatesGetDifferenceRequest) (tg.UpdatesDifferenceClass, error) UpdatesGetChannelDifference(ctx context.Context, request *tg.UpdatesGetChannelDifferenceRequest) (tg.UpdatesChannelDifferenceClass, error) }
RawClient is the interface which contains Telegram RPC methods used by the engine for state synchronization.
type Storage ¶
type Storage interface { GetState() (State, error) SetState(s State) error SetPts(pts int) error SetQts(qts int) error SetSeq(seq int) error SetDate(date int) error SetChannelPts(channelID, pts int) error Channels(iter func(channelID, pts int)) error ForgetAll() error }
Storage interface.