mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
swarm/storage: add size validator
This commit is contained in:
parent
1af15cf52f
commit
c56a21b67b
3 changed files with 18 additions and 6 deletions
|
|
@ -230,6 +230,11 @@ R:
|
||||||
for req := range d.receiveC {
|
for req := range d.receiveC {
|
||||||
processReceivedChunksCount.Inc(1)
|
processReceivedChunksCount.Inc(1)
|
||||||
|
|
||||||
|
if len(req.SData) > cp.DefaultSize+8 {
|
||||||
|
log.Warn("received chunk is bigger than expected", "len", len(req.SData))
|
||||||
|
continue R
|
||||||
|
}
|
||||||
|
|
||||||
// this should be has locally
|
// this should be has locally
|
||||||
chunk, err := d.db.Get(context.TODO(), req.Addr)
|
chunk, err := d.db.Get(context.TODO(), req.Addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -245,10 +250,6 @@ R:
|
||||||
continue R
|
continue R
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if len(req.SData) > cp.DefaultSize {
|
|
||||||
log.Warn("received chunk is bigger than expected", "len", len(req.SData))
|
|
||||||
continue R
|
|
||||||
}
|
|
||||||
|
|
||||||
chunk.SData = req.SData
|
chunk.SData = req.SData
|
||||||
d.db.Put(context.TODO(), chunk)
|
d.db.Put(context.TODO(), chunk)
|
||||||
|
|
|
||||||
|
|
@ -355,3 +355,12 @@ func (v *ContentAddressValidator) Validate(addr Address, data []byte) bool {
|
||||||
|
|
||||||
return bytes.Equal(hash, addr[:])
|
return bytes.Equal(hash, addr[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SizeValidator provides method for validation of max chunk data size
|
||||||
|
type SizeValidator struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate that the chunk has valid size
|
||||||
|
func (v *SizeValidator) Validate(_ Address, data []byte) bool {
|
||||||
|
return len(data) <= 8+chunk.DefaultSize
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -201,8 +201,10 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
|
||||||
}
|
}
|
||||||
resourceHandler.SetStore(netStore)
|
resourceHandler.SetStore(netStore)
|
||||||
|
|
||||||
var validators []storage.ChunkValidator
|
validators := []storage.ChunkValidator{
|
||||||
validators = append(validators, storage.NewContentAddressValidator(storage.MakeHashFunc(storage.DefaultHash)))
|
storage.NewContentAddressValidator(storage.MakeHashFunc(storage.DefaultHash)),
|
||||||
|
&storage.SizeValidator{},
|
||||||
|
}
|
||||||
if resourceHandler != nil {
|
if resourceHandler != nil {
|
||||||
validators = append(validators, resourceHandler)
|
validators = append(validators, resourceHandler)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue