2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-12 13:23:19 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-02-04 16:56:10 +00:00
|
|
|
package kvmetainfo_test
|
2018-11-12 13:23:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2019-02-05 17:22:17 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
|
2018-11-12 13:23:19 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-03-18 10:55:06 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-11-12 13:23:19 +00:00
|
|
|
"github.com/vivint/infectious"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/memory"
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
"storj.io/storj/pkg/eestream"
|
2019-05-24 17:51:27 +01:00
|
|
|
"storj.io/storj/pkg/macaroon"
|
2019-02-04 16:56:10 +00:00
|
|
|
"storj.io/storj/pkg/metainfo/kvmetainfo"
|
2019-01-22 15:48:23 +00:00
|
|
|
ecclient "storj.io/storj/pkg/storage/ec"
|
2018-11-12 13:23:19 +00:00
|
|
|
"storj.io/storj/pkg/storage/segments"
|
|
|
|
"storj.io/storj/pkg/storage/streams"
|
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TestEncKey = "test-encryption-key"
|
2018-11-30 13:50:52 +00:00
|
|
|
TestBucket = "test-bucket"
|
2018-11-12 13:23:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBucketsBasic(t *testing.T) {
|
2019-06-21 12:29:31 +01:00
|
|
|
runTest(t, func(ctx context.Context, planet *testplanet.Planet, db *kvmetainfo.DB, streams streams.Store) {
|
2018-11-12 13:23:19 +00:00
|
|
|
// Create new bucket
|
2018-11-14 09:26:18 +00:00
|
|
|
bucket, err := db.CreateBucket(ctx, TestBucket, nil)
|
2018-11-12 13:23:19 +00:00
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.Equal(t, TestBucket, bucket.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that bucket list include the new bucket
|
2018-11-14 09:26:18 +00:00
|
|
|
bucketList, err := db.ListBuckets(ctx, storj.BucketListOptions{Direction: storj.After})
|
2018-11-12 13:23:19 +00:00
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.False(t, bucketList.More)
|
|
|
|
assert.Equal(t, 1, len(bucketList.Items))
|
|
|
|
assert.Equal(t, TestBucket, bucketList.Items[0].Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that we can get the new bucket explicitly
|
2018-11-14 09:26:18 +00:00
|
|
|
bucket, err = db.GetBucket(ctx, TestBucket)
|
2018-11-12 13:23:19 +00:00
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.Equal(t, TestBucket, bucket.Name)
|
2018-11-14 09:26:18 +00:00
|
|
|
assert.Equal(t, storj.AESGCM, bucket.PathCipher)
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete the bucket
|
2018-11-14 09:26:18 +00:00
|
|
|
err = db.DeleteBucket(ctx, TestBucket)
|
2018-11-12 13:23:19 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Check that the bucket list is empty
|
2018-11-14 09:26:18 +00:00
|
|
|
bucketList, err = db.ListBuckets(ctx, storj.BucketListOptions{Direction: storj.After})
|
2018-11-12 13:23:19 +00:00
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.False(t, bucketList.More)
|
|
|
|
assert.Equal(t, 0, len(bucketList.Items))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the bucket cannot be get explicitly
|
2018-11-14 09:26:18 +00:00
|
|
|
bucket, err = db.GetBucket(ctx, TestBucket)
|
2018-11-21 11:17:28 +00:00
|
|
|
assert.True(t, storj.ErrBucketNotFound.Has(err))
|
2018-11-12 13:23:19 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
func TestBucketsReadWrite(t *testing.T) {
|
|
|
|
runTest(t, func(ctx context.Context, planet *testplanet.Planet, db *kvmetainfo.DB, streams streams.Store) {
|
|
|
|
// Create new bucket
|
|
|
|
bucket, err := db.CreateBucket(ctx, TestBucket, nil)
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.Equal(t, TestBucket, bucket.Name)
|
|
|
|
}
|
2018-11-12 13:23:19 +00:00
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
// Check that bucket list include the new bucket
|
2018-11-14 09:26:18 +00:00
|
|
|
bucketList, err := db.ListBuckets(ctx, storj.BucketListOptions{Direction: storj.After})
|
2018-11-12 13:23:19 +00:00
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.False(t, bucketList.More)
|
|
|
|
assert.Equal(t, 1, len(bucketList.Items))
|
|
|
|
assert.Equal(t, TestBucket, bucketList.Items[0].Name)
|
|
|
|
}
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
// Check that we can get the new bucket explicitly
|
|
|
|
bucket, err = db.GetBucket(ctx, TestBucket)
|
2018-11-12 13:23:19 +00:00
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.Equal(t, TestBucket, bucket.Name)
|
2018-11-14 09:26:18 +00:00
|
|
|
assert.Equal(t, storj.AESGCM, bucket.PathCipher)
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
// Delete the bucket
|
|
|
|
err = db.DeleteBucket(ctx, TestBucket)
|
2018-11-12 13:23:19 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
// Check that the bucket list is empty
|
2018-11-14 09:26:18 +00:00
|
|
|
bucketList, err = db.ListBuckets(ctx, storj.BucketListOptions{Direction: storj.After})
|
2018-11-12 13:23:19 +00:00
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.False(t, bucketList.More)
|
|
|
|
assert.Equal(t, 0, len(bucketList.Items))
|
|
|
|
}
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
// Check that the bucket cannot be get explicitly
|
2018-11-14 09:26:18 +00:00
|
|
|
bucket, err = db.GetBucket(ctx, TestBucket)
|
2018-11-21 11:17:28 +00:00
|
|
|
assert.True(t, storj.ErrBucketNotFound.Has(err))
|
2018-11-12 13:23:19 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestErrNoBucket(t *testing.T) {
|
2019-06-21 12:29:31 +01:00
|
|
|
runTest(t, func(ctx context.Context, planet *testplanet.Planet, db *kvmetainfo.DB, streams streams.Store) {
|
2018-11-14 09:26:18 +00:00
|
|
|
_, err := db.CreateBucket(ctx, "", nil)
|
2018-11-12 13:23:19 +00:00
|
|
|
assert.True(t, storj.ErrNoBucket.Has(err))
|
|
|
|
|
2018-11-14 09:26:18 +00:00
|
|
|
_, err = db.GetBucket(ctx, "")
|
2018-11-12 13:23:19 +00:00
|
|
|
assert.True(t, storj.ErrNoBucket.Has(err))
|
|
|
|
|
2018-11-14 09:26:18 +00:00
|
|
|
err = db.DeleteBucket(ctx, "")
|
2018-11-12 13:23:19 +00:00
|
|
|
assert.True(t, storj.ErrNoBucket.Has(err))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-14 09:26:18 +00:00
|
|
|
func TestBucketCreateCipher(t *testing.T) {
|
2019-06-21 12:29:31 +01:00
|
|
|
runTest(t, func(ctx context.Context, planet *testplanet.Planet, db *kvmetainfo.DB, streams streams.Store) {
|
2018-11-14 09:26:18 +00:00
|
|
|
forAllCiphers(func(cipher storj.Cipher) {
|
|
|
|
bucket, err := db.CreateBucket(ctx, "test", &storj.Bucket{PathCipher: cipher})
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.Equal(t, cipher, bucket.PathCipher)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket, err = db.GetBucket(ctx, "test")
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.Equal(t, cipher, bucket.PathCipher)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.DeleteBucket(ctx, "test")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2018-11-12 13:23:19 +00:00
|
|
|
|
2018-11-14 09:26:18 +00:00
|
|
|
func TestListBucketsEmpty(t *testing.T) {
|
2019-06-21 12:29:31 +01:00
|
|
|
runTest(t, func(ctx context.Context, planet *testplanet.Planet, db *kvmetainfo.DB, streams streams.Store) {
|
2018-11-14 09:26:18 +00:00
|
|
|
_, err := db.ListBuckets(ctx, storj.BucketListOptions{})
|
2018-11-12 13:23:19 +00:00
|
|
|
assert.EqualError(t, err, "kvmetainfo: invalid direction 0")
|
|
|
|
|
|
|
|
for _, direction := range []storj.ListDirection{
|
|
|
|
storj.Before,
|
|
|
|
storj.Backward,
|
|
|
|
storj.Forward,
|
|
|
|
storj.After,
|
|
|
|
} {
|
2018-11-14 09:26:18 +00:00
|
|
|
bucketList, err := db.ListBuckets(ctx, storj.BucketListOptions{Direction: direction})
|
2018-11-12 13:23:19 +00:00
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.False(t, bucketList.More)
|
|
|
|
assert.Equal(t, 0, len(bucketList.Items))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListBuckets(t *testing.T) {
|
2019-06-21 12:29:31 +01:00
|
|
|
runTest(t, func(ctx context.Context, planet *testplanet.Planet, db *kvmetainfo.DB, streams streams.Store) {
|
2018-11-12 13:23:19 +00:00
|
|
|
bucketNames := []string{"a", "aa", "b", "bb", "c"}
|
|
|
|
|
|
|
|
for _, name := range bucketNames {
|
2018-11-14 09:26:18 +00:00
|
|
|
_, err := db.CreateBucket(ctx, name, nil)
|
2019-03-18 10:55:06 +00:00
|
|
|
require.NoError(t, err)
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range []struct {
|
|
|
|
cursor string
|
|
|
|
dir storj.ListDirection
|
|
|
|
limit int
|
|
|
|
more bool
|
|
|
|
result []string
|
|
|
|
}{
|
|
|
|
{cursor: "", dir: storj.After, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "`", dir: storj.After, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "b", dir: storj.After, limit: 0, more: false, result: []string{"bb", "c"}},
|
|
|
|
{cursor: "c", dir: storj.After, limit: 0, more: false, result: []string{}},
|
|
|
|
{cursor: "ca", dir: storj.After, limit: 0, more: false, result: []string{}},
|
|
|
|
{cursor: "", dir: storj.After, limit: 1, more: true, result: []string{"a"}},
|
|
|
|
{cursor: "`", dir: storj.After, limit: 1, more: true, result: []string{"a"}},
|
|
|
|
{cursor: "aa", dir: storj.After, limit: 1, more: true, result: []string{"b"}},
|
|
|
|
{cursor: "c", dir: storj.After, limit: 1, more: false, result: []string{}},
|
|
|
|
{cursor: "ca", dir: storj.After, limit: 1, more: false, result: []string{}},
|
|
|
|
{cursor: "", dir: storj.After, limit: 2, more: true, result: []string{"a", "aa"}},
|
|
|
|
{cursor: "`", dir: storj.After, limit: 2, more: true, result: []string{"a", "aa"}},
|
|
|
|
{cursor: "aa", dir: storj.After, limit: 2, more: true, result: []string{"b", "bb"}},
|
|
|
|
{cursor: "bb", dir: storj.After, limit: 2, more: false, result: []string{"c"}},
|
|
|
|
{cursor: "c", dir: storj.After, limit: 2, more: false, result: []string{}},
|
|
|
|
{cursor: "ca", dir: storj.After, limit: 2, more: false, result: []string{}},
|
|
|
|
{cursor: "", dir: storj.Forward, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "`", dir: storj.Forward, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "b", dir: storj.Forward, limit: 0, more: false, result: []string{"b", "bb", "c"}},
|
|
|
|
{cursor: "c", dir: storj.Forward, limit: 0, more: false, result: []string{"c"}},
|
|
|
|
{cursor: "ca", dir: storj.Forward, limit: 0, more: false, result: []string{}},
|
|
|
|
{cursor: "", dir: storj.Forward, limit: 1, more: true, result: []string{"a"}},
|
|
|
|
{cursor: "`", dir: storj.Forward, limit: 1, more: true, result: []string{"a"}},
|
|
|
|
{cursor: "aa", dir: storj.Forward, limit: 1, more: true, result: []string{"aa"}},
|
|
|
|
{cursor: "c", dir: storj.Forward, limit: 1, more: false, result: []string{"c"}},
|
|
|
|
{cursor: "ca", dir: storj.Forward, limit: 1, more: false, result: []string{}},
|
|
|
|
{cursor: "", dir: storj.Forward, limit: 2, more: true, result: []string{"a", "aa"}},
|
|
|
|
{cursor: "`", dir: storj.Forward, limit: 2, more: true, result: []string{"a", "aa"}},
|
|
|
|
{cursor: "aa", dir: storj.Forward, limit: 2, more: true, result: []string{"aa", "b"}},
|
|
|
|
{cursor: "bb", dir: storj.Forward, limit: 2, more: false, result: []string{"bb", "c"}},
|
|
|
|
{cursor: "c", dir: storj.Forward, limit: 2, more: false, result: []string{"c"}},
|
|
|
|
{cursor: "ca", dir: storj.Forward, limit: 2, more: false, result: []string{}},
|
|
|
|
{cursor: "", dir: storj.Backward, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "`", dir: storj.Backward, limit: 0, more: false, result: []string{}},
|
|
|
|
{cursor: "b", dir: storj.Backward, limit: 0, more: false, result: []string{"a", "aa", "b"}},
|
|
|
|
{cursor: "c", dir: storj.Backward, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "ca", dir: storj.Backward, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "", dir: storj.Backward, limit: 1, more: true, result: []string{"c"}},
|
|
|
|
{cursor: "`", dir: storj.Backward, limit: 1, more: false, result: []string{}},
|
|
|
|
{cursor: "aa", dir: storj.Backward, limit: 1, more: true, result: []string{"aa"}},
|
|
|
|
{cursor: "c", dir: storj.Backward, limit: 1, more: true, result: []string{"c"}},
|
|
|
|
{cursor: "ca", dir: storj.Backward, limit: 1, more: true, result: []string{"c"}},
|
|
|
|
{cursor: "", dir: storj.Backward, limit: 2, more: true, result: []string{"bb", "c"}},
|
|
|
|
{cursor: "`", dir: storj.Backward, limit: 2, more: false, result: []string{}},
|
|
|
|
{cursor: "aa", dir: storj.Backward, limit: 2, more: false, result: []string{"a", "aa"}},
|
|
|
|
{cursor: "bb", dir: storj.Backward, limit: 2, more: true, result: []string{"b", "bb"}},
|
|
|
|
{cursor: "c", dir: storj.Backward, limit: 2, more: true, result: []string{"bb", "c"}},
|
|
|
|
{cursor: "ca", dir: storj.Backward, limit: 2, more: true, result: []string{"bb", "c"}},
|
|
|
|
{cursor: "", dir: storj.Before, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "`", dir: storj.Before, limit: 0, more: false, result: []string{}},
|
|
|
|
{cursor: "b", dir: storj.Before, limit: 0, more: false, result: []string{"a", "aa"}},
|
|
|
|
{cursor: "c", dir: storj.Before, limit: 0, more: false, result: []string{"a", "aa", "b", "bb"}},
|
|
|
|
{cursor: "ca", dir: storj.Before, limit: 0, more: false, result: []string{"a", "aa", "b", "bb", "c"}},
|
|
|
|
{cursor: "", dir: storj.Before, limit: 1, more: true, result: []string{"c"}},
|
|
|
|
{cursor: "`", dir: storj.Before, limit: 1, more: false, result: []string{}},
|
|
|
|
{cursor: "aa", dir: storj.Before, limit: 1, more: false, result: []string{"a"}},
|
|
|
|
{cursor: "c", dir: storj.Before, limit: 1, more: true, result: []string{"bb"}},
|
|
|
|
{cursor: "ca", dir: storj.Before, limit: 1, more: true, result: []string{"c"}},
|
|
|
|
{cursor: "", dir: storj.Before, limit: 2, more: true, result: []string{"bb", "c"}},
|
|
|
|
{cursor: "`", dir: storj.Before, limit: 2, more: false, result: []string{}},
|
|
|
|
{cursor: "aa", dir: storj.Before, limit: 2, more: false, result: []string{"a"}},
|
|
|
|
{cursor: "bb", dir: storj.Before, limit: 2, more: true, result: []string{"aa", "b"}},
|
|
|
|
{cursor: "c", dir: storj.Before, limit: 2, more: true, result: []string{"b", "bb"}},
|
|
|
|
{cursor: "ca", dir: storj.Before, limit: 2, more: true, result: []string{"bb", "c"}},
|
|
|
|
} {
|
|
|
|
errTag := fmt.Sprintf("%d. %+v", i, tt)
|
|
|
|
|
2018-11-14 09:26:18 +00:00
|
|
|
bucketList, err := db.ListBuckets(ctx, storj.BucketListOptions{
|
2018-11-12 13:23:19 +00:00
|
|
|
Cursor: tt.cursor,
|
|
|
|
Direction: tt.dir,
|
|
|
|
Limit: tt.limit,
|
|
|
|
})
|
|
|
|
|
|
|
|
if assert.NoError(t, err, errTag) {
|
|
|
|
assert.Equal(t, tt.more, bucketList.More, errTag)
|
|
|
|
assert.Equal(t, tt.result, getBucketNames(bucketList), errTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBucketNames(bucketList storj.BucketList) []string {
|
|
|
|
names := make([]string, len(bucketList.Items))
|
|
|
|
|
|
|
|
for i, item := range bucketList.Items {
|
|
|
|
names[i] = item.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
return names
|
|
|
|
}
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
func runTest(t *testing.T, test func(context.Context, *testplanet.Planet, *kvmetainfo.DB, streams.Store)) {
|
2019-04-22 10:07:50 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-06-21 12:29:31 +01:00
|
|
|
db, streams, err := newMetainfoParts(planet)
|
2019-04-22 10:07:50 +01:00
|
|
|
require.NoError(t, err)
|
2018-11-12 13:23:19 +00:00
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
test(ctx, planet, db, streams)
|
2019-04-22 10:07:50 +01:00
|
|
|
})
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
func newMetainfoParts(planet *testplanet.Planet) (*kvmetainfo.DB, streams.Store, error) {
|
2018-11-12 13:23:19 +00:00
|
|
|
// TODO(kaloyan): We should have a better way for configuring the Satellite's API Key
|
2019-02-05 17:22:17 +00:00
|
|
|
// add project to satisfy constraint
|
|
|
|
project, err := planet.Satellites[0].DB.Console().Projects().Insert(context.Background(), &console.Project{
|
|
|
|
Name: "testProject",
|
|
|
|
})
|
2019-05-24 17:51:27 +01:00
|
|
|
if err != nil {
|
2019-06-21 12:29:31 +01:00
|
|
|
return nil, nil, err
|
2019-05-24 17:51:27 +01:00
|
|
|
}
|
2019-02-05 17:22:17 +00:00
|
|
|
|
2019-05-24 17:51:27 +01:00
|
|
|
apiKey, err := macaroon.NewAPIKey([]byte("testSecret"))
|
2019-02-05 17:22:17 +00:00
|
|
|
if err != nil {
|
2019-06-21 12:29:31 +01:00
|
|
|
return nil, nil, err
|
2019-02-05 17:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
apiKeyInfo := console.APIKeyInfo{
|
|
|
|
ProjectID: project.ID,
|
|
|
|
Name: "testKey",
|
2019-05-24 17:51:27 +01:00
|
|
|
Secret: []byte("testSecret"),
|
2019-02-05 17:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add api key to db
|
2019-05-24 17:51:27 +01:00
|
|
|
_, err = planet.Satellites[0].DB.Console().APIKeys().Create(context.Background(), apiKey.Head(), apiKeyInfo)
|
2019-02-05 17:22:17 +00:00
|
|
|
if err != nil {
|
2019-06-21 12:29:31 +01:00
|
|
|
return nil, nil, err
|
2019-02-05 17:22:17 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 17:51:27 +01:00
|
|
|
metainfo, err := planet.Uplinks[0].DialMetainfo(context.Background(), planet.Satellites[0], apiKey.Serialize())
|
2018-11-12 13:23:19 +00:00
|
|
|
if err != nil {
|
2019-06-21 12:29:31 +01:00
|
|
|
return nil, nil, err
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 11:17:32 +00:00
|
|
|
ec := ecclient.NewClient(planet.Uplinks[0].Transport, 0)
|
2018-11-12 13:23:19 +00:00
|
|
|
fc, err := infectious.NewFEC(2, 4)
|
|
|
|
if err != nil {
|
2019-06-21 12:29:31 +01:00
|
|
|
return nil, nil, err
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
rs, err := eestream.NewRedundancyStrategy(eestream.NewRSScheme(fc, 1*memory.KiB.Int()), 0, 0)
|
2018-11-12 13:23:19 +00:00
|
|
|
if err != nil {
|
2019-06-21 12:29:31 +01:00
|
|
|
return nil, nil, err
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
segments := segments.NewSegmentStore(metainfo, ec, rs, 8*memory.KiB.Int(), 8*memory.MiB.Int64())
|
2018-11-12 13:23:19 +00:00
|
|
|
|
|
|
|
key := new(storj.Key)
|
|
|
|
copy(key[:], TestEncKey)
|
|
|
|
|
2019-06-11 18:14:05 +01:00
|
|
|
const stripesPerBlock = 2
|
|
|
|
blockSize := stripesPerBlock * rs.StripeSize()
|
2019-06-19 09:11:27 +01:00
|
|
|
inlineThreshold := 8 * memory.KiB.Int()
|
|
|
|
streams, err := streams.NewStreamStore(segments, 64*memory.MiB.Int64(), key, blockSize, storj.AESGCM, inlineThreshold)
|
2018-11-12 13:23:19 +00:00
|
|
|
if err != nil {
|
2019-06-21 12:29:31 +01:00
|
|
|
return nil, nil, err
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 12:29:31 +01:00
|
|
|
return kvmetainfo.New(metainfo, streams, segments, key, int32(blockSize), rs, 64*memory.MiB.Int64()), streams, nil
|
2018-11-14 09:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func forAllCiphers(test func(cipher storj.Cipher)) {
|
|
|
|
for _, cipher := range []storj.Cipher{
|
|
|
|
storj.Unencrypted,
|
|
|
|
storj.AESGCM,
|
|
|
|
storj.SecretBox,
|
|
|
|
} {
|
|
|
|
test(cipher)
|
|
|
|
}
|
2018-11-12 13:23:19 +00:00
|
|
|
}
|