teller: cut long hexadecimal runs from an assigner ask's words #228

Merged
mesh-tools merged 1 commits from fix/teller-short-fingerprints into main 2026-11-16 19:15:43 +00:00
3 changed files with 46 additions and 1 deletions
@@ -133,7 +133,7 @@ func (t *Teller) raiseAssignerAsk(key string) (catchUp string) {
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(a.Ask); err != nil {
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.
@@ -342,3 +342,19 @@ func TestACatchUpWaitingOnTheRouterHoldsNoWarrant(t *testing.T) {
close(release)
<-caught
}
// TestShortWordsCutsLongHex: an ask whose words carry a whole fingerprint reaches the channel with it cut to 12 digits, so the
// channel does not refuse it as a secret; its id and the options' ids are kept.
func TestShortWordsCutsLongHex(t *testing.T) {
fp := "d82700f21be8c9104dd31c8823ceb9c0e351f5fdf8b83d6726c3b2b58113560b"
a := shortWords(oc.Ask{ID: "backup-x-" + fp[:20], Headline: "h " + fp, Explanation: "between src2:" + fp + " and 4eb3cf48",
OnExpiry: fp, Options: []oc.Option{{ID: "again", Label: "Back up again", Does: "at " + fp}}})
for _, s := range []string{a.Headline, a.Explanation, a.OnExpiry, a.Options[0].Does} {
if reLongHex.MatchString(s) || !strings.Contains(s, fp[:12]) {
t.Errorf("words %q: want the fingerprint cut to %s", s, fp[:12])
}
}
if a.ID != "backup-x-"+fp[:20] || a.Options[0].ID != "again" || a.Explanation != "between src2:"+fp[:12]+" and 4eb3cf48" {
t.Errorf("ask %+v: id, option id or other words changed", a)
}
}
@@ -0,0 +1,29 @@
package main
import (
"regexp"
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
)
// reLongHex is a run of hexadecimal digits as long as the operator channel refuses as a secret (32 or more): a fingerprint or
// a composition's digest a node-engine or the assigner writes whole into an ask's words.
var reLongHex = regexp.MustCompile(`(?i)\b[0-9a-f]{32,}\b`)
// shortWords is the ask with every long hexadecimal run in the words the operator reads (headline, explanation, on-expiry and
// each option's label and does) cut to its first 12 digits, as the mesh says a fingerprint. The operator channel refuses an ask
// whose words carry such a run as a secret, and the ask never reaches the operator (mesh-hand-acts on novox, 2026-11-16: a
// backup ask refused for the node-engine's whole fingerprints). Its id, key and options' ids are left as they are.
func shortWords(a oc.Ask) oc.Ask {
short := func(s string) string {
return reLongHex.ReplaceAllStringFunc(s, func(h string) string { return h[:12] })
}
a.Headline, a.Explanation, a.OnExpiry = short(a.Headline), short(a.Explanation), short(a.OnExpiry)
opts := make([]oc.Option, len(a.Options))
for i, o := range a.Options {
o.Label, o.Does = short(o.Label), short(o.Does)
opts[i] = o
}
a.Options = opts
return a
}