mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-27 21:42:16 -08:00
enforce max-keys
This commit is contained in:
parent
2275bed000
commit
db4b23bb48
5 changed files with 33 additions and 2 deletions
|
|
@ -728,7 +728,7 @@ type Config struct {
|
|||
Enabled bool
|
||||
MaxSubs int `yaml:"max-subs"`
|
||||
MaxKeys int `yaml:"max-keys"`
|
||||
MaxValueBytes int `yaml:"max-value-length"`
|
||||
MaxValueBytes int `yaml:"max-value-length"` // todo: currently unenforced!!
|
||||
}
|
||||
|
||||
WebPush struct {
|
||||
|
|
|
|||
|
|
@ -935,6 +935,17 @@ func (channel *Channel) ClearMetadata() MetadataStore {
|
|||
return oldMap
|
||||
}
|
||||
|
||||
func (channel *Channel) CountMetadata() int {
|
||||
channel.stateMutex.RLock()
|
||||
defer channel.stateMutex.RUnlock()
|
||||
|
||||
if channel.metadata == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return len(channel.metadata)
|
||||
}
|
||||
|
||||
func (client *Client) GetMetadata(key string) (string, error) {
|
||||
client.stateMutex.RLock()
|
||||
defer client.stateMutex.RUnlock()
|
||||
|
|
@ -982,3 +993,14 @@ func (client *Client) ClearMetadata() MetadataStore {
|
|||
|
||||
return oldMap
|
||||
}
|
||||
|
||||
func (client *Client) CountMetadata() int {
|
||||
client.stateMutex.RLock()
|
||||
defer client.stateMutex.RUnlock()
|
||||
|
||||
if client.metadata == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return len(client.metadata)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3167,6 +3167,14 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
|
|||
return
|
||||
}
|
||||
|
||||
maxKeys := server.Config().Metadata.MaxKeys
|
||||
isSelf := targetClient != nil && client == targetClient
|
||||
|
||||
if isSelf && maxKeys > 0 && t.CountMetadata() >= maxKeys {
|
||||
rb.Add(nil, server.name, "FAIL", "METADATA", "LIMIT_REACHED", client.nick, client.t("You have too many keys set on yourself"))
|
||||
return
|
||||
}
|
||||
|
||||
server.logger.Debug("metadata", "setting", key, value, "on", target)
|
||||
|
||||
t.SetMetadata(key, value)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ type MetadataHaver = interface {
|
|||
DeleteMetadata(key string)
|
||||
ListMetadata() MetadataStore
|
||||
ClearMetadata() MetadataStore
|
||||
CountMetadata() int
|
||||
}
|
||||
|
||||
func notifySubscribers(server *Server, session *Session, target string, key string, value string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue