Documentation ¶
Index ¶
- Constants
- Variables
- func Run(version string)
- func Stop()
- type ConnMgr
- func (mgr *ConnMgr) GetClientInSize() int64
- func (mgr *ConnMgr) GetClientOutSize() int64
- func (mgr *ConnMgr) GetInNum() int64
- func (mgr *ConnMgr) GetOutNum() int64
- func (mgr *ConnMgr) GetServerInSize() int64
- func (mgr *ConnMgr) GetServerOutSize() int64
- func (mgr *ConnMgr) GetSuccessNum() int64
- func (mgr *ConnMgr) GetdateFailedNum(delta int64)
- func (mgr *ConnMgr) LogDataFlowRecord()
- func (mgr *ConnMgr) StartDataFlowRecord(interval time.Duration)
- func (mgr *ConnMgr) UpdateClientInSize(delta int64)
- func (mgr *ConnMgr) UpdateClientOutSize(delta int64)
- func (mgr *ConnMgr) UpdateFailedNum(delta int64)
- func (mgr *ConnMgr) UpdateInNum(delta int64)
- func (mgr *ConnMgr) UpdateOutNum(delta int64)
- func (mgr *ConnMgr) UpdateServerInSize(delta int64)
- func (mgr *ConnMgr) UpdateServerOutSize(delta int64)
- func (mgr *ConnMgr) UpdateSuccessNum(delta int64)
- type FailedInMunite
- type IProxy
- type Line
- func (line *Line) CheckLine(now time.Time)
- func (line *Line) GetFailedInLastNMinutes(n int) int64
- func (line *Line) HandleRedirect(conn *net.TCPConn, addr string) error
- func (line *Line) Pause()
- func (line *Line) Score() int64
- func (line *Line) Start(idx int)
- func (line *Line) Stop()
- func (line *Line) UnPause()
- func (line *Line) UpdateDelay(delay time.Duration)
- func (line *Line) UpdateFailedNum(delta int64)
- func (line *Line) UpdateLoad(delta int64)
- type ProxyBase
- type ProxyMgr
- type ProxyTcp
- type ProxyWebsocket
- type XMLCert
- type XMLConfig
- type XMLHeartbeat
- type XMLLine
- type XMLNode
- type XMLOptions
- type XMLProxy
- type XMLRoute
Constants ¶
View Source
const (
COUNT_MINUTES = 60
)
Variables ¶
View Source
var ( PT_TCP = "tcp" PT_WEBSOCKET = "websocket" /* 默认配置项 */ DEFAULT_TCP_NODELAY = true /* tcp nodelay */ DEFAULT_TCP_REDIRECT = false /* 是否向服务器发送客户端IP */ DEFAULT_TCP_HEARTBEAT = time.Second * 30 /* tcp代理设置的心跳时间 */ DEFAULT_TCP_KEEPALIVE_INTERVAL = time.Second * 600 /* tcp代理设置的 keepalive 时间 */ DEFAULT_TCP_READ_BUF_LEN = 1024 * 4 /* tcp 接收缓冲区 */ DEFAULT_TCP_WRITE_BUF_LEN = 1024 * 4 /* tcp 发送缓冲区 */ DEFAULT_TCP_READ_BLOCK_TIME = time.Second * 35 /* tcp 读数据超时时间 */ DEFAULT_TCP_WRITE_BLOCK_TIME = time.Second * 5 /* tcp 写数据超时时间 */ DEFAULT_TCP_CHECKLINE_INTERVAL = time.Second * 60 /* 线路检测周期 */ DEFAULT_TCP_CHECKLINE_TIMEOUT = time.Second * 10 /* 线路检测超时时间 */ )
View Source
var ( DefaultSocketOpt = &knet.SocketOpt{ NoDelay: true, Keepalive: false, ReadBufLen: 1024 * 8, WriteBufLen: 1024 * 8, ReadTimeout: time.Second * 35, ReadHeaderTimeout: time.Second * 10, WriteTimeout: time.Second * 5, MaxHeaderBytes: 4096, } DefaultUpgrader = &websocket.Upgrader{CheckOrigin: func(r *http.Request) bool { return true }} )
View Source
var (
ErrorInvalidAddr = errors.New("Invalid Addr")
)
Functions ¶
Types ¶
type ConnMgr ¶
type ConnMgr struct { // sync.Mutex InNum int64 /* 当前客户端连接数 */ OutNum int64 /* 当前服务端连接数 */ SuccessNum int64 /* 启动以来隧道成功总数 */ FailedNum int64 /* 启动以来隧道失败总数 */ ClientInSize int64 /* 启动以来客户端读总流量 */ ClientOutSize int64 /* 启动以来客户端写总流量 */ ServerInSize int64 /* 启动以来服务端读总流量 */ ServerOutSize int64 /* 启动以来服务端写总流量 */ }
func (*ConnMgr) LogDataFlowRecord ¶
func (mgr *ConnMgr) LogDataFlowRecord()
func (*ConnMgr) StartDataFlowRecord ¶
func (*ConnMgr) UpdateClientInSize ¶
更新启动以来客户端读总流量
func (*ConnMgr) UpdateClientOutSize ¶
更新启动以来客户端写总流量
func (*ConnMgr) UpdateServerInSize ¶
更新启动以来服务端读总流量
func (*ConnMgr) UpdateServerOutSize ¶
更新启动以来服务端写总流量
type FailedInMunite ¶
type Line ¶
type Line struct { sync.RWMutex Running bool /* 线路检测是否在进行的标志 */ Born time.Time /* 线路出生时间 */ Remote string /* 线路指向的服务器地址 */ Delay time.Duration /* 线路延迟 */ Timeout time.Duration /* 进行线路检测时的超时时间 */ Interval time.Duration /* 线路检测的时间周期 */ Timer *time.Timer /* 用于定时进行线路检测的定时器 */ CurLoad int64 /* 当前线路负载 */ MaxLoad int64 /* 线路最大负载 */ IsPaused bool /* 线路暂停使用的标志 */ Redirect bool /* 线路是否需要向服务器发送客户端真实IP的标志 */ ChUpdateDelay chan time.Duration /* 用于外部更新线路当前延迟的channel,外部进行更新后本线路的线路检测reset计时周期避免浪费 */ FailedRecord [COUNT_MINUTES]FailedInMunite /* 环形队列,记录过去COUNT_MINUTES分钟内连接失败次数 */ FailedRecordHead int /* 环形队列头 */ }
线路
func NewLine ¶
func NewLine(remote string, timeout time.Duration, interval time.Duration, maxLoad int64, redirect bool) *Line
创建新线路
func (*Line) GetFailedInLastNMinutes ¶
获取近期n分钟内为客户端与服务器建立连接的失败次数
func (*Line) HandleRedirect ¶
根据线路配置决定是否向服务器发送重定向包,应在刚建立与服务器的连接时首先进行然后再发送其他包
func (*Line) UpdateFailedNum ¶
更新为客户端与服务器建立连接的失败总次数,以及近期每分钟内的失败次数记录
type ProxyBase ¶
每个 ProxyBase 管理一组 Line ,Proxy is a ProxyBase
func (*ProxyBase) AddLine ¶
func (mgr *ProxyBase) AddLine(addr string, timeout time.Duration, interval time.Duration, maxLoad int64, redirect bool)
添加一个 Line
func (*ProxyBase) GetBestLineWithoutLock ¶
当前最适合的线路
type ProxyTcp ¶
type ProxyTcp struct { *ProxyBase Running bool Listener *net.TCPListener Heartbeat time.Duration AliveTime time.Duration RecvBlockTime time.Duration RecvBufLen int SendBlockTime time.Duration SendBufLen int Nodelay bool ConnCount uint64 }
tcp 代理
func NewTcpProxy ¶
type ProxyWebsocket ¶
type ProxyWebsocket struct { *ProxyBase Running bool EnableTls bool Listener *net.TCPListener Heartbeat time.Duration AliveTime time.Duration RecvBlockTime time.Duration RecvBufLen int SendBlockTime time.Duration SendBufLen int Nodelay bool ConnCount uint64 Certs []XMLCert Routes map[string]func(w http.ResponseWriter, r *http.Request) }
websocket 代理
func NewWebsocketProxy ¶
func (*ProxyWebsocket) OnNew ¶
func (pws *ProxyWebsocket) OnNew(w http.ResponseWriter, r *http.Request)
func (*ProxyWebsocket) ServeHTTP ¶
func (pws *ProxyWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*ProxyWebsocket) Start ¶
func (pws *ProxyWebsocket) Start()
func (*ProxyWebsocket) Stop ¶
func (pws *ProxyWebsocket) Stop()
type XMLConfig ¶
type XMLConfig struct { XMLName xml.Name `xml:"setting"` Options XMLOptions `xml:"options"` Proxy XMLProxy `xml:"proxy"` }
type XMLHeartbeat ¶
type XMLLine ¶
type XMLLine struct { XMLName xml.Name `xml:"line"` Name string `xml:"name,attr"` Addr string `xml:"addr,attr"` Type string `xml:"type,attr"` Redirect string `xml:"redirect,attr"` // Maxload int64 `xml:"maxload,attr"` TLS bool `xml:"tls,attr"` Routes []XMLRoute `xml:"route"` Certs []XMLCert `xml:"cert"` Nodes []XMLNode `xml:"node"` }
type XMLOptions ¶
Click to show internal directories.
Click to hide internal directories.