package link import ( "context" "encoding/json" ) // **The composition names the withheld subjects** (design 46 approval mark §6, lead answer A-239): the node-engine reads them // through the seat mesh-grants' verb withheld, never from the grants part's state; when the verb does not answer, it says so. // GrantsSeat is the seat of the grants part, whose verb withheld names the marked subjects withheld from a node's runtime. const GrantsSeat = "mesh-grants" // WithheldUnknown is what a composition says when the grants part does not answer withheld (design 46 approval mark §6), // followed by the holder it asked and why (design 47 H, H-A-303 (3), H-A-306). const WithheldUnknown = "withheld unknown: the grants part does not answer" // withheldAsked names the holder the composition read asks what is withheld: the seat and its verb. const withheldAsked = "the seat " + GrantsSeat + "'s verb withheld" // WithheldSubject is one marked subject withheld from this node's runtime, and why. type WithheldSubject struct { Subject string `json:"subject"` Why string `json:"why"` } // WithheldOf is what the grants part withholds of module on this node, asked through its verb withheld: the subjects, or, // when the verb does not answer (not answered, cut by its bound, no responders) or answers what is not its answer, // WithheldUnknown as unknown, naming the holder asked and why. That the part is withheld is said once in the journal // (Say), until it answers again (design 47 H, H-A-303 (3), H-A-306). func (q *Session) WithheldOf(ctx context.Context, module string) (subjects []WithheldSubject, unknown string) { raw, err := q.askCalled(ctx, GrantsSeat, "withheld", map[string]string{"node": q.Membership.Node}, VaultWithin, "the grants part's withheld") if err != nil { return nil, q.withheldUnknown("asked of " + withheldAsked + ", which did not answer: " + err.Error()) } var answer struct { Node string `json:"node"` Modules []struct { Module string `json:"module"` Subjects []WithheldSubject `json:"subjects"` } `json:"modules"` } if json.Unmarshal(raw, &answer) != nil || answer.Node != q.Membership.Node { return nil, q.withheldUnknown("asked of " + withheldAsked + ", which answered what is not its answer for " + q.Membership.Node) } q.withheldMu.Lock() q.withheldSaid = false q.withheldMu.Unlock() for _, m := range answer.Modules { if m.Module == module { subjects = append(subjects, m.Subjects...) } } return subjects, "" } // withheldUnknown is WithheldUnknown with why, said once in the journal until the grants part answers again. func (q *Session) withheldUnknown(why string) string { unknown := WithheldUnknown + " (" + why + ")" q.withheldMu.Lock() said := q.withheldSaid q.withheldSaid = true q.withheldMu.Unlock() if !said && q.Say != nil { q.Say("the grants part is withheld from this node's composition read, which says " + unknown + " until it answers") } return unknown }