aboutsummaryrefslogtreecommitdiffstats
path: root/swarm
diff options
context:
space:
mode:
authorholisticode <holistic.computing@gmail.com>2019-02-07 20:51:24 +0800
committerRafael Matias <rafael@skyle.net>2019-02-19 19:57:53 +0800
commit1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12 (patch)
tree5c5aa2511ae0962ab1e6255471c87a48380794e6 /swarm
parent034f65e9e8976f3ca7d9622e4c362ad9c26ad5f7 (diff)
downloadgo-tangerine-1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12.tar
go-tangerine-1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12.tar.gz
go-tangerine-1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12.tar.bz2
go-tangerine-1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12.tar.lz
go-tangerine-1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12.tar.xz
go-tangerine-1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12.tar.zst
go-tangerine-1ecf2860cff6e4da75abbd1e6b30a9b1d69c5a12.zip
cmd/swarm: hashes command (#19008)
(cherry picked from commit 7f55b0cbd8618a1b0de8d7e37d2b0143ebae4abf)
Diffstat (limited to 'swarm')
-rw-r--r--swarm/storage/filestore.go6
-rw-r--r--swarm/storage/filestore_test.go18
2 files changed, 10 insertions, 14 deletions
diff --git a/swarm/storage/filestore.go b/swarm/storage/filestore.go
index aebe03c1e..4240f5b1c 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 2dbccdf11..06c4be1d7 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])
- }
}