service

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: AGPL-3.0 Imports: 19 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"`
	// 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, preferIPv6 bool) (zerocopy.UDPClient, error)

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.

Both TCPRelay and UDPRelay implement this interface.

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"`

	// 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"`
	// 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, preferIPv6 bool, batchMode string, batchSize, maxClientFrontHeadroom, maxClientRearHeadroom int) (Relay, error)

UDPRelay creates a UDP relay service from the ServerConfig.

type ServiceConfig

type ServiceConfig struct {
	Servers       []ServerConfig       `json:"servers"`
	Clients       []ClientConfig       `json:"clients"`
	DNS           []dns.ResolverConfig `json:"dns"`
	Router        router.RouterConfig  `json:"router"`
	UDPBatchMode  string               `json:"udpBatchMode"`
	UDPBatchSize  int                  `json:"udpBatchSize"`
	UDPPreferIPv6 bool                 `json:"udpPreferIPv6"`
	// contains filtered or unexported fields
}

ServiceConfig is the main configuration structure. It may be marshaled as or unmarshaled from JSON. Call the Start method to start all configured services. Call the Stop method to properly close all running services.

func (*ServiceConfig) Start

func (sc *ServiceConfig) Start(logger *zap.Logger) error

Start starts all configured services.

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

func (*ServiceConfig) Stop

func (sc *ServiceConfig) Stop()

Stop stops all running services.

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, waitForInitialPayload bool, server zerocopy.TCPServer, connCloser zerocopy.TCPConnCloser, 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,
	batchSize, listenerFwmark, mtu, maxClientFrontHeadroom, maxClientRearHeadroom int,
	preferIPv6 bool,
	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,
	batchSize, listenerFwmark, mtu, maxClientFrontHeadroom, maxClientRearHeadroom int,
	preferIPv6 bool,
	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.

Jump to

Keyboard shortcuts

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