socks5

package module
v0.0.0-...-4b25866 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 9 Imported by: 0

README

Documentation Go workflow CircleCI codecov Go Report Card GitHub tag (latest SemVer)

socks5

This is a library designed for performant multiproxy implementations. This means

  • Efficient code
  • Low-level API
  • Stateless objects
  • Both client and server is implemented

Benchmarks

Generated on Apple Air M1

goos: darwin
goarch: arm64
pkg: github.com/nikandfor/socks5
BenchmarkServerHandshake-8   	24888297	        48.11 ns/op	       8 B/op	       1 allocs/op
BenchmarkClientHandshake-8   	39229520	        29.58 ns/op	       8 B/op	       1 allocs/op
BenchmarkWriteRequest-8      	23223670	        51.34 ns/op	      24 B/op	       1 allocs/op
BenchmarkReadRequestName-8   	12071508	       100.1 ns/op	      56 B/op	       3 allocs/op
BenchmarkReadRequestIP16-8   	13279104	        90.60 ns/op	      88 B/op	       3 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedProtocol    = errors.New("unsupported protocol")
	ErrUnsupportedCommand     = errors.New("unsupported command")
	ErrUnsupportedAddressType = errors.New("unsupported address type")
	ErrNoAcceptableAuth       = errors.New("no acceptable auth method")
)

Errors

Functions

func EncodePacketHeader

func EncodePacketHeader(buf []byte, dst int, addr net.Addr) (int, error)

func ParsePacketHeader

func ParsePacketHeader(p []byte) (net.Addr, int, error)

Types

type AuthMethod

type AuthMethod uint8
const (
	AuthNone AuthMethod = iota
	AuthGSSAPI
	AuthUserPass
	AuthChallengeHandshake

	AuthChallengeResponse
	AuthSSL
	AuthNDS
	AuthMultiAuthFramework
	AuthJSON
	AuthN

	AuthNoAcceptable AuthMethod = 0xff
)

Auth Methods

func (AuthMethod) String

func (m AuthMethod) String() string

type Auther

type Auther interface {
	Auth(ctx context.Context, meth AuthMethod, c net.Conn) error
}

type AutherFunc

type AutherFunc func(ctx context.Context, meth AuthMethod, c net.Conn) error

func (AutherFunc) Auth

func (f AutherFunc) Auth(ctx context.Context, meth AuthMethod, c net.Conn) error

type Command

type Command uint8

Command is request command or reply code.

const (
	CommandTCPConn  Command = 0x01
	CommandTCPBind  Command = 0x02
	CommandUDPAssoc Command = 0x03
)

Commands

func (Command) String

func (c Command) String() string

type Dialer

type Dialer struct {
	Dialer interface {
		DialContext(ctx context.Context, nw, addr string) (net.Conn, error)
	}

	Proxy string

	AuthMethods []AuthMethod // in order of preference
	Auther      Auther
}

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, nw, addr string) (_ net.Conn, err error)

type DialerFunc

type DialerFunc func(ctx context.Context, nw, addr string) (net.Conn, error)

func (DialerFunc) DialContext

func (f DialerFunc) DialContext(ctx context.Context, nw, addr string) (net.Conn, error)

type Proto

type Proto struct{}

func (Proto) ClientHandshake

func (p Proto) ClientHandshake(c net.Conn, methods ...AuthMethod) (auth AuthMethod, err error)

func (Proto) ClientHandshakeRead

func (p Proto) ClientHandshakeRead(c net.Conn) (auth AuthMethod, err error)

func (Proto) ClientHandshakeWrite

func (p Proto) ClientHandshakeWrite(c net.Conn, methods ...AuthMethod) error

func (Proto) ReadReply

func (p Proto) ReadReply(c net.Conn, cmd Command) (Reply, net.Addr, error)

func (Proto) ReadRequest

func (p Proto) ReadRequest(c net.Conn) (Command, net.Addr, error)

func (Proto) ServerHandshake

func (p Proto) ServerHandshake(c net.Conn, methods ...AuthMethod) (auth AuthMethod, err error)

func (Proto) ServerHandshakeRead

func (p Proto) ServerHandshakeRead(c net.Conn, methods ...AuthMethod) (auth AuthMethod, err error)

func (Proto) ServerHandshakeWrite

func (p Proto) ServerHandshakeWrite(c net.Conn, auth AuthMethod) (err error)

func (Proto) WriteReply

func (p Proto) WriteReply(c net.Conn, rep Reply, addr net.Addr) (err error)

func (Proto) WriteRequest

func (p Proto) WriteRequest(c net.Conn, cmd Command, addr net.Addr) (err error)

type Reply

type Reply Command
const (
	ReplySuccess Reply = iota
	ReplyGeneralFailure
	ReplyNotAllowed
	ReplyNetworkUnreachable
	ReplyHostUnreachable
	ReplyConnRefused
	ReplyTTLExpired
	ReplyCommandNotSupported
	ReplyAddressTypeNotSupported
)

Reply Codes

func (Reply) Error

func (r Reply) Error() string

func (Reply) String

func (r Reply) String() string

type TCPAddr

type TCPAddr string

TCPAddr is a string address.

func (TCPAddr) Network

func (a TCPAddr) Network() string

func (TCPAddr) String

func (a TCPAddr) String() string

type UDPAddr

type UDPAddr string

UDPAddr is a string address.

func (UDPAddr) Network

func (a UDPAddr) Network() string

func (UDPAddr) String

func (a UDPAddr) String() string

type UDPConn

type UDPConn struct {
	// contains filtered or unexported fields
}

func (UDPConn) Close

func (c UDPConn) Close() (err error)

func (UDPConn) LocalAddr

func (c UDPConn) LocalAddr() net.Addr

func (UDPConn) Read

func (c UDPConn) Read(p []byte) (n int, err error)

func (UDPConn) ReadFrom

func (c UDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)

func (UDPConn) RemoteAddr

func (c UDPConn) RemoteAddr() net.Addr

func (UDPConn) SetDeadline

func (c UDPConn) SetDeadline(t time.Time) error

func (UDPConn) SetReadDeadline

func (c UDPConn) SetReadDeadline(t time.Time) error

func (UDPConn) SetWriteDeadline

func (c UDPConn) SetWriteDeadline(t time.Time) error

func (UDPConn) Write

func (c UDPConn) Write(p []byte) (n int, err error)

func (UDPConn) WriteTo

func (c UDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error)

type UserPassAuth

type UserPassAuth struct{}

func (UserPassAuth) ReadReply

func (a UserPassAuth) ReadReply(c net.Conn) (status int, err error)

func (UserPassAuth) ReadRequest

func (a UserPassAuth) ReadRequest(c net.Conn) (usr, pwd string, err error)

func (UserPassAuth) StatusFailure

func (UserPassAuth) StatusFailure() int

func (UserPassAuth) StatusSuccess

func (UserPassAuth) StatusSuccess() int

func (UserPassAuth) WriteReply

func (a UserPassAuth) WriteReply(c net.Conn, status int) (err error)

func (UserPassAuth) WriteRequest

func (a UserPassAuth) WriteRequest(c net.Conn, usr, pwd string) (err error)

Jump to

Keyboard shortcuts

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