From c0d5a8c0bd8e9de113edc01063f98b2665ca56a3 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 6 Mar 2019 12:09:57 +0000 Subject: [PATCH] Clean up old listeners first --- src/yggdrasil/multicast.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/yggdrasil/multicast.go b/src/yggdrasil/multicast.go index d4a03ff3..0b913ed7 100644 --- a/src/yggdrasil/multicast.go +++ b/src/yggdrasil/multicast.go @@ -115,6 +115,15 @@ func (m *multicast) announce() { } for { interfaces := m.interfaces() + // There might be interfaces that we configured listeners for but are no + // longer up - if that's the case then we should stop the listeners + for name, listener := range m.listeners { + if _, ok := interfaces[name]; !ok { + listener.stop <- true + delete(m.listeners, name) + m.core.log.Debugln("No longer multicasting on", name) + } + } // Now that we have a list of valid interfaces from the operating system, // we can start checking if we can send multicasts on them for _, iface := range interfaces { @@ -164,15 +173,6 @@ func (m *multicast) announce() { } time.Sleep(time.Second) } - // There might be interfaces that we configured listeners for but are no - // longer up - if that's the case then we should stop the listeners - for name, listener := range m.listeners { - if _, ok := interfaces[name]; !ok { - listener.stop <- true - delete(m.listeners, name) - m.core.log.Debugln("No longer multicasting on", name) - } - } time.Sleep(time.Second * 5) } }