dialer

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: GPL-3.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	//LogLevelDebug is debug log level
	LogLevelDebug = 40
	//LogLevelInfo is info log level
	LogLevelInfo = 30
	//LogLevelWarn is warn log level
	LogLevelWarn = 20
	//LogLevelError is error log level
	LogLevelError = 10
)

Variables

View Source
var LogLevel = LogLevelInfo

LogLevel is log leveo config

Logger is the bsck package default log

NewDialer is default all dialer creator

Functions

func DebugLog

func DebugLog(format string, args ...interface{})

DebugLog is the debug level log

func ErrorLog

func ErrorLog(format string, args ...interface{})

ErrorLog is the error level log

func InfoLog

func InfoLog(format string, args ...interface{})

InfoLog is the info level log

func SetLogLevel

func SetLogLevel(l int)

SetLogLevel is set log level to l

func WarnLog

func WarnLog(format string, args ...interface{})

WarnLog is the warn level log

Types

type BalancedDialer

type BalancedDialer struct {
	ID string

	PolicyList []*BalancedPolicy
	Filters    []*BalancedFilter
	Delay      int64
	Timeout    int64
	Conf       xmap.M
	// contains filtered or unexported fields
}

func NewBalancedDialer

func NewBalancedDialer() *BalancedDialer

func (*BalancedDialer) AddDialer

func (b *BalancedDialer) AddDialer(dialers ...Dialer)

func (*BalancedDialer) AddFilter

func (b *BalancedDialer) AddFilter(matcher string, access int) (err error)

func (*BalancedDialer) AddPolicy

func (b *BalancedDialer) AddPolicy(matcher string, limit []int64) (err error)

func (*BalancedDialer) Bootstrap

func (b *BalancedDialer) Bootstrap(options xmap.M) (err error)

initial dialer

func (*BalancedDialer) Dial

func (b *BalancedDialer) Dial(channel Channel, sid uint64, uri string, pipe io.ReadWriteCloser) (r Conn, err error)

func (*BalancedDialer) Matched

func (b *BalancedDialer) Matched(uri string) bool

Matched uri

func (*BalancedDialer) Name

func (b *BalancedDialer) Name() string

func (*BalancedDialer) Options

func (b *BalancedDialer) Options() xmap.M

Options

func (*BalancedDialer) Shutdown

func (b *BalancedDialer) Shutdown() (err error)

Shutdown will shutdown dial

type BalancedFilter

type BalancedFilter struct {
	Matcher *regexp.Regexp
	Access  int
}

type BalancedPolicy

type BalancedPolicy struct {
	Matcher *regexp.Regexp
	Scope   string
	Limit   []int64
}

type Channel

type Channel interface {
	//the connection id
	ID() uint64
	//the channel name
	Name() string
	//the channel index.
	Index() int
	//conn context getter
	Context() xmap.M
}

type CodeError

type CodeError struct {
	Inner    error
	ByteCode byte
}

func (*CodeError) Code

func (c *CodeError) Code() byte

func (*CodeError) Error

func (c *CodeError) Error() string

type Conn

type Conn interface {
	Pipable
	io.ReadWriteCloser
}

type CopyPipable

type CopyPipable struct {
	io.ReadWriteCloser
	// contains filtered or unexported fields
}

func NewCopyPipable

func NewCopyPipable(raw io.ReadWriteCloser) *CopyPipable

func (*CopyPipable) Pipe

func (c *CopyPipable) Pipe(r io.ReadWriteCloser) (err error)

func (*CopyPipable) String

func (c *CopyPipable) String() string

type Dialer

type Dialer interface {
	Name() string
	//initial dialer
	Bootstrap(options xmap.M) error
	//shutdown
	Shutdown() error
	//
	Options() xmap.M
	//match uri
	Matched(uri string) bool
	//dial raw connection
	Dial(channel Channel, sid uint64, uri string, raw io.ReadWriteCloser) (r Conn, err error)
}

Dialer is the interface that wraps the dialer

func DefaultDialerCreator

func DefaultDialerCreator(t string) (dialer Dialer)

DefaultDialerCreator is default all dialer creator

type DuplexPiped

type DuplexPiped struct {
	UpReader   *os.File
	UpWriter   *os.File
	DownReader *os.File
	DownWriter *os.File
	// contains filtered or unexported fields
}

func (*DuplexPiped) Close

func (d *DuplexPiped) Close() error

type EchoDialer

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

EchoDialer is an implementation of the Dialer interface for echo tcp connection.

func NewEchoDialer

func NewEchoDialer() (dialer *EchoDialer)

