mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-30 13:35:19 +00:00
remove session shutdown goroutine, just send a message instead
This commit is contained in:
parent
b2a2e251ad
commit
dffd70119d
@ -304,6 +304,8 @@ func (c *Conn) Close() (err error) {
|
|||||||
// Close the session, if it hasn't been closed already
|
// Close the session, if it hasn't been closed already
|
||||||
if e := c.session.cancel.Cancel(errors.New("connection closed")); e != nil {
|
if e := c.session.cancel.Cancel(errors.New("connection closed")); e != nil {
|
||||||
err = ConnError{errors.New("close failed, session already closed"), false, false, true, 0}
|
err = ConnError{errors.New("close failed, session already closed"), false, false, true, 0}
|
||||||
|
} else {
|
||||||
|
c.session.doRemove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -255,13 +255,6 @@ func (ss *sessions) createSession(theirPermKey *crypto.BoxPubKey) *sessionInfo {
|
|||||||
sinfo.theirSubnet = *address.SubnetForNodeID(crypto.GetNodeID(&sinfo.theirPermPub))
|
sinfo.theirSubnet = *address.SubnetForNodeID(crypto.GetNodeID(&sinfo.theirPermPub))
|
||||||
ss.sinfos[sinfo.myHandle] = &sinfo
|
ss.sinfos[sinfo.myHandle] = &sinfo
|
||||||
ss.byTheirPerm[sinfo.theirPermPub] = &sinfo.myHandle
|
ss.byTheirPerm[sinfo.theirPermPub] = &sinfo.myHandle
|
||||||
go func() {
|
|
||||||
// Run cleanup when the session is canceled
|
|
||||||
<-sinfo.cancel.Finished()
|
|
||||||
sinfo.sessions.router.doAdmin(func() {
|
|
||||||
sinfo.sessions.removeSession(&sinfo)
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
return &sinfo
|
return &sinfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,6 +286,12 @@ func (ss *sessions) cleanup() {
|
|||||||
ss.lastCleanup = time.Now()
|
ss.lastCleanup = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sinfo *sessionInfo) doRemove() {
|
||||||
|
sinfo.sessions.router.RecvFrom(nil, func() {
|
||||||
|
sinfo.sessions.removeSession(sinfo)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Closes a session, removing it from sessions maps.
|
// Closes a session, removing it from sessions maps.
|
||||||
func (ss *sessions) removeSession(sinfo *sessionInfo) {
|
func (ss *sessions) removeSession(sinfo *sessionInfo) {
|
||||||
if s := sinfo.sessions.sinfos[sinfo.myHandle]; s == sinfo {
|
if s := sinfo.sessions.sinfos[sinfo.myHandle]; s == sinfo {
|
||||||
|
Loading…
Reference in New Issue
Block a user