backend

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RTTErrorHappened means health check failed
	RTTErrorHappened = time.Hour * 24 * 365 * 99
	// RTTErrorNotCheck now
	RTTErrorNotCheck = time.Hour * 24 * 365 * 98
)
View Source
const DefaultFastProxyHealthCheckInterval = time.Second * 60

DefaultFastProxyHealthCheckInterval is 60 seconds

View Source
const DefaultHealthCheckEndpoint = "https://www.google.com"

DefaultHealthCheckEndpoint is google

Variables

View Source
var (
	// ErrBackendNotProvided error
	ErrBackendNotProvided = errors.New("backend proxy not provided")
	// ErrHealthCheckStatusNotOk error
	ErrHealthCheckStatusNotOk = errors.New("health check response status not correct")
)

Functions

This section is empty.

Types

type Dial

type Dial func(network, addr string) (c net.Conn, err error)

Dial function

type FastProxyBackendOption

type FastProxyBackendOption struct {
	HealthCheckInterval time.Duration
	Backends            []ProxyBackend
}

FastProxyBackendOption type

type ProxyBackend

type ProxyBackend interface {
	GetDialer() proxy.Dialer
	GetName() string
	// check dialer health, return error if anything wrong
	// if success, record the RTT time
	HealthCheck() error
	GetPingRTT() time.Duration
	IsHealth() bool
}

ProxyBackend interface

func NewDialerProxyBackend

func NewDialerProxyBackend(dial Dial, healthCheckEndpoint string) ProxyBackend

NewDialerProxyBackend instance

func NewDialerProxyBackendDefault

func NewDialerProxyBackendDefault(dial Dial) ProxyBackend

NewDialerProxyBackendDefault instance

func NewSocks5ProxyBackend

func NewSocks5ProxyBackend(opt *Socks5ProxyBackendOption) (ProxyBackend, error)

NewSocks5ProxyBackend instance

addr: a tcp address like '192.168.3.88:18080' name: the id of this socks5 proxy

type ProxyBackendProvider

type ProxyBackendProvider interface {
	GetAll() []ProxyBackend
	// GetOne proxy which fastest & health
	GetOne() ProxyBackend
}

ProxyBackendProvider interface

When create a proxy backend provider, please remember to do health check for all instance firstly

func NewFastProxyBackendProvider

func NewFastProxyBackendProvider(option *FastProxyBackendOption) (ProxyBackendProvider, error)

NewFastProxyBackendProvider instance

this provider will always provide the fastest proxy backend instance

type Socks5ProxyBackendOption

type Socks5ProxyBackendOption struct {
	Addr           string
	Name           string
	HealthEndpoint string
}

Socks5ProxyBackendOption type

Jump to

Keyboard shortcuts

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