systemd-resolved: answer with the generated contract's own types (review r1 C-6, C-8)

C-6: import noderesolver (mesh-networking's seat definition) at the zero
version; routes, route, unroute and uplink-names answer with its
RoutesAnswer, RouteAnswer, UnrouteAnswer and UplinkNamesAnswer, never a
map or a parallel struct, and uplink-names' input names is a JSON array
(arrayArg), never a comma- or space-split string.

C-8: the names file write's 15 s is the stated constant
WriteUplinkNamesBound, not an inline literal.

Builds: design 08 sign-in-page §2, §5, §6, §9, DQ-12, C-6, C-8
This commit is contained in:
jochen
2026-11-24 22:00:15 +01:00
parent ae7d0f874b
commit 717f8ec2e5
6 changed files with 121 additions and 45 deletions
@@ -63,6 +63,25 @@ func arg(a map[string]any, k string) string {
return v
}
// stringArray declares an input as an array of strings, as the seat's definition says `names` is (design 08
// sign-in-page C-6, DQ-12): never a string a caller must separate by hand.
func stringArray(description string) map[string]any {
return map[string]any{"type": "array", "items": map[string]any{"type": "string"}, "description": description}
}
// arrayArg reads an argument declared with stringArray: a JSON array of strings, empty for anything else
// (never comma- or space-split, unlike Split).
func arrayArg(a map[string]any, k string) []string {
list, _ := a[k].([]any)
out := make([]string, 0, len(list))
for _, v := range list {
if s, ok := v.(string); ok {
out = append(out, s)
}
}
return out
}
// verb is one of the seat's verbs: listed as `<seat>.<verb>`, so the runtime serves it on the seat's
// subject, as <node>/node-resolver.<verb>.
func verb(name, description string, input map[string]any, run func(a map[string]any) (any, error)) stdio.Tool {
@@ -81,8 +100,8 @@ func tools(r *Resolver, history string) []stdio.Tool {
if err != nil {
return nil, err
}
return map[string]any{"mesh": routes.Mesh, "links": routes.Links, "outside_writes": ReadHistory(history),
"uplink_names": r.UplinkNamesAnswer(routes), "mesh_resolvers": r.MeshResolversAnswer()}, nil
answer := r.RoutesAnswer(routes, ReadHistory(history))
return &answer, nil
}),
verb("route", "Send these domains, and every name under them, to these servers over this link, and only "+
"them: the link never answers other names, and the mesh's own domain is refused. Replaces whatever the "+
@@ -101,7 +120,7 @@ func tools(r *Resolver, history string) []stdio.Tool {
"working network it tests resolves through the network it tests: at most 8, each a host name of "+
"letters, digits, hyphens and dots; an empty list takes them away. Refused, naming the name and why: "+
"not a host name, the root, the mesh's own domain or under it, or more than 8. (a)",
map[string]any{"names": str("the host names, separated by spaces or commas; empty clears them")},
func(a map[string]any) (any, error) { return r.SetUplinkNames(ctx, Split(a["names"])) }),
map[string]any{"names": stringArray("the host names, at most 8; an empty array clears them")},
func(a map[string]any) (any, error) { return r.SetUplinkNames(ctx, arrayArg(a, "names")) }),
}
}