implement full yanic (to run freifunkmanager at his own)

This commit is contained in:
Martin/Geno 2018-07-17 23:11:47 +02:00
parent b97ac6ea43
commit 140f11257a
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
4 changed files with 34 additions and 50 deletions

View File

@ -8,8 +8,16 @@ secret = "passw0rd"
ssh_key = "~/.ssh/id_rsa"
ssh_interface = "wlp4s0"
# enable receiving
yanic_enable = true
# yanic_synchronize = "1m"
yanic_collect_interval = "1m"
[yanic]
enable = true
ifname = "lo"
address = "::1"
port = 10001
ifname = "wlp4s0"
# e.g. to receive data of real yanic
# - please also disable `yanic_collect_interval`
# ifname = "lo"
# ip_address = "::1"
# send_no_request = no
# port

21
main.go
View File

@ -58,13 +58,19 @@ func main() {
nodes.AddNotifyStats(ws.SendStats)
nodes.AddNotifyNode(ws.SendNode)
if config.Yanic.Enable {
collector = respondYanic.NewCollector(db, nodesYanic, make(map[string][]string), []respondYanic.InterfaceConfig{respondYanic.InterfaceConfig{
InterfaceName: config.Yanic.InterfaceName,
IPAddress: config.Yanic.Address,
Port: config.Yanic.Port,
}})
if config.YanicEnable {
if duration := config.YanicSynchronize.Duration; duration > 0 {
now := time.Now()
delay := duration - now.Sub(now.Truncate(duration))
log.Printf("delaying %0.1f seconds", delay.Seconds())
time.Sleep(delay)
}
collector = respondYanic.NewCollector(db, nodesYanic, make(map[string][]string), []respondYanic.InterfaceConfig{config.Yanic})
if duration := config.YanicCollectInterval.Duration; duration > 0 {
collector.Start(config.YanicCollectInterval.Duration)
}
defer collector.Close()
log.Info("started Yanic collector")
}
// Startwebserver
@ -97,9 +103,6 @@ func main() {
// Stop services
srv.Close()
if config.Yanic.Enable {
collector.Close()
}
nodesSaveWorker.Close()
nodesUpdateWorker.Close()

View File

@ -1,5 +1,11 @@
package runtime
import (
"github.com/FreifunkBremen/yanic/lib/duration"
respondYanic "github.com/FreifunkBremen/yanic/respond"
)
//config file of this daemon (for more the config_example.conf in git repository)
type Config struct {
// prevent crashes
@ -18,10 +24,8 @@ type Config struct {
SSHInterface string `toml:"ssh_interface"`
// yanic socket
Yanic struct {
Enable bool `toml:"enable"`
InterfaceName string `toml:"ifname"`
Address string `toml:"address"`
Port int `toml:"port"`
} `toml:"yanic"`
YanicEnable bool `toml:"yanic_enable"`
YanicSynchronize duration.Duration `toml:"yanic_synchronize"`
YanicCollectInterval duration.Duration `toml:"yanic_collect_interval"`
Yanic respondYanic.InterfaceConfig `toml:"yanic"`
}

View File

@ -1,31 +0,0 @@
[respondd]
enable = true
collect_interval = "1m"
[[respondd.interfaces]]
ifname = "wlp4s0"
[webserver]
enable = false
[nodes]
state_path = "/tmp/state.json"
prune_after = "7d"
save_interval = "5s"
offline_after = "10m"
[[nodes.output.meshviewer-ffrgb]]
enable = true
path = "./webroot/data/meshviewer.json"
[nodes.output.meshviewer-ffrgb.filter]
no_owner = false
[database]
delete_after = "1y"
delete_interval = "1h"
[[database.connection.respondd]]
enable = true
type = "udp6"
address = "[::1]:10001"