Compare commits
1 Commits
master
...
breminale-
Author | SHA1 | Date | |
---|---|---|---|
|
b17d018dba |
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user