Skip to content

Commit

Permalink
Merge pull request #300 from ethersphere/revert_netstore_dbapi_unity
Browse files Browse the repository at this point in the history
swarm/network: revert back DBAPI and NetStore unity
  • Loading branch information
nonsense authored Mar 5, 2018
2 parents d9ae59f + b102bd9 commit 734a182
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
7 changes: 2 additions & 5 deletions swarm/network/stream/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func NewStreamerService(ctx *adapters.ServiceContext) (node.Service, error) {
addr := toAddr(id)
kad := network.NewKademlia(addr.Over(), network.NewKadParams())
store := stores[id].(*storage.LocalStore)
netStore := storage.NewNetStore(store, nil)
db := storage.NewDBAPI(netStore)
db := storage.NewDBAPI(store)
delivery := NewDelivery(kad, db)
deliveries[id] = delivery
r := NewRegistry(addr, delivery, db, state.NewMemStore(), defaultSkipCheck, false)
Expand Down Expand Up @@ -108,9 +107,7 @@ func newStreamerTester(t *testing.T) (*p2ptest.ProtocolTester, *Registry, *stora
return nil, nil, nil, removeDataDir, err
}

netStore := storage.NewNetStore(localStore, nil)
db := storage.NewDBAPI(netStore)

db := storage.NewDBAPI(localStore)
delivery := NewDelivery(to, db)
streamer := NewRegistry(addr, delivery, db, state.NewMemStore(), defaultSkipCheck, false)
teardown := func() {
Expand Down
4 changes: 1 addition & 3 deletions swarm/network/stream/intervals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ func newIntervalsStreamerService(ctx *adapters.ServiceContext) (node.Service, er
addr := toAddr(id)
kad := network.NewKademlia(addr.Over(), network.NewKadParams())
store := stores[id].(*storage.LocalStore)

netStore := storage.NewNetStore(store, nil)
db := storage.NewDBAPI(netStore)
db := storage.NewDBAPI(store)
delivery := NewDelivery(kad, db)
deliveries[id] = delivery
r := NewRegistry(addr, delivery, db, state.NewMemStore(), defaultSkipCheck, false)
Expand Down
3 changes: 1 addition & 2 deletions swarm/network/stream/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
// create DBAPI-s for all nodes
dbs := make([]*storage.DBAPI, nodes)
for i := 0; i < nodes; i++ {
netStore := storage.NewNetStore(sim.Stores[i].(*storage.LocalStore), nil)
dbs[i] = storage.NewDBAPI(netStore)
dbs[i] = storage.NewDBAPI(sim.Stores[i].(*storage.LocalStore))
}

// collect hashes in po 1 bin for each node
Expand Down
17 changes: 9 additions & 8 deletions swarm/storage/dbapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,35 @@ package storage

// wrapper of db-s to provide mockable custom local chunk store access to syncer
type DBAPI struct {
ns *NetStore
db *LDBStore
loc *LocalStore
}

func NewDBAPI(ns *NetStore) *DBAPI {
return &DBAPI{ns: ns}
func NewDBAPI(loc *LocalStore) *DBAPI {
return &DBAPI{loc.DbStore, loc}
}

// to obtain the chunks from key or request db entry only
func (self *DBAPI) Get(key Key) (*Chunk, error) {
return self.ns.localStore.Get(key)
return self.loc.Get(key)
}

// current storage counter of chunk db
func (self *DBAPI) CurrentBucketStorageIndex(po uint8) uint64 {
return self.ns.localStore.DbStore.CurrentBucketStorageIndex(po)
return self.db.CurrentBucketStorageIndex(po)
}

// iteration storage counter and proximity order
func (self *DBAPI) Iterator(from uint64, to uint64, po uint8, f func(Key, uint64) bool) error {
return self.ns.localStore.DbStore.SyncIterator(from, to, po, f)
return self.db.SyncIterator(from, to, po, f)
}

// to obtain the chunks from key or request db entry only
func (self *DBAPI) GetOrCreateRequest(key Key) (*Chunk, bool) {
return self.ns.localStore.GetOrCreateRequest(key)
return self.loc.GetOrCreateRequest(key)
}

// to obtain the chunks from key or request db entry only
func (self *DBAPI) Put(chunk *Chunk) {
self.ns.localStore.Put(chunk)
self.loc.Put(chunk)
}
9 changes: 3 additions & 6 deletions swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
HiveParams: config.HiveParams,
}

// init netStore
ns := storage.NewNetStore(self.lstore, self.streamer.Retrieve)

db := storage.NewDBAPI(ns)
db := storage.NewDBAPI(self.lstore)
delivery := stream.NewDelivery(to, db)
// TODO: decide on intervals store file location
stateStore, err := state.NewDBStore(filepath.Join(config.Path, "state-store.db"))
Expand All @@ -161,10 +158,10 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
self.bzz = network.NewBzz(bzzconfig, to, stateStore, stream.Spec, self.streamer.Run)

// set up DPA, the cloud storage local access layer
//dpaChunkStore := storage.NewNetStore(self.lstore, self.streamer.Retrieve)
dpaChunkStore := storage.NewNetStore(self.lstore, self.streamer.Retrieve)
log.Debug(fmt.Sprintf("-> Local Access to Swarm"))
// Swarm Hash Merklised Chunking for Arbitrary-length Document/File storage
self.dpa = storage.NewDPA(ns, self.config.ChunkerParams)
self.dpa = storage.NewDPA(dpaChunkStore, self.config.ChunkerParams)
log.Debug(fmt.Sprintf("-> Content Store API"))

// Pss = postal service over swarm (devp2p over bzz)
Expand Down

0 comments on commit 734a182

Please sign in to comment.