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_key = "~/.ssh/id_rsa"
ssh_interface = "wlp4s0" ssh_interface = "wlp4s0"
# enable receiving
yanic_enable = true
# yanic_synchronize = "1m"
yanic_collect_interval = "1m"
[yanic] [yanic]
enable = true ifname = "wlp4s0"
ifname = "lo" # e.g. to receive data of real yanic
address = "::1" # - please also disable `yanic_collect_interval`
port = 10001 # 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.AddNotifyStats(ws.SendStats)
nodes.AddNotifyNode(ws.SendNode) nodes.AddNotifyNode(ws.SendNode)
if config.Yanic.Enable { if config.YanicEnable {
collector = respondYanic.NewCollector(db, nodesYanic, make(map[string][]string), []respondYanic.InterfaceConfig{respondYanic.InterfaceConfig{ if duration := config.YanicSynchronize.Duration; duration > 0 {
InterfaceName: config.Yanic.InterfaceName, now := time.Now()
IPAddress: config.Yanic.Address, delay := duration - now.Sub(now.Truncate(duration))
Port: config.Yanic.Port, 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() defer collector.Close()
log.Info("started Yanic collector")
} }
// Startwebserver // Startwebserver
@ -97,9 +103,6 @@ func main() {
// Stop services // Stop services
srv.Close() srv.Close()
if config.Yanic.Enable {
collector.Close()
}
nodesSaveWorker.Close() nodesSaveWorker.Close()
nodesUpdateWorker.Close() nodesUpdateWorker.Close()

View File

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