Add user.stop

This commit is contained in:
Simon Ser 2020-08-03 18:45:13 +02:00
parent b71fcc2e00
commit ef01142a44
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

14
user.go
View File

@ -45,6 +45,8 @@ type eventDownstreamDisconnected struct {
dc *downstreamConn dc *downstreamConn
} }
type eventStop struct{}
type networkHistory struct { type networkHistory struct {
offlineClients map[string]uint64 // indexed by client name offlineClients map[string]uint64 // indexed by client name
ring *Ring // can be nil if there are no offline clients ring *Ring // can be nil if there are no offline clients
@ -416,6 +418,14 @@ func (u *user) run() {
dc.logger.Printf("failed to handle message %q: %v", msg, err) dc.logger.Printf("failed to handle message %q: %v", msg, err)
dc.Close() dc.Close()
} }
case eventStop:
u.forEachDownstream(func(dc *downstreamConn) {
dc.Close()
})
for _, n := range u.networks {
n.stop()
}
return
default: default:
u.srv.Logger.Printf("received unknown event type: %T", e) u.srv.Logger.Printf("received unknown event type: %T", e)
} }
@ -550,3 +560,7 @@ func (u *user) updatePassword(hashed string) error {
u.User.Password = hashed u.User.Password = hashed
return u.srv.db.StoreUser(&u.User) return u.srv.db.StoreUser(&u.User)
} }
func (u *user) stop() {
u.events <- eventStop{}
}