Documentation ¶
Index ¶
- Constants
- Variables
- func Accept(listener net.Listener) (net.Conn, error)
- func GetSeq() uint32
- func InitProxy()
- func ModifyRequest(p interface{}, w http.ResponseWriter, r *http.Request) (code int, err error)
- func ModifyResponse(p interface{}, rsp *http.Response) (err error)
- func ProxyTcpHandle(session *Session)
- func Run(network string, stProxyConf *StProxyConf, protocol protocol.Protocol, ...) (err error)
- func StartHttpProxy(proxyConf *StProxyConf, h HttpController) (err error)
- type Controller
- type Handler
- type HandlerFunc
- type HttpController
- type ReflectServer
- type Session
- func (session *Session) Close(info interface{}) error
- func (session *Session) IsSessionClosed() bool
- func (session *Session) NoticeClose(info interface{})
- func (session *Session) Receive(info interface{}) (interface{}, interface{}, error, int)
- func (session *Session) Send(info, msg interface{}) error
- type StHttpController
- type StLogConf
- type StProxyConf
- type StTcpAppConf
- type StTcpAppServerConf
Constants ¶
View Source
const ( //命令字信息 CMD_DIAL = iota CMD_ACCEPT CMD_CONNECT CMD_REFUSE CMD_CLOSE CMD_PING )
View Source
const ( CLIENT_SIDE = 0 SERVER_SIDE = 1 PEER_NUM = 2 SIDE_NUM = 2 )
View Source
const ( //长度信息 ProtocolHead_LEN_SIZE = 4 //协议头的长度数值大小 ProtocolBody_CMD_FID_SIZE = 4 //协议体的流水号大小 ProtocolBody_CMD_TYPE_SIZE = 1 //协议体的命令字大小 ProtocolBody_CMD_SIZE = ProtocolBody_CMD_FID_SIZE + ProtocolBody_CMD_TYPE_SIZE //位置信息 Position_Of_CMD = ProtocolHead_LEN_SIZE Position_Of_CMD_TYPE = Position_Of_CMD + ProtocolBody_CMD_FID_SIZE Position_Of_MSG = Position_Of_CMD_TYPE + ProtocolBody_CMD_TYPE_SIZE )
View Source
const ( //dial cmd = |fid|type|fid(remoteid)| CMD_SIZE_DIAL = ProtocolBody_CMD_SIZE + ProtocolBody_CMD_FID_SIZE Postition_DIAL_REMOTEID = Position_Of_MSG //accept cmd = |fid|type|fid(connid)|fid(remoteid)| CMD_SIZE_ACCEPT = ProtocolBody_CMD_SIZE + ProtocolBody_CMD_FID_SIZE + ProtocolBody_CMD_FID_SIZE Postition_ACCCEPT_CONNID = Position_Of_MSG Postition_ACCCEPT_REMOTEID = Postition_ACCCEPT_CONNID + ProtocolBody_CMD_FID_SIZE //connect cmd = |fid|type|fid(connid)|fid(remoteid)| CMD_SIZE_CONNECT = ProtocolBody_CMD_SIZE + ProtocolBody_CMD_FID_SIZE + ProtocolBody_CMD_FID_SIZE Postition_CONNECT_CONNID = Position_Of_MSG Postition_CONNECT_REMOTEID = Postition_ACCCEPT_CONNID + ProtocolBody_CMD_FID_SIZE //refuse cmd = |fid|type|fid(remoteid)| CMD_SIZE_REFUSE = ProtocolBody_CMD_SIZE + ProtocolBody_CMD_FID_SIZE Postition_REFUSE_REMOTEID = Position_Of_MSG //close cmd = |fid|type|fid(remoteid)| CMD_SIZE_CLOSE = ProtocolBody_CMD_SIZE + ProtocolBody_CMD_FID_SIZE Postition_CLOSE_REMOTEID = Position_Of_MSG //ping cmd = |fid|type| CMD_SIZE_PING = ProtocolBody_CMD_SIZE )
Variables ¶
View Source
var ( ErrSessionClosed = errors.New("session closed fail") ErrTooLargePacket = errors.New("too large packet size") ErrRefused = errors.New("virtual connection refused error") ErrServerAuthFail = errors.New("server auth fail") ErrEOF = io.EOF )
View Source
var ( TestMaxConn = 10000 TestMaxPacket = 2048 TestBuffsize = 1024 TestSendChanSize = int(runtime.GOMAXPROCS(-1) * 6000) TestRecvChanSize = 6000 TestIdleTimeout = time.Second * 2 TestPingInterval = time.Second TestPingTimeout = time.Second TestAuthKey = "123" TestServerId = uint32(123) )
Functions ¶
func ModifyRequest ¶
func ModifyResponse ¶
func ProxyTcpHandle ¶
func ProxyTcpHandle(session *Session)
func Run ¶
func Run(network string, stProxyConf *StProxyConf, protocol protocol.Protocol, controller Controller) (err error)
func StartHttpProxy ¶
func StartHttpProxy(proxyConf *StProxyConf, h HttpController) (err error)
Types ¶
type Controller ¶
type Controller interface { ReloadConf() (err error) InitProxy(key string) error TcpProxyGet(ip string) (info interface{}) Verify(info interface{}) error HandlePre(info, reqHead, reqBody interface{}) (limitObj string, reqHeadOut, reqBodyOut interface{}, err error) Handle(info, reqHead, reqBody interface{}) (msg []byte, err error) IsExit(info interface{}) int Close(info interface{}) }
type HandlerFunc ¶
type HandlerFunc func(session *Session)
func (HandlerFunc) HandleSession ¶
func (hf HandlerFunc) HandleSession(session *Session)
type HttpController ¶
type HttpController interface { ReloadConf() (err error) InitProxyHTTP(key string, p interface{}, ResponseFunc func(p interface{}, rsp *http.Response) error, RequestFunc func(p interface{}, w http.ResponseWriter, r *http.Request) (int, error)) (err error) ServeHTTP(w http.ResponseWriter, r *http.Request) (err error) }
type ReflectServer ¶
type ReflectServer struct {
// contains filtered or unexported fields
}
func (*ReflectServer) Listener ¶
func (server *ReflectServer) Listener() net.Listener
func (*ReflectServer) Serve ¶
func (server *ReflectServer) Serve() (err error)
func (*ReflectServer) Stop ¶
func (server *ReflectServer) Stop()
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
会话信息
func NewSession ¶
func NewSession(codec protocol.Protocol, controller Controller, conn net.Conn, stProxyConf *StProxyConf) *Session
新建会话
func (*Session) IsSessionClosed ¶
func (*Session) NoticeClose ¶
func (session *Session) NoticeClose(info interface{})
type StHttpController ¶
type StHttpController struct {
// contains filtered or unexported fields
}
func (*StHttpController) ServeHTTP ¶
func (h *StHttpController) ServeHTTP(w http.ResponseWriter, r *http.Request)
实现Handler的接口
type StProxyConf ¶
type StProxyConf struct { LimitObj string `json:"limitObj,omitempty"` Timeout int `json:"timeout,omitempty"` //读写超时时间 Heartbeat int `json:"heartbeat,omitempty"` //心跳间隔 MaxConn int64 `json:"maxConn,omitempty"` //最大连接数 Addr string `json:"addr,omitempty"` //tcp监听地址 MaxRate int64 `json:"maxRate,omitempty"` //最大接收字节数 MaxRatePer int64 `json:"maxRatePer,omitempty"` //每个连接最大接收字节数 ConnCount int64 `json:"connCount,omitempty"` //已连接数 RateCount int64 `json:"rateCount,omitempty"` //已接收字节数 RatePerCount int64 `json:"ratePerCount,omitempty"` //每个连接已接收字节数 Per int64 `json:"per,omitempty"` //限速统计间隔 Switch uint32 `json:"switch,omitempty"` //1开启服务 RateLimitSwitch uint32 `json:"rateLimitSwitch,omitempty"` //1开启服务 App []StTcpAppConf `json:"app,omitempty"` // BlackList []string `json:"blackList,omitempty"` // WhiteList []string `json:"whiteList,omitempty"` // CacheSwitch int64 `json:"cacheSwitch,omitempty"` CacheSize int64 `json:"cacheSize,omitempty"` CacheExpirationTime int64 `json:"cacheExpirationTime,omitempty"` CacheExpirationCleanTime string `json:"cacheExpirationCleanTime,omitempty"` // contains filtered or unexported fields }
func InitHttpProxy ¶
func InitHttpProxy(key string) (proxyConf *StProxyConf, err error)
func InitTcpProxy ¶
func InitTcpProxy(key string) (stProxyConf *StProxyConf, err error)
type StTcpAppConf ¶
type StTcpAppConf struct { Switch uint32 `json:"switch,omitempty"` //1开启服务 RateLimitSwitch uint32 `json:"rateLimitSwitch,omitempty"` //1开启服务 Name string `json:"name,omitempty"` MaxConn int64 `json:"maxConn,omitempty"` //最大连接数 MaxRate int64 `json:"maxRate,omitempty"` //最大接收字节数 MaxRatePer int64 `json:"maxRatePer,omitempty"` //每个连接最大接收字节数 ConnCount int64 `json:"connCount,omitempty"` //已连接数 RateCount int64 `json:"rateCount,omitempty"` //已接收字节数 RatePerCount int64 `json:"ratePerCount,omitempty"` //每个连接已接收字节数 Per int64 `json:"per,omitempty"` //限速统计间隔 Server []StTcpAppServerConf `json:"server,omitempty"` // BlackList []string `json:"blackList,omitempty"` // WhiteList []string `json:"whiteList,omitempty"` // CacheSwitch int64 `json:"cacheSwitch,omitempty"` CacheSize int64 `json:"cacheSize,omitempty"` CacheExpirationTime int64 `json:"cacheExpirationTime,omitempty"` CacheExpirationCleanTime string `json:"cacheExpirationCleanTime,omitempty"` }
type StTcpAppServerConf ¶
type StTcpAppServerConf struct { Switch uint32 `json:"switch,omitempty"` //1开启服务 RateLimitSwitch uint32 `json:"rateLimitSwitch,omitempty"` //1开启服务 Name string `json:"name,omitempty"` MaxConn int64 `json:"maxConn,omitempty"` //最大连接数 MaxRate int64 `json:"maxRate,omitempty"` //最大接收字节数 MaxRatePer int64 `json:"maxRatePer,omitempty"` //每个连接最大接收字节数 ConnCount int64 `json:"connCount,omitempty"` //已连接数 RateCount int64 `json:"rateCount,omitempty"` //已接收字节数 RatePerCount int64 `json:"ratePerCount,omitempty"` //每个连接已接收字节数 Per int64 `json:"per,omitempty"` //限速统计间隔 BlackList []string `json:"blackList,omitempty"` // WhiteList []string `json:"whiteList,omitempty"` // CacheSwitch int64 `json:"cacheSwitch,omitempty"` CacheSize int64 `json:"cacheSize,omitempty"` CacheExpirationTime int64 `json:"cacheExpirationTime,omitempty"` CacheExpirationCleanTime string `json:"cacheExpirationCleanTime,omitempty"` }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.