diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go index c5f97ab775..4ce832863f 100644 --- a/swarm/api/http/server.go +++ b/swarm/api/http/server.go @@ -574,7 +574,23 @@ func (s *Server) HandleGet(w http.ResponseWriter, r *Request) { contentType = typ } w.Header().Set("Content-Type", contentType) - http.ServeContent(w, &r.Request, "", time.Now(), reader) + + var res []byte + var err error + for { + res, err = ioutil.ReadAll(reader) + if err != nil { + log.Error("handle.get", "ruid", r.ruid, "error", err) + time.Sleep(200 * time.Millisecond) + continue + } + log.Debug("handle.get.readall success", "ruid", r.ruid) + break + } + + rdr := bytes.NewReader(res) + + http.ServeContent(w, &r.Request, "", time.Now(), rdr) case r.uri.Hash(): w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) diff --git a/swarm/storage/chunker.go b/swarm/storage/chunker.go index 7e2b3be646..f9b3fe2746 100644 --- a/swarm/storage/chunker.go +++ b/swarm/storage/chunker.go @@ -131,7 +131,7 @@ type TreeChunker struct { The chunks are not meant to be validated by the chunker when joining. This is because it is left to the DPA to decide which sources are trusted. */ -func TreeJoin(key Key, getter Getter, depth int) LazySectionReader { +func TreeJoin(key Key, getter Getter, depth int) *LazyChunkReader { return NewTreeJoiner(NewJoinerParams(key, getter, depth, DefaultChunkSize)).Join() } diff --git a/swarm/storage/dpa.go b/swarm/storage/dpa.go index edf81ad5cb..2257df877c 100644 --- a/swarm/storage/dpa.go +++ b/swarm/storage/dpa.go @@ -84,7 +84,7 @@ func NewDPA(store ChunkStore, params *DPAParams) *DPA { // Chunk retrieval blocks on netStore requests with a timeout so reader will // report error if retrieval of chunks within requested range time out. // It returns a reader with the chunk data and whether the content was encrypted -func (self *DPA) Retrieve(key Key) (reader LazySectionReader, isEncrypted bool) { +func (self *DPA) Retrieve(key Key) (reader *LazyChunkReader, isEncrypted bool) { isEncrypted = len(key) > self.hashFunc().Size() getter := NewHasherStore(self.ChunkStore, self.hashFunc, isEncrypted) reader = TreeJoin(key, getter, 0)