server

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendReply

func SendReply(w io.Writer, rep uint8, bindAddr net.Addr) error

Types

type ConnState added in v0.3.2

type ConnState int
const (
	StateNew ConnState = iota
	StateActive
	StateClosed
)

type GPool

type GPool interface {
	Submit(f func()) error
}

type Logger

type Logger interface {
	Infof(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

type Option

type Option func(s *Server)

func WithAssociateHandle

func WithAssociateHandle(h func(ctx context.Context, writer io.Writer, req *handler.Request) error) Option

WithAssociateHandle replaces the default UDP ASSOCIATE handler.

func WithAssociateMiddleware

func WithAssociateMiddleware(m handler.Middleware) Option

WithAssociateMiddleware appends middleware executed before the UDP ASSOCIATE handler.

func WithAuthMethods

func WithAuthMethods(authMethods []auth.Authenticator) Option

WithAuthMethods appends custom authenticators to the method negotiation list.

func WithBaseContext added in v0.3.2

func WithBaseContext(fn func(net.Listener) context.Context) Option

WithBaseContext installs a base context factory that is invoked once per listener. ServeContext derives each connection context from the returned value.

func WithBindAcceptTimeout

func WithBindAcceptTimeout(d time.Duration) Option

WithBindAcceptTimeout sets how long the server waits for the peer during BIND.

func WithBindHandle

func WithBindHandle(h func(ctx context.Context, writer io.Writer, req *handler.Request) error) Option

WithBindHandle replaces the default BIND handler.

func WithBindIP

func WithBindIP(ip net.IP) Option

WithBindIP sets the bind address used for BIND/UDP sockets.

func WithBindMiddleware

func WithBindMiddleware(m handler.Middleware) Option

WithBindMiddleware appends middleware executed before the BIND handler.

func WithBindPeerCheckIPOnly

func WithBindPeerCheckIPOnly(b bool) Option

WithBindPeerCheckIPOnly switches peer validation to IP-only (ignoring port).

func WithBufferPool

func WithBufferPool(pool buffer.BufPool) Option

WithBufferPool sets the buffer pool used by the proxy I/O fast-paths.

func WithConnContext added in v0.3.2

func WithConnContext(fn func(ctx context.Context, conn net.Conn) context.Context) Option

WithConnContext decorates the per-connection context before handlers and dialers run. The provided ctx is derived from ServeContext; return nil to keep the original value.

func WithConnMetadata added in v0.3.2

func WithConnMetadata(fn func(net.Conn) map[string]string) Option

WithConnMetadata installs a callback used to attach static metadata to handler.Request.Metadata. The returned map is shallow-copied per connection.

func WithConnState added in v0.3.2

func WithConnState(fn func(net.Conn, ConnState)) Option

WithConnState registers a hook that receives connection lifecycle transitions (StateNew, StateActive, StateClosed).

func WithConnectHandle

func WithConnectHandle(h func(ctx context.Context, writer io.Writer, req *handler.Request) error) Option

WithConnectHandle replaces the default CONNECT handler.

func WithConnectMiddleware

func WithConnectMiddleware(m handler.Middleware) Option

WithConnectMiddleware appends middleware executed before the CONNECT handler.

func WithConnectionLogging added in v0.4.1

func WithConnectionLogging(enabled bool) Option

WithConnectionLogging enables or disables per-connection accept/close logs.

func WithCredential

func WithCredential(cs auth.CredentialStore) Option

WithCredential provides a credential store used by the default user/pass authenticator.

func WithDial

func WithDial(dial func(ctx context.Context, network, addr string) (net.Conn, error)) Option

WithDial provides a custom dial function invoked for CONNECT/BIND/ASSOCIATE.

func WithDialAndRequest

func WithDialAndRequest(dial func(ctx context.Context, network, addr string, req *handler.Request) (net.Conn, error)) Option

WithDialAndRequest is like WithDial but also exposes the parsed request.

func WithDialer

func WithDialer(d net.Dialer) Option

WithDialer sets a custom net.Dialer for outbound connections when a custom dial is not provided.

func WithGPool

func WithGPool(pool GPool) Option

WithGPool registers a goroutine pool for request handling.

func WithHandshakeTimeout

func WithHandshakeTimeout(d time.Duration) Option

WithHandshakeTimeout sets a deadline for initial negotiation and request parsing. Zero disables the handshake deadline.

func WithLinkQuality added in v0.4.1

func WithLinkQuality(tr *linkquality.Tracker) Option

WithLinkQuality enables link quality tracking for outbound hops.

func WithLogger

func WithLogger(l Logger) Option

WithLogger replaces the server logger implementation.

func WithResolver

func WithResolver(res resolver.NameResolver) Option

WithResolver overrides the DNS resolver used for FQDN targets.

func WithRewriter

func WithRewriter(rew handler.AddressRewriter) Option

WithRewriter installs an address rewriter that can mutate the destination before dialing.

func WithRule

func WithRule(rule rules.RuleSet) Option

WithRule sets the ACL evaluated before dialing the upstream target.

func WithTCPKeepAlive

func WithTCPKeepAlive(period time.Duration) Option

WithTCPKeepAlive enables TCP keepalives on accepted connections with the given period. Zero disables keepalives.

func WithUDPAssociateLimits

func WithUDPAssociateLimits(maxPeers int, idleTimeout time.Duration) Option

WithUDPAssociateLimits configures UDP ASSOCIATE peer limits and idle cleanup. If maxPeers <= 0, unlimited peers are allowed. If idleTimeout <= 0, peers are not GC'd by idle.

func WithUseBindIpBaseResolveAsUdpAddr

func WithUseBindIpBaseResolveAsUdpAddr(b bool) Option

WithUseBindIpBaseResolveAsUdpAddr forces UDP ASSOCIATE replies to advertise the bind IP.

type Server

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

func New

func New(opts ...Option) *Server

func (*Server) LinkQualityTracker added in v0.4.1

func (sf *Server) LinkQualityTracker() *linkquality.Tracker

LinkQualityTracker returns the tracker used for outbound hops, if enabled.

func (*Server) ListenAndServe

func (sf *Server) ListenAndServe(network, addr string) error

func (*Server) ListenAndServeTLS

func (sf *Server) ListenAndServeTLS(network, addr string, c *tls.Config) error

func (*Server) Proxy

func (sf *Server) Proxy(dst io.Writer, src io.Reader) error

Proxy copies data from src to dst. It prefers optimized io.Copy paths (ReaderFrom/WriterTo) and uses the shared buffer pool for the generic copy case to avoid per-call allocations.

func (*Server) Serve

func (sf *Server) Serve(l net.Listener) error

func (*Server) ServeConn

func (sf *Server) ServeConn(conn net.Conn) error

func (*Server) ServeConnContext added in v0.3.2

func (sf *Server) ServeConnContext(ctx context.Context, conn net.Conn) error

ServeConnContext is like ServeConn but binds the provided context to the connection lifecycle.

func (*Server) ServeContext added in v0.3.2

func (sf *Server) ServeContext(ctx context.Context, l net.Listener) error

ServeContext serves SOCKS5 on l until ctx is done or an unrecoverable error occurs.

type Std

type Std struct {
	*log.Logger
}

func NewLogger

func NewLogger(l *log.Logger) *Std

func (Std) Errorf

func (sf Std) Errorf(format string, args ...interface{})

func (Std) Infof added in v0.4.1

func (sf Std) Infof(format string, args ...interface{})

Jump to

Keyboard shortcuts

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