add lastseen + cleanup
This commit is contained in:
parent
e7499dbae5
commit
17ac739753
|
@ -22,7 +22,7 @@ func (c *Controller) Handler(addr *net.UDPAddr, msg *data.SocketMSG) (*data.Sock
|
|||
Client: c.db.GetClient(msg.Client.Addr),
|
||||
}
|
||||
|
||||
if c.central || !ignore {
|
||||
if !ignore {
|
||||
return msg, nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
@ -15,7 +15,6 @@ type Controller struct {
|
|||
Send func(msg *data.SocketMSG)
|
||||
db *database.DB
|
||||
ticker *time.Ticker
|
||||
central bool
|
||||
}
|
||||
|
||||
func NewController(db *database.DB) *Controller {
|
||||
|
@ -33,6 +32,6 @@ func (c *Controller) Close() {
|
|||
|
||||
func (c *Controller) Repeated() {
|
||||
for range c.ticker.C {
|
||||
log.Debug("lerned: %d APs, %d Clients", len(c.db.APs), len(c.db.Clients))
|
||||
log.Debugf("lerned: %d APs, %d Clients", len(c.db.APs), len(c.db.Clients))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,22 @@
|
|||
package database
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/FreifunkBremen/yanic/lib/jsontime"
|
||||
)
|
||||
|
||||
type AP struct {
|
||||
IP *net.IP
|
||||
IP *net.IP `json:"ip"`
|
||||
Lastseen jsontime.Time `json:"lastseen"`
|
||||
}
|
||||
|
||||
func (db *DB) GetClients(ap *AP) []*Client {
|
||||
var clients []*Client
|
||||
for _, client := range db.Clients {
|
||||
if client.AP == ap {
|
||||
clients = append(clients, client)
|
||||
}
|
||||
}
|
||||
return clients
|
||||
}
|
||||
|
|
|
@ -5,20 +5,23 @@ import (
|
|||
"time"
|
||||
|
||||
// log "github.com/sirupsen/logrus"
|
||||
"github.com/FreifunkBremen/yanic/lib/jsontime"
|
||||
|
||||
"dev.sum7.eu/wifictld/analyzer/data"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
Addr net.HardwareAddr
|
||||
Time time.Time
|
||||
TryProbe uint16
|
||||
TryAuth uint16
|
||||
Connected bool
|
||||
Authed bool
|
||||
FreqHighest uint16
|
||||
SignalLowFreq int16
|
||||
SignalHighFreq int16
|
||||
AP *AP `json:"-"`
|
||||
APAddr string `json:"ap"`
|
||||
Addr net.HardwareAddr `json:"-"`
|
||||
TryProbe uint16 `json:"try_probe"`
|
||||
TryAuth uint16 `json:"try_auth"`
|
||||
Connected bool `json:"connected"`
|
||||
Authed bool `json:"authed"`
|
||||
FreqHighest uint16 `json:"freq_highest"`
|
||||
SignalLowFreq int16 `json:"signal_low_freq"`
|
||||
SignalHighFreq int16 `json:"signal_high_freq"`
|
||||
Lastseen jsontime.Time `json:"lastseen"`
|
||||
}
|
||||
|
||||
func (db *DB) LearnClient(apIP net.IP, clientWifictl *data.WifiClient) bool {
|
||||
|
@ -32,6 +35,7 @@ func (db *DB) LearnClient(apIP net.IP, clientWifictl *data.WifiClient) bool {
|
|||
db.APs[apAddr] = ap
|
||||
}
|
||||
ap.IP = &apIP
|
||||
ap.Lastseen = jsontime.Now()
|
||||
|
||||
// learn client
|
||||
clientAddr := clientWifictl.Addr.String()
|
||||
|
@ -42,7 +46,9 @@ func (db *DB) LearnClient(apIP net.IP, clientWifictl *data.WifiClient) bool {
|
|||
}
|
||||
db.Clients[clientAddr] = client
|
||||
}
|
||||
client.Time = time.Now()
|
||||
client.Lastseen = jsontime.Now()
|
||||
client.AP = ap
|
||||
client.APAddr = apAddr
|
||||
|
||||
if client.FreqHighest < clientWifictl.FreqHighest {
|
||||
ret = (client.FreqHighest != 0)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -23,6 +24,13 @@ func NewDB(path string) *DB {
|
|||
|
||||
file.ReadJSON(path, db)
|
||||
|
||||
for addr, client := range db.Clients {
|
||||
client.Addr, _ = net.ParseMAC(addr)
|
||||
if ap, ok := db.APs[client.APAddr]; ok {
|
||||
client.AP = ap
|
||||
}
|
||||
}
|
||||
|
||||
db.worker = worker.NewWorker(time.Minute, func() {
|
||||
file.SaveJSON(path, db)
|
||||
log.Debug("save db state")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
state_path = "/tmp/wifictld.json"
|
||||
|
||||
[[interfaces]]
|
||||
ifname = "mmfd0"
|
||||
ifname = "wlp4s0"
|
||||
#port = 1000
|
||||
#ip_address = "ff02::31f1"
|
||||
|
|
Loading…
Reference in New Issue