Documentation
¶
Overview ¶
Package dcs contains Telegram DCs list and some helpers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DNSConfig ¶ added in v0.53.0
type DNSConfig struct {
// Date field of HelpConfigSimple.
Date int
// Expires field of HelpConfigSimple.
Expires int
// Rules field of HelpConfigSimple.
Rules []tg.AccessPointRule
}
DNSConfig is DC connection config obtained from DNS.
func ParseDNSConfig ¶ added in v0.53.0
ParseDNSConfig parses tg.HelpConfigSimple from TXT response.
type DialFunc ¶ added in v0.33.0
DialFunc connects to the address on the named network.
Example ¶
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
})
}
Output:
Example (Dialer) ¶
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
})
}
Output:
type HTTPOptions ¶ added in v0.161.0
type HTTPOptions struct {
// 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.
Client *http.Client
// 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.
Scheme string
// 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.
Port int
// PreferIPv6 gives IPv6 DCs higher precedence.
// Default is to prefer IPv4 DCs over IPv6.
PreferIPv6 bool
// MaxDelay, WaitAfter and MaxWait are the http_wait fields in milliseconds.
// Defaults: 0, 0, 25000.
//
// See https://core.telegram.org/mtproto/service_messages.
MaxDelay int
WaitAfter int
MaxWait int
}
HTTPOptions is HTTP resolver creation options.
type List ¶ added in v0.41.0
List is a list of Telegram DC addresses and domains.
func Test ¶ added in v0.51.0
func Test() List
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.
type MTProxyOptions ¶
type MTProxyOptions struct {
// Dial specifies the dial function for creating unencrypted TCP connections.
// If Dial is nil, then the resolver dials using package net.
Dial DialFunc
// Network to use. Defaults to "tcp"
Network string
// Random source for MTProxy obfuscator.
Rand io.Reader
}
MTProxyOptions is MTProxy resolver creation options.
type PlainOptions ¶
type PlainOptions struct {
// Protocol is the transport protocol to use. Defaults to intermediate.
Protocol Protocol
// Dial specifies the dial function for creating unencrypted TCP connections.
// If Dial is nil, then the resolver dials using package net.
Dial DialFunc
// Random source for TCPObfuscated DCs.
Rand io.Reader
// Network to use. Defaults to "tcp".
Network string
// NoObfuscated denotes to filter out TCP Obfuscated Only DCs.
NoObfuscated bool
// 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.
Obfuscated bool
// PreferIPv6 gives IPv6 DCs higher precedence.
// Default is to prefer IPv4 DCs over IPv6.
PreferIPv6 bool
}
PlainOptions is plain resolver creation options.
type Protocol ¶ added in v0.33.0
type Protocol interface {
Codec() transport.Codec
Handshake(conn net.Conn) (transport.Conn, error)
}
Protocol is MTProto transport protocol.
type Resolver ¶
type Resolver interface {
Primary(ctx context.Context, dc int, list List) (transport.Conn, error)
MediaOnly(ctx context.Context, dc int, list List) (transport.Conn, error)
CDN(ctx context.Context, dc int, list List) (transport.Conn, error)
}
Resolver resolves DC and creates transport MTProto connection.
func DefaultResolver ¶ added in v0.41.0
func DefaultResolver() Resolver
DefaultResolver returns default DC resolver for current platform.
func HTTP ¶ added in v0.161.0
func HTTP(opts HTTPOptions) Resolver
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.
func MTProxy ¶ added in v0.41.0
func MTProxy(addr string, secret []byte, opts MTProxyOptions) (Resolver, error)
MTProxy creates MTProxy obfuscated DC resolver.
See https://core.telegram.org/mtproto/mtproto-transports#transport-obfuscation.
func Plain ¶ added in v0.41.0
func Plain(opts PlainOptions) Resolver
Plain creates plain DC resolver.
func Websocket ¶ added in v0.41.0
func Websocket(opts WebsocketOptions) Resolver
Websocket creates Websocket DC resolver.
type WebsocketOptions ¶ added in v0.39.0
type WebsocketOptions struct {
// Dialer specifies the websocket dialer.
// If Dialer is nil, then the resolver dials using websocket.DefaultDialer.
DialOptions *websocket.DialOptions
// Random source for MTProxy obfuscator.
Rand io.Reader
}
WebsocketOptions is Websocket resolver creation options.