socks5

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 10 Imported by: 1

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

Example

There is a cmd/socks5/main.go which can be treated as an example. It can also be used as a command.

go install nikand.dev/go/socks5/cmd/socks5@latest # install

socks5 server -l :1080 -auth user:pass,user2:pass # auth is optional, without it none auth is used

Benchmarks

Generated on Apple Macbook Air M1

goos: darwin
goarch: arm64
pkg: nikand.dev/go/socks5
BenchmarkServerHandshake-8        	36790387	        32.39 ns/op	       0 B/op	       0 allocs/op
BenchmarkClientHandshake-8        	56295850	        21.05 ns/op	       0 B/op	       0 allocs/op
BenchmarkWriteRequest-8           	37399100	        32.51 ns/op	       0 B/op	       0 allocs/op
BenchmarkReadRequestName-8        	16392350	        71.46 ns/op	      32 B/op	       2 allocs/op
BenchmarkReadRequestIP16-8        	22964949	        53.26 ns/op	      64 B/op	       1 allocs/op
BenchmarkReadRequestNetipIP16-8   	23116654	        51.40 ns/op	      32 B/op	       1 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

This section is empty.

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 {
	NetIPAddrs bool
}

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 netip.AddrPort

func (TCPAddr) Network

func (a TCPAddr) Network() string

func (TCPAddr) String

func (a TCPAddr) String() string

type TCPName added in v0.2.0

type TCPName string

TCPName is a string address.

func (TCPName) Network added in v0.2.0

func (a TCPName) Network() string

func (TCPName) String added in v0.2.0

func (a TCPName) String() string

type UDPAddr

type UDPAddr netip.AddrPort

func (UDPAddr) Network

func (a UDPAddr) Network() string

func (UDPAddr) String

func (a UDPAddr) String() string

type UDPConn

type UDPConn struct {
	Proto UDPProto
	// 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 UDPName added in v0.2.0

type UDPName string

UDPName is a string address.

func (UDPName) Network added in v0.2.0

func (a UDPName) Network() string

func (UDPName) String added in v0.2.0

func (a UDPName) String() string

type UDPProto added in v0.2.0

type UDPProto struct {
	Proto
}

func (UDPProto) EncodePacketHeader added in v0.2.0

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

func (UDPProto) ParsePacketHeader added in v0.2.0

func (p UDPProto) ParsePacketHeader(b []byte) (net.Addr, int, 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)

Directories

Path Synopsis
cmd
socks5 Module

Jump to

Keyboard shortcuts

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