Documentation
¶
Overview ¶
Package proto implements MTProto 2.0 primitives.
See https://core.telegram.org/mtproto/description for reference.
Index ¶
Constants ¶
const GZIPTypeID = 0x3072cfa1
GZIPTypeID is TL type id of GZIP.
const MessageContainerTypeID = 0x73f1f8dc
MessageContainerTypeID is TL type id of MessageContainer.
const ResultTypeID = 0xf35c6d01
ResultTypeID is TL type id of Result.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DecompressionBombErr ¶
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 ¶
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.
type Message ¶
Message is element of MessageContainer.
type MessageContainer ¶
type MessageContainer struct {
Messages []Message
}
MessageContainer contains slice of messages.
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 ¶
func NewMessageIDNano(nano int64, typ MessageType) MessageID
NewMessageIDNano returns new message id for provided current unix nanoseconds and type.
type MessageIDBuf ¶
type MessageIDBuf struct {
// contains filtered or unexported fields
}
MessageIDBuf stores the last N received message ids and is used in replay attack mitigation.
It works like TDLib's MessageIdDuplicateChecker: ids are kept sorted in a buffer of 2N, so an id is checked by binary search, an increasing id (the common case) is appended, and the oldest N are dropped at once when the buffer is full.
func NewMessageIDBuf ¶
func NewMessageIDBuf(n int) *MessageIDBuf
NewMessageIDBuf initializes new message id buffer for last N stored values.
func (*MessageIDBuf) Consume ¶
func (b *MessageIDBuf) Consume(newID int64) bool
Consume returns false if message should be discarded.
func (*MessageIDBuf) Reset ¶
func (b *MessageIDBuf) Reset()
Reset forgets all stored message ids, e.g. when a new session is started.
type MessageIDGen ¶
type MessageIDGen struct {
// contains filtered or unexported fields
}
MessageIDGen is message id generator that provides collision prevention.
Ids follow TDLib (AuthData::next_message_id): the time of now() with 22 random bits XORed into the fraction, and if that is not above the last id (now() returned the same or an earlier time, e.g. after a correction of the server time offset), the last id plus a random multiple of 4. So ids always increase, and their lower bits don't reveal the clock resolution.
func NewMessageIDGen ¶
func NewMessageIDGen(now func() time.Time) *MessageIDGen
NewMessageIDGen creates new message id generator.
Current time will be provided by now() function, e.g. the server time of mtproto.ServerTime.
func (*MessageIDGen) New ¶
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.
func (*MessageIDGen) Reset ¶
func (g *MessageIDGen) Reset()
Reset forgets the last generated id, so the next ids follow the current time again even if earlier ones were higher, e.g. generated before the server time offset was corrected. Ids must keep increasing within a server session, so Reset is for a new session only.
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 ¶
func (m MessageType) String() string
type UnencryptedMessage ¶
UnencryptedMessage is plaintext message.