5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 03:41:37 +00:00

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

View File

@ -39,7 +39,9 @@ func (m *Multicast) multicastStarted() {
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 {