Commit c5cb214f authored by Javier Peletier's avatar Javier Peletier Committed by Anton Evangelatov

swarm/storage/feed: Expose MaxUpdateDataLength constant (#17858)

parent f95811e6
...@@ -42,7 +42,9 @@ type Update struct { ...@@ -42,7 +42,9 @@ type Update struct {
} }
const minimumUpdateDataLength = idLength + headerLength + 1 const minimumUpdateDataLength = idLength + headerLength + 1
const maxUpdateDataLength = chunk.DefaultSize - signatureLength - idLength - headerLength
//MaxUpdateDataLength indicates the maximum payload size for a feed update
const MaxUpdateDataLength = chunk.DefaultSize - signatureLength - idLength - headerLength
// binaryPut serializes the feed update information into the given slice // binaryPut serializes the feed update information into the given slice
func (r *Update) binaryPut(serializedData []byte) error { func (r *Update) binaryPut(serializedData []byte) error {
...@@ -51,8 +53,8 @@ func (r *Update) binaryPut(serializedData []byte) error { ...@@ -51,8 +53,8 @@ func (r *Update) binaryPut(serializedData []byte) error {
return NewError(ErrInvalidValue, "a feed update must contain data") return NewError(ErrInvalidValue, "a feed update must contain data")
} }
if datalength > maxUpdateDataLength { if datalength > MaxUpdateDataLength {
return NewErrorf(ErrInvalidValue, "feed update data is too big (length=%d). Max length=%d", datalength, maxUpdateDataLength) return NewErrorf(ErrInvalidValue, "feed update data is too big (length=%d). Max length=%d", datalength, MaxUpdateDataLength)
} }
if len(serializedData) != r.binaryLength() { if len(serializedData) != r.binaryLength() {
......
...@@ -35,7 +35,7 @@ func TestUpdateLengthCheck(t *testing.T) { ...@@ -35,7 +35,7 @@ func TestUpdateLengthCheck(t *testing.T) {
testBinarySerializerLengthCheck(t, getTestFeedUpdate()) testBinarySerializerLengthCheck(t, getTestFeedUpdate())
// Test fail if update is too big // Test fail if update is too big
update := getTestFeedUpdate() update := getTestFeedUpdate()
update.data = make([]byte, maxUpdateDataLength+100) update.data = make([]byte, MaxUpdateDataLength+100)
serialized := make([]byte, update.binaryLength()) serialized := make([]byte, update.binaryLength())
if err := update.binaryPut(serialized); err == nil { if err := update.binaryPut(serialized); err == nil {
t.Fatal("Expected update.binaryPut to fail since update is too big") t.Fatal("Expected update.binaryPut to fail since update is too big")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment