Documentation
¶
Overview ¶
Package bsck provider tcp socket proxy router
the supported router is client->(slaver->master->slaver)*-server,
the channel of slaver to master can be multi physical tcp connect by different router
Index ¶
- Constants
- Variables
- func DebugLog(format string, args ...interface{})
- func ErrorLog(format string, args ...interface{})
- func InfoLog(format string, args ...interface{})
- func WarnLog(format string, args ...interface{})
- type AuthOption
- type Channel
- type ChannelOption
- type Codable
- type Conn
- type ConnectedWaiter
- type DialRawF
- type Forward
- func (f *Forward) AddForward(loc, uri string) (err error)
- func (f *Forward) FindForward(name string) (uri ForwardUri)
- func (f *Forward) HostForwardF(w http.ResponseWriter, req *http.Request)
- func (f *Forward) ProcName(name string, w http.ResponseWriter, req *http.Request)
- func (f *Forward) ProcRouter(router ForwardUri, w http.ResponseWriter, req *http.Request)
- func (f *Forward) ProcWebSubsH(w http.ResponseWriter, req *http.Request)
- func (f *Forward) RemoveForward(name string) (err error)
- type ForwardEntry
- type ForwardUri
- type Handler
- type InfoRWC
- type NormalAcessHandler
- func (n *NormalAcessHandler) DialRaw(sid uint64, uri string) (raw Conn, err error)
- func (n *NormalAcessHandler) OnConnClose(conn Conn) (err error)
- func (n *NormalAcessHandler) OnConnDialURI(channel Conn, conn string, parts []string) (err error)
- func (n *NormalAcessHandler) OnConnLogin(channel Conn, args string) (name string, index int, err error)
- type PendingConn
- type Proxy
- func (p *Proxy) Close() (err error)
- func (p *Proxy) DialRaw(sid uint64, uri string) (raw Conn, err error)
- func (p *Proxy) ListenMaster(addr string) (err error)
- func (p *Proxy) Login(option *ChannelOption) (channel *Channel, err error)
- func (p *Proxy) LoginChannel(reconnect bool, channels ...*ChannelOption) (err error)
- func (p *Proxy) OnConnClose(conn Conn) (err error)
- func (p *Proxy) OnConnDialURI(channel Conn, conn string, parts []string) (err error)
- func (p *Proxy) OnConnLogin(channel Conn, args string) (name string, index int, err error)
- func (p *Proxy) StartForward(name string, listen *url.URL, router string) (listener net.Listener, err error)
- func (p *Proxy) StopForward(name string) (err error)
- type ProxyHandler
- type RawConn
- func (r *RawConn) Close() (err error)
- func (r *RawConn) Context() interface{}
- func (r *RawConn) ID() uint64
- func (r *RawConn) Index() int
- func (r *RawConn) Name() string
- func (r *RawConn) Read(b []byte) (n int, err error)
- func (r *RawConn) ReadFrame() (frame []byte, err error)
- func (r *RawConn) Ready()
- func (r *RawConn) SetContext(v interface{})
- func (r *RawConn) SetReadTimeout(timeout time.Duration)
- func (r *RawConn) SetTimeout(timeout time.Duration)
- func (r *RawConn) SetWriteTimeout(timeout time.Duration)
- func (r *RawConn) String() string
- func (r *RawConn) Type() int
- func (r *RawConn) Wait() bool
- func (r *RawConn) Write(p []byte) (n int, err error)
- func (r *RawConn) WriteFrame(buffer []byte) (n int, err error)
- type RawDialer
- type Router
- func (r *Router) Accept(raw frame.ReadWriteCloser)
- func (r *Router) Bind(src Conn, srcSid uint64, dst Conn, dstSid uint64)
- func (r *Router) Close() (err error)
- func (r *Router) Dial(uri string, raw io.ReadWriteCloser) (sid uint64, err error)
- func (r *Router) DialConn(uri string, raw io.ReadWriteCloser) (sid uint64, conn *RawConn, err error)
- func (r *Router) JoinConn(conn frame.ReadWriteCloser, index int, args interface{}) (channel *Channel, err error)
- func (r *Router) Register(channel Conn)
- func (r *Router) SelectChannel(name string) (dst Conn, err error)
- func (r *Router) StartHeartbeat()
- func (r *Router) State() (state xmap.M)
- func (r *Router) SyncDial(uri string, raw io.ReadWriteCloser) (sid uint64, err error)
- func (r *Router) UniqueSid() (sid uint64)
- type SocksProxy
- type TableRouter
- type WaitReadWriteCloser
Constants ¶
const ( //CmdLogin is the command of login to master CmdLogin = 10 //CmdLoginBack is the command of login return from master CmdLoginBack = 11 //CmdDial is the command of tcp dial by router CmdDial = 100 //CmdDialBack is the command of tcp dial back from master/slaver CmdDialBack = 101 //CmdData is the command of transfter tcp data CmdData = 110 //CmdClosed is the command of tcp closed. CmdClosed = 120 //CmdHeartbeat is the command of heartbeat on slaver/master CmdHeartbeat = 130 )
const ( //ConnTypeRaw is the type of raw connection ConnTypeRaw = 100 //ConnTypeChannel is the type of channel connection ConnTypeChannel = 200 )
const ( SocksUriTypeNormal = 0 SocksUriTypeBS = 1 )
Variables ¶
var Log = log.New(os.Stdout, "", log.Ldate|log.Lmicroseconds|log.Lshortfile)
Log is the bsck package default log
var LogLevel int = 3
LogLevel is log leveo config
var ShowLog = 0
ShowLog will show more log.
Functions ¶
Types ¶
type AuthOption ¶
type AuthOption struct {
//the channel index
Index int `json:"index"`
//the chnnale name
Name string `json:"name"`
//the auth token
Token string `json:"token"`
}
AuthOption is a pojo struct to login auth.
type Channel ¶
type Channel struct {
frame.ReadWriteCloser //the raw connection
Heartbeat int64
// contains filtered or unexported fields
}
Channel is an implementation of the Conn interface for channel network connections.
func (*Channel) SetContext ¶
func (c *Channel) SetContext(v interface{})
SetContext is conn context setter
type ChannelOption ¶
type ChannelOption struct {
//enable
Enable bool `json:"enable"`
//the auth token
Token string `json:"token"`
//local tcp address to connection master
Local string `json:"local"`
//the remote address to login
Remote string `json:"remote"`
//the channel index
Index int `json:"index"`
}
ChannelOption is a pojo struct for adding channel to Router
type Conn ¶
type Conn interface {
//the basic ReadWriteCloser
frame.ReadWriteCloser
//the connection id
ID() uint64
//the channel name
Name() string
//the channel index.
Index() int
//the connection type
Type() int
//conn context getter
Context() interface{}
//conn context setter
SetContext(v interface{})
}
Conn is the interface that wraps the connection will be running on Router.
ID is the unique of connection ¶
Name is the channel name, it will be used when join current connection to channel ¶
Index is the channel index, it will be used when join current connection to channel.
Type is the connection type by ConnTypeRaw/ConnTypeChannel
type ConnectedWaiter ¶
type ConnectedWaiter interface {
Wait() bool
Ready()
}
ConnectedWaiter interface for connected waiter
type Forward ¶
type Forward struct {
WebSuffix string
WebAuth string
Dialer func(uri string, raw io.ReadWriteCloser) (sid uint64, err error)
// contains filtered or unexported fields
}
func NewForward ¶
func NewForward() *Forward
func (*Forward) AddForward ¶
AddForward by local uri and remote uri
func (*Forward) FindForward ¶
func (f *Forward) FindForward(name string) (uri ForwardUri)
FindForward will return the forward
func (*Forward) HostForwardF ¶
func (f *Forward) HostForwardF(w http.ResponseWriter, req *http.Request)
func (*Forward) ProcRouter ¶
func (f *Forward) ProcRouter(router ForwardUri, w http.ResponseWriter, req *http.Request)
func (*Forward) ProcWebSubsH ¶
func (f *Forward) ProcWebSubsH(w http.ResponseWriter, req *http.Request)
func (*Forward) RemoveForward ¶
RemoveForward by alias name
type ForwardUri ¶
type ForwardUri []string
func (ForwardUri) String ¶
func (f ForwardUri) String() string
type Handler ¶
type Handler interface {
//dial raw connection
DialRaw(sid uint64, uri string) (raw Conn, err error)
//on connection dial uri
OnConnDialURI(channel Conn, conn string, parts []string) (err error)
//on connection login
OnConnLogin(channel Conn, args string) (name string, index int, err error)
//on connection close
OnConnClose(raw Conn) error
}
Handler is the interface that wraps the handler of Router.
type InfoRWC ¶
type InfoRWC struct {
frame.ReadWriteCloser
Info string
}
InfoRWC is external ReadWriteCloser to get info to String
func NewInfoRWC ¶
func NewInfoRWC(raw frame.ReadWriteCloser, info string) *InfoRWC
NewInfoRWC will return new nfoRWC
type NormalAcessHandler ¶
type NormalAcessHandler struct {
Name string //the access name
LoginAccess map[string]string //the access control
DialAccess [][]string
Dialer RawDialer
// contains filtered or unexported fields
}
NormalAcessHandler is normal access handler for proxy handler
func NewNormalAcessHandler ¶
func NewNormalAcessHandler(name string, dialer RawDialer) (handler *NormalAcessHandler)
NewNormalAcessHandler will return new handler
func (*NormalAcessHandler) DialRaw ¶
func (n *NormalAcessHandler) DialRaw(sid uint64, uri string) (raw Conn, err error)
DialRaw is proxy handler to dail remove
func (*NormalAcessHandler) OnConnClose ¶
func (n *NormalAcessHandler) OnConnClose(conn Conn) (err error)
OnConnClose is proxy handler when connection is closed
func (*NormalAcessHandler) OnConnDialURI ¶
func (n *NormalAcessHandler) OnConnDialURI(channel Conn, conn string, parts []string) (err error)
OnConnDialURI is proxy handler to handle dial uri
func (*NormalAcessHandler) OnConnLogin ¶
func (n *NormalAcessHandler) OnConnLogin(channel Conn, args string) (name string, index int, err error)
OnConnLogin is proxy handler to handle login
type PendingConn ¶
type PendingConn struct {
Raw io.ReadWriteCloser
// contains filtered or unexported fields
}
PendingConn is an implementation of io.ReadWriteCloser
func NewPendingConn ¶
func NewPendingConn(raw io.ReadWriteCloser) (conn *PendingConn)
NewPendingConn will return new endingConn
type Proxy ¶
type Proxy struct {
*Router //the router
Running bool //proxy is running.
ReconnectDelay time.Duration //reconnect delay
Cert string //the tls cert
Key string //the tls key
Handler ProxyHandler
// contains filtered or unexported fields
}
Proxy is an implementation of proxy router
func (*Proxy) ListenMaster ¶
ListenMaster will listen master router on address
func (*Proxy) Login ¶
func (p *Proxy) Login(option *ChannelOption) (channel *Channel, err error)
Login will add channel by local address, master address, auth token, channel index.
func (*Proxy) LoginChannel ¶
func (p *Proxy) LoginChannel(reconnect bool, channels ...*ChannelOption) (err error)
LoginChannel will login all channel by options.
func (*Proxy) OnConnClose ¶
OnConnClose will be called when connection is closed
func (*Proxy) OnConnDialURI ¶
OnConnDialURI is on connection dial uri
func (*Proxy) OnConnLogin ¶
OnConnLogin is on connection login
func (*Proxy) StartForward ¶
func (p *Proxy) StartForward(name string, listen *url.URL, router string) (listener net.Listener, err error)
StartForward will forward address to uri
func (*Proxy) StopForward ¶
StopForward will forward address to uri
type ProxyHandler ¶
type ProxyHandler interface {
//DialRaw will dial raw connection by uri
DialRaw(sid uint64, uri string) (raw Conn, err error)
//OnConnLogin is event on connection login
OnConnLogin(channel Conn, args string) (name string, index int, err error)
//OnConnDialURI is event on connection dial to remote
OnConnDialURI(channel Conn, conn string, parts []string) (err error)
//OnConnLogin is event on connection close
OnConnClose(conn Conn) (err error)
}
ProxyHandler is proxy handler
type RawConn ¶
type RawConn struct {
//the raw connection
io.ReadWriteCloser
// contains filtered or unexported fields
}
RawConn is an implementation of the Conn interface for raw network connections.
func NewRawConn ¶
NewRawConn returns a new RawConn by raw connection/session id/uri
func (*RawConn) SetContext ¶
func (r *RawConn) SetContext(v interface{})
SetContext is conn context setter
func (*RawConn) SetReadTimeout ¶
SetReadTimeout is read timeout setter
func (*RawConn) SetTimeout ¶
SetTimeout is read/write timeout setter
func (*RawConn) SetWriteTimeout ¶
SetWriteTimeout is write timeout setter
type Router ¶
type Router struct {
Name string //current router name
BufferSize int //buffer size of connection runner
Heartbeat time.Duration //the delay of heartbeat
Handler Handler //the router handler
// contains filtered or unexported fields
}
Router is an implementation of the router control
func (*Router) Accept ¶
func (r *Router) Accept(raw frame.ReadWriteCloser)
Accept one raw connecton as channel, it will auth the raw connecton by ACL.
func (*Router) Dial ¶
Dial to remote by uri and bind channel to raw connection.
return the session id
func (*Router) DialConn ¶
func (r *Router) DialConn(uri string, raw io.ReadWriteCloser) (sid uint64, conn *RawConn, err error)
DialConn will dial to remote by uri and bind channel to raw connection and return raw connection
func (*Router) JoinConn ¶
func (r *Router) JoinConn(conn frame.ReadWriteCloser, index int, args interface{}) (channel *Channel, err error)
JoinConn will add channel by the connected connection
func (*Router) SelectChannel ¶
SelectChannel will pick one channel by name.
func (*Router) StartHeartbeat ¶
func (r *Router) StartHeartbeat()
StartHeartbeat will start the hearbeat on slaver/master
type SocksProxy ¶
type SocksProxy struct {
net.Listener
Dialer func(utype int, uri string, raw io.ReadWriteCloser) (sid uint64, err error)
}
SocksProxy is an implementation of socks5 proxy
func NewSocksProxy ¶
func NewSocksProxy() (socks *SocksProxy)
NewSocksProxy will return new SocksProxy
type TableRouter ¶
type TableRouter []interface{}
TableRouter is the router table item
func (TableRouter) Next ¶
func (t TableRouter) Next(conn Conn) (target Conn, rsid uint64)
Next will return next connection and session id
func (TableRouter) String ¶
func (t TableRouter) String() string
type WaitReadWriteCloser ¶
type WaitReadWriteCloser struct {
io.ReadWriteCloser
// contains filtered or unexported fields
}
func NewWaitReadWriteCloser ¶
func NewWaitReadWriteCloser(raw io.ReadWriteCloser) *WaitReadWriteCloser
func (*WaitReadWriteCloser) Close ¶
func (w *WaitReadWriteCloser) Close() (err error)
func (*WaitReadWriteCloser) String ¶
func (w *WaitReadWriteCloser) String() string
func (*WaitReadWriteCloser) Wait ¶
func (w *WaitReadWriteCloser) Wait()