package dcs

Import Path
	github.com/gotd/td/telegram/dcs (on go.dev)

Dependency Relation
	imports 28 packages, and imported by 2 packages

Involved Source Files dns.go Package dcs contains Telegram DCs list and some helpers. find.go http.go list.go mtproxy.go plain.go prod.go protocol.go resolver.go resolver_notjs.go test.go websocket.go
Code Examples package main import ( "context" "fmt" "time" "golang.org/x/net/proxy" "github.com/gotd/td/telegram" "github.com/gotd/td/telegram/dcs" ) func main() { // Dial using proxy from environment. // Creating connection. ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() client := telegram.NewClient(1, "appHash", telegram.Options{ Resolver: dcs.Plain(dcs.PlainOptions{Dial: proxy.Dial}), }) _ = client.Run(ctx, func(ctx context.Context) error { fmt.Println("Started") return nil }) } package main import ( "context" "fmt" "time" "golang.org/x/net/proxy" "github.com/gotd/td/telegram" "github.com/gotd/td/telegram/dcs" ) func main() { // Dial using SOCKS5 proxy. sock5, _ := proxy.SOCKS5("tcp", "IP:PORT", &proxy.Auth{ User: "YOURUSERNAME", Password: "YOURPASSWORD", }, proxy.Direct) dc := sock5.(proxy.ContextDialer) // Creating connection. ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() client := telegram.NewClient(1, "appHash", telegram.Options{ Resolver: dcs.Plain(dcs.PlainOptions{ Dial: dc.DialContext, }), }) _ = client.Run(ctx, func(ctx context.Context) error { fmt.Println("Started") return nil }) }
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. MaxWait int 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. WaitAfter int func HTTP(opts HTTPOptions) Resolver
List is a list of Telegram DC addresses and domains. Domains map[int]string Options []tg.DCOption Test bool Zero returns true if this List is zero value. func Prod() List func Staging() List func Test() List func Resolver.CDN(ctx context.Context, dc int, list List) (transport.Conn, error) func Resolver.MediaOnly(ctx context.Context, dc int, list List) (transport.Conn, error) func Resolver.Primary(ctx context.Context, dc int, list List) (transport.Conn, error)
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. 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. func Plain(opts PlainOptions) Resolver
Protocol is MTProto transport protocol. See https://core.telegram.org/mtproto/mtproto-transports ( Protocol) Codec() transport.Codec ( Protocol) Handshake(conn net.Conn) (transport.Conn, error) github.com/gotd/td/transport.Protocol
Resolver resolves DC and creates transport MTProto connection. ( Resolver) CDN(ctx context.Context, dc int, list List) (transport.Conn, error) ( Resolver) MediaOnly(ctx context.Context, dc int, list List) (transport.Conn, error) ( Resolver) Primary(ctx context.Context, dc int, list List) (transport.Conn, error) func DefaultResolver() Resolver func HTTP(opts HTTPOptions) Resolver func MTProxy(addr string, secret []byte, opts MTProxyOptions) (Resolver, error) func Plain(opts PlainOptions) Resolver func Websocket(opts WebsocketOptions) Resolver func github.com/gotd/td/telegram.TDesktopResolver() 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. func Websocket(opts WebsocketOptions) Resolver
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 Variables (only one, which is unexported)
Package-Level Constants (total 5, none are exported)