Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions cmd/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,19 @@ type Config struct {
}

// CustomizerConfig holds operator-side knobs for the in-app customizer modal.
// Today only DisabledTabs is exposed: a list of tab ids the operator wants to
// hide from end users (e.g. ["branding","geofilter","export"]). The frontend
// DisabledTabs is a list of tab ids the operator wants to hide from end users
// (e.g. ["branding","geofilter","export"]). The frontend
// (public/customize-v2.js _renderTabs) reads this from /api/config/client and
// filters those tabs out before rendering. Issue #1508.
type CustomizerConfig struct {
DisabledTabs []string `json:"disabledTabs"`
// OneByteHopsDefault (#912 M2) is the 1-byte hop mode (show, mark or
// hide) of a visitor who has not picked one; "" means the operator set
// none, and the browser keeps its built-in (Show on Live, Mark
// elsewhere). Only applyOneByteHopsDefault sets it, from the canonical
// key: the struct decode skips it, so a value of the wrong type warns
// instead of rejecting the whole file.
OneByteHopsDefault string `json:"-"`
}

// PrivacyConfig is the entire privacy feature's configuration: one opt-in
Expand Down Expand Up @@ -1214,6 +1221,7 @@ func (c *Config) applyCanonicalKeys(keys *configkey.Doc) error {
}
}
c.applyMaxHopDist(keys, log.Printf)
c.applyOneByteHopsDefault(keys, log.Printf)
c.Share.Nodes.Enabled = keys.On("share", "nodes", "enabled")
c.Share.Packets.Enabled = keys.On("share", "packets", "enabled")
c.AntennaClaims.ApplyGates(keys.On)
Expand Down Expand Up @@ -1281,6 +1289,39 @@ func (c *Config) applyMaxHopDist(keys *configkey.Doc, logf func(string, ...inter
c.MaxHopDist = &v
}

// oneByteHopsModes are the 1-byte hop modes of public/hop-filter.js (#674).
var oneByteHopsModes = map[string]bool{"show": true, "mark": true, "hide": true}

// applyOneByteHopsDefault (#912 M2) takes customizer.oneByteHopsDefault from
// the exact-case key only (#884). An absent key leaves it unset; any other
// value than show, mark or hide logs one warning and gives mark.
func (c *Config) applyOneByteHopsDefault(keys *configkey.Doc, logf func(string, ...interface{})) {
raw := keys.Get("customizer", "oneByteHopsDefault")
if raw == nil {
return
}
if c.Customizer == nil {
c.Customizer = &CustomizerConfig{}
}
var v string
if json.Unmarshal(raw, &v) != nil || !oneByteHopsModes[v] {
logf("[config] customizer.oneByteHopsDefault is not \"show\", \"mark\" or \"hide\"; using \"mark\"")
v = "mark"
}
c.Customizer.OneByteHopsDefault = v
}

// OneByteHopsDefault is the operator default for the 1-byte hop mode, as
// /api/config/client serves it: "" unless configured. The plan of #912 M2
// keeps an unconfigured instance as before (CS-VM1 review R2), so the server
// sends no effective default of its own.
func (c *Config) OneByteHopsDefault() string {
if c.Customizer == nil {
return ""
}
return c.Customizer.OneByteHopsDefault
}

// jsonObject is a JSON object as encoding/json decodes it into
// interface{}. It is an alias, not a defined type: a decoded object's
// dynamic type is the unnamed map type, and a type assertion to a defined
Expand Down
155 changes: 155 additions & 0 deletions cmd/server/config_one_byte_hops_default_912_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package main

import (
"bytes"
"encoding/json"
"log"
"os"
"reflect"
"strings"
"testing"
)

// #912 M2 — customizer.oneByteHopsDefault: the operator's default for the
// 1-byte hop mode (show / mark / hide). It is read from the exact-case key
// only (#884); an unknown value logs one warning and falls back to mark. An
// absent key is served as no default at all, so the browser keeps its
// built-in, Show on Live and Mark elsewhere, as before M2 (the plan's "if the
// key is absent, the behaviour is as today", CS-VM1 review R2).

func loadOneByteHopsDefault(t *testing.T, cfgJSON string) (*Config, string) {
t.Helper()
dir := t.TempDir()
writeConfigFile(t, dir, "config.json", cfgJSON)
var buf bytes.Buffer
log.SetOutput(&buf)
cfg, err := LoadConfig(dir)
log.SetOutput(os.Stderr)
if err != nil {
t.Fatal(err)
}
return cfg, buf.String()
}

func TestOneByteHopsDefaultValidation912(t *testing.T) {
cases := []struct {
name string
json string
want string
warn bool
}{
{"absent block", `{}`, "", false},
{"absent key", `{"customizer": {"disabledTabs": ["export"]}}`, "", false},
{"show", `{"customizer": {"oneByteHopsDefault": "show"}}`, "show", false},
{"mark", `{"customizer": {"oneByteHopsDefault": "mark"}}`, "mark", false},
{"hide", `{"customizer": {"oneByteHopsDefault": "hide"}}`, "hide", false},
{"unknown", `{"customizer": {"oneByteHopsDefault": "bogus"}}`, "mark", true},
{"wrong case", `{"customizer": {"oneByteHopsDefault": "Hide"}}`, "mark", true},
{"empty", `{"customizer": {"oneByteHopsDefault": ""}}`, "mark", true},
{"proto-ish", `{"customizer": {"oneByteHopsDefault": "constructor"}}`, "mark", true},
{"not a string", `{"customizer": {"oneByteHopsDefault": 2}}`, "mark", true},
{"null", `{"customizer": {"oneByteHopsDefault": null}}`, "mark", true},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
cfg, logs := loadOneByteHopsDefault(t, c.json)
if got := cfg.OneByteHopsDefault(); got != c.want {
t.Fatalf("OneByteHopsDefault() = %q, want %q", got, c.want)
}
n := strings.Count(logs, "customizer.oneByteHopsDefault")
if c.warn && n != 1 {
t.Fatalf("want exactly one oneByteHopsDefault warning, got %d:\n%s", n, logs)
}
if !c.warn && n != 0 {
t.Fatalf("unexpected oneByteHopsDefault warning:\n%s", logs)
}
})
}
}

