Documentation
¶
Index ¶
Constants ¶
const ( Version4 = 0x04 Version5 = 0x05 AddrTypeIPv4 = 0x01 AddrTypeFQDN = 0x03 AddrTypeIPv6 = 0x04 CmdUnset Command = 0x00 CmdConnect Command = 0x01 // establishes an active-open forward proxy connection AuthMethodNotRequired AuthMethod = 0x00 // no authentication required AuthMethodUsernamePassword AuthMethod = 0x02 // use username/password AuthMethodNoAcceptableMethods AuthMethod = 0xff // no acceptable authentication methods StatusSucceeded Reply = 0x00 StatusFailed Reply = 0x01 StatusNetworkUnreachable Reply = 0x03 AuthUsernamePasswordVersion = 0x01 )
Variables ¶
var ( ErrWrongProtocol error = errors.New("wrong protocol") ErrAuthFailed error = errors.New("auth failed") ErrAuthMethodNotSupported error = errors.New("auth method not supported") ErrCmdNotSupported error = errors.New("cmd not supported") ErrWrongFormat error = errors.New("wrong format") ErrBadRequest error = errors.New("bad request") ErrUnknownAddressType error = errors.New("unknown address type") ErrFQDNTooLong error = errors.New("FQDN too long") )
Functions ¶
This section is empty.
Types ¶
type AuthMethod ¶ added in v0.3.2
type AuthMethod byte
An AuthMethod represents a SOCKS authentication method.
type Client ¶ added in v0.2.0
type Client struct {
Cmd Command // either CmdConnect or cmdBind
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
}
A Client holds SOCKS-specific options.
func (*Client) DialContext ¶ added in v0.2.0
DialContext connects to the provided address on the provided network.
The returned error value may be a net.OpError. When the Op field of net.OpError contains "socks", the Source field contains a proxy server address and the Addr field contains a command target address.
See func Dial of the net package of standard library for a description of the network and address parameters.
func (*Client) DialWithConn ¶ added in v0.3.2
func (d *Client) DialWithConn(ctx context.Context, c net.Conn, network, address string) (net.Addr, error)
DialWithConn initiates a connection from SOCKS server to the target network and address using the connection c that is already connected to the SOCKS server.
It returns the connection's local address assigned by the SOCKS server.
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.