5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-10 06:20:26 +00:00

Reconfigure functions now ran by actors

This commit is contained in:
Neil Alexander 2019-08-28 12:46:12 +01:00
parent 607c906820
commit e553f3e013
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
4 changed files with 36 additions and 30 deletions

View File

@ -112,31 +112,41 @@ func (c *Core) addPeerLoop() {
// config.NodeConfig and then signals the various module goroutines to
// reconfigure themselves if needed.
func (c *Core) UpdateConfig(config *config.NodeConfig) {
c.log.Debugln("Reloading node configuration...")
c.log.Infoln("Reloading node configuration...")
c.config.Replace(*config)
errors := 0
// Each reconfigure function should pass any errors to the channel, then close it
components := []func(chan error){
c.link.reconfigure,
c.peers.reconfigure,
components := map[phony.Actor][]func(chan error){
&c.router: []func(chan error){
c.router.reconfigure,
c.router.dht.reconfigure,
c.router.searches.reconfigure,
c.router.sessions.reconfigure,
},
&c.switchTable: []func(chan error){
c.switchTable.reconfigure,
c.link.reconfigure,
c.peers.reconfigure,
},
}
for _, component := range components {
// TODO: We count errors here but honestly that provides us with absolutely no
// benefit over components reporting errors themselves, so maybe we can use
// actor.Act() here instead and stop counting errors
for actor, functions := range components {
for _, function := range functions {
response := make(chan error)
go component(response)
phony.Block(actor, func() {
function(response)
})
for err := range response {
c.log.Errorln(err)
errors++
}
}
}
if errors > 0 {
c.log.Warnln(errors, "node module(s) reported errors during configuration reload")

View File

@ -82,7 +82,7 @@ func (l *link) init(c *Core) error {
func (l *link) reconfigure(e chan error) {
defer close(e)
tcpResponse := make(chan error)
go l.tcp.reconfigure(tcpResponse)
l.tcp.reconfigure(tcpResponse)
for err := range tcpResponse {
e <- err
}

View File

@ -77,13 +77,11 @@ func (r *router) reconfigure(e chan error) {
defer close(e)
var errs []error
// Reconfigure the router
phony.Block(r, func() {
current := r.core.config.GetCurrent()
err := r.nodeinfo.setNodeInfo(current.NodeInfo, current.NodeInfoPrivacy)
if err != nil {
errs = append(errs, err)
}
})
for _, err := range errs {
e <- err
}

View File

@ -164,12 +164,10 @@ func (ss *sessions) init(r *router) {
func (ss *sessions) reconfigure(e chan error) {
defer close(e)
responses := make(map[crypto.Handle]chan error)
phony.Block(ss.router, func() {
for index, session := range ss.sinfos {
responses[index] = make(chan error)
go session.reconfigure(responses[index])
session.reconfigure(responses[index])
}
})
for _, response := range responses {
for err := range response {
e <- err