mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-13 00:40:24 +03:00
Allow multicast to be shut down more sanely
This commit is contained in:
parent
00a972b74e
commit
366fe7e772
@ -27,6 +27,8 @@ type Multicast struct {
|
||||
listeners map[string]*yggdrasil.TcpListener
|
||||
listenPort uint16
|
||||
isOpen bool
|
||||
announcer *time.Timer
|
||||
platformhandler *time.Timer
|
||||
}
|
||||
|
||||
// Init prepares the multicast interface for use.
|
||||
@ -63,9 +65,9 @@ func (m *Multicast) Start() error {
|
||||
}
|
||||
|
||||
m.isOpen = true
|
||||
go m.multicastStarted()
|
||||
go m.listen()
|
||||
go m.announce()
|
||||
m.multicastStarted()
|
||||
m.announce()
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -73,6 +75,8 @@ func (m *Multicast) Start() error {
|
||||
// Stop is not implemented for multicast yet.
|
||||
func (m *Multicast) Stop() error {
|
||||
m.isOpen = false
|
||||
m.announcer.Stop()
|
||||
m.platformhandler.Stop()
|
||||
m.sock.Close()
|
||||
return nil
|
||||
}
|
||||
@ -136,7 +140,6 @@ func (m *Multicast) announce() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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
|
||||
@ -236,8 +239,7 @@ func (m *Multicast) announce() {
|
||||
break
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second * 15)
|
||||
}
|
||||
m.announcer = time.AfterFunc(time.Second*15, m.announce)
|
||||
}
|
||||
|
||||
func (m *Multicast) listen() {
|
||||
|
@ -32,21 +32,14 @@ import (
|
||||
var awdlGoroutineStarted bool
|
||||
|
||||
func (m *Multicast) multicastStarted() {
|
||||
if awdlGoroutineStarted {
|
||||
return
|
||||
}
|
||||
awdlGoroutineStarted = true
|
||||
for {
|
||||
C.StopAWDLBrowsing()
|
||||
for intf := range m.Interfaces() {
|
||||
if intf == "awdl0" {
|
||||
m.log.Infoln("Multicast discovery is using AWDL discovery")
|
||||
C.StartAWDLBrowsing()
|
||||
break
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Minute)
|
||||
}
|
||||
m.platformhandler = time.AfterFunc(time.Minute, m.multicastStarted)
|
||||
}
|
||||
|
||||
func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error {
|
||||
|
Loading…
Reference in New Issue
Block a user