mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-24 00:37:49 +00:00
Reconfigure functions now ran by actors
This commit is contained in:
parent
607c906820
commit
e553f3e013
@ -112,29 +112,39 @@ 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,
|
||||
c.router.reconfigure,
|
||||
c.router.dht.reconfigure,
|
||||
c.router.searches.reconfigure,
|
||||
c.router.sessions.reconfigure,
|
||||
c.switchTable.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 {
|
||||
response := make(chan error)
|
||||
go component(response)
|
||||
for err := range response {
|
||||
c.log.Errorln(err)
|
||||
errors++
|
||||
// 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)
|
||||
phony.Block(actor, func() {
|
||||
function(response)
|
||||
})
|
||||
for err := range response {
|
||||
c.log.Errorln(err)
|
||||
errors++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
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
|
||||
}
|
||||
|
@ -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])
|
||||
}
|
||||
})
|
||||
for index, session := range ss.sinfos {
|
||||
responses[index] = make(chan error)
|
||||
session.reconfigure(responses[index])
|
||||
}
|
||||
for _, response := range responses {
|
||||
for err := range response {
|
||||
e <- err
|
||||
|
Loading…
x
Reference in New Issue
Block a user