do not forward store request to the peer we received it from

This commit is contained in:
zelig 2015-05-13 21:06:03 +02:00
parent 638bc6d364
commit 8ad5bc8450
2 changed files with 7 additions and 3 deletions

View file

@ -61,6 +61,7 @@ type Chunk struct {
req *requestStatus // req *requestStatus //
wg *sync.WaitGroup wg *sync.WaitGroup
dbStored chan bool dbStored chan bool
source peer
} }
type ChunkStore interface { type ChunkStore interface {

View file

@ -98,7 +98,7 @@ func (self *NetStore) put(entry *Chunk) {
func (self *NetStore) addStoreRequest(req *storeRequestMsgData) { func (self *NetStore) addStoreRequest(req *storeRequestMsgData) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
dpaLogger.Debugf("NetStore.addStoreRequest: req = %#v", req) dpaLogger.Debugf("NetStore.addStoreRequest: req = %v", req)
chunk, err := self.localStore.Get(req.Key) chunk, err := self.localStore.Get(req.Key)
dpaLogger.Debugf("NetStore.addStoreRequest: chunk reference %p", chunk) dpaLogger.Debugf("NetStore.addStoreRequest: chunk reference %p", chunk)
// we assume that a returned chunk is the one stored in the memory cache // we assume that a returned chunk is the one stored in the memory cache
@ -114,6 +114,7 @@ func (self *NetStore) addStoreRequest(req *storeRequestMsgData) {
} else { } else {
return return
} }
chunk.source = req.peer
self.put(chunk) self.put(chunk)
} }
@ -224,7 +225,7 @@ only add if less than requesterCount peers forwarded the same request id so far
note this is done irrespective of status (searching or found/timedOut) note this is done irrespective of status (searching or found/timedOut)
*/ */
func (self *NetStore) addRequester(rs *requestStatus, req *retrieveRequestMsgData) { func (self *NetStore) addRequester(rs *requestStatus, req *retrieveRequestMsgData) {
dpaLogger.Debugf("NetStore.addRequester: key %064x - add peer [%#v] to req.Id %064x", req.Key, req.peer, req.Id) dpaLogger.Debugf("NetStore.addRequester: key %064x - add peer [%v] to req.Id %064x", req.Key, req.peer, req.Id)
list := rs.requesters[int64(req.Id)] list := rs.requesters[int64(req.Id)]
rs.requesters[int64(req.Id)] = append(list, req) rs.requesters[int64(req.Id)] = append(list, req)
} }
@ -294,9 +295,11 @@ func (self *NetStore) store(chunk *Chunk) {
Id: uint64(id), Id: uint64(id),
} }
for _, peer := range self.hive.getPeers(chunk.Key, 0) { for _, peer := range self.hive.getPeers(chunk.Key, 0) {
if peer.Addr() != chunk.source.Addr() {
go peer.store(req) go peer.store(req)
} }
} }
}
func (self *NetStore) peers(req *retrieveRequestMsgData, chunk *Chunk, timeout *time.Time) { func (self *NetStore) peers(req *retrieveRequestMsgData, chunk *Chunk, timeout *time.Time) {
var addrs []*peerAddr var addrs []*peerAddr