mesh/delivery-group group fix/154-local-network checking: 0 of 2 member(s) ready
mesh/merge-gate out of date: judged against trunk 1826b68a22b5, the trunk is now 404b4409e70e; judged again on a recheck or when it is merged
mesh/repo-check out of date: judged against trunk 1826b68a22b5, the trunk is now 404b4409e70e; judged again on a recheck or when it is merged
mesh/delivery superseded: a newer head of the same pull request
A local service could only be declared public, which says the internet. local-network is a source and a reach: the private network and the private networks the machine reported on a link facing outside, judged here, shown by plan and node, and said in the rule set when there are none.
68 lines
2.5 KiB
Go
68 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/novox/mesh-controller/internal/catalogue"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
"github.com/novox/mesh-controller/internal/overlay"
|
|
)
|
|
|
|
// localNetworksOf is a machine's attached networks judged (novox/hq ADR 0340): which count as its local
|
|
// network, from what it last said of itself and the links it said face outside it. A machine that has
|
|
// said none judges to nothing, and a port reached from `local-network` is then admitted from the private
|
|
// network only, and said so.
|
|
func localNetworksOf(ctx context.Context, inv *inventory.Inventory, node string) ([]catalogue.LocalNetwork, error) {
|
|
account, had, err := inv.MachineOf(ctx, node)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
outward, err := inv.OutwardLinksOf(ctx, node)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return judgedNetworks(account, had, outward, overlay.Interface), nil
|
|
}
|
|
|
|
// judgedNetworks is the judging alone, from what was read.
|
|
func judgedNetworks(account inventory.MachineAccount, had bool, outward []string, tunnel string) []catalogue.LocalNetwork {
|
|
if !had || account.Machine == nil {
|
|
return nil
|
|
}
|
|
attached := make([]catalogue.AttachedNetwork, 0, len(account.Machine.Networks))
|
|
for _, n := range account.Machine.Networks {
|
|
attached = append(attached, catalogue.AttachedNetwork{Link: n.Link, Network: n.Network})
|
|
}
|
|
return catalogue.JudgeLocalNetworks(attached, outward, tunnel)
|
|
}
|
|
|
|
// localNetworkLines is what `node` shows of a machine's attached networks (ADR 0340 §8): each one, with
|
|
// whether it counts as the local network and why, or why none is shown.
|
|
func localNetworkLines(account inventory.MachineAccount, had bool, judged []catalogue.LocalNetwork) []string {
|
|
out := []string{" its local network (what a port reached from local-network is admitted from):"}
|
|
switch {
|
|
case !had || account.Machine == nil:
|
|
return append(out, " not said — this machine has not reported what it is attached to")
|
|
case len(account.Machine.Networks) == 0:
|
|
why := account.Machine.Unknown["networks"]
|
|
if why == "" {
|
|
why = "its node-engine is older than the one that says it"
|
|
}
|
|
return append(out, " not said — "+why)
|
|
}
|
|
counted := 0
|
|
for _, j := range judged {
|
|
verdict := "not counted"
|
|
if j.Counts {
|
|
verdict = "counts"
|
|
counted++
|
|
}
|
|
out = append(out, fmt.Sprintf(" %-22s on %-10s %s: %s", j.Network, j.Link, verdict, j.Why))
|
|
}
|
|
if counted == 0 {
|
|
out = append(out, " none counts: a port reached from local-network is admitted from the private network only")
|
|
}
|
|
return out
|
|
}
|