[TASk] put multicast address in config file

This commit is contained in:
Martin Geno 2017-07-05 15:51:06 +02:00
parent b4e6cd5864
commit 0a207d0170
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
4 changed files with 10 additions and 5 deletions

View File

@ -49,6 +49,9 @@ func main() {
if config.Respondd.InterfaceSendMulticast == "" { if config.Respondd.InterfaceSendMulticast == "" {
config.Respondd.InterfaceSendMulticast = config.Respondd.InterfaceListen config.Respondd.InterfaceSendMulticast = config.Respondd.InterfaceListen
} }
if config.Respondd.MulticastDestination != "" {
respond.MulticastGroup = config.Respondd.MulticastDestination
}
connections, err = allDB.Connect(config.Database.Connection) connections, err = allDB.Connect(config.Database.Connection)
if err != nil { if err != nil {
@ -88,7 +91,7 @@ func main() {
time.Sleep(delay) time.Sleep(delay)
} }
collector = respond.NewCollector(connections, nodes, config.Respondd.InterfaceListen, config.Respondd.InterfaceSendMulticast, config.Respondd.InterfaceSendUnicast, config.Respondd.Port) collector = respond.NewCollector(connections, nodes, config.Respondd.InterfaceListen, config.Respondd.InterfaceSendMulticast, config.Respondd.InterfaceSendUnicast, config.Respondd.ListenPort)
collector.Start(config.Respondd.CollectInterval.Duration) collector.Start(config.Respondd.CollectInterval.Duration)
defer collector.Close() defer collector.Close()
} }

View File

@ -120,7 +120,7 @@ func (coll *Collector) sendOnce() {
func (coll *Collector) sendMulticast() { func (coll *Collector) sendMulticast() {
log.Println("sending multicast") log.Println("sending multicast")
coll.SendPacket(net.UDPAddr{ coll.SendPacket(net.UDPAddr{
IP: net.ParseIP(multiCastGroup), IP: net.ParseIP(MulticastGroup),
Zone: coll.ifaceSendMulticast, Zone: coll.ifaceSendMulticast,
}) })
} }

View File

@ -4,9 +4,10 @@ import (
"net" "net"
) )
const (
// default multicast group used by announced // default multicast group used by announced
multiCastGroup = "ff02:0:0:0:0:0:2:1001" var MulticastGroup string = "ff02:0:0:0:0:0:2:1001"
const (
// default udp port used by announced // default udp port used by announced
port = 1001 port = 1001

View File

@ -14,7 +14,8 @@ type Config struct {
InterfaceListen string `toml:"interface"` InterfaceListen string `toml:"interface"`
InterfaceSendMulticast string `toml:"interface_send_multicast"` InterfaceSendMulticast string `toml:"interface_send_multicast"`
InterfaceSendUnicast string `toml:"interface_send_unicast"` InterfaceSendUnicast string `toml:"interface_send_unicast"`
Port int `toml:"port"` ListenPort int `toml:"port"`
MulticastDestination string `toml:"destination"`
CollectInterval Duration `toml:"collect_interval"` CollectInterval Duration `toml:"collect_interval"`
} }
Webserver struct { Webserver struct {