-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmds): extend block size check for dag|block put (#8751)
* feat(cmds): extend block size check for dag|block put * feat(cmds): block size check for dag import * style: dag-pb → UnixFS, 1MB → 1MiB Co-authored-by: Marcin Rataj <lidel@lidel.org>
- Loading branch information
Showing
11 changed files
with
120 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cmdutils | ||
|
||
import ( | ||
"fmt" | ||
|
||
cmds "github.com/ipfs/go-ipfs-cmds" | ||
|
||
"github.com/ipfs/go-cid" | ||
coreiface "github.com/ipfs/interface-go-ipfs-core" | ||
) | ||
|
||
const ( | ||
AllowBigBlockOptionName = "allow-big-block" | ||
SoftBlockLimit = 1024 * 1024 // https://github.com/ipfs/go-ipfs/issues/7421#issuecomment-910833499 | ||
) | ||
|
||
var AllowBigBlockOption cmds.Option | ||
|
||
func init() { | ||
AllowBigBlockOption = cmds.BoolOption(AllowBigBlockOptionName, "Disable block size check and allow creation of blocks bigger than 1MiB. WARNING: such blocks won't be transferable over the standard bitswap.").WithDefault(false) | ||
} | ||
|
||
func CheckCIDSize(req *cmds.Request, c cid.Cid, dagAPI coreiface.APIDagService) error { | ||
n, err := dagAPI.Get(req.Context, c) | ||
if err != nil { | ||
return fmt.Errorf("CheckCIDSize: getting dag: %w", err) | ||
} | ||
|
||
nodeSize, err := n.Size() | ||
if err != nil { | ||
return fmt.Errorf("CheckCIDSize: getting node size: %w", err) | ||
} | ||
|
||
return CheckBlockSize(req, nodeSize) | ||
} | ||
|
||
func CheckBlockSize(req *cmds.Request, size uint64) error { | ||
allowAnyBlockSize, _ := req.Options[AllowBigBlockOptionName].(bool) | ||
if allowAnyBlockSize { | ||
return nil | ||
} | ||
|
||
// We do not allow producing blocks bigger than 1 MiB to avoid errors | ||
// when transmitting them over BitSwap. The 1 MiB constant is an | ||
// unenforced and undeclared rule of thumb hard-coded here. | ||
if size > SoftBlockLimit { | ||
return fmt.Errorf("produced block is over 1MiB: big blocks can't be exchanged with other peers. consider using UnixFS for automatic chunking of bigger files, or pass --allow-big-block to override") | ||
} | ||
return nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters