announce useable channels + fix tests

This commit is contained in:
Martin/Geno 2018-07-15 21:04:17 +02:00
parent ca1835fcac
commit 393caf55f8
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
8 changed files with 88 additions and 10 deletions

View File

@ -14,6 +14,7 @@ type Channel struct {
var (
ChannelEU = true
ChannelList = map[uint32]*Channel{
1: &Channel{Frequenz: 2412, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
2: &Channel{Frequenz: 2417, AllowedInEU: true, DFS: false, Indoor: false, SDR: false},
@ -84,16 +85,13 @@ var (
)
func ChannelIs5GHz(channel uint32) bool {
fre, ok := ChannelList[channel]
return ok && fre.Frequenz < FREQ_THREASHOLD
ch, ok := ChannelList[channel]
return ok && (!ChannelEU || ch.AllowedInEU) && ch.Frequenz > FREQ_THREASHOLD
}
func GetChannel(channel uint32) *Channel {
if ch, ok := ChannelList[channel]; ok {
if !ChannelEU {
return ch
}
if ch.AllowedInEU {
if !ChannelEU || ch.AllowedInEU {
return ch
}
}

30
runtime/channel_test.go Normal file
View File

@ -0,0 +1,30 @@
package runtime
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestChannel(t *testing.T) {
assert := assert.New(t)
ChannelEU = true
assert.False(ChannelIs5GHz(11), "is 2.4 GHz in EU")
assert.True(ChannelIs5GHz(40), "is 5 GHz everywhere")
assert.False(ChannelIs5GHz(42), "is not 5 GHz in EU")
assert.NotNil(GetChannel(11), "is 2.4 GHz channel everywhere")
assert.NotNil(GetChannel(40), "is 5 GHz channel everywhere")
assert.Nil(GetChannel(42), "is not a 5 GHz channel in EU")
ChannelEU = false
assert.False(ChannelIs5GHz(11), "is 2.4 GHz in EU")
assert.True(ChannelIs5GHz(40), "is 5 GHz everywhere")
assert.True(ChannelIs5GHz(42), "is 5 GHz somewhere else")
assert.NotNil(GetChannel(11), "is 2.4 GHz channel everywhere")
assert.NotNil(GetChannel(40), "is 5 GHz channel everywhere")
assert.NotNil(GetChannel(42), "is 5 GHz channel somewhere else")
}

View File

@ -10,7 +10,7 @@ import (
func TestExecute(t *testing.T) {
assert := assert.New(t)
addr := net.TCPAddr{IP: net.ParseIP("2a06:8782:ffbb:1337::127"), Port: 22}
addr := net.TCPAddr{IP: net.ParseIP("fd2f:5119:f2c::127"), Port: 22}
mgmt := NewManager("~/.ssh/id_rsa")
assert.NotNil(mgmt, "no new manager created")

View File

@ -13,6 +13,6 @@ func TestManager(t *testing.T) {
mgmt := NewManager("~/.ssh/id_rsa")
assert.NotNil(mgmt, "no new manager created")
client, _ := mgmt.ConnectTo(net.TCPAddr{IP: net.ParseIP("2a06:8782:ffbb:1337::127"), Port: 22})
client, _ := mgmt.ConnectTo(net.TCPAddr{IP: net.ParseIP("fd2f:5119:f2c::127"), Port: 22})
client.Close()
}

View File

@ -10,7 +10,7 @@ import (
func TestRun(t *testing.T) {
assert := assert.New(t)
addr := net.TCPAddr{IP: net.ParseIP("2a06:8782:ffbb:1337::127"), Port: 22}
addr := net.TCPAddr{IP: net.ParseIP("fd2f:5119:f2c::127"), Port: 22}
mgmt := NewManager("~/.ssh/id_rsa")
assert.NotNil(mgmt, "no new manager created")

View File

@ -4,8 +4,13 @@ import (
log "github.com/sirupsen/logrus"
wsLib "github.com/genofire/golang-lib/websocket"
"github.com/FreifunkBremen/freifunkmanager/runtime"
)
var wifi24Channels []uint32
var wifi5Channels []uint32
func (ws *WebsocketServer) connectHandler(logger *log.Entry, msg *wsLib.Message) error {
msg.From.Write(&wsLib.Message{Subject: MessageTypeStats, Body: ws.nodes.Statistics})
@ -15,6 +20,21 @@ func (ws *WebsocketServer) connectHandler(logger *log.Entry, msg *wsLib.Message)
for _, node := range ws.nodes.Current {
msg.From.Write(&wsLib.Message{Subject: MessageTypeCurrentNode, Body: node})
}
msg.From.Write(&wsLib.Message{Subject: MessageTypeChannelsWifi24, Body: wifi24Channels})
msg.From.Write(&wsLib.Message{Subject: MessageTypeChannelsWifi5, Body: wifi5Channels})
logger.Debug("done")
return nil
}
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)
}
}
}

View File

@ -0,0 +1,27 @@
package websocket
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/FreifunkBremen/freifunkmanager/runtime"
)
func TestConnectChannelInit(t *testing.T) {
assert := assert.New(t)
for _, channel := range wifi24Channels {
assert.False(runtime.ChannelIs5GHz(channel), fmt.Sprintf("wifi24-is channel: %d", channel))
assert.NotNil(runtime.GetChannel(channel), fmt.Sprintf("wifi24-get channel: %d", channel))
}
assert.Len(wifi24Channels, 13)
for _, channel := range wifi5Channels {
assert.True(runtime.ChannelIs5GHz(channel), fmt.Sprintf("wifi5-is channel: %d", channel))
assert.NotNil(runtime.GetChannel(channel), fmt.Sprintf("wifi5-get channel: %d", channel))
}
assert.Len(wifi5Channels, 35)
}

View File

@ -7,6 +7,9 @@ const (
MessageTypeAuthStatus = "auth_status"
MessageTypeLogout = "logout"
MessageTypeChannelsWifi24 = "channel_wifi24"
MessageTypeChannelsWifi5 = "channel_wifi5"
MessageTypeSystemNode = "node-system"
MessageTypeCurrentNode = "node-current"
MessageTypeStats = "stats"