коммит произвёл
GitHub
родитель
07c4273280
Коммит
7c09a18ae9
@@ -84,6 +84,7 @@ type Hub struct {
|
||||
stop chan struct{}
|
||||
didStop chan struct{}
|
||||
invalidateUser chan string
|
||||
invalidateAll chan struct{}
|
||||
activity chan *webConnActivityMessage
|
||||
directMsg chan *webConnDirectMessage
|
||||
explicitStop bool
|
||||
@@ -106,6 +107,7 @@ func newWebHub(ps *PlatformService) *Hub {
|
||||
stop: make(chan struct{}),
|
||||
didStop: make(chan struct{}),
|
||||
invalidateUser: make(chan string),
|
||||
invalidateAll: make(chan struct{}),
|
||||
activity: make(chan *webConnActivityMessage),
|
||||
directMsg: make(chan *webConnDirectMessage),
|
||||
checkRegistered: make(chan *webConnSessionMessage),
|
||||
@@ -453,6 +455,15 @@ func (h *Hub) InvalidateUser(userID string) {
|
||||
}
|
||||
}
|
||||
|
||||
// InvalidateAll invalidates the cached session state of every WebConn
|
||||
// registered with this hub. Global counterpart of InvalidateUser.
|
||||
func (h *Hub) InvalidateAll() {
|
||||
select {
|
||||
case h.invalidateAll <- struct{}{}:
|
||||
case <-h.stop:
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateActivity sets the LastUserActivityAt field for the connection
|
||||
// of the user.
|
||||
func (h *Hub) UpdateActivity(userID, sessionToken string, activityAt int64) {
|
||||
@@ -654,6 +665,18 @@ func (h *Hub) Start() {
|
||||
closeAndRemoveConn(connIndex, webConn)
|
||||
}
|
||||
}
|
||||
case <-h.invalidateAll:
|
||||
// Mirrors the invalidateUser arm across every conn,
|
||||
// also clearing the session token so the next
|
||||
// IsBasicAuthenticated check short-circuits instead
|
||||
// of re-fetching from the cache.
|
||||
for webConn := range connIndex.All() {
|
||||
webConn.InvalidateCache()
|
||||
webConn.SetSessionToken("")
|
||||
}
|
||||
if *h.platform.Config().ServiceSettings.EnableWebHubChannelIteration {
|
||||
connIndex.clearChannels()
|
||||
}
|
||||
case activity := <-h.activity:
|
||||
for webConn := range connIndex.ForUser(activity.userID) {
|
||||
if !webConn.Active.Load() {
|
||||
@@ -947,6 +970,16 @@ func (i *hubConnectionIndex) ForChannel(channelID string) iter.Seq[*WebConn] {
|
||||
return maps.Keys(i.byChannelID[channelID])
|
||||
}
|
||||
|
||||
// clearChannels empties the channel-routing index in one shot. Intended
|
||||
// for paths that have already invalidated every conn registered with
|
||||
// the hub: any broadcast addressed to a channel will be filtered out
|
||||
// upstream by ShouldSendEvent, so the routing entries are dead weight
|
||||
// until conns either re-handshake or fully reconnect (both of which
|
||||
// repopulate the index via Add).
|
||||
func (i *hubConnectionIndex) clearChannels() {
|
||||
clear(i.byChannelID)
|
||||
}
|
||||
|
||||
// ForUserActiveCount returns the number of active connections for a userID
|
||||
func (i *hubConnectionIndex) ForUserActiveCount(id string) int {
|
||||
cnt := 0
|
||||
|
||||
Ссылка в новой задаче
Block a user