mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/swarm: fixes for hashes command; PR comments
This commit is contained in:
parent
1ea6548c46
commit
7b7a9b3549
4 changed files with 14 additions and 18 deletions
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"gopkg.in/urfave/cli.v1"
|
"gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var chunkExploreCommand = cli.Command{
|
var hashesCommand = cli.Command{
|
||||||
Action: hashes,
|
Action: hashes,
|
||||||
CustomHelpTemplate: helpTemplate,
|
CustomHelpTemplate: helpTemplate,
|
||||||
Name: "hashes",
|
Name: "hashes",
|
||||||
|
|
@ -39,7 +39,7 @@ var chunkExploreCommand = cli.Command{
|
||||||
func hashes(ctx *cli.Context) {
|
func hashes(ctx *cli.Context) {
|
||||||
args := ctx.Args()
|
args := ctx.Args()
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
utils.Fatalf("Usage: swarm explore <file name>")
|
utils.Fatalf("Usage: swarm hashes <file name>")
|
||||||
}
|
}
|
||||||
f, err := os.Open(args[0])
|
f, err := os.Open(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,8 @@ func init() {
|
||||||
dbCommand,
|
dbCommand,
|
||||||
// See config.go
|
// See config.go
|
||||||
DumpConfigCommand,
|
DumpConfigCommand,
|
||||||
// chunkExploreCommand
|
// hashesCommand
|
||||||
chunkExploreCommand,
|
hashesCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
// append a hidden help subcommand to all commands that have subcommands
|
// append a hidden help subcommand to all commands that have subcommands
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ func NewFileStore(store ChunkStore, params *FileStoreParams) *FileStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public API. Main entry point for document retrieval directly. Used by the
|
// Retrieve is a public API. Main entry point for document retrieval directly. Used by the
|
||||||
// FS-aware API and httpaccess
|
// FS-aware API and httpaccess
|
||||||
// Chunk retrieval blocks on netStore requests with a timeout so reader will
|
// Chunk retrieval blocks on netStore requests with a timeout so reader will
|
||||||
// report error if retrieval of chunks within requested range time out.
|
// report error if retrieval of chunks within requested range time out.
|
||||||
|
|
@ -87,7 +87,7 @@ func (f *FileStore) Retrieve(ctx context.Context, addr Address) (reader *LazyChu
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public API. Main entry point for document storage directly. Used by the
|
// Store is a public API. Main entry point for document storage directly. Used by the
|
||||||
// FS-aware API and httpaccess
|
// FS-aware API and httpaccess
|
||||||
func (f *FileStore) Store(ctx context.Context, data io.Reader, size int64, toEncrypt bool) (addr Address, wait func(context.Context) error, err error) {
|
func (f *FileStore) Store(ctx context.Context, data io.Reader, size int64, toEncrypt bool) (addr Address, wait func(context.Context) error, err error) {
|
||||||
putter := NewHasherStore(f.ChunkStore, f.hashFunc, toEncrypt)
|
putter := NewHasherStore(f.ChunkStore, f.hashFunc, toEncrypt)
|
||||||
|
|
@ -98,7 +98,7 @@ func (f *FileStore) HashSize() int {
|
||||||
return f.hashFunc().Size()
|
return f.hashFunc().Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public API. This endpoint returns all chunk hashes (only) for a given file
|
// GetAllReferences is a public API. This endpoint returns all chunk hashes (only) for a given file
|
||||||
func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader, toEncrypt bool) (addrs AddressCollection, err error) {
|
func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader, toEncrypt bool) (addrs AddressCollection, err error) {
|
||||||
// create a special kind of putter, which only will store the references
|
// create a special kind of putter, which only will store the references
|
||||||
putter := &HashExplorer{
|
putter := &HashExplorer{
|
||||||
|
|
|
||||||
|
|
@ -190,22 +190,18 @@ func TestGetAllReferences(t *testing.T) {
|
||||||
}
|
}
|
||||||
fileStore := NewFileStore(localStore, NewFileStoreParams())
|
fileStore := NewFileStore(localStore, NewFileStoreParams())
|
||||||
|
|
||||||
checkRefs := func(dataSize int, expectedLen int) {
|
// testRuns[i] and expectedLen[i] are dataSize and expected length respectively
|
||||||
slice := testutil.RandomBytes(1, dataSize)
|
testRuns := []int{1024, 8192, 16000, 30000, 1000000}
|
||||||
|
expectedLens := []int{1, 3, 5, 9, 248}
|
||||||
|
for i, r := range testRuns {
|
||||||
|
slice := testutil.RandomBytes(1, r)
|
||||||
|
|
||||||
addrs, err := fileStore.GetAllReferences(context.Background(), bytes.NewReader(slice), false)
|
addrs, err := fileStore.GetAllReferences(context.Background(), bytes.NewReader(slice), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if len(addrs) != expectedLen {
|
if len(addrs) != expectedLens[i] {
|
||||||
t.Fatalf("Expected reference array length to be %d, but is %d", expectedLen, len(addrs))
|
t.Fatalf("Expected reference array length to be %d, but is %d", expectedLens[i], len(addrs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// testRuns[i] and expectedLen[i] are dataSize and expected length respectively
|
|
||||||
testRuns := []int{1024, 8192, 16000, 30000, 1000000}
|
|
||||||
expectedLens := []int{1, 3, 5, 9, 248}
|
|
||||||
for i, r := range testRuns {
|
|
||||||
checkRefs(r, expectedLens[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue