service

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMTUTooSmall = errors.New("MTU must be at least 1280")

Functions

This section is empty.

Types

type ClientConfig

type ClientConfig struct {
	Name         string    `json:"name"`
	Endpoint     conn.Addr `json:"endpoint"`
	Protocol     string    `json:"protocol"`
	DialerFwmark int       `json:"dialerFwmark"`

	// TCP
	EnableTCP bool `json:"enableTCP"`
	DialerTFO bool `json:"dialerTFO"`

	// UDP
	EnableUDP bool `json:"enableUDP"`
	MTU       int  `json:"mtu"`

	// Shadowsocks
	PSK           []byte   `json:"psk"`
	IPSKs         [][]byte `json:"iPSKs"`
	PaddingPolicy string   `json:"paddingPolicy"`

	// Taint
	UnsafeRequestStreamPrefix  []byte `json:"unsafeRequestStreamPrefix"`
	UnsafeResponseStreamPrefix []byte `json:"unsafeResponseStreamPrefix"`
	// contains filtered or unexported fields
}

ClientConfig stores a client configuration. It may be marshaled as or unmarshaled from JSON.

func (*ClientConfig) TCPClient

func (cc *ClientConfig) TCPClient(logger *zap.Logger) (zerocopy.TCPClient, error)

TCPClient creates a zerocopy.TCPClient from the ClientConfig.

func (*ClientConfig) UDPClient

func (cc *ClientConfig) UDPClient(logger *zap.Logger) (zerocopy.UDPClient, error)

type Config added in v1.3.0

type Config struct {
	Servers []ServerConfig       `json:"servers"`
	Clients []ClientConfig       `json:"clients"`
	DNS     []dns.ResolverConfig `json:"dns"`
	Router  router.Config        `json:"router"`
}

Config is the main configuration structure. It may be marshaled as or unmarshaled from JSON.

func (*Config) Manager added in v1.5.0

func (sc *Config) Manager(logger *zap.Logger) (*Manager, error)

Manager initializes the service manager.

Initialization order: clients -> DNS -> router -> servers

type Manager added in v1.5.0

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages the services.

func (*Manager) Close added in v1.5.0

func (m *Manager) Close()

Close closes the manager.

func (*Manager) Start added in v1.5.0

func (m *Manager) Start() error

Start starts all configured services.

func (*Manager) Stop added in v1.5.0

func (m *Manager) Stop()

Stop stops all running services.

type Relay

type Relay interface {
	// String returns the relay service's name.
	String() string

	// Start starts the relay service.
	Start() error

	// Stop stops the relay service.
	Stop() error
}

Relay is a relay service that accepts incoming connections/sessions on a server and dispatches them to a client selected by the router.

func NewUDPTransparentRelay added in v1.4.0

func NewUDPTransparentRelay(
	serverName, listenAddress string,
	relayBatchSize, serverRecvBatchSize, sendChannelCapacity, listenerFwmark, mtu, maxClientFrontHeadroom, maxClientRearHeadroom int,
	natTimeout time.Duration,
	router *router.Router,
	logger *zap.Logger,
) (Relay, error)

type ServerConfig

type ServerConfig struct {
	Name           string `json:"name"`
	Listen         string `json:"listen"`
	Protocol       string `json:"protocol"`
	ListenerFwmark int    `json:"listenerFwmark"`

	// TCP
	EnableTCP                 bool `json:"enableTCP"`
	ListenerTFO               bool `json:"listenerTFO"`
	DisableInitialPayloadWait bool `json:"disableInitialPayloadWait"`

	// UDP
	EnableUDP     bool `json:"enableUDP"`
	MTU           int  `json:"mtu"`
	NatTimeoutSec int  `json:"natTimeoutSec"`

	// UDP performance tuning
	UDPBatchMode           string `json:"udpBatchMode"`
	UDPRelayBatchSize      int    `json:"udpRelayBatchSize"`
	UDPServerRecvBatchSize int    `json:"udpServerRecvBatchSize"`
	UDPSendChannelCapacity int    `json:"udpSendChannelCapacity"`

	// Simple tunnel
	TunnelRemoteAddress conn.Addr `json:"tunnelRemoteAddress"`
	TunnelUDPTargetOnly bool      `json:"tunnelUDPTargetOnly"`

	// Shadowsocks
	PSK           []byte   `json:"psk"`
	UPSKs         [][]byte `json:"uPSKs"`
	PaddingPolicy string   `json:"paddingPolicy"`
	RejectPolicy  string   `json:"rejectPolicy"`

	// Taint
	UnsafeFallbackAddress      *conn.Addr `json:"unsafeFallbackAddress"`
	UnsafeRequestStreamPrefix  []byte     `json:"unsafeRequestStreamPrefix"`
	UnsafeResponseStreamPrefix []byte     `json:"unsafeResponseStreamPrefix"`
	// contains filtered or unexported fields
}

