From 996755c4a832afce8629a771cab8879c88c98355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jano=C5=A1=20Gulja=C5=A1?= Date: Wed, 10 Apr 2019 16:50:58 +0200 Subject: cmd/swarm, swarm: LocalStore storage integration --- swarm/api/config.go | 14 ++++++++++---- swarm/api/config_test.go | 1 - swarm/api/http/test_server.go | 9 +++------ swarm/api/inspector.go | 6 +++++- swarm/api/manifest.go | 1 - 5 files changed, 18 insertions(+), 13 deletions(-) (limited to 'swarm/api') diff --git a/swarm/api/config.go b/swarm/api/config.go index 0a7100c57..3a87488cc 100644 --- a/swarm/api/config.go +++ b/swarm/api/config.go @@ -45,7 +45,13 @@ const ( type Config struct { // serialised/persisted fields *storage.FileStoreParams - *storage.LocalStoreParams + + // LocalStore + ChunkDbPath string + DbCapacity uint64 + CacheCapacity uint + BaseKey []byte + *network.HiveParams Swap *swap.LocalProfile Pss *pss.PssParams @@ -78,7 +84,6 @@ type Config struct { func NewConfig() (c *Config) { c = &Config{ - LocalStoreParams: storage.NewDefaultLocalStoreParams(), FileStoreParams: storage.NewFileStoreParams(), HiveParams: network.NewHiveParams(), Swap: swap.NewDefaultSwapParams(), @@ -130,8 +135,9 @@ func (c *Config) Init(prvKey *ecdsa.PrivateKey, nodeKey *ecdsa.PrivateKey) error c.Swap.Init(c.Contract, prvKey) } - c.LocalStoreParams.Init(c.Path) - c.LocalStoreParams.BaseKey = common.FromHex(c.BzzKey) + c.privateKey = prvKey + c.ChunkDbPath = filepath.Join(c.Path, "chunks") + c.BaseKey = common.FromHex(c.BzzKey) c.Pss = c.Pss.WithPrivateKey(c.privateKey) return nil diff --git a/swarm/api/config_test.go b/swarm/api/config_test.go index a55da6f7b..82f29f8ea 100644 --- a/swarm/api/config_test.go +++ b/swarm/api/config_test.go @@ -41,7 +41,6 @@ func TestConfig(t *testing.T) { one := NewConfig() two := NewConfig() - one.LocalStoreParams = two.LocalStoreParams if equal := reflect.DeepEqual(one, two); !equal { t.Fatal("Two default configs are not equal") } diff --git a/swarm/api/http/test_server.go b/swarm/api/http/test_server.go index 97fdf0d8a..928a6e972 100644 --- a/swarm/api/http/test_server.go +++ b/swarm/api/http/test_server.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/swarm/api" "github.com/ethereum/go-ethereum/swarm/storage" "github.com/ethereum/go-ethereum/swarm/storage/feed" + "github.com/ethereum/go-ethereum/swarm/storage/localstore" ) type TestServer interface { @@ -37,16 +38,12 @@ func NewTestSwarmServer(t *testing.T, serverFunc func(*api.API) TestServer, reso if err != nil { t.Fatal(err) } - - storeParams := storage.NewDefaultLocalStoreParams() - storeParams.DbCapacity = 5000000 - storeParams.CacheCapacity = 5000 - storeParams.Init(swarmDir) - localStore, err := storage.NewLocalStore(storeParams, nil) + localStore, err := localstore.New(dir, make([]byte, 32), nil) if err != nil { os.RemoveAll(swarmDir) t.Fatal(err) } + fileStore := storage.NewFileStore(localStore, storage.NewFileStoreParams()) // Swarm feeds test setup feedsDir, err := ioutil.TempDir("", "swarm-feeds-test") diff --git a/swarm/api/inspector.go b/swarm/api/inspector.go index ea3c4c049..2ae6b4da8 100644 --- a/swarm/api/inspector.go +++ b/swarm/api/inspector.go @@ -60,7 +60,11 @@ func (inspector *Inspector) Has(chunkAddresses []storage.Address) []HasInfo { for _, addr := range chunkAddresses { res := HasInfo{} res.Addr = addr.String() - res.Has = inspector.netStore.Has(context.Background(), addr) + has, err := inspector.netStore.Has(context.Background(), addr) + if err != nil { + has = false + } + res.Has = has results = append(results, res) } return results diff --git a/swarm/api/manifest.go b/swarm/api/manifest.go index 890ed88bd..d753b3f2e 100644 --- a/swarm/api/manifest.go +++ b/swarm/api/manifest.go @@ -235,7 +235,6 @@ func loadManifest(ctx context.Context, fileStore *storage.FileStore, addr storag } func readManifest(mr storage.LazySectionReader, addr storage.Address, fileStore *storage.FileStore, isEncrypted bool, quitC chan bool, decrypt DecryptFunc) (trie *manifestTrie, err error) { // non-recursive, subtrees are downloaded on-demand - // TODO check size for oversized manifests size, err := mr.Size(mr.Context(), quitC) if err != nil { // size == 0 -- cgit v1.2.3