socks5

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: AGPL-3.0 Imports: 13 Imported by: 6

Documentation

Overview

Package socks5 provides a SOCKS5 server implementation. See RFC1928 for protocol specification.

Index

Constants

View Source
const (
	// TopicTunnelEvents is the topic where the tunnels updates are published
	TopicTunnelEvents = "topic_tunnel_events"

	// TopicNetUsage is the topic where bandwidth usage updates are published
	TopicNetUsage = "topic_network_usage"
)

Variables

This section is empty.

Functions

func EncodeAddressBinary

func EncodeAddressBinary(addr string) ([]byte, error)

EncodeAddressBinary expects as input a canonical host:port address and returns the binary representation as speccified in the socks5 protocol (RFC1928). Booster uses the same encoding.

func EncodeHostBinary

func EncodeHostBinary(host string) ([]byte, error)

EncodeHostBinary encodes a canonical host (IPv4, IPv6, FQDN) into a byte slice. Format follows RFC1928.

func EncodePortBinary

func EncodePortBinary(port string) ([]byte, error)

EncodePortBinary encodes a canonical port into 2 bytes. Format follows RFC1928.

func ReadAddress

func ReadAddress(r io.Reader) (addr string, err error)

ReadAddress reads hostname and port and converts them into its string format, properly formatted.

r expects to read one byte that specifies the address format (1/3/4), followed by the address itself and a 16 bit port number.

addr == "" only when err != nil.

func ReadHost

func ReadHost(r io.Reader) (string, error)

ReadHost deals with the host part of ReadAddress.

func ReadPort

func ReadPort(r io.Reader) (string, error)

ReadPort deals with the port part of ReadAddress.

Types

type BandwidthMessage added in v0.3.0

type BandwidthMessage struct {
	Bandwidth int
	Tot       int
	D         time.Duration
	Download  bool
}

type Dialer

type Dialer interface {
	// DialContext opens a connection to addr, which should
	// be a canonical address with host and port.
	DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}

Dialer is the interface that wraps the DialContext function.

type Event added in v0.3.0

type Event int
const (
	EventPush Event = iota
	EventPop
)

Possible proxy operations.

type PubSub

type PubSub interface {
	Sub(cmd *pubsub.Command) (pubsub.CancelFunc, error)
	Pub(message interface{}, topic string)
}

PubSub describes the required functionalities of a publication/subscription object.

type Socks5

type Socks5 struct {
	PubSub

	ReadWriteTimeout time.Duration
	ChunkSize        int64
	BandwidthCheck   time.Duration
	NextCopyDelay    time.Duration
	DownloadIO       *network.NetworkIO
	UploadIO         *network.NetworkIO

	sync.Mutex
	Dialer
	// contains filtered or unexported fields
}

Socks5 represents a SOCKS5 proxy server implementation.

func New added in v0.3.0

func New(d Dialer) *Socks5

SOCKS5 returns a new Socks5 instance with default logger and dialer.

func (*Socks5) Associate

func (s *Socks5) Associate(ctx context.Context, conn net.Conn, target string) (net.Conn, error)

associate -- not yet implemented. See RFC 1928

func (*Socks5) Bind

func (s *Socks5) Bind(ctx context.Context, conn net.Conn, target string) (net.Conn, error)

bind, not yet implemented. See RFC 1928

func (*Socks5) Close added in v0.3.0

func (s *Socks5) Close() error

func (*Socks5) Connect

func (s *Socks5) Connect(ctx context.Context, conn net.Conn, target string) (net.Conn, error)

connect dials a new connection with target, which must be a canonical address with host and port.

func (*Socks5) Handle

func (s *Socks5) Handle(ctx context.Context, conn net.Conn) error

Handle performs the steps required to be SOCKS5 compliant. See RFC 1928 for details.

Should run in its own go routine, closes the connection when returning.

func (*Socks5) ListenAndServe

func (s *Socks5) ListenAndServe(ctx context.Context, port int) error

ListenAndServe accepts and handles TCP connections using the SOCKS5 protocol.

func (*Socks5) Negotiate

func (s *Socks5) Negotiate(conn net.Conn) error

negotiate performs the very first method subnegotiation when handling a new connection.

func (*Socks5) Port

func (s *Socks5) Port() int

Port safely returns proxy's listening port.

func (*Socks5) Proto added in v0.3.0

func (s *Socks5) Proto() string

Proto returns the protocol used by the proxy in string format.

func (*Socks5) ProxyData

func (s *Socks5) ProxyData(src net.Conn, dst net.Conn)

ProxyData copies data from src to dst and the other way around. Closes the connections when they are idle for more than the duration described in ReadWriteTimeout.

func (*Socks5) Run added in v0.3.0

func (s *Socks5) Run(port int) error

Jump to

Keyboard shortcuts

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