wifictld-analyzer/controller/handler.go

44 lines
1018 B
Go

package controller
import (
"net"
"time"
// "github.com/bdlm/log"
"dev.sum7.eu/genofire/golang-lib/database"
"dev.sum7.eu/genofire/wifictld-analyzer/capture"
"dev.sum7.eu/genofire/wifictld-analyzer/data"
)
func (c *Controller) Handler(addr *net.UDPAddr, msg *capture.SocketMSG) (*capture.SocketMSG, error) {
ignore := false
if msg.Types.Is(capture.SocketMSGTypeClient) && msg.Client != nil {
ignore = c.LearnClient(addr.IP, msg.Client)
}
if !msg.Types.Is(capture.SocketMSGTypeRequest) {
return nil, nil
}
client := &data.Client{Addr: msg.Client.Addr}
if result := database.Read.Select([]string{"try_probe", "try_auth"}).First(client); result.Error != nil {
return nil, result.Error
}
msg = &capture.SocketMSG{
Types: (capture.SocketMSGTypeResponse | capture.SocketMSGTypeClient),
Client: &capture.WifiClient{
Addr: msg.Client.Addr,
Time: time.Now(),
TryProbe: client.TryProbe,
TryAuth: client.TryAuth,
},
}
if !ignore {
return msg, nil
}
return nil, nil
}