pool

package
v0.68.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package pool contains Telegram connections pool.

Index

Constants

This section is empty.

Variables

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

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

Functions

This section is empty.

Types

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 added in v0.43.0

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 added in v0.24.0

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

Session represents DC session.

type SyncSession added in v0.24.0

type SyncSession struct {
	// contains filtered or unexported fields
}

SyncSession is synchronization helper for Session.

func NewSyncSession added in v0.24.0

func NewSyncSession(data Session) *SyncSession

NewSyncSession creates new SyncSession.

func (*SyncSession) Load added in v0.24.0

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

Load gets session and returns it.

func (*SyncSession) Migrate added in v0.24.0

func (s *SyncSession) Migrate(dc int)

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

func (*SyncSession) Options added in v0.24.0

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 added in v0.24.0

func (s *SyncSession) Store(data Session)

Store saves given Session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL