Assigner and grants part: record hand acts and warrants through the seat mesh-hand-acts, the controller's log only while that seat has no holder and the controller holds its lease (issue 1953 D8)
Pins mesh-sdk 2d2aa7b in the L5 modules.
This commit is contained in:
@@ -52,7 +52,7 @@ const (
|
||||
)
|
||||
|
||||
// Invokes is every tool the part calls.
|
||||
var Invokes = []string{CallUsers, CallUserCan, CallStreams, CallRootFree}
|
||||
var Invokes = []string{CallUsers, CallUserCan, CallStreams, CallRootFree, CallRecordWarrant, CallRecordWarrantController}
|
||||
|
||||
// Reader reads another part's state, named `<module>.<state>`. A refusal (a read not granted yet, a bucket not there) is
|
||||
// an error the part names as a gap and composes past: it never stops for one.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package grants
|
||||
|
||||
import (
|
||||
"git.novox.be/novox/mesh-sdk/go/handacts"
|
||||
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -378,6 +380,7 @@ func (p *Part) Warranted(o asks.Option, w asks.Warrant) error {
|
||||
if err := p.finish(s, a); err != nil {
|
||||
return err
|
||||
}
|
||||
p.recordWarrant(w.Ask)
|
||||
// The bus node turns on the key: written now, so the switch reaches it on the operator's yes (ADR 0547 clause 8).
|
||||
if err := p.syncFollow(s.State); err != nil {
|
||||
return fmt.Errorf("the switch is recorded and the key the bus node follows could not be written (the next pass writes it): %w", err)
|
||||
@@ -512,3 +515,37 @@ func (p *Part) TakeOverState() (any, error) {
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Module is the grants part's module, the asker of its take-over and hand-back.
|
||||
const Module = "mesh-grants"
|
||||
|
||||
// The hand-act log's verbs the part records its switches by (novox/hq ADR 0565 §11, ADR 0547 §6): the seat's, and the
|
||||
// controller's while the seat has no holder and the controller holds its lease (handacts.Recorder).
|
||||
const (
|
||||
CallRecordWarrant = "seat:" + handacts.Seat + ".warranted"
|
||||
CallRecordWarrantController = "seat:mesh-controller.warranted"
|
||||
)
|
||||
|
||||
// recordWarrant records, in the hand-act log, that a take-over or a hand-back was made on the operator's warrant for ask.
|
||||
// Said, never fatal: the switch stands either way.
|
||||
func (p *Part) recordWarrant(ask string) {
|
||||
if p.Call == nil {
|
||||
return
|
||||
}
|
||||
rec := handacts.Recorder{Ask: p.Call.Call, LeaseAway: func() bool {
|
||||
if p.Read == nil {
|
||||
return false
|
||||
}
|
||||
away, _ := leaseHandedAway(p.Read)
|
||||
return away
|
||||
}}
|
||||
taken, err := rec.RecordWarrant(Module, ask)
|
||||
if p.Logf == nil {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
p.Logf("the switch on the warrant %s is not recorded in the hand-act log: %v", ask, err)
|
||||
return
|
||||
}
|
||||
p.Logf("the switch on the warrant %s is recorded in the log of %s", ask, taken.Log)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user