Config changes

- a source's interval must be greater than 0: a source is turned off with
  enabled, not with a zero interval, so JSCSourcesSource rejects an interval of
  0 or less (its validate is promoted to each source's section);
- max_message_size rejects -1: JSCServerWebSocket rejects a max_message_size
  of -1 (util.ByteSizeNoLimit), as a client could then exhaust the server's
  memory;
- every setting documents what 0 or empty means (zero/none, no limit or a
  default).
This commit is contained in:
bwilliams committed 2026-10-15 16:00:48 +01:00
1 parent 49b824d5a2
commit 0b5fde9563
11 files changed
+116 -23

No files matched your search

+19
View File
@@ -1,6 +1,7 @@
package config
import (
"errors"
"reflect"
"time"
@@ -11,6 +12,10 @@ import (
const JSCKServerWebSocket string = "websocket"
// JSCServerWebSocket configures the server's websocket connections.
// MaxMessageSize is the largest message read from a client; 0 means the
// default (32KiB), and -1 (no limit) is rejected (see validate). A
// WriteTimeout or PongTimeout of 0 or less means no limit, and a
// PingInterval of 0 or less turns pings off.
type JSCServerWebSocket struct {
EnableCompression bool `cfg:"enable_compression" default:"false"`
MaxMessageSize util.ByteSize `cfg:"max_message_size" default:"32KiB"`
@@ -40,3 +45,17 @@ func (c JSCServerWebSocket) ValueOf(key string) (any, error) {
func (c *JSCServerWebSocket) SetValue(key string, value any) error {
return setValue(c, key, value)
}
// ---------- Section specific methods ----------
// validate checks values before they are stored (see validator).
// max_message_size can't be -1 (no limit): a client could then send a
// message of any size, and the server holds each message in memory.
func (c *JSCServerWebSocket) validate(key string, value any) error {
if key == "max_message_size" && value.(util.ByteSize) == util.ByteSizeNoLimit {
return errors.New(
"max_message_size can't be -1 (no limit): set an explicit size, or 0 for the default",
)
}
return nil
}