From 41adbfaef59e8d713153991466a1dc7166a70e9e Mon Sep 17 00:00:00 2001 From: Henry Camacho Date: Sat, 25 Mar 2017 17:22:28 -0500 Subject: [PATCH] ServerName is now 1st domain in token. Awaiting new token structure for true ServerName. --- rvpn/genericlistener/api_collect_server.go | 7 ++----- rvpn/genericlistener/api_collect_servers.go | 7 ++----- rvpn/genericlistener/connection.go | 17 ++++++++++++++++- rvpn/genericlistener/connection_registration.go | 6 +++++- rvpn/genericlistener/connection_table.go | 3 ++- rvpn/genericlistener/listener_generic.go | 5 ++--- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/rvpn/genericlistener/api_collect_server.go b/rvpn/genericlistener/api_collect_server.go index 73e95a5..25bc150 100644 --- a/rvpn/genericlistener/api_collect_server.go +++ b/rvpn/genericlistener/api_collect_server.go @@ -1,9 +1,6 @@ package genericlistener -import ( - "fmt" - "time" -) +import "time" //ServerAPI -- Structure to support the server API type ServerAPI struct { @@ -20,7 +17,7 @@ type ServerAPI struct { //NewServerAPI - Constructor func NewServerAPI(c *Connection) (s *ServerAPI) { s = new(ServerAPI) - s.ServerName = fmt.Sprintf("%p", c) + s.ServerName = c.ServerName() s.ServerID = c.ConnectionID() s.Domains = make([]*DomainAPI, 0) s.Duration = time.Since(c.ConnectTime()).Seconds() diff --git a/rvpn/genericlistener/api_collect_servers.go b/rvpn/genericlistener/api_collect_servers.go index 6e8aa23..cb5648a 100644 --- a/rvpn/genericlistener/api_collect_servers.go +++ b/rvpn/genericlistener/api_collect_servers.go @@ -1,9 +1,6 @@ package genericlistener -import ( - "fmt" - "time" -) +import "time" //ServersAPI -- Structure to support the server API type ServersAPI struct { @@ -22,7 +19,7 @@ type ServersAPI struct { //NewServersAPI - Constructor func NewServersAPI(c *Connection) (s *ServersAPI) { s = new(ServersAPI) - s.ServerName = fmt.Sprintf("%p", c) + s.ServerName = c.ServerName() s.ServerID = c.ConnectionID() s.Domains = make([]*DomainAPI, 0) s.Duration = time.Since(c.ConnectTime()).Seconds() diff --git a/rvpn/genericlistener/connection.go b/rvpn/genericlistener/connection.go index 8c779e7..a23aa07 100755 --- a/rvpn/genericlistener/connection.go +++ b/rvpn/genericlistener/connection.go @@ -39,6 +39,9 @@ type Connection struct { // Address of the Remote End Point source string + // serverName -- Name of the server, at this point 1st domain registered. Will likely change with JWT + serverName string + // bytes in bytesIn int64 @@ -70,13 +73,15 @@ type Connection struct { } //NewConnection -- Constructor -func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress string, initialDomains []interface{}, connectionTrack *Tracking) (p *Connection) { +func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress string, + initialDomains []interface{}, connectionTrack *Tracking, serverName string) (p *Connection) { connectionID = connectionID + 1 p = new(Connection) p.connectionTable = connectionTable p.conn = conn p.source = remoteAddress + p.serverName = serverName p.bytesIn = 0 p.bytesOut = 0 p.requests = 0 @@ -103,6 +108,16 @@ func (c *Connection) AddTrackedDomain(domain string) { c.DomainTrack[domain] = p } +//ServerName -- Property +func (c *Connection) ServerName() string { + return c.serverName +} + +//SetServerName -- Setter +func (c *Connection) SetServerName(serverName string) { + c.serverName = serverName +} + //InitialDomains -- Property func (c *Connection) InitialDomains() []interface{} { return c.initialDomains diff --git a/rvpn/genericlistener/connection_registration.go b/rvpn/genericlistener/connection_registration.go index abaddd6..66a0f87 100644 --- a/rvpn/genericlistener/connection_registration.go +++ b/rvpn/genericlistener/connection_registration.go @@ -14,6 +14,9 @@ type Registration struct { // Address of the Remote End Point source string + // serverName + serverName string + // communications channel between go routines commCh chan bool @@ -24,10 +27,11 @@ type Registration struct { } //NewRegistration -- Constructor -func NewRegistration(conn *websocket.Conn, remoteAddress string, initialDomains []interface{}, connectionTrack *Tracking) (p *Registration) { +func NewRegistration(conn *websocket.Conn, remoteAddress string, initialDomains []interface{}, connectionTrack *Tracking, serverName string) (p *Registration) { p = new(Registration) p.conn = conn p.source = remoteAddress + p.serverName = serverName p.commCh = make(chan bool) p.initialDomains = initialDomains p.connectionTrack = connectionTrack diff --git a/rvpn/genericlistener/connection_table.go b/rvpn/genericlistener/connection_table.go index 14c461b..b98495f 100755 --- a/rvpn/genericlistener/connection_table.go +++ b/rvpn/genericlistener/connection_table.go @@ -103,7 +103,8 @@ func (c *Table) Run(ctx context.Context, defaultMethod string) { case registration := <-c.register: loginfo.Println("register fired") - connection := NewConnection(c, registration.conn, registration.source, registration.initialDomains, registration.connectionTrack) + connection := NewConnection(c, registration.conn, registration.source, registration.initialDomains, + registration.connectionTrack, registration.serverName) c.connections[connection] = make([]string, initialDomains) registration.commCh <- true diff --git a/rvpn/genericlistener/listener_generic.go b/rvpn/genericlistener/listener_generic.go index 6dce8e7..4716a2b 100644 --- a/rvpn/genericlistener/listener_generic.go +++ b/rvpn/genericlistener/listener_generic.go @@ -382,10 +382,9 @@ func handleWssClient(ctx context.Context, oneConn *oneConnListener) { loginfo.Println("before connection table") - //newConnection := connection.NewConnection(connectionTable, conn, r.RemoteAddr, domains) + serverName := domains[0].(string) - //connectionTrack := ctx.Value(ctxConnectionTrack).(*Tracking) - newRegistration := NewRegistration(conn, r.RemoteAddr, domains, serverStatus.ConnectionTracking) + newRegistration := NewRegistration(conn, r.RemoteAddr, domains, serverStatus.ConnectionTracking, serverName) serverStatus.WSSConnectionRegister(newRegistration) ok = <-newRegistration.CommCh()