From b17d018dba9aa2a04cebe3af960d8fa5f1429511 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Thu, 6 Jul 2017 12:38:14 +0200 Subject: [PATCH] Breminale --- respond/collector.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/respond/collector.go b/respond/collector.go index b5406c1..ad18689 100644 --- a/respond/collector.go +++ b/respond/collector.go @@ -33,7 +33,7 @@ func NewCollector(db database.Connection, nodes *runtime.Nodes, iface string, po log.Panic(err) } - // Open socket + // Open link local socket conn, err := net.ListenUDP("udp", &net.UDPAddr{ IP: linkLocalAddr, Port: port, @@ -53,8 +53,9 @@ func NewCollector(db database.Connection, nodes *runtime.Nodes, iface string, po stop: make(chan interface{}), } - go collector.receiver() + go collector.receiver(conn) go collector.parser() + collector.listenPublic() if collector.db != nil { go collector.globalStatsWorker() @@ -83,6 +84,18 @@ func getLinkLocalAddr(ifname string) (net.IP, error) { return nil, fmt.Errorf("unable to find link local unicast address for %s", ifname) } +func (coll *Collector) listenPublic() { + conn, err := net.ListenUDP("udp", &net.UDPAddr{ + IP: net.ParseIP("::"), + Port: 12345, + }) + if err != nil { + log.Panic(err) + } + conn.SetReadBuffer(maxDataGramSize) + go coll.receiver(conn) +} + // Start Collector func (coll *Collector) Start(interval time.Duration) { if coll.interval != 0 { @@ -167,6 +180,7 @@ func (coll *Collector) sender() { func (coll *Collector) parser() { for obj := range coll.queue { + if data, err := obj.parse(); err != nil { log.Println("unable to decode response from", obj.Address.String(), err, "\n", string(obj.Raw)) } else { @@ -215,10 +229,10 @@ func (coll *Collector) saveResponse(addr net.UDPAddr, res *data.ResponseData) { } } -func (coll *Collector) receiver() { +func (coll *Collector) receiver(conn *net.UDPConn) { buf := make([]byte, maxDataGramSize) for { - n, src, err := coll.connection.ReadFromUDP(buf) + n, src, err := conn.ReadFromUDP(buf) if err != nil { log.Println("ReadFromUDP failed:", err)