socks4

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MIT Imports: 14 Imported by: 3

README

Socks4

Socks4/Socks4a server and client

Build Go Report Card GoDoc GitHub license gocover.io

This project is to add protocol support for the Bridge, or it can be used alone

The following is the implementation of other proxy protocols

Usage

API Documentation

Example

  • Support for the CONNECT command
  • Support for the BIND command

License

Licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddrAnfUser

type AddrAnfUser struct {
	Username string
	// contains filtered or unexported fields
}

func (AddrAnfUser) Address added in v0.2.2

func (a AddrAnfUser) Address() string

Address returns a string suitable to dial; prefer returning IP-based address, fallback to Name

func (*AddrAnfUser) Network added in v0.2.2

func (a *AddrAnfUser) Network() string

func (*AddrAnfUser) String added in v0.2.2

func (a *AddrAnfUser) String() string

type Authentication

type Authentication interface {
	Auth(cmd Command, username string) bool
}

Authentication proxy authentication

func UserAuth

func UserAuth(username string) Authentication

UserAuth basic authentication

type AuthenticationFunc

type AuthenticationFunc func(cmd Command, username string) bool

AuthenticationFunc Authentication interface is implemented

func (AuthenticationFunc) Auth

func (f AuthenticationFunc) Auth(cmd Command, username string) bool

Auth authentication processing

type BytesPool added in v0.2.2

type BytesPool interface {
	Get() []byte
	Put([]byte)
}

BytesPool is an interface for getting and returning temporary bytes for use by io.CopyBuffer.

type Command added in v0.2.1

type Command byte

Command is a SOCKS Command.

const (
	ConnectCommand Command = 0x01
	BindCommand    Command = 0x02
)

func (Command) String added in v0.2.1

func (cmd Command) String() string

type Dialer

type Dialer struct {
	// ProxyNetwork network between a proxy server and a client
	ProxyNetwork string
	// ProxyAddress proxy server address
	ProxyAddress string
	// ProxyDial specifies the optional dial function for
	// establishing the transport connection.
	ProxyDial func(ctx context.Context, network string, address string) (net.Conn, error)
	// Username use username authentication if not empty
	Username string
	// IsResolve resolve domain name on locally
	IsResolve bool
	// Resolver optionally specifies an alternate resolver to use
	Resolver *net.Resolver
	// Timeout is the maximum amount of time a dial will wait for
	// a connect to complete. The default is no timeout
	Timeout time.Duration
}

Dialer is a SOCKS4 dialer.

func NewDialer

func NewDialer(addr string) (*Dialer, error)

NewDialer returns a new Dialer that dials through the provided proxy server's network and address.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial connects to the provided address on the provided network.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects to the provided address on the provided network.

func (*Dialer) Listen added in v0.2.1

func (d *Dialer) Listen(ctx context.Context, network, address string) (net.Listener, error)

type Logger added in v0.3.0

type Logger interface {
	Println(v ...interface{})
}

type Server

type Server struct {
	// Authentication is proxy authentication
	Authentication Authentication
	// ProxyDial specifies the optional proxyDial function for
	// establishing the transport connection.
	ProxyDial func(ctx context.Context, network string, address string) (net.Conn, error)
	// Logger error log
	Logger Logger
	// Context is default context
	Context context.Context
	// BytesPool getting and returning temporary bytes for use by io.CopyBuffer
	BytesPool BytesPool
}

Server is accepting connections and handling the details of the SOCKS4 protocol

func NewServer

func NewServer() *Server

NewServer creates a new Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(network, addr string) error

ListenAndServe is used to create a listener and serve on it

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve is used to serve connections from a listener

func (*Server) ServeConn

func (s *Server) ServeConn(conn net.Conn)

ServeConn is used to serve a single connection.

type SimpleServer added in v0.2.3

type SimpleServer struct {
	Server
	Listener net.Listener
	Network  string
	Address  string
	Username string
}

SimpleServer is a simplified server, which can be configured as easily as client.

func NewSimpleServer added in v0.2.3

func NewSimpleServer(addr string) (*SimpleServer, error)

NewServer creates a new NewSimpleServer

func (*SimpleServer) Close added in v0.2.3

func (s *SimpleServer) Close() error

Close closes the listener

func (*SimpleServer) ProxyURL added in v0.2.3

func (s *SimpleServer) ProxyURL() string

ProxyURL returns the URL of the proxy

func (*SimpleServer) Run added in v0.2.3

func (s *SimpleServer) Run(ctx context.Context) error

Run the server

func (*SimpleServer) Start added in v0.2.3

func (s *SimpleServer) Start(ctx context.Context) error

Start the server

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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