42 lines
		
	
	
		
			784 B
		
	
	
	
		
			Go
		
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			784 B
		
	
	
	
		
			Go
		
	
	
	
| package controller
 | |
| 
 | |
| import (
 | |
| 	"net"
 | |
| 	"time"
 | |
| 
 | |
| 	"dev.sum7.eu/genofire/golang-lib/database"
 | |
| 	"github.com/bdlm/log"
 | |
| 
 | |
| 	"dev.sum7.eu/genofire/wifictld-analyzer/capture"
 | |
| 	"dev.sum7.eu/genofire/wifictld-analyzer/data"
 | |
| )
 | |
| 
 | |
| type Controller struct {
 | |
| 	SendTo func(addr *net.UDPAddr, msg *capture.SocketMSG)
 | |
| 	Send   func(msg *capture.SocketMSG)
 | |
| 	ticker *time.Ticker
 | |
| }
 | |
| 
 | |
| func NewController() *Controller {
 | |
| 	ctl := &Controller{
 | |
| 		ticker: time.NewTicker(time.Minute),
 | |
| 	}
 | |
| 	go ctl.Repeated()
 | |
| 	return ctl
 | |
| }
 | |
| 
 | |
| func (c *Controller) Close() {
 | |
| 	c.ticker.Stop()
 | |
| }
 | |
| 
 | |
| func (c *Controller) Repeated() {
 | |
| 	aps := 0
 | |
| 	clients := 0
 | |
| 
 | |
| 	for range c.ticker.C {
 | |
| 		database.Read.Model(&data.AP{}).Count(&aps)
 | |
| 		database.Read.Model(&data.Client{}).Count(&clients)
 | |
| 		log.Debugf("learned: %d APs, %d Clients", aps, clients)
 | |
| 	}
 | |
| }
 |