gost

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 10 * time.Second
)

Variables

View Source
var (
	DefaultNetDialer = &NetDialer{}
)
View Source
var (
	DefaultTlsDialer = &TlsDialer{}
)
View Source
var (
	ErrInvalidResolver = errors.New("invalid resolver")
)

Functions

func ContextWithClientID

func ContextWithClientID(ctx context.Context, clientID ClientID) context.Context

func ContextWithProxyAuthorization

func ContextWithProxyAuthorization(ctx context.Context, auth *url.Userinfo) context.Context

func NetTransport

func NetTransport(rw1, rw2 io.ReadWriter) error

func ProxyAuthorizationFromContext

func ProxyAuthorizationFromContext(ctx context.Context) *url.Userinfo

func Resolve

func Resolve(ctx context.Context, network, addr string, r Resolver, hosts HostMapper, log *logger.Logger) (string, error)

Types

type AuthOption

type AuthOption func(opts *authOptions)

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context, user, password string, opts ...AuthOption) (id string, ok bool)
}

type Bypass

type Bypass interface {
	Contains(ctx context.Context, network, addr string, opts ...BypassOption) bool
}

func BypassGroup

func BypassGroup(bypasses ...Bypass) Bypass

type BypassOption

type BypassOption func(opts *BypassOptions)

func WithBypassHost

func WithBypassHost(host string) BypassOption

func WithBypassPath

func WithBypassPath(path string) BypassOption

type BypassOptions

type BypassOptions struct {
	Host string
	Path string
}

type Chain

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

func NewChain

func NewChain(name string, opts ...ChainOption) *Chain

func (*Chain) AddNode

func (c *Chain) AddNode(node *Node)

func (*Chain) Name

func (c *Chain) Name() string

func (*Chain) Route

func (c *Chain) Route(ctx context.Context, network, address string, opts ...ChainerOption) Route

type ChainOption

type ChainOption func(*chainOptions)

func WithChainLogger

func WithChainLogger(logger *logger.Logger) ChainOption

type ChainRouteOption

type ChainRouteOption func(*chainRouteOptions)

func WithChainRouteChainerOption

func WithChainRouteChainerOption(c Chainer) ChainRouteOption

type Chainer

type Chainer interface {
	Route(ctx context.Context, network, address string, opts ...ChainerOption) Route
}

type ChainerOption

type ChainerOption func(opts *ChainerOptions)

func ChainerHostOption

func ChainerHostOption(host string) ChainerOption

type ChainerOptions

type ChainerOptions struct {
	Host string
}

type ClientID

type ClientID string

func ClientIDFromContext

func ClientIDFromContext(ctx context.Context) ClientID

type ConnectOption

type ConnectOption func(opts *connectOptions)

func NetDialerConnectOption

func NetDialerConnectOption(netd *NetDialer) ConnectOption

type Connector

type Connector interface {
	Connect(ctx context.Context, conn net.Conn, network, address string, opts ...ConnectOption) (net.Conn, error)
}

func NewHttpConnector

func NewHttpConnector(opts ...ConnectorOption) Connector

type ConnectorAuth

type ConnectorAuth interface {
	Auth(ctx context.Context) *url.Userinfo
}

type ConnectorOption

type ConnectorOption func(opts *connectorOptions)

func WithConnectorAuth

func WithConnectorAuth(auth ConnectorAuth) ConnectorOption

func WithConnectorConnectTimeout

func WithConnectorConnectTimeout(connectTimeout time.Duration) ConnectorOption

func WithConnectorLogger

func WithConnectorLogger(logger *logger.Logger) ConnectorOption

func WithConnectorTLSConfig

func WithConnectorTLSConfig(tlsConfig *tls.Config) ConnectorOption

type DialOptions

type DialOptions struct {
	Host      string
	NetDialer *NetDialer
}

type Dialer

type Dialer interface {
	Dial(ctx context.Context, addr string, opts ...DialerOption) (net.Conn, error)
}

func NewTcpDialer

func NewTcpDialer(opts ...TcpDialerOption) Dialer

type DialerOption

type DialerOption func(opts *DialOptions)

func WithDialerHostOption

func WithDialerHostOption(host string) DialerOption

func WithDialerNetDialer

func WithDialerNetDialer(netd *NetDialer) DialerOption

type HandleOption

type HandleOption func(opts *HandleOptions)

type HandleOptions

type HandleOptions struct {
}

type Handler

type Handler interface {
	Handle(context.Context, net.Conn, ...HandleOption) error
}

func NewHttpHandler

func NewHttpHandler(opts ...HandlerOption) Handler

type HandlerOption

type HandlerOption func(opts *handlerOptions)

func WithHandlerAuth

func WithHandlerAuth(auth *url.Userinfo) HandlerOption

func WithHandlerAuther

func WithHandlerAuther(auther Authenticator) HandlerOption

func WithHandlerBypass

func WithHandlerBypass(bypass Bypass) HandlerOption

func WithHandlerLogger

func WithHandlerLogger(logger *logger.Logger) HandlerOption

func WithHandlerRouter

func WithHandlerRouter(router *Router) HandlerOption

func WithHandlerTLSConfig

