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
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user