mtproto

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 28 Imported by: 6

Documentation

Overview

Package mtproto implements MTProto connection.

Code generated by gomacro; DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn represents a MTProto client to Telegram.

func NewConn

func NewConn(addr string, opt Options) *Conn

NewConn creates new unstarted connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes underlying connection.

func (*Conn) Connect

func (c *Conn) Connect(ctx context.Context) (err error)

Connect initializes connection to Telegram server and starts internal read loop.

func (*Conn) InvokeRaw

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

InvokeRaw sens input and decodes result into output.

NOTE: Assuming that call contains content message (seqno increment).

func (*Conn) Ping

func (c *Conn) Ping(ctx context.Context) error

Ping sends ping request to server and waits until pong is received or context is canceled.

func (*Conn) Reconnect

func (c *Conn) Reconnect(ctx context.Context) error

Reconnect performs re-connection. Same as Connect, but does not start new goroutines.

func (*Conn) Session

func (c *Conn) Session() Session

Session returns current connection session info.

type Error

type Error struct {
	Code     int    // 420
	Message  string // FLOOD_WAIT_3
	Type     string // FLOOD_WAIT
	Argument int    // 3
}

Error represents RPC error returned to request.

func (Error) Error

func (e Error) Error() string

func (*Error) ExtractArgument

func (e *Error) ExtractArgument()

ExtractArgument extracts Type and Argument from Message.

type Handler

type Handler func(b *bin.Buffer) error

Handler will be called on received message from Telegram.

type MessageIDSource

type MessageIDSource interface {
	New(t proto.MessageType) int64
}

MessageIDSource is message id generator.

type Options

type Options struct {
	// PublicKeys of telegram.
	//
	// If not provided, embedded public keys will be used.
	PublicKeys []*rsa.PublicKey

	// Transport to use. Default dialer will be used if not provided.
	Transport Transport
	// Network to use. Defaults to tcp.
	Network string
	// Random is random source. Defaults to crypto.
	Random io.Reader
	// Logger is instance of zap.Logger. No logs by default.
	Logger *zap.Logger
	// Handler will be called on received message.
	Handler Handler
	// AckBatchSize is maximum ack-s to buffer.
	AckBatchSize int
	// AckInterval is maximum time to buffer ack.
	AckInterval time.Duration

	RetryInterval time.Duration
	MaxRetries    int
	MessageID     MessageIDSource
	Clock         clock.Clock
	OnReconnect   func() error
	Types         *tmap.Map

	Key  crypto.AuthKeyWithID
	Salt int64
}

Options of Conn.

type Session

type Session struct {
	Key  crypto.AuthKeyWithID
	Salt int64
}

Session represents connection state.

type Transport

type Transport interface {
	Codec() transport.Codec
	DialContext(ctx context.Context, network, address string) (transport.Conn, error)
}

Transport is MTProto connection creator.

Directories

Path Synopsis
Code generated for package internal by go-bindata DO NOT EDIT.
Code generated for package internal by go-bindata DO NOT EDIT.

Jump to

Keyboard shortcuts

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