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 EncodeWebURI(format string, args ...interface{}) string
- func ErrorLog(format string, args ...interface{})
- func InfoLog(format string, args ...interface{})
- func SetLogLevel(l int)
- func WarnLog(format string, args ...interface{})
- type Channel
- type Config
- type Conn
- type Console
- func (c *Console) Close() (err error)
- func (c *Console) Dial(uri string) (conn io.ReadWriteCloser, err error)
- func (c *Console) DialPiper(uri string, bufferSize int) (raw xio.Piper, err error)
- func (c *Console) Ping(uri string, delay time.Duration, max uint64) (err error)
- func (c *Console) PrintState(uri, query string) (err error)
- func (c *Console) Proxy(uri string, process func(listener net.Listener) (err error)) (err error)
- func (c *Console) ProxyExec(uri string, stdin io.Reader, stdout, stderr io.Writer, ...) (err error)
- func (c *Console) ProxyProcess(uri string, stdin, stdout, stderr *os.File, ...) (err error)
- func (c *Console) ProxySSH(uri string, stdin io.Reader, stdout, stderr io.Writer, ...) (err error)
- func (c *Console) Redirect(uri string, reader io.Reader, writer io.Writer, closer io.Closer) (err error)
- func (c *Console) StartForward(loc string, uri string) (listener net.Listener, err error)
- func (c *Console) StartProxy(loc, uri string) (server *proxy.Server, listener net.Listener, err error)
- 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 ForwardFinder
- type ForwardFinderF
- type ForwardUri
- type Handler
- type Hosts
- type InfoRWC
- type NoneHandler
- func (n *NoneHandler) DialRaw(channel Conn, sid uint64, uri string) (raw Conn, err error)
- func (n *NoneHandler) OnConnClose(conn Conn) (err error)
- func (n *NoneHandler) OnConnDialURI(channel Conn, conn string, parts []string) (err error)
- func (n *NoneHandler) OnConnJoin(channel *Channel, option, result xmap.M) (err error)
- func (n *NoneHandler) OnConnLogin(channel Conn, args string) (name string, index int, result xmap.M, err error)
- type NormalAcessHandler
- func (n *NormalAcessHandler) DialRaw(channel Conn, 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) OnConnJoin(channel *Channel, option, result xmap.M) (err error)
- func (n *NormalAcessHandler) OnConnLogin(channel Conn, args string) (name string, index int, result xmap.M, err error)
- type Proxy
- func (p *Proxy) AcceptWsConn(conn *websocket.Conn)
- func (p *Proxy) Close() (err error)
- func (p *Proxy) DialRaw(channel Conn, sid uint64, uri string) (raw Conn, err error)
- func (p *Proxy) ListenMaster(addr string) (err error)
- func (p *Proxy) Login(option xmap.M) (channel *Channel, result xmap.M, err error)
- func (p *Proxy) LoginChannel(reconnect bool, channels ...xmap.M) (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, result xmap.M, 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() xmap.M
- 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) ReadFrom(reader io.Reader) (w int64, err error)
- func (r *RawConn) Ready(failed error, next func(err error))
- 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() error
- func (r *RawConn) Write(p []byte) (n int, err error)
- func (r *RawConn) WriteFrame(buffer []byte) (n int, err error)
- func (r *RawConn) WriteTo(w io.Writer) (n int64, err error)
- type RawDialer
- type RawValuable
- type ReadyWaiter
- type Router
- func (r *Router) Accept(raw frame.ReadWriteCloser)
- func (r *Router) AcceptSync(raw frame.ReadWriteCloser)
- func (r *Router) Close() (err error)
- func (r *Router) CloseChannel(name string) (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 Conn, err error)
- func (r *Router) DialPiper(uri string, bufferSize int) (raw xio.Piper, err error)
- func (r *Router) JoinConn(conn frame.ReadWriteCloser, index int, args interface{}) (channel *Channel, result xmap.M, 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(args ...interface{}) (state xmap.M)
- func (r *Router) StateH(w http.ResponseWriter, req *http.Request)
- func (r *Router) SyncDial(uri string, raw io.ReadWriteCloser) (sid uint64, err error)
- func (r *Router) UniqueSid() (sid uint64)
- type Service
- func (s *Service) AddForward(loc, uri string) (err error)
- func (s *Service) DialAll(uris string, raw io.ReadWriteCloser, sync bool) (sid uint64, err error)
- func (s *Service) DialNet(network, addr string) (conn net.Conn, err error)
- func (s *Service) DialPiper(uri string, bufferSize int) (raw xio.Piper, err error)
- func (s *Service) DialRaw(channel Conn, sid uint64, uri string) (conn Conn, err error)
- func (s *Service) DialSSH(uri string, config *ssh.ClientConfig) (client *ssh.Client, err error)
- func (s *Service) ReloadConfig() (err error)
- func (s *Service) RemoveForward(loc string) (err error)
- func (s *Service) Start() (err error)
- func (s *Service) Stop() (err error)
- func (s *Service) SyncDialAll(uris string, raw io.ReadWriteCloser) (sid uint64, err error)
- type TableRouter
- type WaitReadWriteCloser
- type WaitedPiper
- func (r *WaitedPiper) Close() (err error)
- func (r *WaitedPiper) PipeConn(conn io.ReadWriteCloser, target string) (err error)
- func (r *WaitedPiper) Read(p []byte) (n int, err error)
- func (r *WaitedPiper) Ready(failed error, next func(err error))
- func (r *WaitedPiper) String() string
- func (r *WaitedPiper) Wait() error
- func (r *WaitedPiper) Write(p []byte) (n int, err error)
- type Web
Constants ¶
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 )
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 RDPTemplate = `` /* 499-byte string literal not displayed */
RDPTemplate is the template string for rdp file
const VNCTemplate = `
FriendlyName=%v
FullScreen=1
Host=%v
Password=%v
RelativePtr=0
Scaling=100%%
`
VNCTemplate is the template string for vnc file
const Version = "2.0.0"
Version is bsrouter version
Variables ¶
var ErrForwardNotExist = fmt.Errorf("%v", "forward not exist")
ErrForwardNotExist is forward is not exist error
var LogLevel = LogLevelInfo
LogLevel is log leveo config
var Logger = log.New(os.Stdout, "", log.Ldate|log.Lmicroseconds|log.Lshortfile)
Logger is the bsck package default log
var ShowLog = 0
ShowLog will show more log.
Functions ¶
func EncodeWebURI ¶
EncodeWebURI will replace string in () as base64 encoding
Types ¶
type Channel ¶
type Channel struct {
frame.ReadWriteCloser //the raw connection
Heartbeat time.Time
// contains filtered or unexported fields
}
Channel is an implementation of the Conn interface for channel network connections.
type Config ¶
type Config struct {
Name string `json:"name"`
Dir string `json:"dir"`
Cert string `json:"cert"`
Key string `json:"key"`
Listen string `json:"listen"`
ACL map[string]string `json:"acl"`
Access [][]string `json:"access"`
Console struct {
SOCKS string `json:"socks"`
WS string `json:"ws"`
} `json:"console"`
Web Web `json:"web"`
Log int `json:"log"`
Forwards map[string]string `json:"forwards"`
Channels []xmap.M `json:"channels"`
Dialer xmap.M `json:"dialer"`
Reconnect int64 `json:"reconnect"`
RDPDir string `json:"rdp_dir"`
VNCDir string `json:"vnc_dir"`
}
Config is struct for all configure
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() xmap.M
}
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 Console ¶
type Console struct {
Client *xhttp.Client
SlaverURI string
BufferSize int
Env []string
Hosts *Hosts //hosts to rewrite
// contains filtered or unexported fields
}
Console is node console to dial connection
func NewConsole ¶
NewConsole will return new Console
func NewConsoleByConfig ¶
func (*Console) Dial ¶
func (c *Console) Dial(uri string) (conn io.ReadWriteCloser, err error)
Dial will dial connection by uri
func (*Console) PrintState ¶
PrintState will print state from uri
func (*Console) ProxyExec ¶
func (c *Console) ProxyExec(uri string, stdin io.Reader, stdout, stderr io.Writer, prepare func(listener net.Listener) (env []string, runner string, args []string, err error)) (err error)
ProxyExec will exec command by runner and rewrite all tcp connection by console
func (*Console) ProxyProcess ¶
func (c *Console) ProxyProcess(uri string, stdin, stdout, stderr *os.File, prepare func(listener net.Listener) (env []string, runner string, args []string, err error)) (err error)
ProxyProcess will start process by runner and rewrite all tcp connection by console
func (*Console) ProxySSH ¶
func (c *Console) ProxySSH(uri string, stdin io.Reader, stdout, stderr io.Writer, proxyCommand, command string, args ...string) (err error)
ProxySSH will start ssh client command and connect to uri by proxy command.
it will try load the ssh key from slaver forwarding by bs-ssh-key, bs-ssh-key is forwarding to http server and return ssh key in body by uri argument.
func (*Console) Redirect ¶
func (c *Console) Redirect(uri string, reader io.Reader, writer io.Writer, closer io.Closer) (err error)
Redirect will redirect connection to reader/writer/closer
func (*Console) StartForward ¶
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 ForwardFinder ¶
ForwardFinder is forward finder
type ForwardFinderF ¶
ForwardFinderF is func implement ForwardFinder
func (ForwardFinderF) FindForward ¶
func (f ForwardFinderF) FindForward(uri string) (target string, err error)
FindForward is implement ForwardFinder
type ForwardUri ¶
type ForwardUri []string
func (ForwardUri) String ¶
func (f ForwardUri) String() string
type Handler ¶
type Handler interface {
//dial raw connection
DialRaw(channel Conn, 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, result xmap.M, 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
Raw interface{}
Info string
}
InfoRWC is external ReadWriteCloser to get info to String
func NewInfoRWC ¶
func NewInfoRWC(raw interface{}, rwc frame.ReadWriteCloser, info string) *InfoRWC
NewInfoRWC will return new nfoRWC
type NoneHandler ¶
type NoneHandler struct {
}
NoneHandler is proxy handler
func NewNoneHandler ¶
func NewNoneHandler() (handler *NoneHandler)
NewNoneHandler will return new NoneHandler
func (*NoneHandler) OnConnClose ¶
func (n *NoneHandler) OnConnClose(conn Conn) (err error)
OnConnClose is event on connection close
func (*NoneHandler) OnConnDialURI ¶
func (n *NoneHandler) OnConnDialURI(channel Conn, conn string, parts []string) (err error)
OnConnDialURI is event on connection dial to remote
func (*NoneHandler) OnConnJoin ¶
func (n *NoneHandler) OnConnJoin(channel *Channel, option, result xmap.M) (err error)
OnConnJoin is event on channel join
func (*NoneHandler) OnConnLogin ¶
func (n *NoneHandler) OnConnLogin(channel Conn, args string) (name string, index int, result xmap.M, err error)
OnConnLogin is event on connection login
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) 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) OnConnJoin ¶
func (n *NormalAcessHandler) OnConnJoin(channel *Channel, option, result xmap.M) (err error)
OnConnJoin is proxy handler when channel join
func (*NormalAcessHandler) OnConnLogin ¶
func (n *NormalAcessHandler) OnConnLogin(channel Conn, args string) (name string, index int, result xmap.M, err error)
OnConnLogin is proxy handler to handle login
type Proxy ¶
type Proxy struct {
*Router //the router
Running bool //proxy is running.
ReconnectDelay time.Duration //reconnect delay
Dir string //the work dir
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 NewProxy ¶
func NewProxy(name string, handler ProxyHandler) (proxy *Proxy)
NewProxy will return new Proxy by name
func (*Proxy) AcceptWsConn ¶
func (*Proxy) ListenMaster ¶
ListenMaster will listen master router on address
func (*Proxy) Login ¶
Login will add channel by local address, master address, auth token, channel index.
func (*Proxy) LoginChannel ¶
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 ¶
func (p *Proxy) OnConnLogin(channel Conn, args string) (name string, index int, result xmap.M, err error)
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(channel Conn, sid uint64, uri string) (raw Conn, err error)
//OnConnLogin is event on connection login
OnConnLogin(channel Conn, args string) (name string, index int, result xmap.M, err error)
//OnConnDialURI is event on connection dial to remote
OnConnDialURI(channel Conn, conn string, parts []string) (err error)
//OnConnClose is event on connection close
OnConnClose(conn Conn) (err error)
//OnConnJoin is event on channel join
OnConnJoin(channel *Channel, option, result xmap.M) (err error)
}
ProxyHandler is proxy handler
type RawConn ¶
type RawConn struct {
//the raw connection
*frame.BaseReadWriteCloser
Raw io.ReadWriteCloser
// contains filtered or unexported fields
}
RawConn is an implementation of the Conn interface for raw network connections.
func NewRawConn ¶
func NewRawConn(name string, raw io.ReadWriteCloser, bufferSize int, sid uint64, uri string) (conn *RawConn)
NewRawConn returns a new RawConn by raw connection/session id/uri
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
func (*RawConn) WriteFrame ¶
WriteFrame will write frame to raw
type RawValuable ¶
type RawValuable interface {
RawValue() interface{}
}
type ReadyWaiter ¶
ReadyWaiter interface for ready waiter
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 connection as channel, it will auth the raw connection by ACL.
func (*Router) AcceptSync ¶
func (r *Router) AcceptSync(raw frame.ReadWriteCloser)
Accept one raw connection as channel, and loop read it it will auth the raw connection by ACL.
func (*Router) CloseChannel ¶
CloseChannel will call close on all bond channle by name.
func (*Router) Dial ¶
Dial to remote by uri and bind channel to raw connection.
return the session id
func (*Router) DialConn ¶
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, result xmap.M, 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
func (*Router) StateH ¶
func (r *Router) StateH(w http.ResponseWriter, req *http.Request)
StateH return the current state of router
type Service ¶
type Service struct {
Name string
Node *Proxy
Console struct {
SOCKS *sproxy.Server
WS *wproxy.Server
}
Web net.Listener
Forward *Forward
Dialer *dialer.Pool
Handler ProxyHandler
Finder ForwardFinder
Config *Config
ConfigPath string
Client *xhttp.Client
Webs map[string]http.Handler
BufferSize int
OnReady func()
// contains filtered or unexported fields
}
Service is bound socket service
func (*Service) AddForward ¶
AddForward will add forward by local and remote
func (*Service) ReloadConfig ¶
ReloadConfig will check configure modify time and reload
func (*Service) RemoveForward ¶
RemoveForward will remove forward
func (*Service) SyncDialAll ¶
SyncDialAll will sync dial uri by raw
type TableRouter ¶
type TableRouter []interface{}
TableRouter is the router table item
func (TableRouter) Next ¶
func (t TableRouter) Next(conn Conn) (target Conn, sid 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()
type WaitedPiper ¶
type WaitedPiper struct {
Base io.ReadWriteCloser
// contains filtered or unexported fields
}
WaitedPiper is Waiter/Piper implement
func NewWaitedPiper ¶
func NewWaitedPiper() (piper *WaitedPiper)
NewWaitedPiper will return new WaitedPiper
func (*WaitedPiper) Close ¶
func (r *WaitedPiper) Close() (err error)
Close will close ready piper, it will lock when it is not ready
func (*WaitedPiper) PipeConn ¶
func (r *WaitedPiper) PipeConn(conn io.ReadWriteCloser, target string) (err error)
PipeConn will pipe connection, it must be called after Wait success, or panic
func (*WaitedPiper) Ready ¶
func (r *WaitedPiper) Ready(failed error, next func(err error))
Ready will set piper is ready, failed/next at lasted is not nil
func (*WaitedPiper) String ¶
func (r *WaitedPiper) String() string