mirror of
https://github.com/therootcompany/telebit.git
synced 2025-12-26 15:28:46 +00:00
- debugging issues (not resolved) attempting to move the main executable into the base directory, this did not solve the issue, keeping it here. A main.go and the executable. listener_client — the WSS client - removed support for anything admin - injected the domains from the claim - domains are now included as initialDomains - registration performans as normal but includes adding the domains to a map of domains, and a collection of domains on the connection. - the system now supports look up fast in either direction, not sure if it will be needed. - reads a chan during registration before allowing traffic, making sure all is well. - registration returns a true on the channel if all is well. If it is not, false. Likely will add some text to pass back. Connection - added support for boolean channel - support for initial domains in a slice, these are brought back from the JWT as a interface and then are type asserted into the map - removed all the old timer sender dwell stuff as a POC for traffic counts. ConnectionTable - added support for domain announcement after the WSS is connection. Not sure if we will need these. They have not been implemented. - I assume all domains are registered with JWT unless I hear differently which would require a new WSS session - expanded NewTable constructor - populating domains into the domain map, and into the connection slice. - added support for removing domains when a connection is removed.
117 lines
2.2 KiB
Go
Executable File
117 lines
2.2 KiB
Go
Executable File
package connection
|
|
|
|
import (
|
|
"encoding/hex"
|
|
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
var upgrader = websocket.Upgrader{
|
|
ReadBufferSize: 1024,
|
|
WriteBufferSize: 1024,
|
|
}
|
|
|
|
// Connection track websocket and faciliates in and out data
|
|
type Connection struct {
|
|
connectionTable *Table
|
|
|
|
// The websocket connection.
|
|
conn *websocket.Conn
|
|
|
|
// Buffered channel of outbound messages.
|
|
send chan []byte
|
|
|
|
// Address of the Remote End Point
|
|
source string
|
|
|
|
// bytes in
|
|
bytesIn int64
|
|
|
|
// bytes out
|
|
bytesOut int64
|
|
|
|
// communications channel between go routines
|
|
commCh chan bool
|
|
|
|
//initialDomains - a list of domains from the JWT
|
|
initialDomains []interface{}
|
|
}
|
|
|
|
//NewConnection -- Constructor
|
|
func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress string, initialDomains []interface{}) (p *Connection) {
|
|
p = new(Connection)
|
|
p.connectionTable = connectionTable
|
|
p.conn = conn
|
|
p.source = remoteAddress
|
|
p.bytesIn = 0
|
|
p.bytesOut = 0
|
|
p.send = make(chan []byte, 256)
|
|
p.commCh = make(chan bool)
|
|
p.initialDomains = initialDomains
|
|
return
|
|
}
|
|
|
|
func (c *Connection) addIn(num int64) {
|
|
c.bytesIn = c.bytesIn + num
|
|
}
|
|
|
|
func (c *Connection) addOut(num int64) {
|
|
c.bytesOut = c.bytesOut + num
|
|
}
|
|
|
|
//ConnectionTable -- property
|
|
func (c *Connection) ConnectionTable() (table *Table) {
|
|
table = c.connectionTable
|
|
return
|
|
}
|
|
|
|
//CommCh -- Property
|
|
func (c *Connection) CommCh() chan bool {
|
|
return c.commCh
|
|
}
|
|
|
|
//Reader -- export the reader function
|
|
func (c *Connection) Reader() {
|
|
defer func() {
|
|
c.connectionTable.unregister <- c
|
|
c.conn.Close()
|
|
}()
|
|
c.conn.SetReadLimit(1024)
|
|
for {
|
|
_, message, err := c.conn.ReadMessage()
|
|
if err != nil {
|
|
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
|
|
loginfo.Printf("error: %v", err)
|
|
}
|
|
break
|
|
}
|
|
loginfo.Println(hex.Dump(message))
|
|
c.addIn(int64(len(message)))
|
|
loginfo.Println(c)
|
|
}
|
|
}
|
|
|
|
//Writer -- expoer the writer function
|
|
func (c *Connection) Writer() {
|
|
defer func() {
|
|
c.conn.Close()
|
|
}()
|
|
for {
|
|
select {
|
|
|
|
case message := <-c.send:
|
|
w, err := c.conn.NextWriter(websocket.TextMessage)
|
|
if err != nil {
|
|
return
|
|
}
|
|
w.Write(message)
|
|
|
|
if err := w.Close(); err != nil {
|
|
return
|
|
}
|
|
|
|
c.addOut(int64(len(message)))
|
|
}
|
|
}
|
|
}
|