wifictld-analyzer/database/client.go

84 lines
2.0 KiB
Go
Raw Normal View History

2018-06-03 20:37:52 +02:00
package database
import (
"net"
"time"
2019-02-28 16:24:29 +01:00
// "github.com/bdlm/log"
2018-07-16 13:00:37 +02:00
"github.com/FreifunkBremen/yanic/lib/jsontime"
2018-06-03 20:37:52 +02:00
2019-02-28 16:22:55 +01:00
"dev.sum7.eu/genofire/wifictld-analyzer/data"
2018-06-03 20:37:52 +02:00
)
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-07-25 14:50:47 +02:00
client.Connected = clientWifictl.Connected
client.SignalLowFreq = clientWifictl.SignalLowFreq
client.SignalHighFreq = clientWifictl.SignalHighFreq
if clientWifictl.TryAuth > client.TryAuth {
client.TryAuth = clientWifictl.TryAuth
}
if clientWifictl.TryProbe > client.TryProbe {
client.TryProbe = clientWifictl.TryProbe
}
2018-06-03 20:37:52 +02:00
if client.FreqHighest < clientWifictl.FreqHighest {
ret = (client.FreqHighest != 0)
client.FreqHighest = clientWifictl.FreqHighest
}
2018-07-25 14:50:47 +02:00
if clientWifictl.Authed {
client.Authed = clientWifictl.Authed
}
2018-06-03 20:37:52 +02:00
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
}