From dbfccc4a0cd1bf14ff1dea056fbe39c9677144cb Mon Sep 17 00:00:00 2001 From: Henry Camacho Date: Sun, 19 Feb 2017 14:32:03 -0600 Subject: [PATCH] Added support for connection reaping. --- rvpn/connection/connection.go | 9 --------- rvpn/connection/connection_table.go | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/rvpn/connection/connection.go b/rvpn/connection/connection.go index 1faf09e..6d05a33 100755 --- a/rvpn/connection/connection.go +++ b/rvpn/connection/connection.go @@ -44,9 +44,6 @@ type Connection struct { // bytes out bytesOut int64 - // communications channel between go routines - commCh chan bool - // Connect Time connectTime time.Time @@ -70,7 +67,6 @@ func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress s p.bytesIn = 0 p.bytesOut = 0 p.send = make(chan *SendTrack) - p.commCh = make(chan bool) p.connectTime = time.Now() p.initialDomains = initialDomains p.DomainTrack = make(map[string]*DomainTrack) @@ -133,11 +129,6 @@ func (c *Connection) ConnectionTable() (table *Table) { return } -//CommCh -- Property -func (c *Connection) CommCh() chan bool { - return c.commCh -} - //GetState -- Get state of Socket...this is a high level state. func (c *Connection) GetState() bool { defer func() { diff --git a/rvpn/connection/connection_table.go b/rvpn/connection/connection_table.go index b732453..00fdbcd 100755 --- a/rvpn/connection/connection_table.go +++ b/rvpn/connection/connection_table.go @@ -1,6 +1,7 @@ package connection import "fmt" +import "time" const ( initialDomains = 0 @@ -41,9 +42,30 @@ func (c *Table) ConnByDomain(domain string) (conn *Connection, ok bool) { return } +//reaper -- +func (c *Table) reaper(delay int, idle int) { + for { + loginfo.Println("Reaper waiting for ", delay, " seconds") + time.Sleep(time.Duration(delay) * time.Second) + + loginfo.Println("Running scanning ", len(c.connections)) + for d := range c.connections { + if d.GetState() == false { + if time.Since(d.lastUpdate).Seconds() > float64(idle) { + loginfo.Println("reaper removing ", d.lastUpdate, time.Since(d.lastUpdate).Seconds()) + delete(c.connections, d) + } + } + } + } +} + //Run -- Execute func (c *Table) Run() { loginfo.Println("ConnectionTable starting") + + go c.reaper(10, 20) + for { select { case registration := <-c.register: