mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 06:35:07 +03:00
Handle errors from reconfigure tasks
This commit is contained in:
parent
2925920c70
commit
7fae1c993a
9 changed files with 64 additions and 72 deletions
|
@ -18,7 +18,7 @@ import (
|
|||
// This includes coords, permanent and ephemeral keys, handles and nonces, various sorts of timing information for timeout and maintenance, and some metadata for the admin API.
|
||||
type sessionInfo struct {
|
||||
core *Core
|
||||
reconfigure chan bool
|
||||
reconfigure chan chan error
|
||||
theirAddr address.Address
|
||||
theirSubnet address.Subnet
|
||||
theirPermPub crypto.BoxPubKey
|
||||
|
@ -102,7 +102,7 @@ func (s *sessionInfo) timedout() bool {
|
|||
// Additionally, stores maps of address/subnet onto keys, and keys onto handles.
|
||||
type sessions struct {
|
||||
core *Core
|
||||
reconfigure chan bool
|
||||
reconfigure chan chan error
|
||||
lastCleanup time.Time
|
||||
// Maps known permanent keys to their shared key, used by DHT a lot
|
||||
permShared map[crypto.BoxPubKey]*crypto.BoxSharedKey
|
||||
|
@ -126,19 +126,23 @@ type sessions struct {
|
|||
// Initializes the session struct.
|
||||
func (ss *sessions) init(core *Core) {
|
||||
ss.core = core
|
||||
ss.reconfigure = make(chan bool, 1)
|
||||
ss.reconfigure = make(chan chan error, 1)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case newConfig := <-ss.reconfigure:
|
||||
ss.core.configMutex.RLock()
|
||||
ss.core.log.Println("Notified: sessions")
|
||||
ss.core.configMutex.RUnlock()
|
||||
|
||||
for _, sinfo := range ss.sinfos {
|
||||
sinfo.reconfigure <- newConfig
|
||||
case e := <-ss.reconfigure:
|
||||
responses := make(map[crypto.Handle]chan error)
|
||||
for index, session := range ss.sinfos {
|
||||
responses[index] = make(chan error)
|
||||
session.reconfigure <- responses[index]
|
||||
}
|
||||
continue
|
||||
for _, response := range responses {
|
||||
if err := <-response; err != nil {
|
||||
e <- err
|
||||
continue
|
||||
}
|
||||
}
|
||||
e <- nil
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -289,7 +293,7 @@ func (ss *sessions) createSession(theirPermKey *crypto.BoxPubKey) *sessionInfo {
|
|||
}
|
||||
sinfo := sessionInfo{}
|
||||
sinfo.core = ss.core
|
||||
sinfo.reconfigure = make(chan bool, 1)
|
||||
sinfo.reconfigure = make(chan chan error, 1)
|
||||
sinfo.theirPermPub = *theirPermKey
|
||||
pub, priv := crypto.NewBoxKeys()
|
||||
sinfo.mySesPub = *pub
|
||||
|
@ -558,11 +562,8 @@ func (sinfo *sessionInfo) doWorker() {
|
|||
} else {
|
||||
return
|
||||
}
|
||||
case _ = <-sinfo.reconfigure:
|
||||
sinfo.core.configMutex.RLock()
|
||||
sinfo.core.log.Println("Notified: sessionInfo")
|
||||
sinfo.core.configMutex.RUnlock()
|
||||
continue
|
||||
case e := <-sinfo.reconfigure:
|
||||
e <- nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue