proto

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package proto implements MTProto 2.0 primitives.

See https://core.telegram.org/mtproto/description for reference.

Index

Constants

View Source
const (
	// CodeAuthKeyNotFound means that specified auth key ID cannot be found by the DC.
	CodeAuthKeyNotFound = 404

	// CodeTransportFlood means that too many transport connections are
	// established to the same IP in a too short lapse of time, or if any
	// of the container/service message limits are reached.
	CodeTransportFlood = 429
)
View Source
const GZIPTypeID = 0x3072cfa1

GZIPTypeID is TL type id of GZIP.

View Source
const InitConnectionID = 0xc1cd5ea9

InitConnectionID is TL type id of initConnection#c1cd5ea9.

View Source
const InvokeWithLayerID = 0xda9b0d0d

InvokeWithLayerID is TL type id of invokeWithLayer#da9b0d0d.

View Source
const Layer = 121

Layer is current compatible layer.

View Source
const MessageContainerTypeID = 0x73f1f8dc

MessageContainerTypeID is TL type id of MessageContainer.

View Source
const ResultTypeID = 0xf35c6d01

ResultTypeID is TL type id of Result.

Variables

View Source
var IntermediateClientStart = []byte{0xee, 0xee, 0xee, 0xee}

IntermediateClientStart is starting bytes sent by client in Intermediate mode.

Note that server does not respond with it.

Functions

func TypesMap

func TypesMap() map[uint32]string

TypesMap returns mapping from type ids to TL type names.

Types

type Dialer added in v0.11.0

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

Dialer dials using a context.

type GZIP

type GZIP struct {
	Data []byte
}

GZIP represents a Packed Object.

Used to replace any other object (or rather, a serialization thereof) with its archived (gzipped) representation.

func (*GZIP) Decode

func (g *GZIP) Decode(b *bin.Buffer) error

Decode implements bin.Decoder.

type GetConfig

type GetConfig struct{}

GetConfig is help.getConfig#c4f9186b function.

func (GetConfig) Decode added in v0.11.0

func (GetConfig) Decode(b *bin.Buffer) error

Decode implements bin.Decoder.

func (GetConfig) Encode

func (GetConfig) Encode(b *bin.Buffer) error

Encode implements bin.Encoder.

type InitConnection

type InitConnection struct {
	Flags          bin.Fields
	ID             int
	DeviceModel    string
	SystemVersion  string
	AppVersion     string
	SystemLangCode string
	LangPack       string
	LangCode       string

	Query TType
}

InitConnection is initConnection#c1cd5ea9 function.

func (InitConnection) Decode added in v0.11.0

func (i InitConnection) Decode(b *bin.Buffer) (err error)

Decode implements bin.Decoder.

func (InitConnection) Encode

func (i InitConnection) Encode(b *bin.Buffer) error

Encode implements bin.Encoder.

type Intermediate added in v0.11.0

type Intermediate struct {
	Dialer Dialer
	// contains filtered or unexported fields
}

Intermediate is intermediate MTProto transport.

See https://core.telegram.org/mtproto/mtproto-transports#intermediate

func IntermediateFromConnection added in v0.11.0

func IntermediateFromConnection(conn net.Conn) *Intermediate

IntermediateFromConnection creates Intermediate transport fron given net.Conn For tgtest.Server purposes only.

func (*Intermediate) Close added in v0.11.0

func (i *Intermediate) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*Intermediate) Dial added in v0.11.0

func (i *Intermediate) Dial(ctx context.Context, network, addr string) (err error)

Dial sends protocol version.

func (*Intermediate) Recv added in v0.11.0

func (i *Intermediate) Recv(ctx context.Context, b *bin.Buffer) error

Recv fills buffer with received message.

func (*Intermediate) Send added in v0.11.0

func (i *Intermediate) Send(ctx context.Context, b *bin.Buffer) error

Send sends message from given buffer.

type InvokeWithLayer

type InvokeWithLayer struct {
	Layer int
	Query TType
}

InvokeWithLayer is invokeWithLayer#da9b0d0d function.

invokeWithLayer#da9b0d0d {X:Type} layer:int query:!X = X;

https://core.telegram.org/method/invokeWithLayer

func (InvokeWithLayer) Decode added in v0.11.0

func (i InvokeWithLayer) Decode(b *bin.Buffer) (err error)

Decode implements bin.Decoder.

func (InvokeWithLayer) Encode

func (i InvokeWithLayer) Encode(b *bin.Buffer) error

Encode implements bin.Encoder.

type Message

type Message struct {
	ID    int64
	SeqNo int
	Bytes int
	Body  []byte
}

Message is element of MessageContainer.

func (*Message) Decode

func (m *Message) Decode(b *bin.Buffer) error

Decode implements bin.Decoder.

type MessageContainer

type MessageContainer struct {
	Messages []Message
}

MessageContainer contains slice of messages.

func (*MessageContainer) Decode

func (m *MessageContainer) Decode(b *bin.Buffer) error

Decode implements bin.Decoder.

type MessageID

type MessageID int64

MessageID represents 64-bit message id.

func NewMessageID

func NewMessageID(now time.Time, typ MessageType) MessageID

NewMessageID returns new message id for provided time and type.

func (MessageID) Time

func (id MessageID) Time() time.Time

Time returns approximate time when MessageID were generated.

func (MessageID) Type

func (id MessageID) Type() MessageType

Type returns message type.

type MessageType

type MessageType byte

MessageType is type of message determined by message id.

A message is rejected over 300 seconds after it is created or 30 seconds before it is created (this is needed to protect from replay attacks).

The identifier of a message container must be strictly greater than those of its nested messages.

const (
	// MessageUnknown reports that message id has unknown time and probably
	// should be ignored.
	MessageUnknown MessageType = iota
	// MessageFromClient is client message identifiers.
	MessageFromClient
	// MessageServerResponse is a response to a client message.
	MessageServerResponse
	// MessageFromServer is a message from the server.
	MessageFromServer
)

type ProtocolErr added in v0.11.0

type ProtocolErr struct {
	Code int32
}

ProtocolErr represents protocol level error.

func (ProtocolErr) Error added in v0.11.0

func (p ProtocolErr) Error() string

type Result

type Result struct {
	RequestMessageID int64
	Result           []byte
}

Result is rpc_result#f35c6d01.

func (*Result) Decode

func (r *Result) Decode(b *bin.Buffer) error

Decode implements bin.Decoder.

func (*Result) Encode added in v0.11.0

func (r *Result) Encode(b *bin.Buffer) error

Encode implements bin.Encoder.

type TType added in v0.11.0

type TType interface {
	bin.Encoder
	bin.Decoder
}

TType represents any generic T in TL Schema.

type Transport added in v0.11.0

type Transport interface {
	// Dial sends protocol version.
	Dial(ctx context.Context, network, addr string) error

	// Send sends message from given buffer.
	Send(ctx context.Context, b *bin.Buffer) error

	// Recv fills buffer with received message.
	Recv(ctx context.Context, b *bin.Buffer) error

	// Close closes the connection.
	// Any blocked Read or Write operations will be unblocked and return errors.
	Close() error
}

Transport is MTProto transport protocol abstraction.

type UnencryptedMessage

type UnencryptedMessage struct {
	MessageID   int64
	MessageData []byte
}

UnencryptedMessage is plaintext message.

func (*UnencryptedMessage) Decode

func (u *UnencryptedMessage) Decode(b *bin.Buffer) error

Decode implements bin.Decoder.

func (UnencryptedMessage) Encode

func (u UnencryptedMessage) Encode(b *bin.Buffer) error

Encode implements bin.Encoder.

Jump to

Keyboard shortcuts

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