2018-06-30 16:20:54 +02:00
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2018-07-26 14:14:23 +02:00
|
|
|
wsLib "dev.sum7.eu/genofire/golang-lib/websocket"
|
2018-07-15 21:04:17 +02:00
|
|
|
|
|
|
|
"github.com/FreifunkBremen/freifunkmanager/runtime"
|
2018-06-30 16:20:54 +02:00
|
|
|
)
|
|
|
|
|
2018-07-15 21:04:17 +02:00
|
|
|
var wifi24Channels []uint32
|
|
|
|
var wifi5Channels []uint32
|
|
|
|
|
2018-06-30 16:20:54 +02:00
|
|
|
func (ws *WebsocketServer) connectHandler(logger *log.Entry, msg *wsLib.Message) error {
|
2018-07-26 14:14:23 +02:00
|
|
|
//msg.From.Write(&wsLib.Message{Subject: MessageTypeStats, Body: ws.nodes.Statistics})
|
|
|
|
var nodes []*runtime.Node
|
|
|
|
var count int
|
|
|
|
|
2018-08-10 13:46:18 +02:00
|
|
|
ws.db.Where("blacklist = false").Find(&nodes).Count(&count)
|
2018-07-26 14:14:23 +02:00
|
|
|
|
|
|
|
ws.nodes.Lock()
|
|
|
|
i := 0
|
2018-08-10 13:46:18 +02:00
|
|
|
for _, node := range nodes {
|
|
|
|
//TODO skip blacklist
|
|
|
|
node.Update(ws.nodes.List[node.NodeID], ws.ipPrefix)
|
|
|
|
msg.From.Write(&wsLib.Message{Subject: MessageTypeNode, Body: node})
|
2018-07-26 14:14:23 +02:00
|
|
|
i++
|
|
|
|
}
|
|
|
|
ws.nodes.Unlock()
|
2018-07-15 21:04:17 +02:00
|
|
|
msg.From.Write(&wsLib.Message{Subject: MessageTypeChannelsWifi24, Body: wifi24Channels})
|
|
|
|
msg.From.Write(&wsLib.Message{Subject: MessageTypeChannelsWifi5, Body: wifi5Channels})
|
2018-07-26 14:14:23 +02:00
|
|
|
logger.Debugf("done - fetch %d nodes and send %d", count, i)
|
2018-06-30 16:20:54 +02:00
|
|
|
return nil
|
|
|
|
}
|
2018-07-15 21:04:17 +02:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
for ch, channel := range runtime.ChannelList {
|
|
|
|
if runtime.ChannelEU && !channel.AllowedInEU {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if channel.Frequenz > runtime.FREQ_THREASHOLD {
|
|
|
|
wifi5Channels = append(wifi5Channels, ch)
|
|
|
|
} else {
|
|
|
|
wifi24Channels = append(wifi24Channels, ch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|