// A non-string value must not reject the whole config file: the field is
// read through configkey only, never by the struct decode.
func TestOneByteHopsDefaultBadTypeKeepsTheFile912(t *testing.T) {
cfg, _ := loadOneByteHopsDefault(t, `{"port": 4242, "customizer": {"oneByteHopsDefault": 2, "disabledTabs": ["export"]}}`)
if cfg.Port != 4242 {
t.Fatalf("config file was dropped: port = %d", cfg.Port)
}
if cfg.Customizer == nil || !reflect.DeepEqual(cfg.Customizer.DisabledTabs, []string{"export"}) {
t.Fatalf("disabledTabs lost: %+v", cfg.Customizer)
}
}

// #884: a case variant is not the canonical key, so it is ignored (with the
// configkey warning) and no default is set.
func TestOneByteHopsDefaultCanonicalKeyOnly912(t *testing.T) {
for _, j := range []string{
`{"customizer": {"OneByteHopsDefault": "hide"}}`,
`{"customizer": {"onebytehopsdefault": "hide"}}`,
`{"Customizer": {"oneByteHopsDefault": "hide"}}`,
} {
cfg, _ := loadOneByteHopsDefault(t, j)
if got := cfg.OneByteHopsDefault(); got != "" {
t.Fatalf("%s: OneByteHopsDefault() = %q, want none", j, got)
}
}
// The exact key still wins next to a variant.
cfg, _ := loadOneByteHopsDefault(t, `{"customizer": {"oneByteHopsDefault": "show", "OneByteHopsDefault": "hide"}}`)
if got := cfg.OneByteHopsDefault(); got != "show" {
t.Fatalf("exact key next to a variant: got %q, want show", got)
}
}

func TestOneByteHopsDefaultIsANamedField912(t *testing.T) {
f, ok := reflect.TypeOf(CustomizerConfig{}).FieldByName("OneByteHopsDefault")
if !ok || f.Type.Kind() != reflect.String {
t.Fatalf("CustomizerConfig.OneByteHopsDefault must be a string field, got %v (found=%v)", f.Type, ok)
}
f, ok = reflect.TypeOf(CustomizerClientConfig{}).FieldByName("OneByteHopsDefault")
// omitempty: no configured default, no key on the wire (R2).
if !ok || f.Type.Kind() != reflect.String || f.Tag.Get("json") != "oneByteHopsDefault,omitempty" {
t.Fatalf("CustomizerClientConfig.OneByteHopsDefault must be a string tagged oneByteHopsDefault,omitempty, got %v %q", f.Type, f.Tag)
}
}

