Package-Level Type Names (total 17, in which 9 are exported)
/* sort exporteds by: | */
DialFunc connects to the address on the named network.
DNSConfig is DC connection config obtained from DNS. Date field of HelpConfigSimple. Expires field of HelpConfigSimple. Rules field of HelpConfigSimple. Options returns DC options from this config.
func ParseDNSConfig(txt []string) (DNSConfig, error)
HTTPOptions is HTTP resolver creation options. Client is the HTTP client used for POST requests. If nil, a client with a
bounded transport and a timeout derived from MaxWait is used. A custom
client's timeout must exceed MaxWait, otherwise long-poll responses are cut
off. For Scheme "https" a custom client with an appropriate tls.Config
(SNI/certificates for the DC) is required. MaxDelay, WaitAfter and MaxWait are the http_wait fields in milliseconds.
Defaults: 0, 0, 25000.
See https://core.telegram.org/mtproto/service_messages.MaxWaitint Port overrides the transport port. Defaults to 80 for http and 443 for
https.
The HTTP transport uses this fixed port for every DC and intentionally
ignores tg.DCOption.Port (which is the TCP MTProto port), per the MTProto
HTTP transport specification. PreferIPv6 gives IPv6 DCs higher precedence.
Default is to prefer IPv4 DCs over IPv6. Scheme is "http" (default) or "https".
Note: https support is experimental. Connecting over https to a bare DC IP
needs a custom Client whose tls.Config matches the DC certificate; the
default client will fail TLS verification.WaitAfterint(*HTTPOptions) setDefaults()
func HTTP(opts HTTPOptions) Resolver
MTProxyOptions is MTProxy resolver creation options. Dial specifies the dial function for creating unencrypted TCP connections.
If Dial is nil, then the resolver dials using package net. Network to use. Defaults to "tcp" Random source for MTProxy obfuscator.(*MTProxyOptions) setDefaults()
func MTProxy(addr string, secret []byte, opts MTProxyOptions) (Resolver, error)
PlainOptions is plain resolver creation options. Dial specifies the dial function for creating unencrypted TCP connections.
If Dial is nil, then the resolver dials using package net. Network to use. Defaults to "tcp". NoObfuscated denotes to filter out TCP Obfuscated Only DCs. Obfuscated enables transport obfuscation (Obfuscated2) for all
connections, not only for TCP-obfuscated-only DCs.
The official clients (e.g. Telegram Desktop) always obfuscate direct
connections, so enabling this together with Protocol: transport.Abridged
makes the connection indistinguishable from Telegram Desktop on the wire. PreferIPv6 gives IPv6 DCs higher precedence.
Default is to prefer IPv4 DCs over IPv6. Protocol is the transport protocol to use. Defaults to intermediate. Random source for TCPObfuscated DCs.(*PlainOptions) setDefaults()
func Plain(opts PlainOptions) Resolver
WebsocketOptions is Websocket resolver creation options. Dialer specifies the websocket dialer.
If Dialer is nil, then the resolver dials using websocket.DefaultDialer. Random source for MTProxy obfuscator.(*WebsocketOptions) setDefaults()
func Websocket(opts WebsocketOptions) Resolver
httpConn implements transport.Conn over the MTProto HTTP transport.
See https://core.telegram.org/mtproto/transports#http-transport.
MTProto over HTTP is request/response: the server can only deliver messages
as the body of a response to a client POST. Send posts one raw MTProto frame
(framing is done by HTTP Content-Length, there is no codec tag) and the
response body — the messages the server had queued for the session — is
delivered to Recv through inbox. Send is non-blocking: the POST and its
(possibly long-polling) response are handled on a separate goroutine so a 25s
http_wait long-poll never stalls the mtproto write path.cancelcontext.CancelFuncclient*http.ClientcloseOncesync.Oncectxcontext.Context inbox buffers responses (frames or protocol errors) until Recv consumes
them. http_wait parameters in milliseconds, reported via HTTPWaitParams and used
by the mtproto layer to build http_wait messages.maxWaitintstartOncesync.OnceurlIdxatomic.Uint32 urls holds one /api endpoint per candidate DC address. Requests use the
current index; a failed POST rotates to the next candidate.waitAfterint Close releases the connection and cancels in-flight requests. HTTPWaitParams reports the http_wait fields (milliseconds) the transport wants
the mtproto layer to use. It is part of the mtproto HTTP long-poll capability. Recv blocks until an incoming frame or a transport-level protocol error is
available. Send posts a single MTProto frame. It is non-blocking: the POST and response
are handled on a separate goroutine, so a long-poll response never stalls the
caller. Delivery reliability is provided by the mtproto rpc engine
(acks/retransmits) and liveness by the ping loop; a failed POST is therefore
dropped here and recovered upstream. StartHTTPWait starts the long-poll loop. frame yields a freshly-encrypted
http_wait service message — only the mtproto layer can encrypt it. The loop
keeps exactly one long-poll POST outstanding, re-issuing it as soon as the
previous response arrives, to minimize update latency. It is safe to call at
most once; further calls are no-ops.
The loop runs in a goroutine whose lifetime is bound solely to Close: it is
not part of the mtproto Run errgroup, so the connection must be closed to stop
it (Conn.handleClose does this on teardown).(*httpConn) deliver(r recvResult)(*httpConn) pollLoop(frame func(ctx context.Context) (*bin.Buffer, error)) rotateURL advances to the next candidate address after a failed POST. Failover
is best-effort: a burst of concurrent failures may advance the index by more
than one, but the poll loop's round-robin still reaches every candidate. roundtrip posts one frame and delivers the response to inbox. It reports
whether anything was delivered (a frame or a protocol error) and returns an
error only for transport-level failures (POST error, non-200), which callers
use to back off. sleep waits for d, returning false if the connection was closed while waiting. urlIndex returns the current candidate index. The modulo is taken on the
unsigned counter so the index stays in range even if the counter wraps.
*httpConn : github.com/gotd/td/transport.Conn
*httpConn : io.Closer
*httpConn : github.com/gotd/td/mtproto.httpWaiter
func newHTTPConn(client *http.Client, urls []string, maxDelay, waitAfter, maxWait int) *httpConn
Package-Level Functions (total 14, in which 11 are exported)
DefaultResolver returns default DC resolver for current platform.
FindDCs searches DCs candidates from given config.
FindPrimaryDCs searches new primary DC from given config.
Unlike FindDC, it filters CDNs and MediaOnly servers, returns error
if not found.
HTTP creates an MTProto-over-HTTP DC resolver with http_wait long-polling.
It suits environments where a raw persistent MTProto TCP socket cannot be
held but HTTP POST to the DC is possible. Updates are delivered via http_wait
long-polling, so their latency is bounded by the round-trip rather than being
instantaneous. MediaOnly and CDN DCs are not supported.
See https://core.telegram.org/mtproto/transports#http-transport.
MTProxy creates MTProxy obfuscated DC resolver.
See https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation.
ParseDNSConfig parses tg.HelpConfigSimple from TXT response.
Plain creates plain DC resolver.
Prod returns production DC list.
Staging returns staging DC list.
Deprecated: Use Test().
Test returns test DC list.
NB: as of 2026, the test DCs no longer auto-provision accounts for randomly
generated 99966X test phone numbers (auth.Test) — sign in fails with
PHONE_CODE_INVALID. A real, pre-registered test account is required; see
https://core.telegram.org/api/auth#test-accounts.
Websocket creates Websocket DC resolver.
See https://core.telegram.org/mtproto/transports#websocket.
Package-Level Constants (total 5, none are exported)
defaultHTTPMaxWait is the default http_wait max_wait (ms): the server holds
the long-poll response open up to this long. Matches the MTProto default.
httpClientTimeoutMargin is added on top of max_wait for the HTTP client
timeout so a full-length long-poll response is not cut off.
httpInboxSize buffers response frames until Recv consumes them.
httpMaxConnsPerHost bounds concurrent connections of the default client to
a single DC, so a burst of sends cannot exhaust file descriptors.
httpWaitRetryInterval throttles the poll loop when a wait frame cannot be
built (e.g. during key exchange) or a POST fails, avoiding a busy loop.
The pages are generated with Goldsv0.8.4. (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.