proto

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 10 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 GZIPTypeID = 0x3072cfa1

GZIPTypeID is TL type id of GZIP.

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

This section is empty.

Functions

func TypesMap

func TypesMap() map[uint32]string

TypesMap returns mapping from type ids to TL type names.

Types

type DecompressionBombErr added in v0.48.0

type DecompressionBombErr struct {
	Compressed   int
	Decompressed int
}

DecompressionBombErr means that GZIP decode detected decompression bomb which decompressed payload is significantly higher than initial compressed size and stopped decompression to prevent OOM.

func (*DecompressionBombErr) Error added in v0.48.0

func (d *DecompressionBombErr) Error() string

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) (rErr error)

Decode implements bin.Decoder.

func (GZIP) Encode added in v0.11.2

func (g GZIP) Encode(b *bin.Buffer) (rErr 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.

func (*Message) Encode added in v0.30.0

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

Encode implements bin.Encoder.

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.

func (*MessageContainer) Encode added in v0.30.0

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

Encode 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 NewMessageIDNano added in v0.33.1

func NewMessageIDNano(nano int64, typ MessageType) MessageID

NewMessageIDNano returns new message id for provided current unix nanoseconds and type.

func (MessageID) String added in v0.19.0

func (id MessageID) String() string

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

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

MessageIDBuf stores last N message ids and is used in replay attack mitigation.

func NewMessageIDBuf added in v0.25.0

func NewMessageIDBuf(n int) *MessageIDBuf

NewMessageIDBuf initializes new message id buffer for last N stored values.

func (*MessageIDBuf) Consume added in v0.25.0

func (b *MessageIDBuf) Consume(newID int64) bool

Consume returns false if message should be discarded.

type MessageIDGen added in v0.16.0

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

MessageIDGen is message id generator that provides collision prevention.

The main reason of such structure is that now() can return same time during multiple calls and that leads to duplicate message id.

func NewMessageIDGen added in v0.16.0

func NewMessageIDGen(now func() time.Time) *MessageIDGen

NewMessageIDGen creates new message id generator.

Current time will be provided by now() function.

This generator compensates time resolution problem removing probability of id collision.

Such problem can be observed for relatively high RPS, sequential calls to time.Now() will return same time which leads to equal ids.

func (*MessageIDGen) New added in v0.16.0

func (g *MessageIDGen) New(t MessageType) int64

New generates new message id for provided type, protecting from collisions that are caused by low system time resolution.

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
)

func (MessageType) String added in v0.19.0

func (m MessageType) String() 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 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.

Directories

Path Synopsis
Package codec contains MTProto transport encoding implementations.
Package codec contains MTProto transport encoding implementations.

Jump to

Keyboard shortcuts

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