NewEchoDialer will return new EchoDialer

func (*EchoDialer) Bootstrap

func (e *EchoDialer) Bootstrap(options xmap.M) error

Bootstrap the dialer

func (*EchoDialer) Dial

func (e *EchoDialer) Dial(channel Channel, sid uint64, uri string, pipe io.ReadWriteCloser) (r Conn, err error)

Dial one echo connection.

func (*EchoDialer) Matched

func (e *EchoDialer) Matched(uri string) bool

Matched will return whetheer uri is invalid

func (*EchoDialer) Name

func (e *EchoDialer) Name() string

Name will return dialer name

func (*EchoDialer) Options

func (e *EchoDialer) Options() xmap.M

Options is options getter

func (*EchoDialer) Shutdown

func (e *EchoDialer) Shutdown() (err error)

Shutdown will shutdown dial

type EchoReadWriteCloser

type EchoReadWriteCloser struct {
	*xio.PipedChan
}

EchoReadWriteCloser is an implementation of the io.ReadWriteCloser interface for pipe write to read.

func NewEchoReadWriteCloser

func NewEchoReadWriteCloser() *EchoReadWriteCloser

NewEchoReadWriteCloser will return new EchoReadWriteCloser

func (*EchoReadWriteCloser) Pipe

func (e *EchoReadWriteCloser) Pipe(raw io.ReadWriteCloser) (err error)

Pipe is Pipable implment

func (*EchoReadWriteCloser) String

func (e *EchoReadWriteCloser) String() string

type MapIntSorter

type MapIntSorter struct {
	List  []string
	Data  map[string][]int64
	Index int
}

func NewMapIntSorter

func NewMapIntSorter(data map[string][]int64, index int) *MapIntSorter

func (*MapIntSorter) Len

func (m *MapIntSorter) Len() int

func (*MapIntSorter) Less

func (m *MapIntSorter) Less(i, j int) bool

func (*MapIntSorter) Swap

func (m *MapIntSorter) Swap(i, j int)

type Pipable

type Pipable interface {
	Pipe(r io.ReadWriteCloser) error
}

type PipedConn

type PipedConn struct {
	net.Conn
	Info string
}

PipedConn is an implementation of the net.Conn interface for piped two connection.

func CreatePipedConn

func CreatePipedConn(info ...string) (a, b *PipedConn)

CreatePipedConn will return two piped connection.

func (*PipedConn) String

func (p *PipedConn) String() string

type Pool

type Pool struct {
	Name    string
	Dialers []Dialer
	Webs    map[string]http.Handler
	// contains filtered or unexported fields
}

Pool is the set of Dialer

func NewPool

func NewPool(name string) (pool *Pool)

NewPool will return new Pool

func (*Pool) AddDialer

func (p *Pool) AddDialer(dialers ...Dialer) (err error)

AddDialer will append dialer which is bootstraped to pool

func (*Pool) Bootstrap

func (p *Pool) Bootstrap(options xmap.M) error

Bootstrap will bootstrap all supported dialer

func (*Pool) Dial

func (p *Pool) Dial(channel Channel, sid uint64, uri string, pipe io.ReadWriteCloser) (r Conn, err error)

Dial the uri by dialer poo

func (*Pool) Shutdown

func (p *Pool) Shutdown() (err error)

Shutdown will shutdown all dialer

type SchemaDialer

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

SchemaDialer is an implementation of the Dialer interface for dial tcp connections.

func NewSchemaDialer

func NewSchemaDialer() *SchemaDialer

NewSchemaDialer will return new SchemaDialer

func (*SchemaDialer) Bootstrap

func (t *SchemaDialer) Bootstrap(options xmap.M) error

Bootstrap the dialer.

func (*SchemaDialer) Dial

func (t *SchemaDialer) Dial(channel Channel, sid uint64, uri string, pipe io.ReadWriteCloser) (raw Conn, err error)

Dial one connection by uri

func (*SchemaDialer) Matched

func (t *SchemaDialer) Matched(uri string) bool

Matched will return whether the uri is invalid tcp uri.

func (*SchemaDialer) Name

func (t *SchemaDialer) Name() string

Name will return dialer name

func (*SchemaDialer) Options

func (t *SchemaDialer) Options() xmap.M

Options is options getter

func (*SchemaDialer) Shutdown

func (t *SchemaDialer) Shutdown() (err error)

Shutdown will shutdown dial

func (*SchemaDialer) String

func (t *SchemaDialer) String() string

type SocksProxyAddressPooler

