chain

package
v3.0.0-alpha.3....-0a41b70 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: MIT Imports: 18 Imported by: 11

Documentation

Index

Constants

View Source
const (
	DefaultFailTimeout = 30 * time.Second
)

default options for FailFilter

Variables

View Source
var (
	DefaultSelector = NewSelector(RoundRobinStrategy())
)
View Source
var (
	ErrEmptyRoute = errors.New("empty route")
)

Functions

This section is empty.

Types

type Chain

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

func (*Chain) AddNodeGroup

func (c *Chain) AddNodeGroup(group *NodeGroup)

func (*Chain) Route

func (c *Chain) Route(network, address string) (r *Route)

type Chainer

type Chainer interface {
	Route(network, address string) *Route
}

type FailMarker

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

func (*FailMarker) FailCount

func (m *FailMarker) FailCount() int64

func (*FailMarker) FailTime

func (m *FailMarker) FailTime() int64

func (*FailMarker) Mark

func (m *FailMarker) Mark()

func (*FailMarker) Reset

func (m *FailMarker) Reset()

type Filter

type Filter interface {
	Filter(nodes ...*Node) []*Node
}

func FailFilter

func FailFilter(maxFails int, timeout time.Duration) Filter

FailFilter filters the dead node. A node is marked as dead if its failed count is greater than MaxFails.

func InvalidFilter

func InvalidFilter() Filter

InvalidFilter filters the invalid node. A node is invalid if its port is invalid (negative or zero value).

type Node

type Node struct {
	Name      string
	Addr      string
	Transport *Transport
	Bypass    bypass.Bypass
	Resolver  resolver.Resolver
	Hosts     hosts.HostMapper
	Marker    *FailMarker
}

func (*Node) Copy

func (node *Node) Copy() *Node

type NodeGroup

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

func NewNodeGroup

func NewNodeGroup(nodes ...*Node) *NodeGroup

func (*NodeGroup) AddNode

func (g *NodeGroup) AddNode(node *Node)

func (*NodeGroup) Next

func (g *NodeGroup) Next() *Node

func (*NodeGroup) WithSelector

func (g *NodeGroup) WithSelector(selector Selector) *NodeGroup

type Route

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

func (*Route) Bind

func (r *Route) Bind(ctx context.Context, network, address string, opts ...connector.BindOption) (net.Listener, error)

func (*Route) Dial

func (r *Route) Dial(ctx context.Context, network, address string) (net.Conn, error)

func (*Route) GetNode

func (r *Route) GetNode(index int) *Node

func (*Route) Len

func (r *Route) Len() int

func (*Route) Path

func (r *Route) Path() (path []*Node)

type Router

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

func (*Router) Bind

func (r *Router) Bind(ctx context.Context, network, address string, opts ...connector.BindOption) (ln net.Listener, err error)

func (*Router) Dial

func (r *Router) Dial(ctx context.Context, network, address string) (conn net.Conn, err error)

func (*Router) Hosts

func (r *Router) Hosts() hosts.HostMapper

func (*Router) WithChain

func (r *Router) WithChain(chain Chainer) *Router

func (*Router) WithHosts

func (r *Router) WithHosts(hosts hosts.HostMapper) *Router

func (*Router) WithInterface

func (r *Router) WithInterface(ifceName string) *Router

func (*Router) WithLogger

func (r *Router) WithLogger(logger logger.Logger) *Router

func (*Router) WithResolver

func (r *Router) WithResolver(resolver resolver.Resolver) *Router

func (*Router) WithRetries

func (r *Router) WithRetries(retries int) *Router

func (*Router) WithTimeout

func (r *Router) WithTimeout(timeout time.Duration) *Router

type Selector

type Selector interface {
	Select(nodes ...*Node) *Node
}

func NewSelector

func NewSelector(strategy Strategy, filters ...Filter) Selector

type Strategy

type Strategy interface {
	Apply(nodes ...*Node) *Node
}

func FIFOStrategy

func FIFOStrategy() Strategy

FIFOStrategy is a strategy for node selector. The node will be selected from first to last, and will stick to the selected node until it is failed.

func RandomStrategy

func RandomStrategy() Strategy

RandomStrategy is a strategy for node selector. The node will be selected randomly.

func RoundRobinStrategy

func RoundRobinStrategy() Strategy

RoundRobinStrategy is a strategy for node selector. The node will be selected by round-robin algorithm.

type Transport

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

func (*Transport) Bind

func (tr *Transport) Bind(ctx context.Context, conn net.Conn, network, address string, opts ...connector.BindOption) (net.Listener, error)

func (*Transport) Connect

func (tr *Transport) Connect(ctx context.Context, conn net.Conn, network, address string) (net.Conn, error)

func (*Transport) Copy

func (tr *Transport) Copy() *Transport

func (*Transport) Dial

func (tr *Transport) Dial(ctx context.Context, addr string) (net.Conn, error)

func (*Transport) Handshake

func (tr *Transport) Handshake(ctx context.Context, conn net.Conn) (net.Conn, error)

func (*Transport) Multiplex

func (tr *Transport) Multiplex() bool

func (*Transport) WithAddr

func (tr *Transport) WithAddr(addr string) *Transport

func (*Transport) WithConnector

func (tr *Transport) WithConnector(connector connector.Connector) *Transport

func (*Transport) WithDialer

func (tr *Transport) WithDialer(dialer dialer.Dialer) *Transport

func (*Transport) WithInterface

func (tr *Transport) WithInterface(ifceName string) *Transport

func (*Transport) WithRoute

func (tr *Transport) WithRoute(r *Route) *Transport

Jump to

Keyboard shortcuts

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