mirror of
				https://github.com/therootcompany/telebit.git
				synced 2025-10-31 13:22:46 +00:00 
			
		
		
		
	Added support for connection reaping.
This commit is contained in:
		
							parent
							
								
									ff3e63da8d
								
							
						
					
					
						commit
						dbfccc4a0c
					
				| @ -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() { | ||||
|  | ||||
| @ -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: | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user