telebit/relay/api/status.go

83 lines
2.2 KiB
Go
Raw Normal View History

2020-05-01 05:47:46 +00:00
package api
import (
"context"
"time"
2020-05-01 05:47:46 +00:00
"git.coolaj86.com/coolaj86/go-telebitd/tunnel"
)
//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
TrafficStats *TrafficStats
ExtConnections *ConnectionStats
WSSConnections *ConnectionStats
2020-04-30 10:43:36 +00:00
//servers *MPlexy
}
//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
}
// 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) {
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
}