package proto
Import Path
github.com/gotd/td/proto (on go.dev)
Dependency Relation
imports 11 packages, and imported by 3 packages
Involved Source Files
container.go
Package proto implements MTProto 2.0 primitives.
See https://core.telegram.org/mtproto/description for reference.
gzip.go
message_id.go
registry.go
rpc_result.go
unencrypted_message.go
Package-Level Type Names (total 12, in which 10 are exported)
DecompressionBombErr means that GZIP decode detected decompression bomb
which decompressed payload is significantly higher than initial compressed
size and stopped decompression to prevent OOM.
Compressed int
Decompressed int
(*DecompressionBombErr) Error() string
*DecompressionBombErr : error
GZIP represents a Packed Object.
Used to replace any other object (or rather, a serialization thereof)
with its archived (gzipped) representation.
Data []byte
Decode implements bin.Decoder.
Encode implements bin.Encoder.
*GZIP : github.com/gotd/td/bin.Decoder
GZIP : github.com/gotd/td/bin.Encoder
*GZIP : github.com/gotd/td/bin.Object
Message is element of MessageContainer.
Body []byte
Bytes int
ID int64
SeqNo int
Decode implements bin.Decoder.
Encode implements bin.Encoder.
*Message : github.com/gotd/td/bin.Decoder
*Message : github.com/gotd/td/bin.Encoder
*Message : github.com/gotd/td/bin.Object
func github.com/gotd/td/mtproto.(*Conn).processContainerMessage(ctx context.Context, msg Message) error
MessageContainer contains slice of messages.
Messages []Message
Decode implements bin.Decoder.
Encode implements bin.Decoder.
*MessageContainer : github.com/gotd/td/bin.Decoder
*MessageContainer : github.com/gotd/td/bin.Encoder
*MessageContainer : github.com/gotd/td/bin.Object
MessageID represents 64-bit message id.
( MessageID) String() string
Time returns approximate time when MessageID were generated.
Type returns message type.
MessageID : fmt.Stringer
MessageID : context.stringer
MessageID : runtime.stringer
func NewMessageID(now time.Time, typ MessageType) MessageID
func NewMessageIDNano(nano int64, typ MessageType) MessageID
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.
buf[:end] holds the stored ids in increasing order.
end int
mux sync.Mutex
n int
Consume returns false if message should be discarded.
Reset forgets all stored message ids, e.g. when a new session is started.
*MessageIDBuf : github.com/gotd/td/mtproto.MessageBuf
func NewMessageIDBuf(n int) *MessageIDBuf
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.
last int64
mux sync.Mutex
now func() time.Time
New generates new message id for provided type, protecting from collisions
that are caused by low system time resolution.
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.
*MessageIDGen : github.com/gotd/td/mtproto.MessageIDSource
func NewMessageIDGen(now func() time.Time) *MessageIDGen
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.
( MessageType) String() string
MessageType : fmt.Stringer
MessageType : context.stringer
MessageType : runtime.stringer
func MessageID.Type() MessageType
func NewMessageID(now time.Time, typ MessageType) MessageID
func NewMessageIDNano(nano int64, typ MessageType) MessageID
func (*MessageIDGen).New(t MessageType) int64
func github.com/gotd/td/mtproto.MessageIDSource.New(t MessageType) int64
func messageYield(typ MessageType) int
func github.com/gotd/td/exchange.Exchanger.unencryptedWriter(input, output MessageType) exchange.unencryptedWriter
const MessageFromClient
const MessageFromServer
const MessageServerResponse
const MessageUnknown
Package-Level Functions (total 9, in which 5 are exported)
NewMessageID returns new message id for provided time and type.
NewMessageIDBuf initializes new message id buffer for last N stored values.
NewMessageIDGen creates new message id generator.
Current time will be provided by now() function, e.g. the server time of
mtproto.ServerTime.
NewMessageIDNano returns new message id for provided current unix
nanoseconds and type.
TypesMap returns mapping from type ids to TL type names.
Package-Level Variables (total 2, neither is exported)
Package-Level Constants (total 12, in which 7 are exported)
GZIPTypeID is TL type id of GZIP.
MessageContainerTypeID is TL type id of MessageContainer.
MessageFromClient is client message identifiers.
MessageFromServer is a message from the server.
MessageServerResponse is a response to a client message.
MessageUnknown reports that message id has unknown time and probably
should be ignored.
ResultTypeID is TL type id of Result.
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |