swarm/storage: simplify ChunkValidator interface (#18285)

This commit is contained in:
Javier Peletier
2018-12-12 16:22:17 +01:00
committed by Anton Evangelatov
parent ebbf3dfafb
commit 4e6f53ac33
7 changed files with 20 additions and 18 deletions

View File

@ -82,9 +82,8 @@ func (h *Handler) SetStore(store *storage.NetStore) {
// Validate is a chunk validation method
// If it looks like a feed update, the chunk address is checked against the userAddr of the update's signature
// It implements the storage.ChunkValidator interface
func (h *Handler) Validate(chunkAddr storage.Address, data []byte) bool {
dataLength := len(data)
if dataLength < minimumSignedUpdateLength {
func (h *Handler) Validate(chunk storage.Chunk) bool {
if len(chunk.Data()) < minimumSignedUpdateLength {
return false
}
@ -94,8 +93,8 @@ func (h *Handler) Validate(chunkAddr storage.Address, data []byte) bool {
// First, deserialize the chunk
var r Request
if err := r.fromChunk(chunkAddr, data); err != nil {
log.Debug("Invalid feed update chunk", "addr", chunkAddr.Hex(), "err", err.Error())
if err := r.fromChunk(chunk); err != nil {
log.Debug("Invalid feed update chunk", "addr", chunk.Address(), "err", err)
return false
}
@ -198,7 +197,7 @@ func (h *Handler) Lookup(ctx context.Context, query *Query) (*cacheEntry, error)
}
var request Request
if err := request.fromChunk(chunk.Address(), chunk.Data()); err != nil {
if err := request.fromChunk(chunk); err != nil {
return nil, nil
}
if request.Time <= timeLimit {