localrelay

package module
v2.0.0-...-a439472 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownProxyType is returned when a relay has a proxy type which is invalid
	ErrUnknownProxyType = errors.New("unknown proxytype used in creation of relay")
	// ErrAddrNotMatch is returned when a server object has a addr which is not nil
	// and does not equal the relay's address
	ErrAddrNotMatch = errors.New("addr does not match the relays host address")
	// ErrNoDestination is returned when the user did not provide a destination
	ErrNoDestination = errors.New("at least one destination must be set")
	// ErrManyDestinations is returned if attempting to use more than one destination
	// on a http(s) relay.
	ErrManyDestinations = errors.New("too many destinations for this relay type")
)
View Source
var (
	// ErrFailConnect will be returned if the remote failed to dial
	ErrFailConnect = errors.New("failed to dial remote")
	// Timeout is only used when dialling without a proxy
	Timeout = time.Second * 5
)
View Source
var (
	ErrProxyDefine = errors.New("proxy is not defined")
)

Functions

func HandleHTTP

func HandleHTTP(relay *Relay) http.HandlerFunc

HandleHTTP is to be used as the HTTP relay's handler set in the http.Server object

Types

type Loadbalance

type Loadbalance struct {
	Enabled   bool
	Algorithm string
}

type Logger

type Logger struct {
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
}

Logger is used for logging debug information such as connections being created, dropped etc

func NewLogger

func NewLogger(w io.Writer, name string) *Logger

NewLogger creates a new logging system

type Metrics

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

Metrics stores information such as bandwidth usage conn stats etc

func (*Metrics) Connections

func (m *Metrics) Connections() (active int, total uint64)

Connections returns the amount of active and total connections

func (*Metrics) Dialer

func (m *Metrics) Dialer() (success, failed uint64)

Dialer returns the successful dials and failed dials

func (*Metrics) DialerAvg

func (m *Metrics) DialerAvg() (milliseconds int)

DialerAvg returns the 10 point average dial time this average includes failed dials

func (*Metrics) Download

func (m *Metrics) Download() int

Download returns the amount of bytes downloaded through the relay

func (*Metrics) Requests

func (m *Metrics) Requests() uint64

Requests returns the amount of requests made via http

func (*Metrics) Upload

func (m *Metrics) Upload() int

Upload returns the amount of bytes uploaded through the relay

type PooledConn

type PooledConn struct {
	Conn       net.Conn
	RemoteAddr string
	Opened     time.Time
}

PooledConn allows meta data to be attached to a connection

type ProxyType

type ProxyType string

ProxyType represents what type of proxy the relay is.

Raw TCP is used for just forwarding the raw connection to the remote address.

const (
	// ProxyTCP is for raw TCP forwarding
	ProxyTCP ProxyType = "tcp"
	// ProxyUDP forwards UDP traffic
	ProxyUDP ProxyType = "udp"
	// ProxyHTTP creates a HTTP server and forwards the traffic to
	// either a HTTP or HTTPs server
	ProxyHTTP ProxyType = "http"
	// ProxyHTTPS is the same as HTTP but listens on TLS
	ProxyHTTPS ProxyType = "https"

	// VERSION uses semantic versioning
	// this version number is for the library not the CLI
	VERSION = "v2.0.0"
)

type ProxyURL

type ProxyURL struct {
	*url.URL
}

func NewProxyURL

func NewProxyURL(u *url.URL) ProxyURL

func (*ProxyURL) Dialer

func (p *ProxyURL) Dialer() proxy.Dialer

func (*ProxyURL) HttpProxyURL

func (p *ProxyURL) HttpProxyURL()

type Relay

type Relay struct {
	// Name is a generic name which can be assigned to this relay
	Name string
	// Listener is the address and protocol to listen on.
	// Example A (listen on loopback):
	// tcp://127.0.0.1:443
	// Example B (listen on all interfaces):
	// tcp://0.0.0.0:443
	Listener TargetLink

	// Destination is an array of connection URLs.
	// Example A:
	// tcp://127.0.0.1:443
	// Example B:
	// udp://127.0.0.1:23
	// Example C:
	// tcp://example.com:443?proxy=tor
	Destination []TargetLink

	// ProxyEnabled is set to true when a proxy has been set for this relay
	ProxyEnabled bool

	// Metrics is used to store information such as upload/download
	// and other statistics
	*Metrics
	// contains filtered or unexported fields
}

Relay represents a reverse proxy and all of its settings

func New

func New(name string, logger io.Writer, listener TargetLink, destination ...TargetLink) (*Relay, error)

New creates a new TCP relay

func (*Relay) Close

func (r *Relay) Close() error

Close will close the relay's listener

func (*Relay) GetConns

func (r *Relay) GetConns() []*PooledConn

GetConns returns all the active connections to this relay

func (*Relay) ListenServe

func (r *Relay) ListenServe() error

ListenServe will start a listener and handle the incoming requests

func (*Relay) Running

func (r *Relay) Running() bool

Running returns true if relay is running

func (*Relay) Serve

func (r *Relay) Serve(l net.Listener) error

Serve lets you set your own listener and then serve on it

func (*Relay) SetClient

func (r *Relay) SetClient(client *http.Client)

SetClient will set the http client used by the relay

func (*Relay) SetHTTP

func (r *Relay) SetHTTP(server *http.Server) error

SetHTTP is used to set the relay as a type HTTP relay addr will auto be set in the server object if left blank

func (*Relay) SetLoadbalance

func (r *Relay) SetLoadbalance(enabled bool)

func (*Relay) SetProxy

func (r *Relay) SetProxy(proxies map[string]ProxyURL)

SetProxy sets the proxy dialer to be used proxy.SOCKS5() can be used to setup a socks5 proxy or a list of proxies

func (*Relay) SetTLS

func (r *Relay) SetTLS(certificateFile, keyFile string)

SetTLS sets the TLS certificates for use in the ProxyHTTPS relay. This function will upgrade this relay to a HTTPS relay

type TargetLink string

func (*TargetLink) Addr

func (t *TargetLink) Addr() string

Addr returns the address within the target link. Example: 127.0.0.1:443

func (*TargetLink) Host

func (t *TargetLink) Host() string

Host returns the host/ip of the target

func (*TargetLink) Lb

func (t *TargetLink) Lb() bool

Lb returns true if loadbalancing is enabled

func (*TargetLink) LbWeight

func (t *TargetLink) LbWeight() uint

LbWeight returns the weight provided or the default value of 100

func (*TargetLink) Port

func (t *TargetLink) Port() string

Port returns the port number of the target

func (*TargetLink) Print

func (t *TargetLink) Print() string

Print returns the targetlink string

func (*TargetLink) Protocol

func (t *TargetLink) Protocol() string

Protocol returns the protocol of the target

func (*TargetLink) Proxy

func (t *TargetLink) Proxy(r *Relay) ([]ProxyURL, []string, error)

Proxy parses the TargetLink and uses the relay to lookup proxy dialers. The returned array is in the same order as written.

func (*TargetLink) ProxyType

func (t *TargetLink) ProxyType() ProxyType

ProxyType returns the protocol as a ProxyType

func (*TargetLink) String

func (t *TargetLink) String() string

Jump to

Keyboard shortcuts

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