mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 19:30:44 +00:00
dpa implements ChunkStore interface, still half baked
This commit is contained in:
parent
05d636d47e
commit
827ef3e111
1 changed files with 25 additions and 9 deletions
34
bzz/dpa.go
34
bzz/dpa.go
|
|
@ -47,11 +47,12 @@ type DPA struct {
|
|||
// but the size of the subtree encoded in the chunk
|
||||
// 0 if request, to be supplied by the dpa
|
||||
type Chunk struct {
|
||||
Reader SectionReader // nil if request, to be supplied by dpa
|
||||
Data []byte // nil if request, to be supplied by dpa
|
||||
Size int64 // size of the data covered by the subtree encoded in this chunk
|
||||
Key Key // always
|
||||
C chan bool // to signal data delivery by the dpa
|
||||
Reader SectionReader // nil if request, to be supplied by dpa
|
||||
Data []byte // nil if request, to be supplied by dpa
|
||||
Size int64 // size of the data covered by the subtree encoded in this chunk
|
||||
Key Key // always
|
||||
C chan bool // to signal data delivery by the dpa
|
||||
req *requestStatus //
|
||||
}
|
||||
|
||||
type ChunkStore interface {
|
||||
|
|
@ -111,13 +112,15 @@ func (self *DPA) Store(data SectionReader) (key Key, err error) {
|
|||
|
||||
// DPA is itself a chunk store , to stores a chunk only
|
||||
// its integrity is checked ?
|
||||
func (self *DPA) Put(*Chunk) (err error) {
|
||||
func (self *DPA) Put(chunk *Chunk) {
|
||||
// rely on storeC
|
||||
return
|
||||
}
|
||||
|
||||
// Get(chunk *Chunk) looks up a chunk in the local stores
|
||||
// This method is blocking until the chunk is retrieved so additional timeout is needed to wrap this call
|
||||
func (self *DPA) Get(*Chunk) (err error) {
|
||||
func (self *DPA) Get(key Key) (chunk *Chunk, err error) {
|
||||
// rely on retrieveC
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -150,9 +153,22 @@ func (self *DPA) retrieveLoop() {
|
|||
LOOP:
|
||||
for chunk := range self.retrieveC {
|
||||
go func() {
|
||||
for _, store := range self.Stores {
|
||||
if _, err := store.Get(chunk.Key); err != nil { // no waiting/blocking here
|
||||
for i, store := range self.Stores {
|
||||
storedChunk, err := store.Get(chunk.Key)
|
||||
if err == notFound {
|
||||
dpaLogger.DebugDetailf("%v retrieving chunk %x: NOT FOUND", store, chunk.Key)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
dpaLogger.DebugDetailf("%v retrieving chunk %x: %v", store, chunk.Key, err)
|
||||
return
|
||||
}
|
||||
chunk.Reader = NewChunkReaderFromBytes(storedChunk.Data)
|
||||
chunk.Size = storedChunk.Size
|
||||
close(chunk.C)
|
||||
// if not in cache, cache it in memstore
|
||||
if i > 0 {
|
||||
self.Stores[0].Put(chunk)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
Loading…
Reference in a new issue