netproxy

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netproxy is SSHYard's proxies, both ways: dialing out through an HTTP CONNECT or SOCKS5 proxy (the first hop to a host), and serving HTTP (CONNECT and plain absolute-URI requests), SOCKS4, SOCKS4a and SOCKS5 on a local port (a dynamic -D forward). It has no UI and no secrets of its own: a password is passed in by the caller.

Index

Constants

This section is empty.

Variables

View Source
var ErrAuth = errors.New("proxy: authentication failed")

ErrAuth reports a proxy that refused the user name and password, or that wants them and was given none.

View Source
var ErrClientLimit = errors.New("proxy: active client limit reached")

ErrClientLimit reports a rejected connection when all slots are occupied.

View Source
var ErrHandshakeTooLarge = errors.New("proxy: handshake too large")

ErrHandshakeTooLarge reports a rejected handshake exceeding its wire limit.

View Source
var ErrProtocol = errors.New("proxy: protocol not accepted")

ErrProtocol is a client speaking a protocol the server does not take.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	ID       uint64
	Source   string
	Target   string
	Protocol string // "socks5", "socks4", "socks4a", "http", "connect"; "" for a fixed target
	Start    time.Time
	// contains filtered or unexported fields
}

Conn is one connection relayed by a forward or a proxy: from Source, to Target, since Start. It lives in memory only.

func (*Conn) Bytes

func (c *Conn) Bytes() (up, down int64)

Bytes are what went from the source to the target (up) and back.

func (*Conn) Close

func (c *Conn) Close()

Close ends the connection both ways, at once: what the kernel still holds to send is dropped (a reset), so a client that reads slowly sees the disconnect now rather than after its buffer drains.

type Dialer

type Dialer struct {
	Kind Kind
	Addr string // the proxy's host:port
	User string
	// Password is read when dialing; nil or "" is none.
	Password func(ctx context.Context) (string, error)
	// Forward dials the proxy itself; nil is net.Dialer.
	Forward func(ctx context.Context, network, addr string) (net.Conn, error)
}

Dialer dials TCP connections through a proxy.

func (*Dialer) DialContext

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

DialContext connects to addr (host:port) through the proxy. A host name is resolved by the proxy, never locally.

type Error

type Error struct {
	Addr string
	Err  error
}

Error is a failure of the proxy itself (reaching it, or what it said), not of what was dialed through it.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Kind

type Kind string

Kind is a proxy protocol.

const (
	HTTP   Kind = "http"
	SOCKS5 Kind = "socks5"
)

type Protocol

type Protocol string

Protocol limits what a Server accepts; Auto takes them all, told apart by the first byte.

const (
	Auto       Protocol = ""
	OnlyHTTP   Protocol = "http"
	OnlySOCKS4 Protocol = "socks4" // SOCKS4 and SOCKS4a
	OnlySOCKS5 Protocol = "socks5"
)

type RefusedError

type RefusedError struct{ Reason string }

RefusedError is a proxy that reached itself but would not connect to the target.

func (*RefusedError) Error

func (e *RefusedError) Error() string

type Registry

type Registry struct {

	// OnChange, when set, is called when a connection comes or goes.
	OnChange func()
	// contains filtered or unexported fields
}

Registry is the connections a forward relays now.

func (*Registry) Close

func (r *Registry) Close(id uint64) bool

Close ends the connection of id; false when there is none.

func (*Registry) CloseAll

func (r *Registry) CloseAll()

CloseAll ends every connection.

func (*Registry) Len

func (r *Registry) Len() int

Len is how many connections there are.

func (*Registry) List

func (r *Registry) List() []*Conn

List returns the connections, oldest first.

func (*Registry) Relay

func (r *Registry) Relay(src, dst net.Conn, target, protocol string)

Relay copies between src (the connection accepted) and dst (the one dialed) until either ends, listed in the registry meanwhile. It blocks.

type Server

type Server struct {
	Protocol Protocol
	// User and Password, when User is set, are required of HTTP (Basic)
	// and SOCKS5 (username/password) clients; SOCKS4, which cannot carry
	// a password, is then refused.
	User, Password string
	Dial           func(ctx context.Context, network, addr string) (net.Conn, error)
	Conns          *Registry
	// OnError, when set, hears why a client was turned away.
	OnError func(err error)
	// contains filtered or unexported fields
}

Server serves a local proxy (a dynamic forward): HTTP CONNECT and plain HTTP requests with an absolute URI, SOCKS4, SOCKS4a and SOCKS5 CONNECT. Every target is dialed with Dial, so names are resolved on the far side.

func (*Server) Serve

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

Serve accepts on l until it is closed.

func (*Server) ServeConn

func (s *Server) ServeConn(c net.Conn) error

ServeConn serves one client connection; it blocks until it ends.

Jump to

Keyboard shortcuts

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