Documentation
¶
Overview ¶
Package mtproto implements MTProto connection.
Index ¶
Constants ¶
const ErrFloodWait = "FLOOD_WAIT"
ErrFloodWait is error type of "FLOOD_WAIT" error.
Variables ¶
This section is empty.
Functions ¶
func AsFloodWait ¶ added in v0.22.0
AsFloodWait returns wait duration and true boolean if err is the "FLOOD_WAIT" error.
Client should wait for that duration before issuing new requests with same method.
Types ¶
type Cipher ¶ added in v0.19.0
type Cipher interface {
DecryptFromBuffer(k crypto.AuthKey, buf *bin.Buffer) (*crypto.EncryptedMessageData, error)
Encrypt(key crypto.AuthKey, data crypto.EncryptedMessageData, b *bin.Buffer) error
}
Cipher handles message encryption and decryption.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a MTProto client to Telegram.
func (*Conn) InvokeRaw ¶
InvokeRaw sens input and decodes result into output.
NOTE: Assuming that call contains content message (seqno increment).
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 NewError ¶ added in v0.22.0
NewError creates new *Error from code and message, extracting argument and type.
func (*Error) IsCodeOneOf ¶ added in v0.22.0
IsCodeOneOf returns true if error code is one of codes.
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 is duration between retries.
RetryInterval time.Duration
// MaxRetries is max retry count until rpc request failure.
MaxRetries int
// MessageID is message id source. Share source between connection to
// reduce collision probability.
MessageID MessageIDSource
// Clock is current time source. Defaults to system time.
Clock clock.Clock
// Types map, used in verbose logging of incoming message.
Types *tmap.Map
// Key that can be used to restore previous connection.
Key crypto.AuthKey
// Salt from server that can be used to restore previous connection.
Salt int64
// ReadConcurrency limits maximum concurrently handled messages.
// Can be CPU or IO bound depending on message handlers.
// Defaults to GOMAXPROCS if it is not less than 10.
ReadConcurrency int
// Cipher defines message crypto.
Cipher Cipher
// contains filtered or unexported fields
}
Options of Conn.
Source Files
¶
- ack.go
- conn.go
- create_auth_key.go
- doc.go
- error.go
- flood_wait.go
- handle_ack.go
- handle_bad_msg.go
- handle_container.go
- handle_gzip.go
- handle_message.go
- handle_result.go
- handle_session_created.go
- invoke_raw.go
- message_id.go
- new_encrypted_msg.go
- options.go
- ping.go
- read.go
- rpc.go
- seq_no.go
- session.go
- vendored_keys.go
- write.go
- zap.go