mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 02:01:36 +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
|
// config.NodeConfig and then signals the various module goroutines to
|
||||||
// reconfigure themselves if needed.
|
// reconfigure themselves if needed.
|
||||||
func (c *Core) UpdateConfig(config *config.NodeConfig) {
|
func (c *Core) UpdateConfig(config *config.NodeConfig) {
|
||||||
c.log.Debugln("Reloading node configuration...")
|
c.log.Infoln("Reloading node configuration...")
|
||||||
|
|
||||||
c.config.Replace(*config)
|
c.config.Replace(*config)
|
||||||
|
|
||||||
errors := 0
|
errors := 0
|
||||||
|
|
||||||
// Each reconfigure function should pass any errors to the channel, then close it
|
// Each reconfigure function should pass any errors to the channel, then close it
|
||||||
components := []func(chan error){
|
components := map[phony.Actor][]func(chan error){
|
||||||
c.link.reconfigure,
|
&c.router: []func(chan error){
|
||||||
c.peers.reconfigure,
|
c.router.reconfigure,
|
||||||
c.router.reconfigure,
|
c.router.dht.reconfigure,
|
||||||
c.router.dht.reconfigure,
|
c.router.searches.reconfigure,
|
||||||
c.router.searches.reconfigure,
|
c.router.sessions.reconfigure,
|
||||||
c.router.sessions.reconfigure,
|
},
|
||||||
c.switchTable.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
|
||||||
response := make(chan error)
|
// benefit over components reporting errors themselves, so maybe we can use
|
||||||
go component(response)
|
// actor.Act() here instead and stop counting errors
|
||||||
for err := range response {
|
for actor, functions := range components {
|
||||||
c.log.Errorln(err)
|
for _, function := range functions {
|
||||||
errors++
|
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) {
|
func (l *link) reconfigure(e chan error) {
|
||||||
defer close(e)
|
defer close(e)
|
||||||
tcpResponse := make(chan error)
|
tcpResponse := make(chan error)
|
||||||
go l.tcp.reconfigure(tcpResponse)
|
l.tcp.reconfigure(tcpResponse)
|
||||||
for err := range tcpResponse {
|
for err := range tcpResponse {
|
||||||
e <- err
|
e <- err
|
||||||
}
|
}
|
||||||
|
@ -77,13 +77,11 @@ func (r *router) reconfigure(e chan error) {
|
|||||||
defer close(e)
|
defer close(e)
|
||||||
var errs []error
|
var errs []error
|
||||||
// Reconfigure the router
|
// Reconfigure the router
|
||||||
phony.Block(r, func() {
|
current := r.core.config.GetCurrent()
|
||||||
current := r.core.config.GetCurrent()
|
err := r.nodeinfo.setNodeInfo(current.NodeInfo, current.NodeInfoPrivacy)
|
||||||
err := r.nodeinfo.setNodeInfo(current.NodeInfo, current.NodeInfoPrivacy)
|
if err != nil {
|
||||||
if err != nil {
|
errs = append(errs, err)
|
||||||
errs = append(errs, err)
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
e <- err
|
e <- err
|
||||||
}
|
}
|
||||||
|
@ -164,12 +164,10 @@ func (ss *sessions) init(r *router) {
|
|||||||
func (ss *sessions) reconfigure(e chan error) {
|
func (ss *sessions) reconfigure(e chan error) {
|
||||||
defer close(e)
|
defer close(e)
|
||||||
responses := make(map[crypto.Handle]chan error)
|
responses := make(map[crypto.Handle]chan error)
|
||||||
phony.Block(ss.router, func() {
|
for index, session := range ss.sinfos {
|
||||||
for index, session := range ss.sinfos {
|
responses[index] = make(chan error)
|
||||||
responses[index] = make(chan error)
|
session.reconfigure(responses[index])
|
||||||
go session.reconfigure(responses[index])
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
for _, response := range responses {
|
for _, response := range responses {
|
||||||
for err := range response {
|
for err := range response {
|
||||||
e <- err
|
e <- err
|
||||||
|
Loading…
Reference in New Issue
Block a user