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
116d95e1
Unverified
Commit
116d95e1
authored
Jun 04, 2020
by
lash
Committed by
GitHub
Jun 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix deadlock in concurrent uploads (#256)
parent
42c4eb40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
14 deletions
+7
-14
validator.go
pkg/validator/validator.go
+7
-14
No files found.
pkg/validator/validator.go
View file @
116d95e1
...
@@ -9,9 +9,7 @@ import (
...
@@ -9,9 +9,7 @@ import (
"encoding/binary"
"encoding/binary"
"hash"
"hash"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bmt"
bmtlegacy
"github.com/ethersphere/bmt/legacy"
bmtlegacy
"github.com/ethersphere/bmt/legacy"
"golang.org/x/crypto/sha3"
"golang.org/x/crypto/sha3"
)
)
...
@@ -25,21 +23,18 @@ func hashFunc() hash.Hash {
...
@@ -25,21 +23,18 @@ func hashFunc() hash.Hash {
// 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
ContentAddressValidator
struct
{
hasher
bmt
.
Hash
logger
logging
.
Logger
}
}
// New constructs a new ContentAddressValidator
// New constructs a new ContentAddressValidator
func
NewContentAddressValidator
()
swarm
.
ChunkValidator
{
func
NewContentAddressValidator
()
swarm
.
ChunkValidator
{
p
:=
bmtlegacy
.
NewTreePool
(
hashFunc
,
swarm
.
Branches
,
bmtlegacy
.
PoolSize
)
return
&
ContentAddressValidator
{
return
&
ContentAddressValidator
{}
hasher
:
bmtlegacy
.
New
(
p
),
}
}
}
// Validate performs the validation check
// Validate performs the validation check
func
(
v
*
ContentAddressValidator
)
Validate
(
ch
swarm
.
Chunk
)
(
valid
bool
)
{
func
(
v
*
ContentAddressValidator
)
Validate
(
ch
swarm
.
Chunk
)
(
valid
bool
)
{
p
:=
bmtlegacy
.
NewTreePool
(
hashFunc
,
swarm
.
Branches
,
bmtlegacy
.
PoolSize
)
hasher
:=
bmtlegacy
.
New
(
p
)
// prepare data
// prepare data
data
:=
ch
.
Data
()
data
:=
ch
.
Data
()
...
@@ -47,18 +42,16 @@ func (v *ContentAddressValidator) Validate(ch swarm.Chunk) (valid bool) {
...
@@ -47,18 +42,16 @@ func (v *ContentAddressValidator) Validate(ch swarm.Chunk) (valid bool) {
span
:=
binary
.
LittleEndian
.
Uint64
(
data
[
:
8
])
span
:=
binary
.
LittleEndian
.
Uint64
(
data
[
:
8
])
// execute hash, compare and return result
// execute hash, compare and return result
v
.
hasher
.
Reset
()
hasher
.
Reset
()
err
:=
v
.
hasher
.
SetSpan
(
int64
(
span
))
err
:=
hasher
.
SetSpan
(
int64
(
span
))
if
err
!=
nil
{
if
err
!=
nil
{
v
.
logger
.
Debugf
(
"SetSpan on bmt legacy hasher gave error: %v"
,
err
)
return
false
return
false
}
}
_
,
err
=
v
.
hasher
.
Write
(
data
[
8
:
])
_
,
err
=
hasher
.
Write
(
data
[
8
:
])
if
err
!=
nil
{
if
err
!=
nil
{
v
.
logger
.
Debugf
(
"Write on bmt legacy hasher gave error: %v"
,
err
)
return
false
return
false
}
}
s
:=
v
.
hasher
.
Sum
(
nil
)
s
:=
hasher
.
Sum
(
nil
)
return
address
.
Equal
(
swarm
.
NewAddress
(
s
))
return
address
.
Equal
(
swarm
.
NewAddress
(
s
))
}
}
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