Commit ea04cd05 authored by lash's avatar lash Committed by GitHub

Add soc validator to node (#470)

parent 8d903cb7
...@@ -8,20 +8,20 @@ import ( ...@@ -8,20 +8,20 @@ import (
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
) )
var _ swarm.ChunkValidator = (*ContentAddressValidator)(nil) var _ swarm.ChunkValidator = (*Validator)(nil)
// ContentAddressValidator validates that the address of a given chunk // ContentAddressValidator validates that the address of a given chunk
// is the content address of its contents. // is the content address of its contents.
type ContentAddressValidator struct { type Validator struct {
} }
// NewContentAddressValidator constructs a new ContentAddressValidator // NewContentAddressValidator constructs a new ContentAddressValidator
func NewContentAddressValidator() swarm.ChunkValidator { func NewValidator() swarm.ChunkValidator {
return &ContentAddressValidator{} return &Validator{}
} }
// Validate performs the validation check. // Validate performs the validation check.
func (v *ContentAddressValidator) Validate(ch swarm.Chunk) (valid bool) { func (v *Validator) Validate(ch swarm.Chunk) (valid bool) {
chunkData := ch.Data() chunkData := ch.Data()
rch, err := contentChunkFromBytes(chunkData) rch, err := contentChunkFromBytes(chunkData)
if err != nil { if err != nil {
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
func TestContentAddressValidator(t *testing.T) { func TestContentAddressValidator(t *testing.T) {
// instantiate validator // instantiate validator
validator := content.NewContentAddressValidator() validator := content.NewValidator()
// generate address from pre-generated hex of 'foo' from legacy bmt // generate address from pre-generated hex of 'foo' from legacy bmt
bmtHashOfFoo := "2387e8e7d8a48c2a9339c97c1dc3461a9a7aa07e994c5cb8b38fd7c1b3e6ea48" bmtHashOfFoo := "2387e8e7d8a48c2a9339c97c1dc3461a9a7aa07e994c5cb8b38fd7c1b3e6ea48"
......
...@@ -41,6 +41,7 @@ import ( ...@@ -41,6 +41,7 @@ import (
"github.com/ethersphere/bee/pkg/pusher" "github.com/ethersphere/bee/pkg/pusher"
"github.com/ethersphere/bee/pkg/pushsync" "github.com/ethersphere/bee/pkg/pushsync"
"github.com/ethersphere/bee/pkg/retrieval" "github.com/ethersphere/bee/pkg/retrieval"
"github.com/ethersphere/bee/pkg/soc"
"github.com/ethersphere/bee/pkg/statestore/leveldb" "github.com/ethersphere/bee/pkg/statestore/leveldb"
mockinmem "github.com/ethersphere/bee/pkg/statestore/mock" mockinmem "github.com/ethersphere/bee/pkg/statestore/mock"
"github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/storage"
...@@ -254,7 +255,7 @@ func NewBee(o Options) (*Bee, error) { ...@@ -254,7 +255,7 @@ func NewBee(o Options) (*Bee, error) {
return nil, fmt.Errorf("retrieval service: %w", err) return nil, fmt.Errorf("retrieval service: %w", err)
} }
ns := netstore.New(storer, retrieve, content.NewContentAddressValidator()) ns := netstore.New(storer, retrieve, content.NewValidator(), soc.NewValidator())
retrieve.SetStorer(ns) retrieve.SetStorer(ns)
......
...@@ -7,20 +7,20 @@ import ( ...@@ -7,20 +7,20 @@ import (
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
) )
var _ swarm.ChunkValidator = (*SocValidator)(nil) var _ swarm.ChunkValidator = (*Validator)(nil)
// SocVaildator validates that the address of a given chunk // SocVaildator validates that the address of a given chunk
// is a single-owner chunk. // is a single-owner chunk.
type SocValidator struct { type Validator struct {
} }
// NewSocValidator creates a new SocValidator. // NewSocValidator creates a new SocValidator.
func NewSocValidator() swarm.ChunkValidator { func NewValidator() swarm.ChunkValidator {
return &SocValidator{} return &Validator{}
} }
// Validate performs the validation check. // Validate performs the validation check.
func (v *SocValidator) Validate(ch swarm.Chunk) (valid bool) { func (v *Validator) Validate(ch swarm.Chunk) (valid bool) {
s, err := FromChunk(ch) s, err := FromChunk(ch)
if err != nil { if err != nil {
return false return false
......
...@@ -40,7 +40,7 @@ func TestSocValidator(t *testing.T) { ...@@ -40,7 +40,7 @@ func TestSocValidator(t *testing.T) {
} }
// check valid chunk // check valid chunk
v := soc.NewSocValidator() v := soc.NewValidator()
if !v.Validate(sch) { if !v.Validate(sch) {
t.Fatal("valid chunk evaluates to invalid") t.Fatal("valid chunk evaluates to invalid")
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment