From ef01142a443da76115e9f6d7ea71c1863a6d3531 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 3 Aug 2020 18:45:13 +0200 Subject: [PATCH] Add user.stop --- user.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/user.go b/user.go index 734cc7a..6cfe8c5 100644 --- a/user.go +++ b/user.go @@ -45,6 +45,8 @@ type eventDownstreamDisconnected struct { dc *downstreamConn } +type eventStop struct{} + type networkHistory struct { offlineClients map[string]uint64 // indexed by client name 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.Close() } + case eventStop: + u.forEachDownstream(func(dc *downstreamConn) { + dc.Close() + }) + for _, n := range u.networks { + n.stop() + } + return default: 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 return u.srv.db.StoreUser(&u.User) } + +func (u *user) stop() { + u.events <- eventStop{} +}