Multicast actor to prevent races

This commit is contained in:
Neil Alexander 2019-09-18 16:51:46 +01:00
parent b959f53fee
commit 2dc136f94a
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 10 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import (
"regexp" "regexp"
"time" "time"
"github.com/Arceliar/phony"
"github.com/gologme/log" "github.com/gologme/log"
"github.com/yggdrasil-network/yggdrasil-go/src/config" "github.com/yggdrasil-network/yggdrasil-go/src/config"
@ -19,6 +20,7 @@ import (
// configured multicast interface, Yggdrasil will attempt to peer with that node // configured multicast interface, Yggdrasil will attempt to peer with that node
// automatically. // automatically.
type Multicast struct { type Multicast struct {
phony.Inbox
core *yggdrasil.Core core *yggdrasil.Core
config *config.NodeState config *config.NodeState
log *log.Logger log *log.Logger
@ -66,8 +68,8 @@ func (m *Multicast) Start() error {
m.isOpen = true m.isOpen = true
go m.listen() go m.listen()
m.multicastStarted() m.Act(m, m.multicastStarted)
m.announce() m.Act(m, m.announce)
return nil return nil
} }
@ -243,7 +245,9 @@ func (m *Multicast) announce() {
break break
} }
} }
m.announcer = time.AfterFunc(time.Second*15, m.announce) m.announcer = time.AfterFunc(time.Second*15, func() {
m.Act(m, m.announce)
})
} }
func (m *Multicast) listen() { func (m *Multicast) listen() {

View File

@ -39,7 +39,9 @@ func (m *Multicast) multicastStarted() {
break break
} }
} }
m.platformhandler = time.AfterFunc(time.Minute, m.multicastStarted) m.platformhandler = time.AfterFunc(time.Minute, func() {
m.Act(m, m.multicastStarted)
})
} }
func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error { func (m *Multicast) multicastReuse(network string, address string, c syscall.RawConn) error {