Documentation ¶
Overview ¶
Package service consists of encapsulations that utilize packet handlers to provide swgp service over a connection or other abstractions.
Index ¶
Constants ¶
const ( IPv4HeaderLength = 20 IPv6HeaderLength = 40 UDPHeaderLength = 8 WireGuardDataPacketOverhead = 32 // WireGuard pads data packets so the length is always a multiple of 16. WireGuardDataPacketLengthMask = 0xFFF0 )
Used to calculate max packet size from MTU.
const RejectAfterTime = 180 * time.Second
We use WireGuard's RejectAfterTime as NAT timeout.
Variables ¶
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"` WgListenNetwork string `json:"wgListenNetwork"` WgListenAddress string `json:"wgListen"` WgFwmark int `json:"wgFwmark"` WgTrafficClass int `json:"wgTrafficClass"` ProxyEndpointNetwork string `json:"proxyEndpointNetwork"` ProxyEndpointAddress conn.Addr `json:"proxyEndpoint"` ProxyConnListenNetwork string `json:"proxyConnListenNetwork"` ProxyConnListenAddress string `json:"proxyConnListenAddress"` ProxyMode string `json:"proxyMode"` ProxyPSK []byte `json:"proxyPSK"` ProxyFwmark int `json:"proxyFwmark"` ProxyTrafficClass int `json:"proxyTrafficClass"` MTU int `json:"mtu"` PerfConfig }
ClientConfig stores configurations for a swgp client service. It may be marshaled as or unmarshaled from JSON.
func (*ClientConfig) Client ¶ added in v1.3.0
func (cc *ClientConfig) Client(logger *zap.Logger, listenConfigCache conn.ListenConfigCache) (*client, error)
Client creates a swgp client service from the client config. Call the Start method on the returned service to start it.
type Config ¶ added in v1.2.3
type Config struct { Servers []ServerConfig `json:"servers"` Clients []ClientConfig `json:"clients"` Pprof pprof.PprofConfig `json:"pprof"` }
Config stores configurations for a typical swgp service. It may be marshaled as or unmarshaled from JSON.
type Manager ¶ added in v1.3.0
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the services.
type PerfConfig ¶ added in v1.4.0
type PerfConfig struct { // BatchMode controls the mode of batch receiving and sending. // // Available values: // - "": Platform default. // - "no": Do not receive or send packets in batches. // - "sendmmsg": Use recvmmsg(2) and sendmmsg(2) calls. This is the default on Linux and NetBSD. BatchMode string `json:"batchMode"` // RelayBatchSize is the batch size of recvmmsg(2) and sendmmsg(2) calls in relay sessions. RelayBatchSize int `json:"relayBatchSize"` // MainRecvBatchSize is the batch size of a relay service's main receive routine. MainRecvBatchSize int `json:"mainRecvBatchSize"` // SendChannelCapacity is the capacity of a relay session's uplink send channel. SendChannelCapacity int `json:"sendChannelCapacity"` }
PerfConfig exposes performance tuning knobs.
func (*PerfConfig) CheckAndApplyDefaults ¶ added in v1.4.0
func (pc *PerfConfig) CheckAndApplyDefaults() error
CheckAndApplyDefaults checks and applies default values to the configuration.
type ServerConfig ¶
type ServerConfig struct { Name string `json:"name"` ProxyListenNetwork string `json:"proxyListenNetwork"` ProxyListenAddress string `json:"proxyListen"` ProxyMode string `json:"proxyMode"` ProxyPSK []byte `json:"proxyPSK"` ProxyFwmark int `json:"proxyFwmark"` ProxyTrafficClass int `json:"proxyTrafficClass"` WgEndpointNetwork string `json:"wgEndpointNetwork"` WgEndpointAddress conn.Addr `json:"wgEndpoint"` WgConnListenNetwork string `json:"wgConnListenNetwork"` WgConnListenAddress string `json:"wgConnListenAddress"` WgFwmark int `json:"wgFwmark"` WgTrafficClass int `json:"wgTrafficClass"` MTU int `json:"mtu"` PerfConfig }
ServerConfig stores configurations for a swgp server service. It may be marshaled as or unmarshaled from JSON.
func (*ServerConfig) Server ¶ added in v1.3.0
func (sc *ServerConfig) Server(logger *zap.Logger, listenConfigCache conn.ListenConfigCache) (*server, error)
Server creates a swgp server service from the server config. Call the Start method on the returned service to start it.
type Service ¶
type Service interface { // String returns the service's name. String() string // Start starts the service. Start(ctx context.Context) error // Stop stops the service. Stop() error }
Service is implemented by encapsulations that utilize packet handlers to provide swgp service over a connection or other abstractions.