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 BufferConn
- type Channel
- type ChannelOption
- type CmdReader
- 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 InfoRWC
- 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) (err error)
- func (p *Proxy) LoginChannel(reconnect bool, channels ...*ChannelOption) (err error)
- func (p *Proxy) OnConnClose(conn Conn) 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 RawConn
- func (r *RawConn) Close() (err error)
- 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) ReadCmd(b []byte) (n uint32, err error)
- func (r *RawConn) Ready()
- 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)
- type Router
- func (r *Router) Accept(raw io.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 io.ReadWriteCloser, option *ChannelOption) (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 util.Map)
- func (r *Router) SyncDial(uri string, raw io.ReadWriteCloser) (sid uint64, err error)
- func (r *Router) UniqueSid() (sid uint64)
- type RouterHandler
- 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 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 BufferConn ¶
type BufferConn struct {
*bufio.Reader //the buffer reader.
io.Writer //the writer.
Raw io.ReadWriteCloser //the raw connection
}
BufferConn is an implementation of buffer connecton
func NewBufferConn ¶
func NewBufferConn(raw io.ReadWriteCloser, bufferSize int) (buf *BufferConn)
NewBufferConn will return new BufferConn
func (*BufferConn) String ¶
func (b *BufferConn) String() string
type Channel ¶
type Channel struct {
io.ReadWriteCloser //the raw connection
Option *ChannelOption //the option
Heartbeat int64
// contains filtered or unexported fields
}
Channel is an implementation of the Conn interface for channel network connections.
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 CmdReader ¶
CmdReader is the interface that wraps the basic ReadCmd method.
ReadCmd will read one command to b buffer, return the command length ¶
the command mode is length(4 byte)|data
type Conn ¶
type Conn interface {
//the basic ReadWriteCloser
io.ReadWriteCloser
//the connection id
ID() uint64
//the channel name
Name() string
//the channel index.
Index() int
//the connection type
Type() int
}
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()
}
type DialRawF ¶
DialRawF is a function type to dial raw connection.
func (DialRawF) OnConnClose ¶
OnConnClose will be called when connection is closed
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 InfoRWC ¶
type InfoRWC struct {
io.ReadWriteCloser
Info string
}
InfoRWC is external ReadWriteCloser to get info to String
func NewInfoRWC ¶
func NewInfoRWC(raw io.ReadWriteCloser, info string) *InfoRWC
NewInfoRWC will return new nfoRWC
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 RouterHandler
// 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) (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) 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 RawConn ¶
type RawConn struct {
//the raw connection
Raw io.ReadWriteCloser
// contains filtered or unexported fields
}
RawConn is an implementation of the Conn interface for raw network connections.
func NewRawConn ¶
func NewRawConn(raw io.ReadWriteCloser, sid uint64, uri string) (conn *RawConn)
NewRawConn returns a new RawConn by raw connection/session id/uri
type Router ¶
type Router struct {
Name string //current router name
BufferSize uint32 //buffer size of connection runner
ACL map[string]string //the access control
Heartbeat time.Duration //the delay of heartbeat
Handler RouterHandler //the router handler
// contains filtered or unexported fields
}
Router is an implementation of the router control
func (*Router) Accept ¶
func (r *Router) Accept(raw io.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) JoinConn ¶
func (r *Router) JoinConn(conn io.ReadWriteCloser, option *ChannelOption) (err error)
JoinConn will add channel by the connected connection, auth token, channel index
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 RouterHandler ¶
type RouterHandler interface {
//dial raw connection
DialRaw(sid uint64, uri string) (raw Conn, err error)
//on connection close
OnConnClose(conn Conn) error
}
RouterHandler is the interface that wraps the handler of Router.
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()