socket

package
v0.0.0-...-e082079 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Socks4Version = 4
	Socks5Version = 5
	MethodNoAuth  = 0
	CmdConnect    = 1
)

Variables

View Source
var (
	ERR_VERSION      = errors.New("unknown socks version")
	ERR_METHOD       = errors.New("unsupported method")
	ERR_CMD          = errors.New("unsupported command")
	ERR_READ_FAILED  = errors.New("read failed")
	ERR_ADDRESS_TYPE = errors.New("unsupported address type")
	ERR_AUTH_FAILED  = errors.New("auth failed")
)
View Source
var ErrServerClosed = errors.New("socket: Server closed")

Functions

func AllowedIPSubnet

func AllowedIPSubnet(subnet string) func(net.Listener) *Filter

func NewNeverStopBackOff

func NewNeverStopBackOff() *backoff.ExponentialBackOff

Types

type Address

type Address struct {
	NetworkType string
	DomainName  string
	net.IP
	Port int
	AddressType
}

func NewAddressFromAddr

func NewAddressFromAddr(network string, addr string) (*Address, error)

func NewAddressFromHostPort

func NewAddressFromHostPort(network string, host string, port int) *Address

func (*Address) From

func (a *Address) From(r io.Reader) (err error)

func (*Address) Network

func (a *Address) Network() string

func (*Address) ResolveIP

func (a *Address) ResolveIP() (net.IP, error)

func (*Address) String

func (a *Address) String() string

func (*Address) To

func (a *Address) To(w io.Writer) (err error)

type AddressType

type AddressType byte
const (
	IPv4       AddressType = 1
	DomainName AddressType = 3
	IPv6       AddressType = 4
)

type Context

type Context struct {
	net.Conn        // by conn
	context.Context // by Serve
}

type Filter

type Filter struct {
	Listener net.Listener
	Filter   func(net.Conn) bool
}

func (*Filter) Accept

func (i *Filter) Accept() (conn net.Conn, err error)

func (*Filter) Addr

func (i *Filter) Addr() net.Addr

func (*Filter) Close

func (i *Filter) Close() error

type Handler

type Handler func(*Context) //close socket when return

func NewForwardHandler

func NewForwardHandler(open func(socket *Context) (net.Conn, error)) Handler

type Proxy

type Proxy struct {
	Dial    func(ctx context.Context, network, addr string) (net.Conn, error)
	Timeout time.Duration
}

func (Proxy) Socks5Connect

func (proxy Proxy) Socks5Connect(socket *Context)

Socks5Connect only support socks5 NoAuth and only CONNECT command

type Server

type Server struct {
	BaseContext  func(net.Listener) context.Context
	ErrorHandler func(*Context, ...interface{})
	// contains filtered or unexported fields
}

func (*Server) Close

func (server *Server) Close() (err error)

func (*Server) Serve

func (server *Server) Serve(listener net.Listener, handler Handler) (err error)

func (*Server) Shutdown

func (server *Server) Shutdown(ctx context.Context) (err error)

Jump to

Keyboard shortcuts

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