Documentation
¶
Index ¶
Constants ¶
View Source
const ( Version4 = 0x04 Version5 = 0x05 AddrTypeIPv4 = 0x01 AddrTypeFQDN = 0x03 AddrTypeIPv6 = 0x04 CmdConnect byte = 0x01 // establishes an active-open forward proxy connection AuthMethodNotRequired byte = 0x00 // no authentication required AuthMethodUsernamePassword byte = 0x02 // use username/password AuthMethodNoAcceptableMethods byte = 0xff // no acceptable authentication methods StatusSucceeded byte = 0x00 StatusFailed byte = 0x01 StatusNetworkUnreachable byte = 0x03 )
Variables ¶
View Source
var ErrAuthFailed error = fmt.Errorf("auth failed")
View Source
var ErrAuthMethodNotSupported error = fmt.Errorf("auth method not supported")
View Source
var ErrBadRequest error = fmt.Errorf("bad request")
View Source
var ErrCmdNotSupported error = fmt.Errorf("cmd not supported")
View Source
var ErrWrongFormat error = fmt.Errorf("wrong format")
View Source
var ErrWrongProtocol error = fmt.Errorf("wrong protocol")
Functions ¶
Types ¶
type Client ¶ added in v0.2.0
type Client struct {
ProxyUrl *url.URL
// Dialer specifies an optional dial function with context for
// creating connections for requests.
//
// If Dialer is nil, &net.Dialer{} is used.
Dialer koNet.ContextDialer
}
type Server ¶
type Server struct {
// Dialer specifies an optional ContextDialer.
// If non-nil, it will be used on outbound.
Dialer koNet.ContextDialer
// Logger specifies an optional logger for errors.
// If nil, log nothing.
Logger *slog.Logger
// AuthContext handles user authentication for a proxy.
//
// It returns a boolean indicating whether the provided username and password are
// valid. If true, a non-nil Context must also be returned, which will be used
// for dialing. The original context is passed in via the 'ctx' parameter.
//
// Authentication is optional. SOCKS4(a) connections are supported only when
// both AuthContext and AuthHandler are nil. If AuthContext is set, it takes
// precedence over AuthHandler, and SOCKS4(a) connections are not supported.
AuthContext func(ctx context.Context, username, password string) (bool, context.Context)
// AuthHandler authenticates a user based on the provided username and password,
// returning true on success. This handler is only used if AuthContext is nil.
AuthHandler func(username, password string) bool
// ConnContext optionally specifies a function that modifies
// the context used for a new connection c. The provided ctx
// is derived from the base context and has a ServerContextKey
// value.
ConnContext func(ctx context.Context, c net.Conn, req *Request) context.Context
// Context is used to shut down the server.
// If not nil, the server will be shut down when the context is done.
Context context.Context
}
A Server defines parameters for running an SOCKS4/SOCKS5 server. The zero value for Server is a valid configuration.
Click to show internal directories.
Click to hide internal directories.