handler

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package handler defines the request type flowing through the SOCKS5 server, the per-command Handler/Middleware extension points, and the AddressRewriter hook for mutating destinations before dialing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressRewriter

type AddressRewriter interface {
	Rewrite(ctx context.Context, request *Request) (context.Context, *protocol.AddrSpec)
}

AddressRewriter mutates the destination of a request before rules run and the target is dialed. Returning a nil AddrSpec keeps the current destination; the returned context replaces the request context when non-nil.

type Handler

type Handler func(ctx context.Context, writer io.Writer, req *Request) error

Handler processes one SOCKS5 command (CONNECT, BIND or UDP ASSOCIATE). writer is the client control connection; the handler is responsible for sending the SOCKS reply and relaying traffic.

type Middleware

type Middleware func(ctx context.Context, writer io.Writer, req *Request) error

Middleware runs before the command handler. Returning a non-nil error aborts the request without invoking the handler.

type MiddlewareChain

type MiddlewareChain []Middleware

MiddlewareChain is an ordered list of Middleware executed front to back.

func (MiddlewareChain) Execute

func (m MiddlewareChain) Execute(ctx context.Context, writer io.Writer, req *Request, last Handler) error

Execute runs every middleware in order and, if none failed, the final handler.

type Request

type Request struct {
	protocol.Request
	Context     context.Context
	Metadata    map[string]string
	AuthContext *auth.AContext
	LocalAddr   net.Addr
	RemoteAddr  net.Addr
	DestAddr    *protocol.AddrSpec
	Reader      io.Reader
	RawDestAddr *protocol.AddrSpec
}

Request is a parsed SOCKS5 command request enriched with connection state. RawDestAddr is the destination exactly as sent by the client; DestAddr is the effective destination after resolution and rewriting. Reader wraps the client connection and must not be retained after the request completes.

func ParseRequest

func ParseRequest(bufConn io.Reader) (*Request, error)

ParseRequest reads a SOCKS5 command request from the client connection.

Jump to

Keyboard shortcuts

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