Ask the packet filter's holder allowed at every compose of the filter
The node-engine stays the one renderer of the filter file: at each compose of a converged node's filter it asks the holder of node-packet-filter its verb allowed within the setting compose-ask-bound (10 s) and renders the answer. When allowed does not answer, or answers what is not its answer, no filter file is composed: the one loaded is kept as it runs, the holder's module is not held (an old holder must stay replaceable), and the part withheld is said once in the journal until an answer comes between. The node hears allowances-changed on its own node's subject and composes again. The manifest invokes seat:node-packet-filter.allowed and consumes node-packet-filter.allowances-changed. Builds: design 08 control-verbs §1, §3, §4, §5, §7, §8; ADR 0683; H-A-305, H-A-307 (1), (2), H-A-314 (3), (5), (7), H-A-315 (2), (6), H-A-321
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-networking/modules/mesh-connectivity-contracts/go/seats/nodepacketfilter"
|
||||
"git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go/overlay"
|
||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||
"github.com/novox/mesh-host/internal/agent"
|
||||
@@ -1234,6 +1235,12 @@ func composerEnv(session *link.Session, node string, say func(string), hooks com
|
||||
env.Entry = selfcompose.EntryCall(session.AskMeshSeat)
|
||||
// And the registry seats' verb versions, to resolve a want that names its version to its artifacts' digests (A-430a).
|
||||
env.Registry = selfcompose.EntryCall(session.AskMeshSeat)
|
||||
// And the holder of node-packet-filter's verb allowed of this node, at every compose of the filter, within the setting
|
||||
// compose-ask-bound (design 08 control-verbs §1).
|
||||
env.Allowed = func(ctx context.Context, within time.Duration) (json.RawMessage, error) {
|
||||
return session.AskSeat(ctx, nodepacketfilter.Seat, nodepacketfilter.VerbAllowed, nodepacketfilter.AllowedInput{}, within)
|
||||
}
|
||||
env.ComposeAskBound = composeAskBound()
|
||||
return env
|
||||
}
|
||||
|
||||
|
||||
@@ -111,4 +111,21 @@ func TestTheViewWaitsBoundIsTheManifestsSetting(t *testing.T) {
|
||||
if got := resolveAgainBound(); got != time.Minute {
|
||||
t.Errorf("no file gives %v", got)
|
||||
}
|
||||
// Design 08 control-verbs §1, H-A-314 (5): the compose-ask bound is the file `compose-ask-bound` feeds, in seconds, ten when
|
||||
// it holds nothing usable.
|
||||
wasAsk := composeAskBoundFile
|
||||
defer func() { composeAskBoundFile = wasAsk }()
|
||||
for content, want := range map[string]time.Duration{"3\n": 3 * time.Second, "": 10 * time.Second, "0": 10 * time.Second, "x": 10 * time.Second} {
|
||||
composeAskBoundFile = filepath.Join(t.TempDir(), "a")
|
||||
if err := os.WriteFile(composeAskBoundFile, []byte(content), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := composeAskBound(); got != want {
|
||||
t.Errorf("the file %q gives %v, want %v", content, got, want)
|
||||
}
|
||||
}
|
||||
composeAskBoundFile = filepath.Join(t.TempDir(), "missing")
|
||||
if got := composeAskBound(); got != 10*time.Second {
|
||||
t.Errorf("no file gives %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,6 +300,24 @@ func resolveAgainBound() time.Duration {
|
||||
return time.Duration(n) * time.Minute
|
||||
}
|
||||
|
||||
// composeAskBoundFile is the file the manifest declares with the content ${config:compose-ask-bound} (design 08 control-verbs
|
||||
// §1, H-A-314 (5)), read at the engine's start as resolveAgainFile is.
|
||||
var composeAskBoundFile = "/var/lib/mesh-host/compose-ask-bound"
|
||||
|
||||
// composeAskBound is how long a compose waits for an input it asks (the packet filter's allowed): the file's seconds, the
|
||||
// design's ten (selfcompose.DefaultComposeAskBound) when the file is missing, empty or not a positive number.
|
||||
func composeAskBound() time.Duration {
|
||||
raw, err := os.ReadFile(composeAskBoundFile)
|
||||
if err != nil {
|
||||
return selfcompose.DefaultComposeAskBound
|
||||
}
|
||||
n, err := strconv.Atoi(strings.TrimSpace(string(raw)))
|
||||
if err != nil || n < 1 {
|
||||
return selfcompose.DefaultComposeAskBound
|
||||
}
|
||||
return time.Duration(n) * time.Second
|
||||
}
|
||||
|
||||
// entryAsksFile is the file the manifest declares with the content ${config:entry-asks} (design 47 H, H-A-60), read at the
|
||||
// engine's start as recoveryWaitFile is.
|
||||
var entryAsksFile = "/var/lib/mesh-host/entry-asks"
|
||||
|
||||
Reference in New Issue
Block a user