type SocksProxyAddressPooler interface {
	//Get will return the proxy server address
	Get(uri string) (address string, err error)
	//Done will mark one address is free
	Done(address, uri string, err error)
}

SocksProxyAddressPooler is an interface to handler proxy server address get/set

type SocksProxyDialer

type SocksProxyDialer struct {
	ID     string
	Pooler SocksProxyAddressPooler
	// contains filtered or unexported fields
}

SocksProxyDialer is an implementation of the Dialer interface for dial by socks proxy.

func NewSocksProxyDialer

func NewSocksProxyDialer() *SocksProxyDialer

NewSocksProxyDialer will return new SocksProxyDialer

func (*SocksProxyDialer) Bootstrap

func (s *SocksProxyDialer) Bootstrap(options xmap.M) (err error)

Bootstrap the dialer.

func (*SocksProxyDialer) Dial

func (s *SocksProxyDialer) Dial(channel Channel, sid uint64, uri string, pipe io.ReadWriteCloser) (raw Conn, err error)

Dial one connection by uri

func (*SocksProxyDialer) Matched

func (s *SocksProxyDialer) Matched(uri string) bool

Matched will return whether the uri is invalid tcp uri.

func (*SocksProxyDialer) Name

func (s *SocksProxyDialer) Name() string

Name will return dialer name

func (*SocksProxyDialer) Options

func (s *SocksProxyDialer) Options() xmap.M

Options is options getter

func (*SocksProxyDialer) Shutdown

func (s *SocksProxyDialer) Shutdown() (err error)

Shutdown will shutdown dial

func (*SocksProxyDialer) String

func (s *SocksProxyDialer) String() string

type Statable

type Statable interface {
	State(args ...interface{}) xmap.M
}

Statable is interface for get current state.

type StateBuffer

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

StateBuffer is an io.ReadWriteCloser by read from bytes.Buffer and write discard

func NewStateBuffer

func NewStateBuffer(alias string, buf *bytes.Buffer) *StateBuffer

NewStateBuffer is the default creator by buffer.

func (*StateBuffer) Close

func (s *StateBuffer) Close() (err error)

Close is impl to io.Closer

func (*StateBuffer) Read

func (s *StateBuffer) Read(p []byte) (n int, err error)

func (*StateBuffer) String

func (s *StateBuffer) String() string

func (*StateBuffer) Write

func (s *StateBuffer) Write(p []byte) (n int, err error)

type StateDialer

type StateDialer struct {
	Alias string
	State Statable
	// contains filtered or unexported fields
}

StateDialer is an impl of dialer.Dialer for get router status

func NewStateDialer

func NewStateDialer(alias string, s Statable) *StateDialer

NewStateDialer is the default creator by router.

func (*StateDialer) Bootstrap

func (s *StateDialer) Bootstrap(options xmap.M) error

Bootstrap the dialer by configure

func (*StateDialer) Dial

func (s *StateDialer) Dial(channel Channel, sid uint64, uri string, raw io.ReadWriteCloser) (conn Conn, err error)

Dial raw connection

func (*StateDialer) Matched

func (s *StateDialer) Matched(uri string) bool

Matched return if uri is supported for this dialer.

func (*StateDialer) Name

func (s *StateDialer) Name() string

Name return dialer name.s

func (*StateDialer) Options

func (s *StateDialer) Options() xmap.M

Options return the current configure of dialer.

func (*StateDialer) Shutdown

func (s *StateDialer) Shutdown() (err error)

Shutdown will shutdown dial

type StringAddressPooler

type StringAddressPooler string

StringAddressPooler is an implementation of the SocksProxyAddressPooler interface for one string address.

func (StringAddressPooler) Done

func (s StringAddressPooler) Done(address, uri string, err error)

Done will mark one address is fress

func (StringAddressPooler) Get

func (s StringAddressPooler) Get(uri string) (address string, err error)

Get will return the proxy server address

type TCPDialer

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

TCPDialer is an implementation of the Dialer interface for dial tcp connections.

func NewTCPDialer

func NewTCPDialer() *TCPDialer

NewTCPDialer will return new TCPDialer

func (*TCPDialer) Bootstrap

func (t *TCPDialer) Bootstrap(options xmap.M) error

Bootstrap the dialer.

func (*TCPDialer) Dial

func (t *TCPDialer) Dial(channel Channel, sid uint64, uri string, pipe io.ReadWriteCloser) (raw Conn, err error)

Dial one connection by uri

func (*TCPDialer) Matched

func (t *TCPDialer) Matched(uri string) bool

Matched will return whether the uri is invalid tcp uri.

func (*TCPDialer) Name

