Documentation ¶
Index ¶
- Variables
- func HandleHTTP(relay *Relay) http.HandlerFunc
- type Loadbalance
- type Logger
- type Metrics
- type PooledConn
- type ProxyType
- type ProxyURL
- type Relay
- func (r *Relay) Close() error
- func (r *Relay) Failover() bool
- func (r *Relay) GetConns() []*PooledConn
- func (r *Relay) ListenServe() error
- func (r *Relay) Loadbalancer() bool
- func (r *Relay) Running() bool
- func (r *Relay) Serve(l net.Listener) error
- func (r *Relay) SetClient(client *http.Client)
- func (r *Relay) SetHTTP(server *http.Server) error
- func (r *Relay) SetLoadbalance(enabled bool)
- func (r *Relay) SetProxy(proxies map[string]ProxyURL)
- func (r *Relay) SetTLS(certificateFile, keyFile string)
- type TargetLink
- func (t *TargetLink) Addr() string
- func (t *TargetLink) Host() string
- func (t *TargetLink) Lb() bool
- func (t *TargetLink) LbWeight() uint
- func (t *TargetLink) Port() string
- func (t *TargetLink) Print() string
- func (t *TargetLink) Protocol() string
- func (t *TargetLink) Proxy(r *Relay) ([]ProxyURL, []string, error)
- func (t *TargetLink) ProxyType() ProxyType
- func (t *TargetLink) String() string
Constants ¶
This section is empty.
Variables ¶
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") )
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 )
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 Logger ¶
Logger is used for logging debug information such as connections being created, dropped etc
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics stores information such as bandwidth usage conn stats etc
func (*Metrics) Connections ¶
Connections returns the amount of active and total connections
func (*Metrics) DialerAvg ¶
DialerAvg returns the 10 point average dial time this average includes failed dials
type PooledConn ¶
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 ¶
func NewProxyURL ¶
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 // Tags are used to propogate relay properties to the API client/CLI Targs map[string]struct{} // 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) Failover ¶
Failover returns true if the relay offers failover but is not a load balancer
func (*Relay) GetConns ¶
func (r *Relay) GetConns() []*PooledConn
GetConns returns all the active connections to this relay
func (*Relay) ListenServe ¶
ListenServe will start a listener and handle the incoming requests
func (*Relay) Loadbalancer ¶
Loadbalancer returns true if the relay is a load balancer
func (*Relay) SetHTTP ¶
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 ¶
type TargetLink ¶
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) 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) 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