Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-chunker
Commits
4414aa26
Commit
4414aa26
authored
Jan 21, 2020
by
Peter Rabbitson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address block/chunk logical mismatch, name things correctly
parent
5f9fd98c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
20 deletions
+15
-20
parse.go
parse.go
+8
-13
parse_test.go
parse_test.go
+7
-7
No files found.
parse.go
View file @
4414aa26
...
...
@@ -12,21 +12,16 @@ const (
// DefaultBlockSize is the chunk size that splitters produce (or aim to).
DefaultBlockSize
int64
=
1024
*
256
// 1 MB, on-wire block size for "datablocks ( unixfs, etc )"
// copy of https://github.com/ipfs/go-unixfs/blob/v0.2.3/importer/helpers/helpers.go#L8
BlockSizeLimit
int
=
1048576
// in case we are using raw-leaves: this would match BlockSizeLimit, but we can't assume that
// be conservative and substract the PB wraping size of a full DAG-PB+UnixFS node describing 1M
// (2b(type2/file)+4b(data-field:3-byte-len-delimited)+4b(size-field:3-byte-varint))+(4b(DAG-type-1:3-byte-len-delimited))
// FIXME - this calculation will need an update for CBOR
BlockPayloadLimit
int
=
(
BlockSizeLimit
-
(
2
+
4
+
4
+
4
))
// No leaf block should contain more than 1MiB of payload data ( wrapping overhead aside )
// This effectively mandates the maximum chunk size
// See discussion at https://github.com/ipfs/go-ipfs-chunker/pull/21#discussion_r369124879 for background
ChunkSizeLimit
int
=
1048576
)
var
(
ErrRabinMin
=
errors
.
New
(
"rabin min must be greater than 16"
)
ErrSize
=
errors
.
New
(
"chunker size must be greater than 0"
)
ErrSizeMax
=
fmt
.
Errorf
(
"chunker parameters may not exceed the maximum
block payload
size of %d"
,
BlockPayload
Limit
)
ErrSizeMax
=
fmt
.
Errorf
(
"chunker parameters may not exceed the maximum
chunk
size of %d"
,
ChunkSize
Limit
)
)
// FromString returns a Splitter depending on the given string:
...
...
@@ -44,7 +39,7 @@ func FromString(r io.Reader, chunker string) (Splitter, error) {
return
nil
,
err
}
else
if
size
<=
0
{
return
nil
,
ErrSize
}
else
if
size
>
BlockPayload
Limit
{
}
else
if
size
>
ChunkSize
Limit
{
return
nil
,
ErrSizeMax
}
return
NewSizeSplitter
(
r
,
int64
(
size
)),
nil
...
...
@@ -69,7 +64,7 @@ func parseRabinString(r io.Reader, chunker string) (Splitter, error) {
size
,
err
:=
strconv
.
Atoi
(
parts
[
1
])
if
err
!=
nil
{
return
nil
,
err
}
else
if
int
(
float32
(
size
)
*
1.5
)
>
BlockPayload
Limit
{
// FIXME - th
ere is probably a better way to bubble up this calculation from NewRabin()
}
else
if
int
(
float32
(
size
)
*
1.5
)
>
ChunkSize
Limit
{
// FIXME - th
is will be addressed in a subsequent PR
return
nil
,
ErrSizeMax
}
return
NewRabin
(
r
,
uint64
(
size
)),
nil
...
...
@@ -108,7 +103,7 @@ func parseRabinString(r io.Reader, chunker string) (Splitter, error) {
return
nil
,
errors
.
New
(
"incorrect format: rabin-min must be smaller than rabin-avg"
)
}
else
if
avg
>=
max
{
return
nil
,
errors
.
New
(
"incorrect format: rabin-avg must be smaller than rabin-max"
)
}
else
if
max
>
BlockPayload
Limit
{
}
else
if
max
>
ChunkSize
Limit
{
return
nil
,
ErrSizeMax
}
...
...
parse_test.go
View file @
4414aa26
...
...
@@ -7,7 +7,7 @@ import (
)
const
(
testTwoThirdsOf
BlockPayload
Limit
=
2
*
(
float32
(
BlockPayload
Limit
)
/
float32
(
3
))
testTwoThirdsOf
Chunk
Limit
=
2
*
(
float32
(
ChunkSize
Limit
)
/
float32
(
3
))
)
func
TestParseRabin
(
t
*
testing
.
T
)
{
...
...
@@ -33,22 +33,22 @@ func TestParseRabin(t *testing.T) {
t
.
Fatalf
(
"Expected an arg-out-of-order error, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-19-21-%d"
,
BlockPayload
Limit
))
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-19-21-%d"
,
ChunkSize
Limit
))
if
err
!=
nil
{
t
.
Fatalf
(
"Expected success, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-19-21-%d"
,
1
+
BlockPayload
Limit
))
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-19-21-%d"
,
1
+
ChunkSize
Limit
))
if
err
!=
ErrSizeMax
{
t
.
Fatalf
(
"Expected 'ErrSizeMax', got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-%.0f"
,
testTwoThirdsOf
BlockPayload
Limit
))
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-%.0f"
,
testTwoThirdsOf
Chunk
Limit
))
if
err
!=
nil
{
t
.
Fatalf
(
"Expected success, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-%.0f"
,
1
+
testTwoThirdsOf
BlockPayload
Limit
))
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-%.0f"
,
1
+
testTwoThirdsOf
Chunk
Limit
))
if
err
!=
ErrSizeMax
{
t
.
Fatalf
(
"Expected 'ErrSizeMax', got: %#v"
,
err
)
}
...
...
@@ -68,12 +68,12 @@ func TestParseSize(t *testing.T) {
t
.
Fatalf
(
"Expected success, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"size-%d"
,
BlockPayload
Limit
))
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"size-%d"
,
ChunkSize
Limit
))
if
err
!=
nil
{
t
.
Fatalf
(
"Expected success, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"size-%d"
,
1
+
BlockPayload
Limit
))
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"size-%d"
,
1
+
ChunkSize
Limit
))
if
err
!=
ErrSizeMax
{
t
.
Fatalf
(
"Expected 'ErrSizeMax', got: %#v"
,
err
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment