1
0
Fork 0
forked from External/ergo

Send fake channel joins on RESUME

This commit is contained in:
Daniel Oaks 2018-01-21 13:13:20 +10:00
parent d13b2ee095
commit f8b39cfe61
3 changed files with 40 additions and 23 deletions

View file

@ -145,29 +145,33 @@ func (channel *Channel) IsRegistered() bool {
return channel.registeredFounder != ""
}
func (channel *Channel) regenerateMembersCache() {
func (channel *Channel) regenerateMembersCache(noLocksNeeded bool) {
// this is eventually consistent even without holding stateMutex.Lock()
// throughout the update; all updates to `members` while holding Lock()
// have a serial order, so the call to `regenerateMembersCache` that
// happens-after the last one will see *all* the updates. then,
// `membersCacheMutex` ensures that this final read is correctly paired
// with the final write to `membersCache`.
channel.membersCacheMutex.Lock()
defer channel.membersCacheMutex.Unlock()
if !noLocksNeeded {
channel.membersCacheMutex.Lock()
defer channel.membersCacheMutex.Unlock()
channel.stateMutex.RLock()
}
channel.stateMutex.RLock()
result := make([]*Client, len(channel.members))
i := 0
for client := range channel.members {
result[i] = client
i++
}
channel.stateMutex.RUnlock()
channel.stateMutex.Lock()
if !noLocksNeeded {
channel.stateMutex.RUnlock()
channel.stateMutex.Lock()
}
channel.membersCache = result
channel.stateMutex.Unlock()
return
if !noLocksNeeded {
channel.stateMutex.Unlock()
}
}
// Names sends the list of users joined to the channel to the given client.
@ -413,7 +417,7 @@ func (channel *Channel) Join(client *Client, key string) {
channel.members.Add(client)
firstJoin := len(channel.members) == 1
channel.stateMutex.Unlock()
channel.regenerateMembersCache()
channel.regenerateMembersCache(false)
client.addChannel(channel)
@ -722,7 +726,7 @@ func (channel *Channel) Quit(client *Client) {
channel.stateMutex.Lock()
channel.members.Remove(client)
channel.stateMutex.Unlock()
channel.regenerateMembersCache()
channel.regenerateMembersCache(false)
client.removeChannel(channel)
}