Version: v0.48.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 9 Imported by: 0



Package pool contains Telegram connections pool.



This section is empty.


View Source
var ErrConnDead = xerrors.New("connection dead")

ErrConnDead means that connection is closed and can't be used anymore.


This section is empty.


type Conn

type Conn interface {
	Run(ctx context.Context) error
	Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error
	Ping(ctx context.Context) error
	Ready() <-chan struct{}

Conn represents Telegram MTProto connection.

type DC

type DC struct {
	// contains filtered or unexported fields

DC represents connection pool to one data center.

func NewDC

func NewDC(ctx context.Context, id int, newConn func() Conn, opts DCOptions) *DC

NewDC creates new uninitialized DC.

func (*DC) Close

func (c *DC) Close() error

Close waits while all ongoing requests will be done or until given context is done. Then, closes the DC.

func (*DC) Invoke

func (c *DC) Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error

Invoke sends MTProto request using one of pool connection.

type DCOptions

type DCOptions struct {
	// Logger is instance of zap.Logger. No logs by default.
	Logger *zap.Logger
	// MTProto options for connections.
	// Opened connection limit to the DC.
	MaxOpenConnections int64

DCOptions is a Telegram data center connections pool options.

type Session

type Session struct {
	DC      int
	AuthKey crypto.AuthKey
	Salt    int64

Session represents DC session.

type SyncSession

type SyncSession struct {
	// contains filtered or unexported fields

SyncSession is synchronization helper for Session.

func NewSyncSession

func NewSyncSession(data Session) *SyncSession

NewSyncSession creates new SyncSession.

func (*SyncSession) Load

func (s *SyncSession) Load() (data Session)

Load gets session and returns it.

func (*SyncSession) Migrate

func (s *SyncSession) Migrate(dc int)

Migrate changes current DC and its addr, zeroes AuthKey and Salt.

func (*SyncSession) Options

func (s *SyncSession) Options(opts mtproto.Options) (mtproto.Options, Session)

Options fills Key and Salt field of given Options using stored session and returns it.

func (*SyncSession) Store

func (s *SyncSession) Store(data Session)

Store saves given Session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to