telemt

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFakeTLSSecret

func BuildFakeTLSSecret(rawSecret, domain string, maskingEnabled bool) string

BuildFakeTLSSecret constructs the full FakeTLS secret for sharing. Format: ee + raw_secret + domain_hex (when masking enabled) Format: dd + raw_secret (when masking disabled)

func BuildProxyLink(serverIP string, port int, secret string) string

BuildProxyLink generates a tg://proxy link.

func BuildWebLink(serverIP string, port int, secret string) string

BuildWebLink generates a https://t.me proxy link.

func DomainToHex

func DomainToHex(domain string) string

DomainToHex converts a domain string to its hex representation.

func GenerateSecret

func GenerateSecret() (string, error)

GenerateSecret creates a random 32-character hex secret.

func ValidateSecretKey

func ValidateSecretKey(key string) bool

ValidateSecretKey checks if a secret key is valid (32 hex chars).

func WriteConfigTOML

func WriteConfigTOML(cfg *TelemtConfig, path string) error

WriteConfigTOML writes the TOML configuration to a file atomically.

Types

type AccessConfig

type AccessConfig struct {
	ReplayCheckLen   int                  `toml:"replay_check_len"`
	ReplayWindowSecs int                  `toml:"replay_window_secs"`
	IgnoreTimeSkew   bool                 `toml:"ignore_time_skew"`
	Users            map[string]string    `toml:"users"`
	UserMaxTCPConns  map[string]int       `toml:"user_max_tcp_conns,omitempty"`
	UserMaxUniqueIPs map[string]int       `toml:"user_max_unique_ips,omitempty"`
	UserDataQuota    map[string]int64     `toml:"user_data_quota,omitempty"`
	UserExpirations  map[string]string    `toml:"user_expirations,omitempty"`
	UserRateLimits   map[string]RateLimit `toml:"user_rate_limits,omitempty"`
	UserEnabled      map[string]bool      `toml:"user_enabled,omitempty"`
}

type CensorshipConfig

type CensorshipConfig struct {
	TLSDomain         string            `toml:"tls_domain"`
	TLSDomains        []string          `toml:"tls_domains,omitempty"`
	UnknownSNIAction  string            `toml:"unknown_sni_action"`
	Mask              bool              `toml:"mask"`
	MaskPort          int               `toml:"mask_port"`
	MaskHost          string            `toml:"mask_host,omitempty"`
	MaskRelayMaxBytes int64             `toml:"mask_relay_max_bytes,omitempty"`
	FakeCertLen       int               `toml:"fake_cert_len"`
	TLSEmulation      bool              `toml:"tls_emulation"`
	TLSFrontDir       string            `toml:"tls_front_dir,omitempty"`
	ExclusiveMask     map[string]string `toml:"exclusive_mask,omitempty"`
}

type ConfigParams

type ConfigParams struct {
	Settings              *model.Settings
	Secrets               []SecretEntry
	Upstreams             []UpstreamEntry
	ExtraMetricsWhitelist []string
}

ConfigParams holds the parameters needed to generate a telemt config.

type GeneralConfig

type GeneralConfig struct {
	PreferIPv6     bool        `toml:"prefer_ipv6"`
	FastMode       bool        `toml:"fast_mode"`
	UseMiddleProxy bool        `toml:"use_middle_proxy"`
	LogLevel       string      `toml:"log_level"`
	AdTag          string      `toml:"ad_tag,omitempty"`
	Modes          ModesConfig `toml:"modes"`
	Links          LinksConfig `toml:"links"`
}

type InstanceConfigParams added in v0.1.0

type InstanceConfigParams struct {
	Instance              *model.Instance
	DockerImage           string
	FakeCertLen           int
	UseMiddleProxy        bool
	AdTag                 string
	ProxyProtocol         bool
	ProxyProtocolCIDRs    []string
	Telegram              TelegramConfig
	Secrets               []SecretEntry
	Upstreams             []UpstreamEntry
	ExtraMetricsWhitelist []string
	// SYN limiter (opt-in). Empty Backend = disabled.
	SynlimitBackend  string
	SynlimitSeconds  int
	SynlimitHitcount int
	SynlimitBurst    int
}

InstanceConfigParams holds per-instance parameters for config generation.

type LinksConfig

type LinksConfig struct {
	Show []string `toml:"show"`
}

type ModesConfig

type ModesConfig struct {
	Classic bool `toml:"classic"`
	Secure  bool `toml:"secure"`
	TLS     bool `toml:"tls"`
}

type RateLimit added in v0.7.0

