Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
ea04cd05
Unverified
Commit
ea04cd05
authored
Jul 24, 2020
by
lash
Committed by
GitHub
Jul 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add soc validator to node (#470)
parent
8d903cb7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
13 deletions
+14
-13
validator.go
pkg/content/validator.go
+5
-5
validator_test.go
pkg/content/validator_test.go
+1
-1
node.go
pkg/node/node.go
+2
-1
validator.go
pkg/soc/validator.go
+5
-5
validator_test.go
pkg/soc/validator_test.go
+1
-1
No files found.
pkg/content/validator.go
View file @
ea04cd05
...
@@ -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
=
(
*
ContentAddress
Validator
)(
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
ContentAddress
Validator
struct
{
type
Validator
struct
{
}
}
// NewContentAddressValidator constructs a new ContentAddressValidator
// NewContentAddressValidator constructs a new ContentAddressValidator
func
New
ContentAddress
Validator
()
swarm
.
ChunkValidator
{
func
NewValidator
()
swarm
.
ChunkValidator
{
return
&
ContentAddress
Validator
{}
return
&
Validator
{}
}
}
// Validate performs the validation check.
// Validate performs the validation check.
func
(
v
*
ContentAddress
Validator
)
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
{
...
...
pkg/content/validator_test.go
View file @
ea04cd05
...
@@ -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
.
New
ContentAddress
Validator
()
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"
...
...
pkg/node/node.go
View file @
ea04cd05
...
@@ -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
.
New
ContentAddress
Validator
())
ns
:=
netstore
.
New
(
storer
,
retrieve
,
content
.
New
Validator
(),
soc
.
New
Validator
())
retrieve
.
SetStorer
(
ns
)
retrieve
.
SetStorer
(
ns
)
...
...
pkg/soc/validator.go
View file @
ea04cd05
...
@@ -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
=
(
*
Soc
Validator
)(
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
Soc
Validator
struct
{
type
Validator
struct
{
}
}
// NewSocValidator creates a new SocValidator.
// NewSocValidator creates a new SocValidator.
func
New
Soc
Validator
()
swarm
.
ChunkValidator
{
func
NewValidator
()
swarm
.
ChunkValidator
{
return
&
Soc
Validator
{}
return
&
Validator
{}
}
}
// Validate performs the validation check.
// Validate performs the validation check.
func
(
v
*
Soc
Validator
)
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
...
...
pkg/soc/validator_test.go
View file @
ea04cd05
...
@@ -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
.
New
Soc
Validator
()
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"
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment