mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 12:16:44 +00:00
Multiple bug fixes.
This commit is contained in:
parent
9ad312a90f
commit
cfe9304b5c
4 changed files with 26 additions and 7 deletions
|
|
@ -165,6 +165,7 @@ func (r *ChunkReader) WriteTo(w io.Writer) (n int64, err error) {
|
|||
}
|
||||
|
||||
func (self *LazyChunkReader) Size() (n int64) {
|
||||
self.ReadAt(nil, 0)
|
||||
return self.size
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -289,12 +289,13 @@ type LazyChunkReader struct {
|
|||
}
|
||||
|
||||
func (self *LazyChunkReader) ReadAt(b []byte, off int64) (read int, err error) {
|
||||
self.errC = make(chan error)
|
||||
chunk := &Chunk{
|
||||
Key: self.key,
|
||||
C: make(chan bool), // close channel to signal data delivery
|
||||
}
|
||||
self.chunkC <- chunk // submit retrieval request, someone should be listening on the other side (or we will time out globally)
|
||||
dpaLogger.Debugf("readAt %x", chunk.Key[:4])
|
||||
dpaLogger.Debugf("readAt %x into %d bytes at %d.", chunk.Key[:4], len(b), off)
|
||||
|
||||
// waiting for the chunk retrieval
|
||||
select {
|
||||
|
|
@ -304,15 +305,19 @@ func (self *LazyChunkReader) ReadAt(b []byte, off int64) (read int, err error) {
|
|||
return
|
||||
case <-chunk.C: // bells are ringing, data have been delivered
|
||||
dpaLogger.Debugf("chunk data received for %x", chunk.Key[:4])
|
||||
fmt.Printf("chunk data received for %x\n", chunk.Key[:4])
|
||||
}
|
||||
if len(chunk.Data) == 0 {
|
||||
dpaLogger.Debugf("No payload.")
|
||||
return 0, notFound
|
||||
}
|
||||
|
||||
self.size = chunk.Size
|
||||
if b == nil {
|
||||
dpaLogger.Debugf("Size query for %x.", chunk.Key[:4])
|
||||
return
|
||||
}
|
||||
want := int64(len(b))
|
||||
if off < 0 || want+off > chunk.Size {
|
||||
return 0, io.EOF
|
||||
if off+want > self.size {
|
||||
want = self.size - off
|
||||
}
|
||||
var treeSize int64
|
||||
var depth int
|
||||
|
|
@ -330,8 +335,14 @@ func (self *LazyChunkReader) ReadAt(b []byte, off int64) (read int, err error) {
|
|||
}()
|
||||
select {
|
||||
case err = <-self.errC:
|
||||
case <-self.quitC:
|
||||
dpaLogger.Debugf("ReadAt received %v.", err)
|
||||
read = len(b)
|
||||
if off+int64(read) == self.size {
|
||||
err = io.EOF
|
||||
}
|
||||
dpaLogger.Debugf("ReadAt returning with %d, %v.", read, err)
|
||||
case <-self.quitC:
|
||||
dpaLogger.Debugf("ReadAt aborted with %d, %v.", read, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,9 @@ func handler(w http.ResponseWriter, r *http.Request, dpa *DPA) {
|
|||
dpaLogger.Debugf("Swarm: Raw GET request %s received", uri)
|
||||
name := uri[5:]
|
||||
key := ethutil.Hex2Bytes(name)
|
||||
http.ServeContent(w, r, name+".bin", time.Unix(0, 0), dpa.Retrieve(key))
|
||||
reader := dpa.Retrieve(key)
|
||||
dpaLogger.Debugf("Swarm: Reading %d bytes.", reader.Size())
|
||||
http.ServeContent(w, r, name+".bin", time.Unix(0, 0), reader)
|
||||
dpaLogger.Debugf("Swarm: Object %s returned.", name)
|
||||
} else if manifestMatcher.MatchString(uri) {
|
||||
dpaLogger.Debugf("Swarm: Structured GET request %s received.", uri)
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ func NewNetStore(path string) *NetStore {
|
|||
|
||||
func (self *NetStore) Put(entry *Chunk) {
|
||||
chunk, err := self.localStore.Get(entry.Key)
|
||||
dpaLogger.Debugf("NetStore.Put: localStore.Get returned with %v.", err)
|
||||
if err != nil {
|
||||
chunk = entry
|
||||
} else if chunk.Data == nil {
|
||||
|
|
@ -68,6 +69,7 @@ func (self *NetStore) Put(entry *Chunk) {
|
|||
|
||||
func (self *NetStore) put(entry *Chunk) {
|
||||
self.localStore.Put(entry)
|
||||
dpaLogger.Debugf("NetStore.put: localStore.Put of %064x completed.", entry.Key)
|
||||
self.store(entry)
|
||||
// only send responses once
|
||||
if entry.req != nil && entry.req.status == reqSearching {
|
||||
|
|
@ -104,6 +106,8 @@ func (self *NetStore) Get(key Key) (chunk *Chunk, err error) {
|
|||
timeout := time.Now().Add(searchTimeout)
|
||||
if chunk.Data == nil {
|
||||
self.startSearch(chunk, id, timeout)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
timer := time.After(searchTimeout)
|
||||
select {
|
||||
|
|
@ -117,6 +121,7 @@ func (self *NetStore) Get(key Key) (chunk *Chunk, err error) {
|
|||
func (self *NetStore) get(key Key) (chunk *Chunk) {
|
||||
var err error
|
||||
chunk, err = self.localStore.Get(key)
|
||||
dpaLogger.Debugf("NetStore.get: localStore.Get of %064x returned with %v.", key, err)
|
||||
// we assume that a returned chunk is the one stored in the memory cache
|
||||
if err != nil {
|
||||
// no data and no request status
|
||||
|
|
|
|||
Loading…
Reference in a new issue