diff options
Diffstat (limited to 'swarm/swarm.go')
-rw-r--r-- | swarm/swarm.go | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/swarm/swarm.go b/swarm/swarm.go index 61813e23f..d004bcd2f 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -20,6 +20,7 @@ import ( "bytes" "context" "crypto/ecdsa" + "errors" "fmt" "io" "math/big" @@ -29,6 +30,11 @@ import ( "time" "unicode" + "github.com/ethereum/go-ethereum/swarm/chunk" + + "github.com/ethereum/go-ethereum/swarm/storage/feed" + "github.com/ethereum/go-ethereum/swarm/storage/localstore" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/contracts/chequebook" @@ -48,7 +54,6 @@ import ( "github.com/ethereum/go-ethereum/swarm/pss" "github.com/ethereum/go-ethereum/swarm/state" "github.com/ethereum/go-ethereum/swarm/storage" - "github.com/ethereum/go-ethereum/swarm/storage/feed" "github.com/ethereum/go-ethereum/swarm/storage/mock" "github.com/ethereum/go-ethereum/swarm/swap" "github.com/ethereum/go-ethereum/swarm/tracing" @@ -143,11 +148,31 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e resolver = api.NewMultiResolver(opts...) self.dns = resolver } + // check that we are not in the old database schema + // if so - fail and exit + isLegacy := localstore.IsLegacyDatabase(config.ChunkDbPath) + + if isLegacy { + return nil, errors.New("Legacy database format detected! Please read the migration announcement at: https://github.com/ethersphere/go-ethereum/wiki/Swarm-v0.4-local-store-migration") + } + + var feedsHandler *feed.Handler + fhParams := &feed.HandlerParams{} - lstore, err := storage.NewLocalStore(config.LocalStoreParams, mockStore) + feedsHandler = feed.NewHandler(fhParams) + + localStore, err := localstore.New(config.ChunkDbPath, config.BaseKey, &localstore.Options{ + MockStore: mockStore, + Capacity: config.DbCapacity, + }) if err != nil { return nil, err } + lstore := chunk.NewValidatorStore( + localStore, + storage.NewContentAddressValidator(storage.MakeHashFunc(storage.DefaultHash)), + feedsHandler, + ) self.netStore, err = storage.NewNetStore(lstore, nil) if err != nil { @@ -161,6 +186,8 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e delivery := stream.NewDelivery(to, self.netStore) self.netStore.NewNetFetcherFunc = network.NewFetcherFactory(delivery.RequestFromPeers, config.DeliverySkipCheck).New + feedsHandler.SetStore(self.netStore) + if config.SwapEnabled { balancesStore, err := state.NewDBStore(filepath.Join(config.Path, "balances.db")) if err != nil { @@ -177,38 +204,17 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e syncing = stream.SyncingDisabled } - retrieval := stream.RetrievalEnabled - if config.LightNodeEnabled { - retrieval = stream.RetrievalClientOnly - } - registryOptions := &stream.RegistryOptions{ SkipCheck: config.DeliverySkipCheck, Syncing: syncing, - Retrieval: retrieval, SyncUpdateDelay: config.SyncUpdateDelay, MaxPeerServers: config.MaxStreamPeerServers, } self.streamer = stream.NewRegistry(nodeID, delivery, self.netStore, self.stateStore, registryOptions, self.swap) + tags := chunk.NewTags() //todo load from state store // Swarm Hash Merklised Chunking for Arbitrary-length Document/File storage - self.fileStore = storage.NewFileStore(self.netStore, self.config.FileStoreParams) - - var feedsHandler *feed.Handler - fhParams := &feed.HandlerParams{} - - feedsHandler = feed.NewHandler(fhParams) - feedsHandler.SetStore(self.netStore) - - lstore.Validators = []storage.ChunkValidator{ - storage.NewContentAddressValidator(storage.MakeHashFunc(storage.DefaultHash)), - feedsHandler, - } - - err = lstore.Migrate() - if err != nil { - return nil, err - } + self.fileStore = storage.NewFileStore(self.netStore, self.config.FileStoreParams, tags) log.Debug("Setup local storage") @@ -223,7 +229,7 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e pss.SetHandshakeController(self.ps, pss.NewHandshakeParams()) } - self.api = api.NewAPI(self.fileStore, self.dns, feedsHandler, self.privateKey) + self.api = api.NewAPI(self.fileStore, self.dns, feedsHandler, self.privateKey, tags) self.sfs = fuse.NewSwarmFS(self.api) log.Debug("Initialized FUSE filesystem") |