server

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UDPTimeout is how long before we stop listening on UDP sockets opened in support of an ASSOCIATE command.
	UDPTimeout = time.Second * 10

	// ListenerTimeout is how long to keep a BIND socket open after the client is done with it.
	ListenerTimeout = time.Second * 1
)

Functions

This section is empty.

Types

type Authenticator added in v0.0.4

type Authenticator interface {
	// Socks5Authenticate provide authentication of users. Return socks5.ErrAuthMethodNotSupported if the method is
	// not supported by the authenticator. For non-anonymous methods, the returned username must not be the
	// empty string.
	Socks5Authenticate(rw io.ReadWriter, am socks5.AuthMethod, address string) (username string, err error)
}

Authenticator provide authentication of users.

type CredentialsValidator added in v0.0.18

type CredentialsValidator interface {
	ValidateCredentials(username, password, address string) bool
}

CredentialsValidator is used to support user/pass authentication optional network address filtering.

type DialerSelector added in v0.0.5

type DialerSelector interface {
	// SelectDialer returns the ContextDialer to use.
	//
	// When called, client has already logged in. If username is the empty string, AuthMethodNone was used.
	// In case of error, it is recommended to return one of the socks5.ErrReply... errors,
	// as those will be mapped to SOCKS5 error codes in the reply to the client.
	SelectDialer(username, network, address string) (cd socks5.ContextDialer, err error)
}

A socks5.DialerSelector returns the ContextDialer to use.

type NoAuthAuthenticator added in v0.0.4

type NoAuthAuthenticator struct{}

NoAuthAuthenticator is used to handle the "No Authentication" mode

func (NoAuthAuthenticator) Socks5Authenticate added in v0.0.9

func (a NoAuthAuthenticator) Socks5Authenticate(rw io.ReadWriter, am socks5.AuthMethod, _ string) (username string, err error)

type Request

type Request struct {
	Addr socks5.Addr
	Cmd  socks5.CommandType
}

Request is the request packet

func ReadRequest

func ReadRequest(r io.Reader) (req *Request, err error)

ReadRequest read request packet from client

type Response

type Response struct {
	Addr  socks5.Addr
	Reply socks5.ReplyCode
}

Response contains the contents of a Response packet sent from the proxy to the client.

func (*Response) MarshalBinary

func (res *Response) MarshalBinary() (pkt []byte, err error)

MarshalBinary converts a Response struct into a packet.

type Server

type Server struct {
	// List of authentication providers. If nil, uses NoAuthAuthenticator.
	// Order matters; they are tried in the given order.
	Authenticators []Authenticator

	// DialerSelector is called to get the ContextDialer to use for an outgoing connection.
	// If nil, socks5.DefaultDialer will be used, which if not changed is a net.Dialer.
	DialerSelector

	Logger socks5.Logger // If not nil, use this Logger (compatible with log/slog)
	Debug  bool          // If true, output debug logging using Logger.Info
	// contains filtered or unexported fields
}

Server is a SOCKS5 proxy server.

func (*Server) LogDebug

func (s *Server) LogDebug(msg string, keyvaluepairs ...any) bool

func (*Server) LogError

func (s *Server) LogError(msg string, keyvaluepairs ...any)

func (*Server) LogInfo

func (s *Server) LogInfo(msg string, keyvaluepairs ...any)

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, l net.Listener) (err error)

Serve accepts and handles incoming connections on the given listener.

func (*Server) Serving added in v0.0.11

func (s *Server) Serving() (n int)

Serving returns the number of active calls to Serve()

type StaticCredentials added in v0.0.4

type StaticCredentials map[string]string

StaticCredentials enables using a map directly as a credential store

func (StaticCredentials) ValidateCredentials added in v0.0.18

func (s StaticCredentials) ValidateCredentials(username, password, _ string) bool

type UserPassAuthenticator added in v0.0.4

type UserPassAuthenticator struct {
	Credentials CredentialsValidator
}

UserPassAuthenticator is used to handle username/password based authentication.

func (UserPassAuthenticator) Socks5Authenticate added in v0.0.9

func (a UserPassAuthenticator) Socks5Authenticate(rw io.ReadWriter, am socks5.AuthMethod, address string) (username string, err error)

Jump to

Keyboard shortcuts

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