Files
mesh-catalog/modules/networkmanager/cmd/uplink-tools/tools.go
T
jochen 397e627b02 networkmanager: the watcher's health is its unit's state
The sign-in process is judged by its unit being active, on the machine without the bus,
and NetworkManager's service keeps no state and no health again. The watcher exits
non-zero when it cannot subscribe once the system bus came back, so its unit shows
failing; uplink_health stays a tool that reads and no longer gives the names again.

Builds: design 08 sign-in-page §11, §13, §14, §23, §24, §25, §27; lead answer C-2c (hq 6752a5cf)
2026-11-24 21:53:29 +01:00

127 lines
5.4 KiB
Go

package main
// networkmanager's own tools, served by the bundle (design 08 sign-in-page §23): the read of the sign-in reaction, the
// three acts that start by hand what the two parts do by themselves, and the health tool of the watcher's process.
import (
"fmt"
"strings"
"git.novox.be/novox/mesh-networking/modules/mesh-connectivity-contracts/go/seats/noderesolver"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/health"
)
// signInRead is uplink_sign_in's answer.
type signInRead struct {
Watcher *watcherState `json:"watcher,omitempty"`
WatcherError string `json:"watcher_error,omitempty"`
Waiting int `json:"waiting"`
RefusedSince int `json:"publishes_refused_since_start"`
Names *NamesCall `json:"names,omitempty"`
ResolverRefused *string `json:"resolver_refused,omitempty"`
ResolverError string `json:"resolver_error,omitempty"`
}
func (b *bundle) tools() []stdio.Tool {
return []stdio.Tool{
{Name: "uplink_sign_in",
Description: "The network's sign-in page as this machine reacts to it: whether the watcher hears the network " +
"manager, the last rating it heard and when, the sign-in asked now (network, link, since), the asks opened " +
"and ended since its start, the last page opened with its outcome, the last notification, the last session " +
"start and what it did, the kept events dropped past the bound of 256, the events waiting to be published " +
"and the publishes refused since the bundle's start, the last uplink-names call with its result, and the " +
"resolver's refusal of the names where a holder of node-resolver runs here. (r)",
Run: func(map[string]any) (any, error) { return b.signIn(), nil }},
{Name: "uplink_names_again",
Description: "Give this machine's resolver the network manager's check host now, as the bundle does at its " +
"moments: calls node-resolver's uplink-names on this node and answers the call as names.json keeps it. (a)",
Run: func(map[string]any) (any, error) { return b.names.give("uplink_names_again"), nil }},
{Name: "uplink_rating_again",
Description: "Make the watcher subscribe on the system bus again, read the network manager's rating now and " +
"act on it as on a change; answers the watcher's state after it. (a)",
Run: func(map[string]any) (any, error) {
var s watcherState
if err := b.folder.askWatcher(askRatingAgain, &s); err != nil {
return nil, err
}
return s, nil
}},
{Name: "uplink_publish_again",
Description: "Publish the kept sign-in events now, in order under their own message ids, as the bundle does at " +
"its moments: answers how many were published and how many still wait. (a)",
Run: func(map[string]any) (any, error) { return b.pub.publishKept("uplink_publish_again"), nil }},
{Name: "uplink_health",
Description: "Whether the sign-in reaction works: unhealthy while the watcher's socket does not answer, while " +
"the watcher is not subscribed on the system bus, or while the last uplink-names call stands failed, naming " +
"which; no holder of node-resolver is healthy. A tool to read, not the watcher's health check, which is its " +
"unit's state. (r)",
Run: func(map[string]any) (any, error) { return b.health(), nil }},
}
}
// signIn reads the watcher's state, the folder and, where a holder of node-resolver runs here, the resolver's refusal.
func (b *bundle) signIn() signInRead {
var out signInRead
var s watcherState
if err := b.folder.askWatcher(askState, &s); err != nil {
out.WatcherError = err.Error()
} else {
out.Watcher = &s
}
if kept, err := b.folder.pending(); err == nil {
out.Waiting = len(kept)
}
out.RefusedSince = b.pub.refusedSince()
out.Names, _ = b.folder.names()
routes, held, err := b.resolverRoutes()
switch {
case err != nil:
out.ResolverError = err.Error()
case held:
out.ResolverRefused = &routes.UplinkNames.Refused
}
return out
}
// resolverRoutes is node-resolver's routes on this node, held false when no module holds the seat here.
func (b *bundle) resolverRoutes() (noderesolver.RoutesAnswer, bool, error) {
holder, err := b.names.resolverHolder()
if err != nil || holder == "" {
return noderesolver.RoutesAnswer{}, false, err
}
raw, err := b.names.ask("seat:"+noderesolver.Seat+"."+noderesolver.VerbRoutes+"@"+b.folder.Node, struct{}{})
if err != nil {
return noderesolver.RoutesAnswer{}, true, fmt.Errorf("%s/%s.%s: %w", b.folder.Node, noderesolver.Seat,
noderesolver.VerbRoutes, err)
}
routes, _, err := noderesolver.DecodeRoutesAnswer(raw)
return routes, true, err
}
// health is uplink_health's answer, a tool of the bundle and not a node-engine check (§23; lead answer C-2c).
func (b *bundle) health() health.Answer {
var faults []string
var s watcherState
if err := b.folder.askWatcher(askState, &s); err != nil {
faults = append(faults, err.Error())
} else if !s.Subscribed {
faults = append(faults, "the watcher is not subscribed on the system bus")
}
call, err := b.folder.names()
if err != nil {
faults = append(faults, "names.json does not read: "+err.Error())
}
if call != nil && call.Failed() {
faults = append(faults, "the last uplink-names call failed: "+call.Result)
}
if len(faults) > 0 {
return health.Unhealthy(strings.Join(faults, "; ") + ".")
}
why := "the watcher hears the network manager"
if call != nil {
why += "; the last uplink-names call: " + call.Result
}
return health.Healthy(why + ".")
}