wifictld-analyzer/database/client.go

71 lines
1.6 KiB
Go
Raw Normal View History

2018-06-03 20:37:52 +02:00
package database
import (
"net"
"time"
// log "github.com/sirupsen/logrus"
2018-07-16 13:00:37 +02:00
"github.com/FreifunkBremen/yanic/lib/jsontime"
2018-06-03 20:37:52 +02:00
"dev.sum7.eu/wifictld/analyzer/data"
)
type Client struct {
2018-07-16 13:00:37 +02:00
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"`
2018-06-03 20:37:52 +02:00
}
func (db *DB) LearnClient(apIP net.IP, clientWifictl *data.WifiClient) bool {
ret := false
2018-07-10 21:40:38 +02:00
// learn ap
2018-06-03 20:37:52 +02:00
apAddr := apIP.String()
ap, ok := db.APs[apAddr]
if !ok {
ap = &AP{}
db.APs[apAddr] = ap
}
2018-07-10 21:40:38 +02:00
ap.IP = &apIP
2018-07-16 13:00:37 +02:00
ap.Lastseen = jsontime.Now()
2018-07-10 21:40:38 +02:00
// learn client
2018-06-03 20:37:52 +02:00
clientAddr := clientWifictl.Addr.String()
client, ok := db.Clients[clientAddr]
if !ok {
client = &Client{
Addr: clientWifictl.Addr,
}
db.Clients[clientAddr] = client
}
2018-07-16 13:00:37 +02:00
client.Lastseen = jsontime.Now()
client.AP = ap
client.APAddr = apAddr
2018-06-03 20:37:52 +02:00
if client.FreqHighest < clientWifictl.FreqHighest {
ret = (client.FreqHighest != 0)
client.FreqHighest = clientWifictl.FreqHighest
}
return ret
}
func (db *DB) GetClient(addr net.HardwareAddr) *data.WifiClient {
client, ok := db.Clients[addr.String()]
wClient := &data.WifiClient{
Addr: addr,
Time: time.Now(),
}
if ok {
wClient.TryProbe = client.TryProbe
}
return wClient
}