The channel holds no room to wait for (A-424): a refusal for want of room is said as any refusal is, and its waiting, its bound of refusals and their tests go. The wait for asks the router did not take stays. Builds: design 47 H2 §813 (10)
232 lines
10 KiB
Go
232 lines
10 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
|
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-teller/tellerevents"
|
|
)
|
|
|
|
// The assigner's asks reach the operator (issue 1906). The assigner writes its asks (the hold of a fingerprint, the restore
|
|
// of a data module, the backup before an apply and a move of a module of policy record) in its bucket asks; until now the
|
|
// teller only filled them from an answer given in the view, so an ask nobody opened the view for reached nobody: on
|
|
// 2026-10-25 seven modules stayed held on every machine and the operator was never asked. Now the teller raises each on the
|
|
// operator channel as it raises the gate's merge asks: as the asker mesh-delivery-teller, once per router id, through the same
|
|
// records, the same wait and the same warrants. The operator's answer, from the phone or from the view, is written
|
|
// under the ask's own key in the bucket answers, which the assigner reads (mesh-delivery-assigner pass.go answeredWith); none
|
|
// of these asks needs proof of who answered (mesh-sdk go/delivery AskNeedsProof).
|
|
|
|
// The operator channel keeps no count of an asker's open asks and holds none back for room (design 47 G A-424): the teller asks
|
|
// each of the assigner's asks when the assigner writes it, as many as there are. The record `room` keeps only the asks the
|
|
// teller could not hand the router (a transport fault, a word not heard), asked again at the next end and at the start.
|
|
|
|
// lapsed says whether the assigner's ask lapsed: past the expiry its words name. A lapsed ask is asked of nobody: its proposal or
|
|
// question has ended, and the router would let it lapse at once (A-424: an ask lapses at its expiry).
|
|
func lapsed(a oc.Ask, now time.Time) (time.Time, bool) {
|
|
at, err := time.Parse(time.RFC3339, a.Expires)
|
|
if err != nil || at.IsZero() {
|
|
return time.Time{}, false
|
|
}
|
|
return at, !now.Before(at)
|
|
}
|
|
|
|
// isAssignerKey says whether an ask key is one of the assigner's, not the merge ask's key of before the Approve per merge went.
|
|
func isAssignerKey(key string) bool {
|
|
k, err := asks.ParseAnyAskKey(key)
|
|
return err == nil && k.Kind != meshdeliveryclient.AskKindMerge
|
|
}
|
|
|
|
// assignerAsk reads the assigner's ask at key: found false when the key holds none.
|
|
func (t *Teller) assignerAsk(key string) (assignerAsked, bool, error) {
|
|
if t.Assigner == nil {
|
|
return assignerAsked{}, false, fmt.Errorf("the teller reads no assigner asks")
|
|
}
|
|
raw, found, err := t.Assigner.Get(key)
|
|
if err != nil || !found {
|
|
return assignerAsked{}, false, err
|
|
}
|
|
a, err := decodeAssignerAsk(key, raw)
|
|
if err != nil {
|
|
return assignerAsked{}, false, fmt.Errorf("the assigner's key %s holds no ask: %w", key, err)
|
|
}
|
|
return a, true, nil
|
|
}
|
|
|
|
// assignerAsked is the assigner's ask with the router's ask decoded from its JSON.
|
|
type assignerAsked struct {
|
|
Asking int
|
|
Ask oc.Ask
|
|
}
|
|
|
|
// decodeAssignerAsk reads the assigner's ask at key as asks.DecodeAsk did before the ask was JSON: it refuses an
|
|
// id other than the one the key and the asking give, and an ask with no option (occ.Carried).
|
|
func decodeAssignerAsk(key string, data []byte) (assignerAsked, error) {
|
|
a, err := asks.DecodeAsk(key, data)
|
|
if err != nil {
|
|
return assignerAsked{}, err
|
|
}
|
|
ask, err := occ.Carried(a.Ask, meshdeliveryclient.AskingID(key, a.Asking))
|
|
if err != nil {
|
|
return assignerAsked{}, err
|
|
}
|
|
return assignerAsked{Asking: a.Asking, Ask: ask}, nil
|
|
}
|
|
|
|
// raiseAssignerAsk asks the operator the assigner's ask at key, once per router id: an ask answered already (from the view or
|
|
// the phone) is not asked; an earlier asking still open is taken back first; an asking already made is only caught up with
|
|
// at the router, and one that ended is not asked again, for the router drops a second ask under an id it keeps. An asking
|
|
// still open is answered as catchUp, for the caller to catch up with once it let go of the teller's lock.
|
|
func (t *Teller) raiseAssignerAsk(key string) (catchUp string) {
|
|
a, found, err := t.assignerAsk(key)
|
|
if err != nil {
|
|
t.logf("%s: the ask is not raised: %v", key, err)
|
|
return
|
|
}
|
|
if !found {
|
|
return
|
|
}
|
|
id := a.Ask.ID
|
|
if raw, _, has, err := t.Answers.Get(answerKey(key)); err != nil {
|
|
t.logf("%s: the answers could not be read, so the ask is not raised: %v", key, err)
|
|
return
|
|
} else if has && answeredAsking(raw) == id {
|
|
return
|
|
}
|
|
prior, grec, err := t.seenAt(gateRecordKey(key))
|
|
if err != nil {
|
|
t.logf("%s: %v", key, err)
|
|
return
|
|
}
|
|
if grec != nil && prior.ID != id {
|
|
t.cancelOpen(key, prior.ID) // a new asking of the same key: the earlier one is taken back
|
|
}
|
|
k, _, err := t.keptOf(id)
|
|
if err != nil {
|
|
t.logf("%s: %v", key, err)
|
|
return
|
|
}
|
|
if k != nil {
|
|
byHand := grec != nil && prior.ID == id && prior.Hand
|
|
if grec == nil || prior.ID != id {
|
|
_ = t.note(id, key, 0, grec)
|
|
}
|
|
switch {
|
|
case open(k):
|
|
catchUp = id
|
|
case endedUnanswered(k) && !byHand:
|
|
// The key stands under an asking that ended at the channel without an answer, heard now or at the teller's start
|
|
// (issue 1966: the nats yes on novox and three backup asks stood so after #195, and nothing asked them again): the
|
|
// assigner is told, and writes the key again under a new asking where its kind allows it.
|
|
t.sayAssignerAskEnded(key, id, k.Ended)
|
|
default:
|
|
// Said, never silent (issue 1966): an answered asking, or one a person ended by hand, is not asked again.
|
|
t.logf("%s: the ask %s ended (%s) and the assigner's key still stands under it: not asked again, the router would drop it; a writing under a new asking is asked", key, id, endedWords(k, byHand))
|
|
}
|
|
return
|
|
}
|
|
if err := t.note(id, key, 0, grec); err != nil {
|
|
t.logf("%s: the record of the ask %s could not be kept, so it is not raised: %v", key, id, err)
|
|
return
|
|
}
|
|
if err := t.Asker.Ask(shortWords(a.Ask)); err != nil {
|
|
// Kept but not published (a transport fault, the router restarting): nothing writes the key again, so the ask is not
|
|
// forgotten but waits, kept on the bus, to be asked again at the next end and at the teller's start (issue 1966,
|
|
// ADR 0668 §1). Before, the record was deleted for "the next writing of the key", which never came.
|
|
t.logf("%s: the ask %s was not asked: %v; it waits to be asked again at the next end and at the start", key, id, err)
|
|
t.unheard(id)
|
|
return
|
|
}
|
|
t.logf("%s: the assigner's ask %s is asked of the operator (%s)", key, id, a.Ask.Headline)
|
|
return
|
|
}
|
|
|
|
// OnAssignerAskGone handles a key the assigner took away from its asks (a hold it lifted by itself): the open router ask of
|
|
// its latest asking is taken back, so the operator is not asked about what no longer holds.
|
|
func (t *Teller) OnAssignerAskGone(key string) {
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
if !isAssignerKey(key) {
|
|
t.logf("the assigner's key %s was taken away and is no ask key of the assigner, and is left", key)
|
|
return
|
|
}
|
|
prior, grec, err := t.seenAt(gateRecordKey(key))
|
|
if err != nil || grec == nil {
|
|
if err != nil {
|
|
t.logf("%s: %v", key, err)
|
|
}
|
|
return
|
|
}
|
|
t.cancelOpen(key, prior.ID)
|
|
}
|
|
|
|
// answerAssigner is the act of a warrant for one of the assigner's asks: the ask must still stand at its key under the asking
|
|
// and the words the operator answered, and then the answer is written under the ask's key, once. Its options bind no act:
|
|
// the assigner reads the option chosen (occ.Client.Take has checked the option, its level and the ask's digest).
|
|
func (t *Teller) answerAssigner(key string, o oc.Option, w oc.Warrant) error {
|
|
a, found, err := t.assignerAsk(key)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !found {
|
|
t.logf("%s: the ask %s was answered and the assigner has taken it away: the answer changes nothing", key, w.Ask)
|
|
return nil
|
|
}
|
|
if a.Ask.ID != w.Ask {
|
|
t.logf("%s: the ask %s was answered, and the assigner has asked again under %s: an answer to an earlier asking changes nothing", key, w.Ask, a.Ask.ID)
|
|
return nil
|
|
}
|
|
// The warrant is over the ask as the channel was asked it, its words cut (shortWords), not as the assigner keeps it.
|
|
if d := occ.Digest(shortWords(a.Ask)); d != w.AskDigest {
|
|
return fmt.Errorf("the assigner's ask %s is no longer the ask the operator answered (its digest is %s, the warrant's %s)", key, d, w.AskDigest)
|
|
}
|
|
body, err := meshdeliveryclient.EncodeAnswer(meshdeliveryclient.Answer{Option: o.ID, Warrant: warrantID(w), Words: occ.Says(w)})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return t.writeAnswer(key, w.Ask, body, occ.Says(w))
|
|
}
|
|
|
|
// endedUnanswered says whether an asking ended at the channel without an answer the assigner could ask again for: it lapsed,
|
|
// or it was cancelled (at the router, or by the teller when its key was taken away). A refusal would be refused again, and a
|
|
// replaced asking has a newer one standing.
|
|
func endedUnanswered(k *occ.Kept) bool {
|
|
return k != nil && !k.Acted && (k.Ended == occ.OutcomeExpired || k.Ended == occ.OutcomeCancelled)
|
|
}
|
|
|
|
// endedWords says how an ended asking ended, for the journal.
|
|
func endedWords(k *occ.Kept, byHand bool) string {
|
|
switch {
|
|
case byHand:
|
|
return "ended by hand"
|
|
case k.Acted:
|
|
return "answered"
|
|
}
|
|
return k.Ended
|
|
}
|
|
|
|
// sayAssignerAskEnded says the teller's event ask-ended for the assigner's ask at key whose asking id ended at the channel
|
|
// with outcome, once per asking (the bus drops a second message under its id): the assigner writes the key again under a new
|
|
// asking (issue 1966). An outcome the assigner could not ask again for is not said.
|
|
func (t *Teller) sayAssignerAskEnded(key, id, outcome string) {
|
|
if outcome != occ.OutcomeExpired && outcome != occ.OutcomeCancelled {
|
|
return
|
|
}
|
|
body, err := tellerevents.EncodeEnded(tellerevents.Ended{Key: key, Ask: id, Outcome: outcome})
|
|
if err == nil && t.Emit == nil {
|
|
err = fmt.Errorf("the teller says no events here")
|
|
}
|
|
if err == nil {
|
|
err = t.Emit(tellerevents.AskEnded, body, tellerevents.AskEnded+"."+id)
|
|
}
|
|
if err != nil {
|
|
t.logf("%s: the ask %s ended (%s) without an answer, and the assigner could not be told (%v): it is told again at the teller's next start", key, id, outcome, err)
|
|
return
|
|
}
|
|
t.logf("%s: the ask %s ended (%s) without an answer: the assigner is told (%s), and writes the key again under a new asking where its kind allows it", key, id, outcome, tellerevents.AskEnded)
|
|
}
|