Documentation
¶
Index ¶
- Constants
- Variables
- func CopyWithPool(dst io.Writer, src io.Reader) (int64, error)
- func GetBuffer() []byte
- func NewFixedResolver(tnet *netstack.Net, systemDNS bool, defaultTTL time.Duration, cacheSize int) *fixedResolver
- func ParseInterface(cfg *ini.File, device *DeviceConfig) error
- func ParsePeers(cfg *ini.File, peers *[]PeerConfig) error
- func PutBuffer(buf []byte)
- func STDIOTcpForward(ctx context.Context, vt *VirtualTun, raddr *addressPort)
- func SetLogLevel(level string) error
- func ValidateASecConfig(config *ASecConfigType) error
- type ASecConfigType
- type Configuration
- type CredentialValidator
- type DeviceConfig
- type DeviceSetting
- type HTTPConfig
- type HTTPServer
- type PeerConfig
- type Reloadable
- type ResolveConfig
- type RoutineSpawner
- type STDIOTunnelConfig
- type Socks5Config
- type TCPClientTunnelConfig
- type TCPServerTunnelConfig
- type UDPProxyTunnelConfig
- func (c *UDPProxyTunnelConfig) Reload(newConfig *Configuration) error
- func (conf *UDPProxyTunnelConfig) SetCacheSize(newSize int) error
- func (conf *UDPProxyTunnelConfig) SpawnRoutine(ctx context.Context, vt *VirtualTun) error
- func (conf *UDPProxyTunnelConfig) SpawnUDPProxy(ctx context.Context, vt *VirtualTun) error
- type VirtualTun
- func (d VirtualTun) LookupAddr(ctx context.Context, name string) ([]string, error)
- func (d VirtualTun) Resolve(ctx context.Context, name string) (context.Context, net.IP, error)
- func (d VirtualTun) ResolveAddrWithContext(ctx context.Context, name string) (*netip.Addr, error)
- func (d VirtualTun) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (d *VirtualTun) StartPingIPs()
- func (d *VirtualTun) StopPingIPs()
Constants ¶
const ( // IdleTimeout – время бездействия, после которого соединение принудительно закрывается IdleTimeout = 5 * time.Minute // DialTimeout – максимальное время на установку TCP-соединения DialTimeout = 10 * time.Second // ReadTimeout – таймаут на чтение данных из соединения ReadTimeout = 30 * time.Second // WriteTimeout – таймаут на запись данных в соединение WriteTimeout = 30 * time.Second // HTTPTimeout – общий таймаут для HTTP-запросов (не CONNECT) HTTPTimeout = 30 * time.Second )
Глобальные таймауты для всех TCP-соединений
Variables ¶
var Log *slog.Logger
Functions ¶
func CopyWithPool ¶
CopyWithPool копирует данные из src в dst, используя буфер из пула
func NewFixedResolver ¶
func NewFixedResolver(tnet *netstack.Net, systemDNS bool, defaultTTL time.Duration, cacheSize int) *fixedResolver
NewFixedResolver создаёт новый резолвер.
func ParseInterface ¶
func ParseInterface(cfg *ini.File, device *DeviceConfig) error
func ParsePeers ¶
func ParsePeers(cfg *ini.File, peers *[]PeerConfig) error
func STDIOTcpForward ¶
func STDIOTcpForward(ctx context.Context, vt *VirtualTun, raddr *addressPort)
STDIOTcpForward starts a new connection via wireguard and forward traffic from `conn`
func SetLogLevel ¶
SetLogLevel устанавливает уровень логирования.
func ValidateASecConfig ¶
func ValidateASecConfig(config *ASecConfigType) error
ValidateASecConfig — расширенная валидация всех параметров AmneziaWG.
Types ¶
type ASecConfigType ¶
type ASecConfigType struct {
// contains filtered or unexported fields
}
func ParseASecConfig ¶
func ParseASecConfig(section *ini.Section) (*ASecConfigType, error)
ParseASecConfig загружает и валидирует секцию AmneziaWG.
type Configuration ¶
type Configuration struct {
Device *DeviceConfig
Routines []RoutineSpawner
Resolve *ResolveConfig
DnsCacheSize int
PingCacheSize int
UdpSessionCacheSize int
DnsTtl int
DnsCacheSizeSet bool
PingCacheSizeSet bool
UdpSessionCacheSizeSet bool
DnsTtlSet bool
}
func ParseConfig ¶
func ParseConfig(path string) (*Configuration, error)
type CredentialValidator ¶
type CredentialValidator struct {
// contains filtered or unexported fields
}
CredentialValidator stores the authentication data of a socks5 proxy
func (CredentialValidator) Valid ¶
func (c CredentialValidator) Valid(username, password string) bool
Valid checks username and password in constant time.
type DeviceConfig ¶
type DeviceSetting ¶
DeviceSetting contains the parameters for setting up a tun interface
func CreateIPCRequest ¶
func CreateIPCRequest(conf *DeviceConfig) (*DeviceSetting, error)
CreateIPCRequest serialize the config into an IPC request and DeviceSetting
type HTTPConfig ¶
type HTTPConfig struct {
BindAddress string
Username string
Password string
CertFile string
KeyFile string
}
func (*HTTPConfig) SpawnRoutine ¶
func (config *HTTPConfig) SpawnRoutine(ctx context.Context, vt *VirtualTun) error
SpawnRoutine for HTTPConfig
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
func NewHTTPServer ¶
func NewHTTPServer(config *HTTPConfig, dial func(network, address string) (net.Conn, error)) *HTTPServer
func (*HTTPServer) ListenAndServe ¶
func (s *HTTPServer) ListenAndServe(ctx context.Context, network, addr string) error
type PeerConfig ¶
type Reloadable ¶
type Reloadable interface {
Reload(newConfig *Configuration) error
}
Reloadable позволяет динамически перезагружать конфигурацию.
type ResolveConfig ¶
type ResolveConfig struct {
ResolveStrategy string
}
type RoutineSpawner ¶
type RoutineSpawner interface {
SpawnRoutine(ctx context.Context, vt *VirtualTun) error
}
RoutineSpawner spawns a routine (e.g. socks5, tcp static routes) after the configuration is parsed
type STDIOTunnelConfig ¶
func (*STDIOTunnelConfig) SpawnRoutine ¶
func (conf *STDIOTunnelConfig) SpawnRoutine(ctx context.Context, vt *VirtualTun) error
SpawnRoutine for STDIOTunnelConfig
type Socks5Config ¶
type Socks5Config struct {
BindAddress string
Username string
Password string
// contains filtered or unexported fields
}
func (*Socks5Config) Reload ¶
func (c *Socks5Config) Reload(newConfig *Configuration) error
Реализация Reload для Socks5Config
func (*Socks5Config) SpawnRoutine ¶
func (config *Socks5Config) SpawnRoutine(ctx context.Context, vt *VirtualTun) error
SpawnRoutine for Socks5Config
func (*Socks5Config) Stop ¶
func (c *Socks5Config) Stop()
type TCPClientTunnelConfig ¶
func (*TCPClientTunnelConfig) SpawnRoutine ¶
func (conf *TCPClientTunnelConfig) SpawnRoutine(ctx context.Context, vt *VirtualTun) error
SpawnRoutine for TCPClientTunnelConfig
type TCPServerTunnelConfig ¶
func (*TCPServerTunnelConfig) SpawnRoutine ¶
func (conf *TCPServerTunnelConfig) SpawnRoutine(ctx context.Context, vt *VirtualTun) error
SpawnRoutine for TCPServerTunnelConfig
type UDPProxyTunnelConfig ¶
type UDPProxyTunnelConfig struct {
BindAddress string
Target string
InactivityTimeout int
// contains filtered or unexported fields
}
UDPProxyTunnelConfig — структура с полями для управления кэшем
func (*UDPProxyTunnelConfig) Reload ¶
func (c *UDPProxyTunnelConfig) Reload(newConfig *Configuration) error
Реализация Reload для UDPProxyTunnelConfig
func (*UDPProxyTunnelConfig) SetCacheSize ¶
func (conf *UDPProxyTunnelConfig) SetCacheSize(newSize int) error
SetCacheSize изменяет размер кэша сессий.
func (*UDPProxyTunnelConfig) SpawnRoutine ¶
func (conf *UDPProxyTunnelConfig) SpawnRoutine(ctx context.Context, vt *VirtualTun) error
SpawnRoutine for UDPProxyTunnelConfig
func (*UDPProxyTunnelConfig) SpawnUDPProxy ¶
func (conf *UDPProxyTunnelConfig) SpawnUDPProxy(ctx context.Context, vt *VirtualTun) error
SpawnUDPProxy реализует основную логику UDP-прокси с поддержкой graceful shutdown. Возвращает ошибку вместо вызова log.Fatal.
type VirtualTun ¶
type VirtualTun struct {
Tnet *netstack.Net
Dev *device.Device
SystemDNS bool
Conf *DeviceConfig
// PingRecord — LRU-кэш для хранения времени последнего успешного ping-а (IP -> timestamp)
PingRecord *lru.Cache[string, uint64]
// DnsCacheSize, UdpSessionCacheSize, DnsTtl — размеры кэшей и TTL
DnsCacheSize int
UdpSessionCacheSize int
DnsTtl time.Duration
// contains filtered or unexported fields
}
VirtualTun stores a reference to netstack network and DNS configuration
func StartWireguard ¶
func StartWireguard(conf *DeviceConfig, logLevel int, pingCacheSize int) (*VirtualTun, error)
StartWireguard creates a tun interface on netstack given a configuration. pingCacheSize задаёт максимальное количество записей в кэше PingRecord (LRU).
func (VirtualTun) LookupAddr ¶
LookupAddr lookups a hostname.
func (VirtualTun) ResolveAddrWithContext ¶
ResolveAddrWithContext resolves a hostname and returns an AddrPort.
func (VirtualTun) ServeHTTP ¶
func (d VirtualTun) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles health and metrics requests
func (*VirtualTun) StartPingIPs ¶
func (d *VirtualTun) StartPingIPs()
StartPingIPs starts a background goroutine that periodically pings all configured IPs.
func (*VirtualTun) StopPingIPs ¶
func (d *VirtualTun) StopPingIPs()
StopPingIPs stops the background ping goroutine if it is running.