2020-05-01 05:47:46 +00:00
|
|
|
package api
|
2017-03-20 00:04:47 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
2020-05-01 05:47:46 +00:00
|
|
|
|
|
|
|
"git.coolaj86.com/coolaj86/go-telebitd/tunnel"
|
2017-03-20 00:04:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
//Status --
|
|
|
|
type Status struct {
|
|
|
|
ctx context.Context
|
|
|
|
Name string
|
|
|
|
StartTime time.Time
|
|
|
|
WssDomain string
|
|
|
|
AdminDomain string
|
|
|
|
DeadTime *StatusDeadTime
|
|
|
|
ConnectionTracking *Tracking
|
|
|
|
ConnectionTable *Table
|
|
|
|
LoadbalanceDefaultMethod string
|
|
|
|
AdminStats *TrafficStats
|
2017-03-23 23:10:49 +00:00
|
|
|
AdminReqTyoe *AdminReqType
|
2017-03-20 00:04:47 +00:00
|
|
|
TrafficStats *TrafficStats
|
|
|
|
ExtConnections *ConnectionStats
|
|
|
|
WSSConnections *ConnectionStats
|
2020-04-30 10:43:36 +00:00
|
|
|
//servers *MPlexy
|
2017-03-20 00:04:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//NewStatus --
|
|
|
|
func NewStatus(ctx context.Context) (p *Status) {
|
|
|
|
p = new(Status)
|
|
|
|
p.ctx = ctx
|
|
|
|
p.AdminStats = new(TrafficStats)
|
|
|
|
p.TrafficStats = new(TrafficStats)
|
|
|
|
p.ExtConnections = new(ConnectionStats)
|
|
|
|
p.WSSConnections = new(ConnectionStats)
|
2020-04-30 10:43:36 +00:00
|
|
|
// TODO any reason not to set StartTime like this?
|
|
|
|
p.StartTime = time.Now()
|
|
|
|
return p
|
2017-03-20 00:04:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// South Facing Functions
|
|
|
|
|
|
|
|
//WSSConnectionRegister --
|
|
|
|
func (p *Status) WSSConnectionRegister(newRegistration *Registration) {
|
|
|
|
p.ConnectionTable.Register() <- newRegistration
|
|
|
|
p.WSSConnections.IncConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
//WSSConnectionUnregister --
|
|
|
|
//unregisters a south facing connection
|
|
|
|
//intercept and update global statistics
|
|
|
|
func (p *Status) WSSConnectionUnregister() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// External Facing Functions
|
|
|
|
|
|
|
|
//ExtConnectionRegister --
|
|
|
|
//registers an ext facing connection
|
|
|
|
//intercept and update global statistics
|
|
|
|
func (p *Status) ExtConnectionRegister(newTrack *Track) {
|
|
|
|
p.ConnectionTracking.register <- newTrack
|
|
|
|
p.ExtConnections.IncConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
//ExtConnectionUnregister --
|
|
|
|
//unregisters an ext facing connection
|
|
|
|
//intercept and update global statistics
|
2020-05-01 05:47:46 +00:00
|
|
|
func (p *Status) ExtConnectionUnregister(extConn *tunnel.WedgeConn) {
|
2017-03-20 00:04:47 +00:00
|
|
|
p.ConnectionTracking.unregister <- extConn
|
|
|
|
p.ExtConnections.DecConnections()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//SendExtRequest --
|
|
|
|
//sends a request to a south facing connection
|
|
|
|
//intercept the send, update our global stats
|
|
|
|
func (p *Status) SendExtRequest(conn *Connection, sendTrack *SendTrack) {
|
|
|
|
p.TrafficStats.IncRequests()
|
|
|
|
p.TrafficStats.AddBytesOut(int64(len(sendTrack.data)))
|
|
|
|
conn.SendCh() <- sendTrack
|
|
|
|
}
|