mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
swarm: for loop on reader
This commit is contained in:
parent
09713314c7
commit
426bc4f26b
3 changed files with 19 additions and 3 deletions
|
|
@ -574,7 +574,23 @@ func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
|
||||||
contentType = typ
|
contentType = typ
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", contentType)
|
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():
|
case r.uri.Hash():
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ type TreeChunker struct {
|
||||||
The chunks are not meant to be validated by the chunker when joining. This
|
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.
|
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()
|
return NewTreeJoiner(NewJoinerParams(key, getter, depth, DefaultChunkSize)).Join()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ func NewDPA(store ChunkStore, params *DPAParams) *DPA {
|
||||||
// Chunk retrieval blocks on netStore requests with a timeout so reader will
|
// Chunk retrieval blocks on netStore requests with a timeout so reader will
|
||||||
// report error if retrieval of chunks within requested range time out.
|
// 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
|
// 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()
|
isEncrypted = len(key) > self.hashFunc().Size()
|
||||||
getter := NewHasherStore(self.ChunkStore, self.hashFunc, isEncrypted)
|
getter := NewHasherStore(self.ChunkStore, self.hashFunc, isEncrypted)
|
||||||
reader = TreeJoin(key, getter, 0)
|
reader = TreeJoin(key, getter, 0)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue