Documentation ¶
Overview ¶
Package proxylite is a dynamic reverse proxy package for Go.
Index ¶
- Constants
- func AskFreePort(addr string) ([]uint32, error)
- func GenConnId(conn *net.Conn) uint64
- type AskFreePortReq
- type AskFreePortRsp
- type AskServiceReq
- type AskServiceRsp
- type Context
- func (ctx *Context) AbortTunnel() error
- func (ctx *Context) AbortUser() error
- func (ctx *Context) DataBuffer() []byte
- func (ctx *Context) GetValue(key interface{}) (interface{}, bool)
- func (ctx *Context) InnerLocalConn() net.Addr
- func (ctx *Context) InnerRemoteConn() net.Addr
- func (ctx *Context) PutValue(key, value interface{})
- func (ctx *Context) ServiceInfo() ServiceInfo
- func (ctx *Context) UserLocalAddress() net.Addr
- func (ctx *Context) UserRemoteAddress() net.Addr
- type ControlInfo
- type HookFunc
- type ProxyLiteClient
- func (c *ProxyLiteClient) ActiveServices() ([]ServiceInfo, error)
- func (c *ProxyLiteClient) AnyPort() (uint32, bool)
- func (c *ProxyLiteClient) AvailablePorts() ([]uint32, bool)
- func (c *ProxyLiteClient) GetRegisterEntryByName(name string) (*RegisterEntry, bool)
- func (c *ProxyLiteClient) GetRegisterEntryByPort(port int) (*RegisterEntry, bool)
- func (c *ProxyLiteClient) RegisterInnerService(info RegisterInfo, ctrl ControlInfo) (func(), chan struct{}, error)
- func (c *ProxyLiteClient) SetLogger(logger *log.Logger)
- type ProxyLiteServer
- func (s *ProxyLiteServer) AddPort(from, to int) bool
- func (s *ProxyLiteServer) OnForwardTunnelToUser(f HookFunc)
- func (s *ProxyLiteServer) OnForwardUserToTunnel(f HookFunc)
- func (s *ProxyLiteServer) OnTunnelCreated(f HookFunc)
- func (s *ProxyLiteServer) OnTunnelDestroyed(f HookFunc)
- func (s *ProxyLiteServer) OnUserComming(f HookFunc)
- func (s *ProxyLiteServer) OnUserLeaving(f HookFunc)
- func (s *ProxyLiteServer) Run(addr string) error
- func (s *ProxyLiteServer) SetLogger(logger *log.Logger)
- func (s *ProxyLiteServer) Stop() error
- type RegisterEntry
- type RegisterInfo
- type RegisterServiceReq
- type RegisterServiceRsp
- type ServiceInfo
Constants ¶
const ( TypeMsgUndefined = iota TypeMsgMalformed TypeAskFreePortReq TypeAskFreePortRsp TypeAskServiceReq TypeAskServiceRsp TypeRegisterServiceReq TypeRegisterServiceRsp TypeDataSegment = 64 )
const ( RegisterRspOK = iota RegisterRspPortNotAllowed RegisterRspPortOccupied RegisterRspServerError )
Variables ¶
This section is empty.
Functions ¶
func AskFreePort ¶
AskFreePort Ask available free port from proxy server with given address.
Types ¶
type AskFreePortRsp ¶
type AskFreePortRsp struct {
Ports []uint32
}
AskFreePortRsp Ask available free ports response
type AskServiceReq ¶
type AskServiceReq struct {
Prefix string
}
AskServiceReq Service discovery request
type AskServiceRsp ¶
type AskServiceRsp struct {
Services []ServiceInfo
}
AskServiceRsp Service discovery response
type Context ¶ added in v0.3.0
type Context struct {
// contains filtered or unexported fields
}
func (*Context) AbortTunnel ¶ added in v0.3.0
func (*Context) DataBuffer ¶ added in v0.3.0
func (*Context) InnerLocalConn ¶ added in v0.3.0
func (*Context) InnerRemoteConn ¶ added in v0.3.0
func (*Context) ServiceInfo ¶ added in v0.3.0
func (ctx *Context) ServiceInfo() ServiceInfo
func (*Context) UserLocalAddress ¶ added in v0.3.0
func (*Context) UserRemoteAddress ¶ added in v0.3.0
type ControlInfo ¶ added in v0.2.0
ControlInfo Register Controlling information
type ProxyLiteClient ¶
type ProxyLiteClient struct {
// contains filtered or unexported fields
}
ProxyLiteClient inner client that forwards traffic between inner service and proxy server server.
func NewProxyLiteClient ¶
func NewProxyLiteClient(serverAddr string) *ProxyLiteClient
NewProxyLiteClient Create a inner client binding with a proxy server.
func (*ProxyLiteClient) ActiveServices ¶
func (c *ProxyLiteClient) ActiveServices() ([]ServiceInfo, error)
ActiveServices Discover all active services from proxy server.
func (*ProxyLiteClient) AnyPort ¶
func (c *ProxyLiteClient) AnyPort() (uint32, bool)
AnyPort Get a random available port from proxy server.
func (*ProxyLiteClient) AvailablePorts ¶ added in v0.2.1
func (c *ProxyLiteClient) AvailablePorts() ([]uint32, bool)
availablePorts Get available ports from proxy server.
func (*ProxyLiteClient) GetRegisterEntryByName ¶
func (c *ProxyLiteClient) GetRegisterEntryByName(name string) (*RegisterEntry, bool)
GetRegisterEntryByName Get RegisterEntry
func (*ProxyLiteClient) GetRegisterEntryByPort ¶
func (c *ProxyLiteClient) GetRegisterEntryByPort(port int) (*RegisterEntry, bool)
GetRegisterEntryByPort Get RegisterEntry
func (*ProxyLiteClient) RegisterInnerService ¶
func (c *ProxyLiteClient) RegisterInnerService(info RegisterInfo, ctrl ControlInfo) (func(), chan struct{}, error)
RegisterInnerService Register inner server to proxy server's outer port.
func (*ProxyLiteClient) SetLogger ¶
func (c *ProxyLiteClient) SetLogger(logger *log.Logger)
SetLogger Set customized logrus logger for the inner client.
type ProxyLiteServer ¶
type ProxyLiteServer struct {
// contains filtered or unexported fields
}
ProxyLiteServer Public server that forwards traffic between user and inner client.
func NewProxyLiteServer ¶
func NewProxyLiteServer(portIntervals ...[2]int) *ProxyLiteServer
NewProxyLiteServer Create a Proxy server with available ports intervals.
func (*ProxyLiteServer) AddPort ¶
func (s *ProxyLiteServer) AddPort(from, to int) bool
AddPort Add available ports intervals for server. Return false if port is invalid.
func (*ProxyLiteServer) OnForwardTunnelToUser ¶ added in v0.3.0
func (s *ProxyLiteServer) OnForwardTunnelToUser(f HookFunc)
func (*ProxyLiteServer) OnForwardUserToTunnel ¶ added in v0.3.0
func (s *ProxyLiteServer) OnForwardUserToTunnel(f HookFunc)
func (*ProxyLiteServer) OnTunnelCreated ¶ added in v0.3.0
func (s *ProxyLiteServer) OnTunnelCreated(f HookFunc)
func (*ProxyLiteServer) OnTunnelDestroyed ¶ added in v0.3.0
func (s *ProxyLiteServer) OnTunnelDestroyed(f HookFunc)
func (*ProxyLiteServer) OnUserComming ¶ added in v0.3.0
func (s *ProxyLiteServer) OnUserComming(f HookFunc)
func (*ProxyLiteServer) OnUserLeaving ¶ added in v0.3.0
func (s *ProxyLiteServer) OnUserLeaving(f HookFunc)
func (*ProxyLiteServer) Run ¶
func (s *ProxyLiteServer) Run(addr string) error
Run Run the server and let it listen on given address.
func (*ProxyLiteServer) SetLogger ¶
func (s *ProxyLiteServer) SetLogger(logger *log.Logger)
SetLogger Set customized logrus logger for the server.
func (*ProxyLiteServer) Stop ¶ added in v0.3.0
func (s *ProxyLiteServer) Stop() error
Stop Stop the server
type RegisterEntry ¶
type RegisterEntry struct { // Basic Info Info RegisterInfo // Control Info Ctrl ControlInfo // Cancel function Cancel func() // Done channel Done <-chan struct{} }
RegisterEntry entry to describe a single service registration
type RegisterInfo ¶
RegisterInfo Register information
type RegisterServiceReq ¶
type RegisterServiceReq struct { Info RegisterInfo Ctrl ControlInfo }
RegisterServiceReq inner service registration request
type RegisterServiceRsp ¶
type RegisterServiceRsp struct {
Code int32
}
RegisterServiceRsp inner service registration response
type ServiceInfo ¶
type ServiceInfo struct { Port uint32 Name string Message string Birth time.Time Online uint32 // online user count Capacity uint32 // max concurrency user count AlreadyServe uint32 // already served user number TotalServe uint32 // total user number can serve DeadLine time.Time // time to close this port }
ServiceInfo Service basic information
func DiscoverServices ¶
func DiscoverServices(addr string) ([]ServiceInfo, error)
DiscoverServices Discover all active services from proxy server with given address.