github.com/divan/go-ethereum@v1.8.14-0.20180820134928-1de9ada4016d/swarm/storage/dbapi.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package storage 18 19 import "context" 20 21 // wrapper of db-s to provide mockable custom local chunk store access to syncer 22 type DBAPI struct { 23 db *LDBStore 24 loc *LocalStore 25 } 26 27 func NewDBAPI(loc *LocalStore) *DBAPI { 28 return &DBAPI{loc.DbStore, loc} 29 } 30 31 // to obtain the chunks from address or request db entry only 32 func (d *DBAPI) Get(ctx context.Context, addr Address) (*Chunk, error) { 33 return d.loc.Get(ctx, addr) 34 } 35 36 // current storage counter of chunk db 37 func (d *DBAPI) CurrentBucketStorageIndex(po uint8) uint64 { 38 return d.db.CurrentBucketStorageIndex(po) 39 } 40 41 // iteration storage counter and proximity order 42 func (d *DBAPI) Iterator(from uint64, to uint64, po uint8, f func(Address, uint64) bool) error { 43 return d.db.SyncIterator(from, to, po, f) 44 } 45 46 // to obtain the chunks from address or request db entry only 47 func (d *DBAPI) GetOrCreateRequest(ctx context.Context, addr Address) (*Chunk, bool) { 48 return d.loc.GetOrCreateRequest(ctx, addr) 49 } 50 51 // to obtain the chunks from key or request db entry only 52 func (d *DBAPI) Put(ctx context.Context, chunk *Chunk) { 53 d.loc.Put(ctx, chunk) 54 }