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),
|
Client: c.db.GetClient(msg.Client.Addr),
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.central || !ignore {
|
if !ignore {
|
||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -11,11 +11,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
SendTo func(addr *net.UDPAddr, msg *data.SocketMSG)
|
SendTo func(addr *net.UDPAddr, msg *data.SocketMSG)
|
||||||
Send func(msg *data.SocketMSG)
|
Send func(msg *data.SocketMSG)
|
||||||
db *database.DB
|
db *database.DB
|
||||||
ticker *time.Ticker
|
ticker *time.Ticker
|
||||||
central bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(db *database.DB) *Controller {
|
func NewController(db *database.DB) *Controller {
|
||||||
|
@ -33,6 +32,6 @@ func (c *Controller) Close() {
|
||||||
|
|
||||||
func (c *Controller) Repeated() {
|
func (c *Controller) Repeated() {
|
||||||
for range c.ticker.C {
|
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
|
package database
|
||||||
|
|
||||||
import "net"
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/FreifunkBremen/yanic/lib/jsontime"
|
||||||
|
)
|
||||||
|
|
||||||
type AP struct {
|
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"
|
"time"
|
||||||
|
|
||||||
// log "github.com/sirupsen/logrus"
|
// log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/FreifunkBremen/yanic/lib/jsontime"
|
||||||
|
|
||||||
"dev.sum7.eu/wifictld/analyzer/data"
|
"dev.sum7.eu/wifictld/analyzer/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
Addr net.HardwareAddr
|
AP *AP `json:"-"`
|
||||||
Time time.Time
|
APAddr string `json:"ap"`
|
||||||
TryProbe uint16
|
Addr net.HardwareAddr `json:"-"`
|
||||||
TryAuth uint16
|
TryProbe uint16 `json:"try_probe"`
|
||||||
Connected bool
|
TryAuth uint16 `json:"try_auth"`
|
||||||
Authed bool
|
Connected bool `json:"connected"`
|
||||||
FreqHighest uint16
|
Authed bool `json:"authed"`
|
||||||
SignalLowFreq int16
|
FreqHighest uint16 `json:"freq_highest"`
|
||||||
SignalHighFreq int16
|
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 {
|
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
|
db.APs[apAddr] = ap
|
||||||
}
|
}
|
||||||
ap.IP = &apIP
|
ap.IP = &apIP
|
||||||
|
ap.Lastseen = jsontime.Now()
|
||||||
|
|
||||||
// learn client
|
// learn client
|
||||||
clientAddr := clientWifictl.Addr.String()
|
clientAddr := clientWifictl.Addr.String()
|
||||||
|
@ -42,7 +46,9 @@ func (db *DB) LearnClient(apIP net.IP, clientWifictl *data.WifiClient) bool {
|
||||||
}
|
}
|
||||||
db.Clients[clientAddr] = client
|
db.Clients[clientAddr] = client
|
||||||
}
|
}
|
||||||
client.Time = time.Now()
|
client.Lastseen = jsontime.Now()
|
||||||
|
client.AP = ap
|
||||||
|
client.APAddr = apAddr
|
||||||
|
|
||||||
if client.FreqHighest < clientWifictl.FreqHighest {
|
if client.FreqHighest < clientWifictl.FreqHighest {
|
||||||
ret = (client.FreqHighest != 0)
|
ret = (client.FreqHighest != 0)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -23,6 +24,13 @@ func NewDB(path string) *DB {
|
||||||
|
|
||||||
file.ReadJSON(path, 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() {
|
db.worker = worker.NewWorker(time.Minute, func() {
|
||||||
file.SaveJSON(path, db)
|
file.SaveJSON(path, db)
|
||||||
log.Debug("save db state")
|
log.Debug("save db state")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
state_path = "/tmp/wifictld.json"
|
state_path = "/tmp/wifictld.json"
|
||||||
|
|
||||||
[[interfaces]]
|
[[interfaces]]
|
||||||
ifname = "mmfd0"
|
ifname = "wlp4s0"
|
||||||
#port = 1000
|
#port = 1000
|
||||||
#ip_address = "ff02::31f1"
|
#ip_address = "ff02::31f1"
|
||||||
|
|
Loading…
Reference in New Issue