package catalogue import ( "fmt" "strings" ) // AttachedNetwork is one network a machine said it is directly attached to: the link it is on and the // network as address and prefix (novox/hq ADR 0340 §7), as the node-engine reports it among its facts. type AttachedNetwork struct { Link string `json:"link"` Network string `json:"network"` } // LocalNetwork is one attached network judged: whether it counts as this machine's local network for a // port reached from `local-network`, and why — said for one that counts as well as for one that does // not, so `node` can show which counted and why the others did not (ADR 0340 §8). type LocalNetwork struct { Link string Network string Counts bool Why string } // LocalNetworkPort is one port the filter admits from `local-network`, and what that resolved to on this // machine (ADR 0340 §8): what `plan` shows for it. type LocalNetworkPort struct { Port int Protocol string Because []string // Networks is the local networks it is admitted from; empty when the machine reported none (§6). Networks []string } // Said is how `plan` says one such port: the networks, or that there are none and the port is admitted // from the private network only. func (p LocalNetworkPort) Said() string { by := strings.Join(p.Because, ", ") if len(p.Networks) == 0 { return fmt.Sprintf("%s/%d (%s) from the local network: none — this machine reported no private "+ "network on a link facing outside, so it is admitted from the private network only", p.Protocol, p.Port, by) } return fmt.Sprintf("%s/%d (%s) from the local network: %s, and the private network", p.Protocol, p.Port, by, strings.Join(p.Networks, ", ")) }