ServerConfig stores a server configuration. It may be marshaled as or unmarshaled from JSON.

func (*ServerConfig) TCPRelay

func (sc *ServerConfig) TCPRelay(router *router.Router, logger *zap.Logger) (*TCPRelay, error)

TCPRelay creates a TCP relay service from the ServerConfig.

func (*ServerConfig) UDPRelay

func (sc *ServerConfig) UDPRelay(router *router.Router, logger *zap.Logger, maxClientFrontHeadroom, maxClientRearHeadroom int) (Relay, error)

UDPRelay creates a UDP relay service from the ServerConfig.

type TCPRelay

type TCPRelay struct {
	// contains filtered or unexported fields
}

TCPRelay is a relay service for TCP traffic.

When started, the relay service accepts incoming TCP connections on the server, and dispatches them to a client selected by the router.

TCPRelay implements the Service interface.

func NewTCPRelay

func NewTCPRelay(serverName, listenAddress string, listenerFwmark int, listenerTFO, listenerTransparent, waitForInitialPayload bool, server zerocopy.TCPServer, connCloser zerocopy.TCPConnCloser, fallbackAddress *conn.Addr, router *router.Router, logger *zap.Logger) *TCPRelay

func (*TCPRelay) Start

func (s *TCPRelay) Start() error

Start implements the Service Start method.

func (*TCPRelay) Stop

func (s *TCPRelay) Stop() error

Stop implements the Service Stop method.

func (*TCPRelay) String

func (s *TCPRelay) String() string

String implements the Service String method.

type UDPNATRelay

type UDPNATRelay struct {
	// contains filtered or unexported fields
}

UDPNATRelay is an address-based UDP relay service.

Incoming UDP packets are dispatched to NAT sessions based on the source address and port.

func NewUDPNATRelay

func NewUDPNATRelay(
	batchMode, serverName, listenAddress string,
	relayBatchSize, serverRecvBatchSize, sendChannelCapacity, listenerFwmark, mtu, maxClientFrontHeadroom, maxClientRearHeadroom int,
	natTimeout time.Duration,
	server zerocopy.UDPNATServer,
	router *router.Router,
	logger *zap.Logger,
) *UDPNATRelay

func (*UDPNATRelay) Start

func (s *UDPNATRelay) Start() error

Start implements the Service Start method.

func (*UDPNATRelay) Stop

func (s *UDPNATRelay) Stop() error

Stop implements the Service Stop method.

func (*UDPNATRelay) String

func (s *UDPNATRelay) String() string

String implements the Service String method.

type UDPSessionRelay

type UDPSessionRelay struct {
	// contains filtered or unexported fields
}

UDPSessionRelay is a session-based UDP relay service.

Incoming UDP packets are dispatched to NAT sessions based on the client session ID.

func NewUDPSessionRelay

func NewUDPSessionRelay(
	batchMode, serverName, listenAddress string,
	relayBatchSize, serverRecvBatchSize, sendChannelCapacity, listenerFwmark, mtu, maxClientFrontHeadroom, maxClientRearHeadroom int,
	natTimeout time.Duration,
	server zerocopy.UDPSessionServer,
	router *router.Router,
	logger *zap.Logger,
) *UDPSessionRelay

func (*UDPSessionRelay) Start

func (s *UDPSessionRelay) Start() error

Start implements the Service Start method.

func (*UDPSessionRelay) Stop

func (s *UDPSessionRelay) Stop() error

Stop implements the Service Stop method.

func (*UDPSessionRelay) String

func (s *UDPSessionRelay) String() string

String implements the Service String method.

type UDPTransparentRelay added in v1.4.0

type UDPTransparentRelay struct {
	// contains filtered or unexported fields
}

UDPTransparentRelay is like UDPNATRelay, but for transparent proxy.

func (*UDPTransparentRelay) Start added in v1.4.0

func (s *UDPTransparentRelay) Start() error

Start implements the Relay Start method.

func (*UDPTransparentRelay) Stop added in v1.4.0

func (s *UDPTransparentRelay) Stop() error

Stop implements the Relay Stop method.

func (*UDPTransparentRelay) String added in v1.4.0

func (s *UDPTransparentRelay) String() string

String implements the Relay String method.

Jump to

Keyboard shortcuts

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