mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
swarm/network: integrity on incoming known chunks
This commit is contained in:
parent
73d322ec48
commit
a43cd3f9bf
1 changed files with 7 additions and 1 deletions
|
|
@ -99,6 +99,7 @@ func (self *Depo) HandleDeliveryRequestMsg(req *deliveryRequestMsgData, p *peer)
|
||||||
// if key found locally, return. otherwise
|
// if key found locally, return. otherwise
|
||||||
// remote is untrusted, so hash is verified and chunk passed on to NetStore
|
// remote is untrusted, so hash is verified and chunk passed on to NetStore
|
||||||
func (self *Depo) HandleStoreRequestMsg(req *storeRequestMsgData, p *peer) {
|
func (self *Depo) HandleStoreRequestMsg(req *storeRequestMsgData, p *peer) {
|
||||||
|
var islocal bool
|
||||||
req.from = p
|
req.from = p
|
||||||
chunk, err := self.localStore.Get(req.Key)
|
chunk, err := self.localStore.Get(req.Key)
|
||||||
switch {
|
switch {
|
||||||
|
|
@ -116,8 +117,10 @@ func (self *Depo) HandleStoreRequestMsg(req *storeRequestMsgData, p *peer) {
|
||||||
// data is found, store request ignored
|
// data is found, store request ignored
|
||||||
// this should update access count?
|
// this should update access count?
|
||||||
glog.V(logger.Detail).Infof("Depo.HandleStoreRequest: %v found locally. ignore.", req)
|
glog.V(logger.Detail).Infof("Depo.HandleStoreRequest: %v found locally. ignore.", req)
|
||||||
return
|
islocal = true
|
||||||
|
//return
|
||||||
}
|
}
|
||||||
|
|
||||||
hasher := self.hashfunc()
|
hasher := self.hashfunc()
|
||||||
hasher.Write(req.SData)
|
hasher.Write(req.SData)
|
||||||
if !bytes.Equal(hasher.Sum(nil), req.Key) {
|
if !bytes.Equal(hasher.Sum(nil), req.Key) {
|
||||||
|
|
@ -127,6 +130,9 @@ func (self *Depo) HandleStoreRequestMsg(req *storeRequestMsgData, p *peer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if islocal {
|
||||||
|
return
|
||||||
|
}
|
||||||
// update chunk with size and data
|
// update chunk with size and data
|
||||||
chunk.SData = req.SData // protocol validates that SData is minimum 9 bytes long (int64 size + at least one byte of data)
|
chunk.SData = req.SData // protocol validates that SData is minimum 9 bytes long (int64 size + at least one byte of data)
|
||||||
chunk.Size = int64(binary.LittleEndian.Uint64(req.SData[0:8]))
|
chunk.Size = int64(binary.LittleEndian.Uint64(req.SData[0:8]))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue