mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-14 16:10:29 +00:00
make GetSessions use the session workers to avoid races
This commit is contained in:
parent
d39428735d
commit
40553a6a44
@ -211,7 +211,8 @@ func (c *Core) GetSessions() []Session {
|
|||||||
var sessions []Session
|
var sessions []Session
|
||||||
getSessions := func() {
|
getSessions := func() {
|
||||||
for _, sinfo := range c.sessions.sinfos {
|
for _, sinfo := range c.sessions.sinfos {
|
||||||
// TODO? skipped known but timed out sessions?
|
var session Session
|
||||||
|
workerFunc := func() {
|
||||||
session := Session{
|
session := Session{
|
||||||
Coords: append([]byte{}, sinfo.coords...),
|
Coords: append([]byte{}, sinfo.coords...),
|
||||||
MTU: sinfo.getMTU(),
|
MTU: sinfo.getMTU(),
|
||||||
@ -221,6 +222,20 @@ func (c *Core) GetSessions() []Session {
|
|||||||
WasMTUFixed: sinfo.wasMTUFixed,
|
WasMTUFixed: sinfo.wasMTUFixed,
|
||||||
}
|
}
|
||||||
copy(session.PublicKey[:], sinfo.theirPermPub[:])
|
copy(session.PublicKey[:], sinfo.theirPermPub[:])
|
||||||
|
}
|
||||||
|
var skip bool
|
||||||
|
func() {
|
||||||
|
defer func() {
|
||||||
|
if recover() != nil {
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
sinfo.doWorker(workerFunc)
|
||||||
|
}()
|
||||||
|
if skip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// TODO? skipped known but timed out sessions?
|
||||||
sessions = append(sessions, session)
|
sessions = append(sessions, session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user