swarm/storage: NewLocalStoreFromAddr and set bucketCnt to access index

This commit is contained in:
zelig 2018-01-17 04:10:15 +01:00
parent 365bd3b6d2
commit 22b4959709
2 changed files with 15 additions and 1 deletions

View file

@ -542,10 +542,11 @@ func (s *DbStore) doPut(chunk *Chunk, ikey []byte, index *dpaDBIndex, po uint8)
data := encodeData(chunk)
s.batch.Put(getDataKey(s.dataIdx, po), data)
index.Idx = s.dataIdx
s.bucketCnt[po] = s.dataIdx
s.entryCnt++
s.dataIdx++
s.bucketCnt[po]++
// s.bucketCnt[po]++
cntKey := make([]byte, 2)
cntKey[0] = keyDistanceCnt
cntKey[1] = po

View file

@ -56,6 +56,19 @@ func NewTestLocalStore(path string) (*LocalStore, error) {
return localStore, nil
}
func NewTestLocalStoreForAddr(path string, basekey []byte) (*LocalStore, error) {
hasher := MakeHashFunc("SHA3")
dbStore, err := NewDbStore(path, hasher, singletonSwarmDbCapacity, func(k Key) (ret uint8) { return uint8(Proximity(basekey[:], k[:])) })
if err != nil {
return nil, err
}
localStore := &LocalStore{
memStore: NewMemStore(dbStore, singletonSwarmDbCapacity),
DbStore: dbStore,
}
return localStore, nil
}
// LocalStore is itself a chunk store
// unsafe, in that the data is not integrity checked
func (self *LocalStore) Put(chunk *Chunk) {