func WithHandlerTLSConfig(tlsConfig *tls.Config) HandlerOption

func WithProxyOnly

func WithProxyOnly() HandlerOption

type HostMapper

type HostMapper interface {
	Lookup(ctx context.Context, network, host string, opts ...HostsOption) ([]net.IP, bool)
}

type HostsOption

type HostsOption func(opts *hostsOptions)

type Listener

type Listener interface {
	Init(ctx context.Context) error
	Accept() (net.Conn, error)
	Addr() net.Addr
	Close() error
}

func NewTcpListener

func NewTcpListener(opts ...ListenerOption) Listener

type ListenerOption

type ListenerOption func(opts *listenerOptions)

func WithListenerAddr

func WithListenerAddr(addr string) ListenerOption

func WithListenerLogger

func WithListenerLogger(logger *logger.Logger) ListenerOption

func WithListenerTLSConfig

func WithListenerTLSConfig(tlsConfig *tls.Config) ListenerOption

type NetDialer

type NetDialer struct {
	Timeout  time.Duration
	DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)
	Logger   *logger.Logger
}

func (*NetDialer) Dial

func (d *NetDialer) Dial(ctx context.Context, network, addr string) (conn net.Conn, err error)

type Node

type Node struct {
	Name string
	Addr string
	// contains filtered or unexported fields
}

func NewNode

func NewNode(name string, addr string, opts ...NodeOption) *Node

func (*Node) Copy

func (node *Node) Copy() *Node

func (*Node) Options

func (node *Node) Options() *NodeOptions

type NodeOption

type NodeOption func(*NodeOptions)

func WithNodeHostMapper

func WithNodeHostMapper(m HostMapper) NodeOption

func WithNodeResolver

func WithNodeResolver(resolver Resolver) NodeOption

func WithNodeTransport

func WithNodeTransport(tr *Transport) NodeOption

type NodeOptions

type NodeOptions struct {
	Transport  *Transport
	Resolver   Resolver
	HostMapper HostMapper
}

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, network, host string, opts ...ResolverOption) ([]net.IP, error)
}

type ResolverOption

type ResolverOption func(opts *resolverOptions)

type Route

type Route interface {
	Dial(ctx context.Context, network, address string, opts ...RouteDialOption) (net.Conn, error)
	Nodes() []*Node
}
var (
	DefaultRoute Route = &defaultRoute{}
)

type RouteDialOption

type RouteDialOption func(opts *routeDialOptions)

func WithRouteDialLogger

func WithRouteDialLogger(logger *logger.Logger) RouteDialOption

func WithRouteDialTimeout

func WithRouteDialTimeout(d time.Duration) RouteDialOption

type Router

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

func NewRouter

func NewRouter(opts ...RouterOption) *Router

func (*Router) Dial

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

func (*Router) Options

func (r *Router) Options() *RouterOptions

type RouterOption

type RouterOption func(*RouterOptions)

func WithRouterChainer

func WithRouterChainer(chain Chainer) RouterOption

func WithRouterHostMapper

func WithRouterHostMapper(m HostMapper) RouterOption

func WithRouterLogger

func WithRouterLogger(logger *logger.Logger) RouterOption

func WithRouterResolver

func WithRouterResolver(resolver Resolver) RouterOption

func WithRouterRetriesOption

func WithRouterRetriesOption(retries int) RouterOption

func WithRouterTimeout

func WithRouterTimeout(timeout time.Duration) RouterOption

type RouterOptions

type RouterOptions struct {
	Retries    int
	Timeout    time.Duration
	Chain      Chainer
	Resolver   Resolver
	HostMapper HostMapper
	Logger     *logger.Logger
}

type Service

type Service interface {
	Serve() error
	Addr() net.Addr
	Close() error
}

func NewService

func NewService(ln Listener, h Handler, opts ...ServiceOption) Service

type ServiceOption

type ServiceOption func(opts *serviceOptions)

func WithServiceLogger

func WithServiceLogger(logger *logger.Logger) ServiceOption

type TcpDialerOption

type TcpDialerOption func(opts *tcpDialerOptions)

func WithTcpDialerLogger

func WithTcpDialerLogger(logger *logger.Logger) TcpDialerOption

type TlsDialer

type TlsDialer struct {
	Timeout       time.Duration
	Logger        *logger.Logger
	TLSConfigFunc func() *tls.Config
}

func (*TlsDialer) Dial

func (d *TlsDialer) Dial(ctx context.Context, network, addr string) (conn net.Conn, err error)

type Transport

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

func NewTransport

func NewTransport(d Dialer, c Connector, opts ...TransportOption) *Transport

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) Options

func (tr *Transport) Options() *TransportOptions

type TransportOption

type TransportOption func(*TransportOptions)

func WithTransportAddr

func WithTransportAddr(addr string) TransportOption

func WithTransportRoute

func WithTransportRoute(route Route) TransportOption

func WithTransportTimeout

func WithTransportTimeout(timeout time.Duration) TransportOption

type TransportOptions

type TransportOptions struct {
	Addr    string
	Route   Route
	Timeout time.Duration
}

Jump to

Keyboard shortcuts

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