// A configured mode is served; without one the key is left out of the
// customizer block, so Live keeps Show and other pages Mark (R2). Red with a
// server that serves mark when the key is absent.
func TestClientConfigOneByteHopsDefaultShape912(t *testing.T) {
for _, c := range []struct {
cfg string
want string // "" = the key must be absent
}{
{`{}`, ""},
{`{"customizer": {"disabledTabs": ["export"]}}`, ""},
{`{"customizer": {"OneByteHopsDefault": "hide"}}`, ""},
{`{"customizer": {"oneByteHopsDefault": "hide"}}`, "hide"},
{`{"customizer": {"oneByteHopsDefault": "show", "disabledTabs": ["export"]}}`, "show"},
{`{"customizer": {"oneByteHopsDefault": "mark"}}`, "mark"},
{`{"customizer": {"oneByteHopsDefault": "nope"}}`, "mark"},
} {
body, _ := clientConfigFor(t, c.cfg)
var got struct {
Customizer map[string]json.RawMessage `json:"customizer"`
}
if err := json.Unmarshal([]byte(body), &got); err != nil {
t.Fatal(err)
}
if got.Customizer == nil {
t.Fatalf("cfg %s: no customizer block in %s", c.cfg, body)
}
raw, ok := got.Customizer["oneByteHopsDefault"]
if c.want == "" {
if ok {
t.Fatalf("cfg %s: no default configured, but customizer.oneByteHopsDefault = %s", c.cfg, raw)
}
} else {
var v string
if !ok || json.Unmarshal(raw, &v) != nil || v != c.want {
t.Fatalf("cfg %s: customizer.oneByteHopsDefault = %s (present %v), want %q", c.cfg, raw, ok, c.want)
}
}
if _, ok := got.Customizer["disabledTabs"]; !ok {
t.Fatalf("cfg %s: customizer.disabledTabs must stay in the block", c.cfg)
}
}
}
2 changes: 1 addition & 1 deletion cmd/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func (s *Server) handleConfigClient(w http.ResponseWriter, r *http.Request) {
DebugAffinity: s.cfg.DebugAffinity,
MapDarkTileProvider: s.cfg.MapDarkTileProvider,
Tiles: s.cfg.Tiles,
Customizer: CustomizerClientConfig{DisabledTabs: disabledTabs},
Customizer: CustomizerClientConfig{DisabledTabs: disabledTabs, OneByteHopsDefault: s.cfg.OneByteHopsDefault()},
ClientRxCoverage: s.cfg.ClientRxCoverageEnabled(),
Moments: s.cfg.momentsClientConfig(),
Kiosk: s.cfg.kioskClientConfig(),
Expand Down
5 changes: 4 additions & 1 deletion cmd/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1721,8 +1721,11 @@ type PrivacyClientConfig struct {
// /api/config/client surfaces to the frontend. Issue #1508. The field is
// always present (DisabledTabs defaults to an empty slice) so the frontend
// can blindly call `.disabledTabs.includes(...)` without an undefined guard.
// OneByteHopsDefault (#912 M2) is the configured mode (show, mark or hide),
// left out when the operator set none: the browser then keeps its built-in.
type CustomizerClientConfig struct {
DisabledTabs []string `json:"disabledTabs"`
DisabledTabs []string `json:"disabledTabs"`
OneByteHopsDefault string `json:"oneByteHopsDefault,omitempty"`
}

// ─── IATA Coords ───────────────────────────────────────────────────────────────
Expand Down
3 changes: 2 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@
"_comment_analytics": "Issue #1240 + #1256 + #1265. Each analytics endpoint (topology, rf, distance, channels, hashCollisions, hashSizes, roles, observersClockSkew, nodesClockSkew, advertIntervals) is recomputed in the background on the configured interval and served from an atomic-pointer cache. Reads never block on compute. Default 300s (5 min) per endpoint reflects the operator principle: serving slightly stale data quickly beats real-time data slowly. Lower values = fresher data at higher CPU cost. Only the default query (no region/window) is precomputed; region- and window-filtered requests fall back to the legacy on-request compute + 60s TTL cache.",
"customizer": {
"disabledTabs": [],
"_comment_disabledTabs": "Issue #1508. List of customizer-modal tab ids to hide from end users. Useful when operators want to expose only daily-use viewer controls and keep one-shot admin chrome out of the way. Recognized ids: branding, theme, nodes, home, display, geofilter, export. Example: [\"branding\", \"geofilter\", \"export\"] hides the admin tabs and leaves theme/colors/home/display visible. Default [] keeps the legacy behavior (all tabs visible). Operators edit this in config.json directly — there is no in-app UI for this list (by design)."
"_comment_disabledTabs": "Issue #1508. List of customizer-modal tab ids to hide from end users. Useful when operators want to expose only daily-use viewer controls and keep one-shot admin chrome out of the way. Recognized ids: branding, theme, nodes, home, display, geofilter, export. Example: [\"branding\", \"geofilter\", \"export\"] hides the admin tabs and leaves theme/colors/home/display visible. Default [] keeps the legacy behavior (all tabs visible). Operators edit this in config.json directly — there is no in-app UI for this list (by design).",
"_comment_oneByteHopsDefault": "#912 M2. Optional key customizer.oneByteHopsDefault, left out here on purpose: the 1-byte path hop mode (Display tab, Path Display) for a visitor who has not picked one. \"show\" draws 1-byte hops without markings; \"mark\" flags them: the map route marks only the uncertain inferred 1-byte hops, while the Live map dashes every segment that touches any 1-byte hop; \"hide\" leaves 1-byte hops out of the route view, the Live map and feed, and the node path panel (nothing stored changes). A configured value applies on every page, Live included. Without the key nothing changes: the Live map shows every hop unmarked and the other pages use mark. A visitor's own pick is stored in their browser and wins; one who never picked follows this value, also when you change it later. Any other value logs one warning and uses mark. The customizer labels the configured value '(server default)'. Example: \"oneByteHopsDefault\": \"hide\"."
},
"privacy": {
"enabled": false,
Expand Down
11 changes: 10 additions & 1 deletion docs/CUSTOMIZATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ User themes take priority over admin themes. Users can reset their personal them

### Operator display defaults (`config.json`)

Two Display settings take a default for every browser from `config.json`, served on `/api/config/client`:
Three Display settings take a default for every browser from `config.json`, served on `/api/config/client`:

- **Timestamps:** the `timestamps` block.

Expand All @@ -198,6 +198,15 @@ Two Display settings take a default for every browser from `config.json`, served

`defaultMode` is `ago` or `absolute`, `timezone` is `local` or `utc`, and `formatPreset` is `iso`, `iso-seconds` or `locale`. An invalid value logs a warning and takes the built-in (`ago`, `local`, `iso`). `allowCustomFormat: true` offers the **Custom Format** field in the Display tab; `customFormat` is then its default, with the tokens `YYYY`, `MM`, `DD`, `HH`, `mm`, `ss`, `SSS` and `Z`.
- **Live Moments:** `moments.display`, while `moments.enabled` is on. See [moments.md](moments.md#display-defaults-for-your-viewers).
- **Short (1-byte) path-hash hops** (Path Display, #912): `customizer.oneByteHopsDefault`.

```json
"customizer": {
"oneByteHopsDefault": "hide"
}
```

`show` draws 1-byte hops without markings. `mark` flags them: the map route view marks only the uncertain inferred 1-byte hops, while the Live map dashes every segment that touches any 1-byte hop. `hide` leaves 1-byte hops out of the route view, the Live map and feed, and the node path panel. Nothing stored changes. A configured value applies on every page, Live included. Without the key nothing changes from before: the Live map shows every hop unmarked and the other pages use `mark`, and the server sends no `oneByteHopsDefault` on `/api/config/client`. Any other value logs one warning and takes `mark`. The customizer labels the operator's mode "(server default)"; without one it labels Mark "(default)", as before. A viewer's pick is always stored in their browser, so it keeps winning when the operator later changes the default. While a pick is stored, **↺ Use server default** (**↺ Use default** when no default is configured) under the setting removes it (Reset All removes it too), and the open page follows the default at once; a viewer who never picked follows the current default. Before #912, choosing Mark stored nothing, so a viewer who explicitly picked Mark then cannot be told apart from one who never picked: they now follow your default.

A viewer's own value in the customizer wins over the operator's, and the operator's wins over the built-in. For Moments on/off, a `?moments=` link and the viewer's Live checkbox win over both. Keys are case-sensitive: a different spelling (`AllowCustomFormat`) is ignored with a warning in the server log.

Expand Down
6 changes: 5 additions & 1 deletion docs/api-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -3063,7 +3063,11 @@ Client-side configuration values.
"cacheInvalidateMs": number | null,
"externalUrls": object | null,
"propagationBufferMs": number, // default: 5000
"estimatedPositions": { "enabled": boolean } // default: true; operator policy
"estimatedPositions": { "enabled": boolean }, // default: true; operator policy
"customizer": {
"disabledTabs": string[], // default: []
"oneByteHopsDefault": "show" | "mark" | "hide" // optional; only when configured, #912 M2
}
}
```

Expand Down
Loading
Loading