func (t *TCPDialer) Name() string

Name will return dialer name

func (*TCPDialer) Options

func (t *TCPDialer) Options() xmap.M

Options is options getter

func (*TCPDialer) Shutdown

func (t *TCPDialer) Shutdown() (err error)

Shutdown will shutdown dial

func (*TCPDialer) String

func (t *TCPDialer) String() string

type WebDialer

type WebDialer struct {
	Handler http.Handler
	// contains filtered or unexported fields
}

WebDialer is an implementation of the Dialer interface for dial to web server

func NewWebDialer

func NewWebDialer(host string, handler http.Handler) (dialer *WebDialer)

NewWebDialer will return new WebDialer

func (*WebDialer) Accept

func (web *WebDialer) Accept() (conn net.Conn, err error)

Accept one connection to process web server.

func (*WebDialer) Addr

func (web *WebDialer) Addr() net.Addr

Addr return the web dialer address, it always return dialer

func (*WebDialer) Bootstrap

func (web *WebDialer) Bootstrap(options xmap.M) error

Bootstrap the web dialer

func (*WebDialer) Close

func (web *WebDialer) Close() error

Close is not used

func (*WebDialer) Dial

func (web *WebDialer) Dial(channel Channel, sid uint64, uri string, pipe io.ReadWriteCloser) (raw Conn, err error)

Dial to web server

func (*WebDialer) FindChannelByRequest

func (web *WebDialer) FindChannelByRequest(req *http.Request) (channel Channel, err error)

FindConnByRequest will find connection by id

func (*WebDialer) FindConnByID

func (web *WebDialer) FindConnByID(sid string) (conn *WebDialerConn, err error)

FindConnByID will find connection by id

func (*WebDialer) FindConnByRequest

func (web *WebDialer) FindConnByRequest(req *http.Request) (conn *WebDialerConn, err error)

FindConnByRequest will find connection by id

func (*WebDialer) Matched

func (web *WebDialer) Matched(uri string) bool

Matched will return whether the uri is a invalid uri

func (*WebDialer) Name

func (web *WebDialer) Name() string

Name will return dialer name

func (*WebDialer) Network

func (web *WebDialer) Network() string

Network return "tcp"

func (*WebDialer) Options

func (web *WebDialer) Options() xmap.M

Options is options getter

func (*WebDialer) Shutdown

func (web *WebDialer) Shutdown() error

Shutdown the web dialer

func (*WebDialer) String

func (web *WebDialer) String() string

type WebDialerAddr

type WebDialerAddr struct {
	Net  string
	Info string
}

WebDialerAddr is net.Addr implement

func NewWebDialerAddr

func NewWebDialerAddr(net, info string) (addr *WebDialerAddr)

NewWebDialerAddr will return new web dialer address

func (*WebDialerAddr) Network

func (w *WebDialerAddr) Network() string

Network return WebDialerConn

func (*WebDialerAddr) String

func (w *WebDialerAddr) String() string

String will info

type WebDialerConn

type WebDialerConn struct {
	*PipedConn //the piped connection
	Channel    Channel
	SID        uint64 //session id
	URI        string //target uri
}

WebDialerConn is an implementation of the net.Conn interface for pipe WebDialerConn to raw connection.

func PipeWebDialerConn

func PipeWebDialerConn(channel Channel, sid uint64, uri string) (conn *WebDialerConn, raw io.ReadWriteCloser, err error)

PipeWebDialerConn will return new WebDialerConn and piped raw connection.

func (*WebDialerConn) LocalAddr

func (w *WebDialerConn) LocalAddr() net.Addr

LocalAddr return self

func (*WebDialerConn) Network

func (w *WebDialerConn) Network() string

Network return WebDialerConn

func (*WebDialerConn) RemoteAddr

func (w *WebDialerConn) RemoteAddr() net.Addr

RemoteAddr return self

func (*WebDialerConn) String

func (w *WebDialerConn) String() string

String will info

type WebdavFileHandler

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

WebdavFileHandler is an implementation of the http.Handler interface for handling web GET/DAV

func NewWebdavFileHandler

func NewWebdavFileHandler(dir string) *WebdavFileHandler

NewWebdavFileHandler will return new WebdavHandler

func (*WebdavFileHandler) ServeHTTP

func (w *WebdavFileHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request)

type WebdavHandler

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

WebdavHandler is webdav handler

func NewWebdavHandler

func NewWebdavHandler(dirs xmap.M) (handler *WebdavHandler)

NewWebdavHandler will return new WebdavHandler

func (*WebdavHandler) ServeHTTP

func (web *WebdavHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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