Documentation ¶
Overview ¶
Package socks provides SOCKS server framework.
Features: * SOCKS4, SOCS4a, SOCKS5 protocols. * Username/password authentication. * CONNECT command (BIND and UDP ASSOCIATE is not supported). * Graceful stop (thanks to github.com/cybozu-go/well package).
Index ¶
Constants ¶
const ( SOCKS4 = version(0x04) SOCKS5 = version(0x05) )
SOCKS versions.
const ( CmdConnect = commandType(0x01) CmdBind = commandType(0x02) CmdUDP = commandType(0x03) )
SOCKS commands.
const ( AddrIPv4 = addressType(0x01) AddrDomain = addressType(0x03) AddrIPv6 = addressType(0x04) )
SOCKS address types.
const ( AuthNo = authType(0x00) AuthGSSAPI = authType(0x01) AuthBasic = authType(0x02) )
SOCKS authentication types.
const ( Status4Granted = socks4ResponseStatus(0x5a) Status4Rejected = socks4ResponseStatus(0x5b) Status4NoIdentd = socks4ResponseStatus(0x5c) Status4InvalidUser = socks4ResponseStatus(0x5d) )
SOCKS4 response status codes.
const ( Status5Granted = socks5ResponseStatus(0x00) Status5Failure = socks5ResponseStatus(0x01) Status5DeniedByRuleset = socks5ResponseStatus(0x02) Status5NetworkUnreachable = socks5ResponseStatus(0x03) Status5HostUnreachable = socks5ResponseStatus(0x04) Status5ConnectionRefused = socks5ResponseStatus(0x05) Status5TTLExpired = socks5ResponseStatus(0x06) Status5CommandNotSupported = socks5ResponseStatus(0x07) Status5AddressNotSupported = socks5ResponseStatus(0x08) )
SOCKS5 response status codes.
const UNKNOWN = "unknown"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
Authenticator is the interface for user authentication. It should look Username and Password field in the request and returns true if authentication succeeds.
Note that both Username and Password may be empty.
type Request ¶
type Request struct { // Version is either SOCKS4 or SOCKS5 Version version // Hostname is the destination DNS hostname. // If this is empty, IP is set to the destination address. Hostname string // Command is the requested command. Command commandType // IP is the destination IP address. // This may not be set if Hostname is not empty. IP net.IP // Port is the destination port number. Port int // Username is user name string for authentication. // Username may be empty when no authencation is requested. Username string // Password is password string for authentication. Password string // Conn is the connection from the client. Conn net.Conn // contains filtered or unexported fields }
Request is a struct to represent a request from SOCKS client.
Authenticator, RuleSet, and Dialer can use Context and SetContext to associate any value with the request, and to cancel lengthy operations.
func (*Request) SetContext ¶
SetContext sets the request context.
type RuleSet ¶
RuleSet is the interface for access control. It should look the request properties and returns true if the request matches rules.
type Server ¶
type Server struct { // Auth can be used to authenticate a request. // If nil, all requests are allowed. Auth Authenticator // Rules can be used to test a request if it matches rules. // If nil, all requests passes. Rules RuleSet // Dialer is used to make connections to destination servers. // If nil, net.DialContext is used. Dialer Dialer // Logger can be used to provide a custom logger. // If nil, the default logger is used. Logger *log.Logger // ShutdownTimeout is the maximum duration the server waits for // all connections to be closed before shutdown. // // Zero duration disables timeout. ShutdownTimeout time.Duration // Env is the environment where this server runs. // // The global environment is used if Env is nil. Env *well.Environment // SilenceLogs changes Info-level logs to Debug-level ones. SilenceLogs bool // contains filtered or unexported fields }
Server implement SOCKS protocol.