type RateLimit struct {
	UpBps   int64
	DownBps int64
}

RateLimit holds per-user up/down rate limits in bits per second (0 = unlimited).

type SecretEntry

type SecretEntry struct {
	Label            string
	SecretKey        string
	Enabled          bool
	MaxConns         int
	MaxIPs           int
	QuotaBytes       int64
	RateLimitUpBps   int64
	RateLimitDownBps int64
	ExpiresAt        string
}

SecretEntry represents a secret for TOML generation.

type ServerConfig

type ServerConfig struct {
	Port                      int      `toml:"port"`
	ListenAddrIPv4            string   `toml:"listen_addr_ipv4"`
	ListenAddrIPv6            string   `toml:"listen_addr_ipv6"`
	ProxyProtocol             bool     `toml:"proxy_protocol"`
	ProxyProtocolTrustedCIDRs []string `toml:"proxy_protocol_trusted_cidrs,omitempty"`
	MetricsListen             string   `toml:"metrics_listen"`
	MetricsWhitelist          []string `toml:"metrics_whitelist"`
	ClientMSS                 int      `toml:"client_mss,omitempty"`
	ClientMSSBulk             int      `toml:"client_mss_bulk,omitempty"`
	// SYN limiter (netfilter). Empty backend = disabled (not rendered).
	Synlimit         string `toml:"synlimit,omitempty"` // "nftables" | "iptables"
	SynlimitSeconds  int    `toml:"synlimit_seconds,omitempty"`
	SynlimitHitcount int    `toml:"synlimit_hitcount,omitempty"`
	SynlimitBurst    int    `toml:"synlimit_burst,omitempty"`
	// Control-plane API ([server.api]). APIPort 0 = disabled (rendered enabled=false
	// to override the engine's on-by-default 0.0.0.0:9091 listener). Bound to loopback.
	APIPort int `toml:"-"`
}

type TelegramConfig added in v0.0.10

type TelegramConfig struct {
	ProxySecretURL   string `toml:"proxy_secret_url,omitempty"`
	ProxyConfigV4URL string `toml:"proxy_config_v4_url,omitempty"`
	ProxyConfigV6URL string `toml:"proxy_config_v6_url,omitempty"`
}

type TelemtConfig

type TelemtConfig struct {
	General    GeneralConfig    `toml:"general"`
	Server     ServerConfig     `toml:"server"`
	Timeouts   TimeoutsConfig   `toml:"timeouts"`
	Censorship CensorshipConfig `toml:"censorship"`
	Access     AccessConfig     `toml:"access"`
	Upstreams  []UpstreamConfig `toml:"upstreams,omitempty"`
	Telegram   TelegramConfig   `toml:"telegram,omitempty"`
}

TelemtConfig represents the full TOML configuration for the telemt engine.

func BuildConfig

func BuildConfig(params *ConfigParams) *TelemtConfig

BuildConfig constructs the telemt TOML configuration (legacy: from global settings).

func BuildInstanceConfig added in v0.1.0

func BuildInstanceConfig(params *InstanceConfigParams) *TelemtConfig

BuildInstanceConfig constructs a telemt TOML config for a specific instance.

type TimeoutsConfig

type TimeoutsConfig struct {
	ClientHandshake int `toml:"client_handshake"`
	TGConnect       int `toml:"tg_connect"`
	ClientKeepalive int `toml:"client_keepalive"`
	ClientAck       int `toml:"client_ack"`
}

type UpstreamConfig

type UpstreamConfig struct {
	Type         string `toml:"type"`
	Weight       int    `toml:"weight"`
	Address      string `toml:"address,omitempty"`
	Username     string `toml:"username,omitempty"`
	Password     string `toml:"password,omitempty"`
	UserID       string `toml:"user_id,omitempty"`
	URL          string `toml:"url,omitempty"`
	Interface    string `toml:"interface,omitempty"`
	IPv4         *bool  `toml:"ipv4,omitempty"`
	IPv6         *bool  `toml:"ipv6,omitempty"`
	Prefer       int    `toml:"prefer,omitempty"`
	BindToDevice string `toml:"bindtodevice,omitempty"`
}

type UpstreamEntry

type UpstreamEntry struct {
	Type         model.UpstreamType
	Address      string
	Username     string
	Password     string
	URL          string // shadowsocks ss:// URL (shadowsocks type only)
	Weight       int
	Iface        string
	Enabled      bool
	IPv4         *bool
	IPv6         *bool
	Prefer       int
	BindToDevice string
}

UpstreamEntry represents an upstream for TOML generation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL