simplified some function inputs and returns
This commit is contained in:
parent
87a1d9c0ae
commit
92f951544b
|
@ -9,12 +9,12 @@ type TrafficAPI struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewTrafficStats -- Consttuctor
|
//NewTrafficStats -- Consttuctor
|
||||||
func NewTrafficAPI(requests int64, responses int64, bytes_in int64, bytes_out int64) (p *TrafficAPI) {
|
func NewTrafficAPI(requests, responses, bytesIn, bytesOut int64) (p *TrafficAPI) {
|
||||||
p = new(TrafficAPI)
|
p = new(TrafficAPI)
|
||||||
p.Requests = requests
|
p.Requests = requests
|
||||||
p.Responses = responses
|
p.Responses = responses
|
||||||
p.BytesIn = bytes_in
|
p.BytesIn = bytesIn
|
||||||
p.BytesOut = bytes_out
|
p.BytesOut = bytesOut
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -79,17 +79,14 @@ func (p *Tracking) list() {
|
||||||
|
|
||||||
//Lookup --
|
//Lookup --
|
||||||
// - get connection from key
|
// - get connection from key
|
||||||
func (p *Tracking) Lookup(key string) (c *Track, err error) {
|
func (p *Tracking) Lookup(key string) (*Track, error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
p.mutex.Unlock()
|
p.mutex.Unlock()
|
||||||
}()
|
}()
|
||||||
p.mutex.Lock()
|
p.mutex.Lock()
|
||||||
|
|
||||||
if _, ok := p.connections[key]; ok {
|
if _, ok := p.connections[key]; ok {
|
||||||
c = p.connections[key]
|
return p.connections[key], nil
|
||||||
} else {
|
|
||||||
err = fmt.Errorf("Lookup failed for %s", key)
|
|
||||||
c = nil
|
|
||||||
}
|
}
|
||||||
return
|
return nil, fmt.Errorf("Lookup failed for %s", key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func NewWedgeConnSize(c net.Conn, size int) (p *WedgeConn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Discard - discard a number of bytes, perhaps after peeking at the
|
//Discard - discard a number of bytes, perhaps after peeking at the
|
||||||
func (w *WedgeConn) Discard(n int) (discarded int, err error) {
|
func (w *WedgeConn) Discard(n int) (int, error) {
|
||||||
return w.reader.Discard(n)
|
return w.reader.Discard(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,7 @@ func (w *WedgeConn) ReadByte() (byte, error) {
|
||||||
|
|
||||||
//Read -- A normal reader.
|
//Read -- A normal reader.
|
||||||
func (w *WedgeConn) Read(p []byte) (int, error) {
|
func (w *WedgeConn) Read(p []byte) (int, error) {
|
||||||
cnt, err := w.reader.Read(p)
|
return w.reader.Read(p)
|
||||||
return cnt, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Buffered --
|
//Buffered --
|
||||||
|
@ -56,13 +55,6 @@ func (w *WedgeConn) Buffered() int {
|
||||||
//PeekAll --
|
//PeekAll --
|
||||||
// - get all the chars available
|
// - get all the chars available
|
||||||
// - pass then back
|
// - pass then back
|
||||||
func (w *WedgeConn) PeekAll() (buf []byte, err error) {
|
func (w *WedgeConn) PeekAll() ([]byte, error) {
|
||||||
|
return w.Peek(w.Buffered())
|
||||||
_, err = w.Peek(1)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, err = w.Peek(w.Buffered())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,27 +106,23 @@ func (c *Connection) AddTrackedDomain(domain string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//InitialDomains -- Property
|
//InitialDomains -- Property
|
||||||
func (c *Connection) InitialDomains() (i []interface{}) {
|
func (c *Connection) InitialDomains() []interface{} {
|
||||||
i = c.initialDomains
|
return c.initialDomains
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//ConnectTime -- Property
|
//ConnectTime -- Property
|
||||||
func (c *Connection) ConnectTime() (t time.Time) {
|
func (c *Connection) ConnectTime() time.Time {
|
||||||
t = c.connectTime
|
return c.connectTime
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//BytesIn -- Property
|
//BytesIn -- Property
|
||||||
func (c *Connection) BytesIn() (b int64) {
|
func (c *Connection) BytesIn() int64 {
|
||||||
b = c.bytesIn
|
return c.bytesIn
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//BytesOut -- Property
|
//BytesOut -- Property
|
||||||
func (c *Connection) BytesOut() (b int64) {
|
func (c *Connection) BytesOut() int64 {
|
||||||
b = c.bytesOut
|
return c.bytesOut
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//SendCh -- property to sending channel
|
//SendCh -- property to sending channel
|
||||||
|
@ -156,9 +152,8 @@ func (c *Connection) addResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//ConnectionTable -- property
|
//ConnectionTable -- property
|
||||||
func (c *Connection) ConnectionTable() (table *Table) {
|
func (c *Connection) ConnectionTable() *Table {
|
||||||
table = c.connectionTable
|
return c.connectionTable
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetState -- Get state of Socket...this is a high level state.
|
//GetState -- Get state of Socket...this is a high level state.
|
||||||
|
@ -203,21 +198,24 @@ func (c *Connection) ConnectionID() int64 {
|
||||||
//NextWriter -- Wrapper to allow a high level state check before offering NextWriter
|
//NextWriter -- Wrapper to allow a high level state check before offering NextWriter
|
||||||
//The libary failes if client abends during write-cycle. a fast moving write is not caught before socket state bubbles up
|
//The libary failes if client abends during write-cycle. a fast moving write is not caught before socket state bubbles up
|
||||||
//A synchronised state is maintained
|
//A synchronised state is maintained
|
||||||
func (c Connection) NextWriter(wssMessageType int) (w io.WriteCloser, err error) {
|
func (c *Connection) NextWriter(wssMessageType int) (io.WriteCloser, error) {
|
||||||
if c.GetState() == true {
|
if c.GetState() == true {
|
||||||
w, err = c.conn.NextWriter(wssMessageType)
|
return c.conn.NextWriter(wssMessageType)
|
||||||
} else {
|
|
||||||
loginfo.Println("NextWriter aborted, state is not true")
|
|
||||||
}
|
}
|
||||||
return
|
|
||||||
|
// Is returning a nil error actually the proper thing to do here?
|
||||||
|
loginfo.Println("NextWriter aborted, state is not true")
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Write -- Wrapper to allow a high level state check before allowing a write to the socket.
|
//Write -- Wrapper to allow a high level state check before allowing a write to the socket.
|
||||||
func (c *Connection) Write(w io.WriteCloser, message []byte) (cnt int, err error) {
|
func (c *Connection) Write(w io.WriteCloser, message []byte) (int, error) {
|
||||||
if c.GetState() == true {
|
if c.GetState() == true {
|
||||||
cnt, err = w.Write(message)
|
return w.Write(message)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
|
// Is returning a nil error actually the proper thing to do here?
|
||||||
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reader -- export the reader function
|
//Reader -- export the reader function
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Table struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewTable -- consructor
|
//NewTable -- consructor
|
||||||
func NewTable(dwell int, idle int) (p *Table) {
|
func NewTable(dwell, idle int) (p *Table) {
|
||||||
p = new(Table)
|
p = new(Table)
|
||||||
p.connections = make(map[*Connection][]string)
|
p.connections = make(map[*Connection][]string)
|
||||||
p.domains = make(map[string]*Connection)
|
p.domains = make(map[string]*Connection)
|
||||||
|
@ -38,15 +38,14 @@ func NewTable(dwell int, idle int) (p *Table) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Connections Property
|
//Connections Property
|
||||||
func (c *Table) Connections() (table map[*Connection][]string) {
|
func (c *Table) Connections() map[*Connection][]string {
|
||||||
table = c.connections
|
return c.connections
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//ConnByDomain -- Obtains a connection from a domain announcement.
|
//ConnByDomain -- Obtains a connection from a domain announcement.
|
||||||
func (c *Table) ConnByDomain(domain string) (conn *Connection, ok bool) {
|
func (c *Table) ConnByDomain(domain string) (*Connection, bool) {
|
||||||
conn, ok = c.domains[domain]
|
conn, ok := c.domains[domain]
|
||||||
return
|
return conn, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
//reaper --
|
//reaper --
|
||||||
|
@ -69,16 +68,14 @@ func (c *Table) reaper(delay int, idle int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetConnection -- find connection by server-id
|
//GetConnection -- find connection by server-id
|
||||||
func (c *Table) GetConnection(serverID int64) (conn *Connection, err error) {
|
func (c *Table) GetConnection(serverID int64) (*Connection, error) {
|
||||||
for conn := range c.connections {
|
for conn := range c.connections {
|
||||||
if conn.ConnectionID() == serverID {
|
if conn.ConnectionID() == serverID {
|
||||||
return conn, err
|
return conn, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = fmt.Errorf("Server-id %d not found", serverID)
|
return nil, fmt.Errorf("Server-id %d not found", serverID)
|
||||||
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Run -- Execute
|
//Run -- Execute
|
||||||
|
@ -144,7 +141,6 @@ func (c *Table) Run(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Register -- Property
|
//Register -- Property
|
||||||
func (c *Table) Register() (r chan *Registration) {
|
func (c *Table) Register() chan *Registration {
|
||||||
r = c.register
|
return c.register
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,13 @@ func NewDomainTrack(domainName string) (p *DomainTrack) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//BytesIn -- Property
|
//BytesIn -- Property
|
||||||
func (c *DomainTrack) BytesIn() (b int64) {
|
func (c *DomainTrack) BytesIn() int64 {
|
||||||
b = c.bytesIn
|
return c.bytesIn
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//BytesOut -- Property
|
//BytesOut -- Property
|
||||||
func (c *DomainTrack) BytesOut() (b int64) {
|
func (c *DomainTrack) BytesOut() int64 {
|
||||||
b = c.bytesOut
|
return c.bytesOut
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//AddIn - Property
|
//AddIn - Property
|
||||||
|
|
|
@ -271,7 +271,7 @@ func handleStream(ctx context.Context, wConn *WedgeConn) {
|
||||||
|
|
||||||
//handleExternalHTTPRequest -
|
//handleExternalHTTPRequest -
|
||||||
// - get a wConn and start processing requests
|
// - get a wConn and start processing requests
|
||||||
func handleExternalHTTPRequest(ctx context.Context, extConn *WedgeConn, hostname string, service string) {
|
func handleExternalHTTPRequest(ctx context.Context, extConn *WedgeConn, hostname, service string) {
|
||||||
//connectionTracking := ctx.Value(ctxConnectionTrack).(*Tracking)
|
//connectionTracking := ctx.Value(ctxConnectionTrack).(*Tracking)
|
||||||
serverStatus := ctx.Value(ctxServerStatus).(*Status)
|
serverStatus := ctx.Value(ctxServerStatus).(*Status)
|
||||||
|
|
||||||
|
|
|
@ -9,18 +9,16 @@ type oneConnListener struct {
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *oneConnListener) Accept() (c net.Conn, err error) {
|
func (l *oneConnListener) Accept() (net.Conn, error) {
|
||||||
c = l.conn
|
if l.conn == nil {
|
||||||
|
loginfo.Println("Accept EOF")
|
||||||
if c == nil {
|
return nil, io.EOF
|
||||||
err = io.EOF
|
|
||||||
loginfo.Println("Accept")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
err = nil
|
|
||||||
|
c := l.conn
|
||||||
l.conn = nil
|
l.conn = nil
|
||||||
loginfo.Println("Accept", c.LocalAddr().String(), c.RemoteAddr().String())
|
loginfo.Println("Accept", c.LocalAddr().String(), c.RemoteAddr().String())
|
||||||
return
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *oneConnListener) Close() error {
|
func (l *oneConnListener) Close() error {
|
||||||
|
|
|
@ -46,7 +46,6 @@ func (p *Status) WSSConnectionRegister(newRegistration *Registration) {
|
||||||
//unregisters a south facing connection
|
//unregisters a south facing connection
|
||||||
//intercept and update global statistics
|
//intercept and update global statistics
|
||||||
func (p *Status) WSSConnectionUnregister() {
|
func (p *Status) WSSConnectionUnregister() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// External Facing Functions
|
// External Facing Functions
|
||||||
|
|
|
@ -8,7 +8,7 @@ type StatusDeadTime struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewStatusDeadTime -- constructor
|
//NewStatusDeadTime -- constructor
|
||||||
func NewStatusDeadTime(dwell int, idle int, cancelcheck int) (p *StatusDeadTime) {
|
func NewStatusDeadTime(dwell, idle, cancelcheck int) (p *StatusDeadTime) {
|
||||||
p = new(StatusDeadTime)
|
p = new(StatusDeadTime)
|
||||||
p.dwell = dwell
|
p.dwell = dwell
|
||||||
p.idle = idle
|
p.idle = idle
|
||||||
|
|
Loading…
Reference in New Issue