telebit/rvpn/connection/connection_table.go
Henry Camacho 07380af871 lots of changes
- 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.
2017-02-12 14:39:50 -06:00

96 lines
2.3 KiB
Go
Executable File

package connection
import "fmt"
const (
initialDomains = 0
incrementDomains = 0
)
//Table maintains the set of connections
type Table struct {
connections map[*Connection][]string
domains map[string]*Connection
register chan *Connection
unregister chan *Connection
domainAnnounce chan *DomainMapping
domainRevoke chan *DomainMapping
}
//NewTable -- consructor
func NewTable() (p *Table) {
p = new(Table)
p.connections = make(map[*Connection][]string)
p.domains = make(map[string]*Connection)
p.register = make(chan *Connection)
p.unregister = make(chan *Connection)
p.domainAnnounce = make(chan *DomainMapping)
p.domainRevoke = make(chan *DomainMapping)
return
}
//Run -- Execute
func (c *Table) Run() {
loginfo.Println("ConnectionTable starting")
for {
select {
case connection := <-c.register:
loginfo.Println("register fired")
c.connections[connection] = make([]string, incrementDomains)
connection.commCh <- true
// handle initial domain additions
for _, domain := range connection.initialDomains {
// add to the domains regirstation
newDomain := string(domain.(string))
loginfo.Println("adding domain ", newDomain, " to connection ", connection)
c.domains[newDomain] = connection
// add to the connection domain list
s := c.connections[connection]
c.connections[connection] = append(s, newDomain)
}
fmt.Println(c.domains)
fmt.Println(c.connections)
loginfo.Println("register exiting")
case connection := <-c.unregister:
loginfo.Println("closing connection ", connection)
if _, ok := c.connections[connection]; ok {
for _, domain := range c.connections[connection] {
fmt.Println("removing domain ", domain)
if _, ok := c.domains[domain]; ok {
delete(c.domains, domain)
}
}
delete(c.connections, connection)
close(connection.send)
fmt.Println(c.domains)
fmt.Println(c.connections)
}
case domainMapping := <-c.domainAnnounce:
loginfo.Println("domainMapping fired ", domainMapping)
//check to make sure connection is already regiered, you can no register a domain without an apporved connection
//if connection, ok := connections[domainMapping.connection]; ok {
//} else {
//}
}
}
}
//Register -- Property
func (c *Table) Register() (r chan *Connection) {
r = c.register
return
}