From 528745e5aa12eca97d8031c5d14cfdc87e31e40b Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Sun, 3 Feb 2019 19:19:22 -0500 Subject: [PATCH 01/10] swarm/storage: GetAllReferences returns all chunk references --- swarm/storage/filestore.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/swarm/storage/filestore.go b/swarm/storage/filestore.go index aebe03c1ef6b..978db1342c84 100644 --- a/swarm/storage/filestore.go +++ b/swarm/storage/filestore.go @@ -99,14 +99,15 @@ func (f *FileStore) HashSize() int { } // 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) (addrs []Address, err error) { + var addrs = make([]Address, 0) // create a special kind of putter, which only will store the references putter := &HashExplorer{ - hasherStore: NewHasherStore(f.ChunkStore, f.hashFunc, toEncrypt), + hasherStore: NewHasherStore(f.ChunkStore, f.hashFunc, false), References: make([]Reference, 0), } // do the actual splitting anyway, no way around it - _, _, err = PyramidSplit(ctx, data, putter, putter) + _, _, err := PyramidSplit(ctx, data, putter, putter) if err != nil { return nil, err } From fa4a008c37a543ed44a89606d6dd5be0afde9a4b Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Sun, 3 Feb 2019 20:07:24 -0500 Subject: [PATCH 02/10] swarm/storage: GetAllReferences test and fixes --- swarm/storage/filestore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swarm/storage/filestore.go b/swarm/storage/filestore.go index 978db1342c84..86bbd6f48e11 100644 --- a/swarm/storage/filestore.go +++ b/swarm/storage/filestore.go @@ -100,14 +100,14 @@ func (f *FileStore) HashSize() int { // Public API. This endpoint returns all chunk hashes (only) for a given file func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader) (addrs []Address, err error) { - var addrs = make([]Address, 0) + addrs = make([]Address, 0) // create a special kind of putter, which only will store the references putter := &HashExplorer{ hasherStore: NewHasherStore(f.ChunkStore, f.hashFunc, false), References: make([]Reference, 0), } // do the actual splitting anyway, no way around it - _, _, err := PyramidSplit(ctx, data, putter, putter) + _, _, err = PyramidSplit(ctx, data, putter, putter) if err != nil { return nil, err } From 871740c7b29d7460ba073f523a97465974400c17 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Sun, 3 Feb 2019 20:31:11 -0500 Subject: [PATCH 03/10] swarm/storage: with toEncrypt flag --- swarm/storage/filestore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swarm/storage/filestore.go b/swarm/storage/filestore.go index 86bbd6f48e11..499e40ef5c30 100644 --- a/swarm/storage/filestore.go +++ b/swarm/storage/filestore.go @@ -99,11 +99,11 @@ func (f *FileStore) HashSize() int { } // Public API. This endpoint returns all chunk hashes (only) for a given file -func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader) (addrs []Address, err error) { +func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader, toEncrypt bool) (addrs []Address, err error) { addrs = make([]Address, 0) // create a special kind of putter, which only will store the references putter := &HashExplorer{ - hasherStore: NewHasherStore(f.ChunkStore, f.hashFunc, false), + hasherStore: NewHasherStore(f.ChunkStore, f.hashFunc, toEncrypt), References: make([]Reference, 0), } // do the actual splitting anyway, no way around it From 5ed219efe22252fe8d6260b5d4f36997441d9303 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Sun, 3 Feb 2019 20:08:42 -0500 Subject: [PATCH 04/10] cmd/swarm: chunk-explorer query --- cmd/swarm/explore.go | 58 ++++++++++++++++++++++++++ cmd/swarm/main.go | 2 + cmd/swarm/swarm-smoke/chunkExplorer.go | 56 +++++++++++++++++++++++++ cmd/swarm/swarm-smoke/main.go | 12 ++++++ 4 files changed, 128 insertions(+) create mode 100644 cmd/swarm/explore.go create mode 100644 cmd/swarm/swarm-smoke/chunkExplorer.go diff --git a/cmd/swarm/explore.go b/cmd/swarm/explore.go new file mode 100644 index 000000000000..9fdb2c674ebc --- /dev/null +++ b/cmd/swarm/explore.go @@ -0,0 +1,58 @@ +// Copyright 2016 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// go-ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with go-ethereum. If not, see . + +// Command bzzhash computes a swarm tree hash. +package main + +import ( + "context" + "fmt" + "os" + + "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/swarm/storage" + "gopkg.in/urfave/cli.v1" +) + +var chunkExploreCommand = cli.Command{ + Action: explore, + CustomHelpTemplate: helpTemplate, + Name: "explore", + Usage: "print all hashes of a file to STDOUT", + ArgsUsage: "", + Description: "Prints all hashes of a file to STDOUT", +} + +func explore(ctx *cli.Context) { + args := ctx.Args() + if len(args) < 1 { + utils.Fatalf("Usage: swarm explore ") + } + f, err := os.Open(args[0]) + if err != nil { + utils.Fatalf("Error opening file " + args[1]) + } + defer f.Close() + + fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams()) + _, err = fileStore.StoreToExplore(context.TODO(), f) + if err != nil { + utils.Fatalf("%v\n", err) + } else { + //fmt.Printf("%v\n", addr) + fmt.Println("Done.") + } +} diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 53888b615f96..7f45db74c809 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -142,6 +142,8 @@ func init() { dbCommand, // See config.go DumpConfigCommand, + // chunkExploreCommand + chunkExploreCommand, } // append a hidden help subcommand to all commands that have subcommands diff --git a/cmd/swarm/swarm-smoke/chunkExplorer.go b/cmd/swarm/swarm-smoke/chunkExplorer.go new file mode 100644 index 000000000000..437d5894cc0e --- /dev/null +++ b/cmd/swarm/swarm-smoke/chunkExplorer.go @@ -0,0 +1,56 @@ +// Copyright 2018 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// go-ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with go-ethereum. If not, see . + +package main + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/rpc" + cli "gopkg.in/urfave/cli.v1" +) + +var ( + addr string +) + +func chunkExplorer(c *cli.Context) error { + fmt.Println("generate endpoints...") + //generateEndpoints(scheme, cluster, appName, from, to) + fmt.Println("done.") + + var has bool + //for _, e := range endpoints { + e := "ws://localhost" + fmt.Println("dialing...." + e + ":8546") + client, _ := rpc.Dial(e + ":8546") + fmt.Println("Trying...." + e) + if err := client.Call(&has, "debugapi_hasChunk", addr); err != nil { + fmt.Println("err") + log.Error("Error requesting hasChunk from endpoint", "endpoint", e, "chunkAddress", addr, "err", err) + } else { + if has { + fmt.Println("has") + log.Info("Endpoint "+e+" reports to HAVE chunk", "chunk", addr) + } else { + fmt.Println("not") + log.Debug("Endpoint "+e+" reports to NOT have chunk", "chunk", addr) + } + } + //} + return nil +} diff --git a/cmd/swarm/swarm-smoke/main.go b/cmd/swarm/swarm-smoke/main.go index 55967146052e..c5ce718f5e41 100644 --- a/cmd/swarm/swarm-smoke/main.go +++ b/cmd/swarm/swarm-smoke/main.go @@ -88,6 +88,12 @@ func main() { Usage: "http or https", Destination: &scheme, }, + cli.StringFlag{ + Name: "addr", + Value: "", + Usage: "chunk address", + Destination: &addr, + }, cli.BoolFlag{ Name: "include-localhost", Usage: "whether to include localhost:8500 as an endpoint", @@ -160,6 +166,12 @@ func main() { Usage: "measure network aggregate capacity", Action: wrapCliCommand("sliding-window", false, slidingWindow), }, + { + Name: "chunk_explorer", + Aliases: []string{"x"}, + Usage: "query nodes if they are storing a specific chunk (by address)", + Action: wrapCliCommand("chunkExplorer", false, chunkExplorer), + }, } sort.Sort(cli.FlagsByName(app.Flags)) From ba3849af4a32fd517828f9f2a5f7c6728b1f3726 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Sun, 3 Feb 2019 20:45:00 -0500 Subject: [PATCH 05/10] cmd/swarm: cleanup --- cmd/swarm/explore.go | 2 +- cmd/swarm/swarm-smoke/chunkExplorer.go | 33 ++++++++++++-------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/cmd/swarm/explore.go b/cmd/swarm/explore.go index 9fdb2c674ebc..992852d5cc3d 100644 --- a/cmd/swarm/explore.go +++ b/cmd/swarm/explore.go @@ -48,7 +48,7 @@ func explore(ctx *cli.Context) { defer f.Close() fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams()) - _, err = fileStore.StoreToExplore(context.TODO(), f) + _, err = fileStore.GetAllReferences(context.TODO(), f, false) if err != nil { utils.Fatalf("%v\n", err) } else { diff --git a/cmd/swarm/swarm-smoke/chunkExplorer.go b/cmd/swarm/swarm-smoke/chunkExplorer.go index 437d5894cc0e..0b727071ff96 100644 --- a/cmd/swarm/swarm-smoke/chunkExplorer.go +++ b/cmd/swarm/swarm-smoke/chunkExplorer.go @@ -29,28 +29,25 @@ var ( ) func chunkExplorer(c *cli.Context) error { - fmt.Println("generate endpoints...") - //generateEndpoints(scheme, cluster, appName, from, to) - fmt.Println("done.") + log.Debug("generate endpoints...") + generateEndpoints(scheme, cluster, appName, from, to) + log.Debug("done.") var has bool - //for _, e := range endpoints { - e := "ws://localhost" - fmt.Println("dialing...." + e + ":8546") - client, _ := rpc.Dial(e + ":8546") - fmt.Println("Trying...." + e) - if err := client.Call(&has, "debugapi_hasChunk", addr); err != nil { - fmt.Println("err") - log.Error("Error requesting hasChunk from endpoint", "endpoint", e, "chunkAddress", addr, "err", err) - } else { - if has { - fmt.Println("has") - log.Info("Endpoint "+e+" reports to HAVE chunk", "chunk", addr) + for _, e := range endpoints { + e = e + ":8546" + log.Debug("dialing...." + e) + client, _ := rpc.Dial(e) + log.Debug("Trying...." + e) + if err := client.Call(&has, "debugapi_hasChunk", addr); err != nil { + log.Error("Error requesting hasChunk from endpoint", "endpoint", e, "chunkAddress", addr, "err", err) } else { - fmt.Println("not") - log.Debug("Endpoint "+e+" reports to NOT have chunk", "chunk", addr) + if has { + log.Info("Endpoint "+e+" reports to HAVE chunk", "chunk", addr) + } else { + log.Info("Endpoint "+e+" reports to NOT have chunk", "chunk", addr) + } } } - //} return nil } From 3a783d508c3624fae32a57b1baddd103b6953a2a Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Sun, 3 Feb 2019 20:53:37 -0500 Subject: [PATCH 06/10] cmd/swarm: explore command (prints refs) and chunk-explorer in swarm-smoke --- cmd/swarm/explore.go | 7 ++++--- cmd/swarm/swarm-smoke/chunkExplorer.go | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/swarm/explore.go b/cmd/swarm/explore.go index 992852d5cc3d..0add64900aad 100644 --- a/cmd/swarm/explore.go +++ b/cmd/swarm/explore.go @@ -48,11 +48,12 @@ func explore(ctx *cli.Context) { defer f.Close() fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams()) - _, err = fileStore.GetAllReferences(context.TODO(), f, false) + refs, err := fileStore.GetAllReferences(context.TODO(), f, false) if err != nil { utils.Fatalf("%v\n", err) } else { - //fmt.Printf("%v\n", addr) - fmt.Println("Done.") + for _, r := range refs { + fmt.Println(r.String()) + } } } diff --git a/cmd/swarm/swarm-smoke/chunkExplorer.go b/cmd/swarm/swarm-smoke/chunkExplorer.go index 0b727071ff96..f50ee3adf063 100644 --- a/cmd/swarm/swarm-smoke/chunkExplorer.go +++ b/cmd/swarm/swarm-smoke/chunkExplorer.go @@ -17,8 +17,6 @@ package main import ( - "fmt" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" cli "gopkg.in/urfave/cli.v1" From efa7a4083f873f99c443101d3f3965553efbf6f0 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Mon, 4 Feb 2019 12:57:34 -0500 Subject: [PATCH 07/10] cmd/swarm: explore -> hashes command; remove chunk-explorer in swarm-smoke --- cmd/swarm/explore.go | 8 ++-- cmd/swarm/swarm-smoke/chunkExplorer.go | 51 -------------------------- cmd/swarm/swarm-smoke/main.go | 12 ------ 3 files changed, 4 insertions(+), 67 deletions(-) delete mode 100644 cmd/swarm/swarm-smoke/chunkExplorer.go diff --git a/cmd/swarm/explore.go b/cmd/swarm/explore.go index 0add64900aad..5f83a57abc4b 100644 --- a/cmd/swarm/explore.go +++ b/cmd/swarm/explore.go @@ -1,4 +1,4 @@ -// Copyright 2016 The go-ethereum Authors +// Copyright 2019 The go-ethereum Authors // This file is part of go-ethereum. // // go-ethereum is free software: you can redistribute it and/or modify @@ -28,15 +28,15 @@ import ( ) var chunkExploreCommand = cli.Command{ - Action: explore, + Action: hashes, CustomHelpTemplate: helpTemplate, - Name: "explore", + Name: "hashes", Usage: "print all hashes of a file to STDOUT", ArgsUsage: "", Description: "Prints all hashes of a file to STDOUT", } -func explore(ctx *cli.Context) { +func hashes(ctx *cli.Context) { args := ctx.Args() if len(args) < 1 { utils.Fatalf("Usage: swarm explore ") diff --git a/cmd/swarm/swarm-smoke/chunkExplorer.go b/cmd/swarm/swarm-smoke/chunkExplorer.go deleted file mode 100644 index f50ee3adf063..000000000000 --- a/cmd/swarm/swarm-smoke/chunkExplorer.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2018 The go-ethereum Authors -// This file is part of go-ethereum. -// -// go-ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// go-ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with go-ethereum. If not, see . - -package main - -import ( - "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/rpc" - cli "gopkg.in/urfave/cli.v1" -) - -var ( - addr string -) - -func chunkExplorer(c *cli.Context) error { - log.Debug("generate endpoints...") - generateEndpoints(scheme, cluster, appName, from, to) - log.Debug("done.") - - var has bool - for _, e := range endpoints { - e = e + ":8546" - log.Debug("dialing...." + e) - client, _ := rpc.Dial(e) - log.Debug("Trying...." + e) - if err := client.Call(&has, "debugapi_hasChunk", addr); err != nil { - log.Error("Error requesting hasChunk from endpoint", "endpoint", e, "chunkAddress", addr, "err", err) - } else { - if has { - log.Info("Endpoint "+e+" reports to HAVE chunk", "chunk", addr) - } else { - log.Info("Endpoint "+e+" reports to NOT have chunk", "chunk", addr) - } - } - } - return nil -} diff --git a/cmd/swarm/swarm-smoke/main.go b/cmd/swarm/swarm-smoke/main.go index c5ce718f5e41..55967146052e 100644 --- a/cmd/swarm/swarm-smoke/main.go +++ b/cmd/swarm/swarm-smoke/main.go @@ -88,12 +88,6 @@ func main() { Usage: "http or https", Destination: &scheme, }, - cli.StringFlag{ - Name: "addr", - Value: "", - Usage: "chunk address", - Destination: &addr, - }, cli.BoolFlag{ Name: "include-localhost", Usage: "whether to include localhost:8500 as an endpoint", @@ -166,12 +160,6 @@ func main() { Usage: "measure network aggregate capacity", Action: wrapCliCommand("sliding-window", false, slidingWindow), }, - { - Name: "chunk_explorer", - Aliases: []string{"x"}, - Usage: "query nodes if they are storing a specific chunk (by address)", - Action: wrapCliCommand("chunkExplorer", false, chunkExplorer), - }, } sort.Sort(cli.FlagsByName(app.Flags)) From 61752ac4dc75dae697e924b102a6b5943409ed2d Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Mon, 4 Feb 2019 11:45:10 -0500 Subject: [PATCH 08/10] swarm/storage: sorted references for GetAllReferences --- swarm/storage/filestore.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/swarm/storage/filestore.go b/swarm/storage/filestore.go index 499e40ef5c30..bed9fc04da9b 100644 --- a/swarm/storage/filestore.go +++ b/swarm/storage/filestore.go @@ -99,8 +99,7 @@ func (f *FileStore) HashSize() int { } // 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 []Address, err error) { - addrs = make([]Address, 0) +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 putter := &HashExplorer{ hasherStore: NewHasherStore(f.ChunkStore, f.hashFunc, toEncrypt), @@ -114,7 +113,7 @@ func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader, toEncr // collect all references addrs = NewAddressCollection(0) for _, ref := range putter.References { - addrs = append(addrs, Address(ref)) + arr = append(arr, Address(ref)) } sort.Sort(addrs) return addrs, nil From 1ea6548c46c0eb6dd332672f7eee33c66478cfdc Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Mon, 4 Feb 2019 13:06:56 -0500 Subject: [PATCH 09/10] swarm/storage: bug fix in GetAllReferences --- swarm/storage/filestore.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swarm/storage/filestore.go b/swarm/storage/filestore.go index bed9fc04da9b..aebe03c1ef6b 100644 --- a/swarm/storage/filestore.go +++ b/swarm/storage/filestore.go @@ -113,7 +113,7 @@ func (f *FileStore) GetAllReferences(ctx context.Context, data io.Reader, toEncr // collect all references addrs = NewAddressCollection(0) for _, ref := range putter.References { - arr = append(arr, Address(ref)) + addrs = append(addrs, Address(ref)) } sort.Sort(addrs) return addrs, nil From 7b7a9b35495fcfaed596d905da4ebddeba087641 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Tue, 5 Feb 2019 20:10:14 -0500 Subject: [PATCH 10/10] cmd/swarm: fixes for hashes command; PR comments --- cmd/swarm/explore.go | 4 ++-- cmd/swarm/main.go | 4 ++-- swarm/storage/filestore.go | 6 +++--- swarm/storage/filestore_test.go | 18 +++++++----------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/cmd/swarm/explore.go b/cmd/swarm/explore.go index 5f83a57abc4b..5b5b8bf41f39 100644 --- a/cmd/swarm/explore.go +++ b/cmd/swarm/explore.go @@ -27,7 +27,7 @@ import ( "gopkg.in/urfave/cli.v1" ) -var chunkExploreCommand = cli.Command{ +var hashesCommand = cli.Command{ Action: hashes, CustomHelpTemplate: helpTemplate, Name: "hashes", @@ -39,7 +39,7 @@ var chunkExploreCommand = cli.Command{ func hashes(ctx *cli.Context) { args := ctx.Args() if len(args) < 1 { - utils.Fatalf("Usage: swarm explore ") + utils.Fatalf("Usage: swarm hashes ") } f, err := os.Open(args[0]) if err != nil { diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 7f45db74c809..8af5d8c322ef 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -142,8 +142,8 @@ func init() { dbCommand, // See config.go DumpConfigCommand, - // chunkExploreCommand - chunkExploreCommand, + // hashesCommand + hashesCommand, } // append a hidden help subcommand to all commands that have subcommands diff --git a/swarm/storage/filestore.go b/swarm/storage/filestore.go index aebe03c1ef6b..4240f5b1c553 100644 --- a/swarm/storage/filestore.go +++ b/swarm/storage/filestore.go @@ -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 // Chunk retrieval blocks on netStore requests with a timeout so reader will // 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 } -// 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 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) @@ -98,7 +98,7 @@ func (f *FileStore) HashSize() int { 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) { // create a special kind of putter, which only will store the references putter := &HashExplorer{ diff --git a/swarm/storage/filestore_test.go b/swarm/storage/filestore_test.go index 2dbccdf114e2..06c4be1d78bb 100644 --- a/swarm/storage/filestore_test.go +++ b/swarm/storage/filestore_test.go @@ -190,22 +190,18 @@ func TestGetAllReferences(t *testing.T) { } fileStore := NewFileStore(localStore, NewFileStoreParams()) - checkRefs := func(dataSize int, expectedLen int) { - slice := testutil.RandomBytes(1, dataSize) + // 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 { + slice := testutil.RandomBytes(1, r) addrs, err := fileStore.GetAllReferences(context.Background(), bytes.NewReader(slice), false) if err != nil { t.Fatal(err) } - if len(addrs) != expectedLen { - t.Fatalf("Expected reference array length to be %d, but is %d", expectedLen, len(addrs)) + if len(addrs) != expectedLens[i] { + 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]) - } }