Let a declared file travel by its sha256 digest instead of its content, so a node's declaration is no longer bounded by one bus message (issue 1694, ADR 0486 step 1) #59

Merged
mesh-tools merged 2 commits from fix/1694-file-references into main 2026-10-21 12:43:57 +00:00
2 changed files with 10 additions and 1 deletions
Showing only changes of commit 6c857e1c02 - Show all commits
+3 -1
View File
@@ -85,7 +85,9 @@ func (f *File) TravelsByDigest() bool {
return false
}
if f.Bytes != "" {
return base64.StdEncoding.DecodedLen(len(f.Bytes)) > FileReferenceThreshold
// DecodedLen counts padding, so the exact length is taken off the decoded bytes.
body, err := f.Body()
return err == nil && len(body) > FileReferenceThreshold
}
return len(f.Content) > FileReferenceThreshold
}
+7
View File
@@ -111,6 +111,13 @@ func TestWhichFilesTravelByDigest(t *testing.T) {
t.Errorf("%s was made a reference", name)
}
}
exact := File{ID: "m.e", Bytes: base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, FileReferenceThreshold))}
if exact.TravelsByDigest() {
t.Error("a bytes file of exactly the threshold travels by digest")
}
if _, _, err := exact.AsReference(); err == nil {
t.Error("a bytes file of exactly the threshold was made a reference")
}
raw := bytes.Repeat([]byte{0, 1, 2}, FileReferenceThreshold)
f := File{ID: "m.b", Bytes: base64.StdEncoding.EncodeToString(raw)}
ref, body, err := f.AsReference()