Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-blockstore
Commits
f49cb353
Commit
f49cb353
authored
Jun 24, 2016
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
blockstore: add fetch rehashing
License: MIT Signed-off-by:
Jakub Sztandera
<
kubuxu@protonmail.ch
>
parent
34f3ab65
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
blockstore.go
blockstore.go
+18
-2
No files found.
blockstore.go
View file @
f49cb353
...
...
@@ -22,7 +22,8 @@ var log = logging.Logger("blockstore")
// BlockPrefix namespaces blockstore datastores
var
BlockPrefix
=
ds
.
NewKey
(
"blocks"
)
var
ValueTypeMismatch
=
errors
.
New
(
"The retrieved value is not a Block"
)
var
ValueTypeMismatch
=
errors
.
New
(
"the retrieved value is not a Block"
)
var
ErrHashMismatch
=
errors
.
New
(
"block in storage has different hash than requested"
)
var
ErrNotFound
=
errors
.
New
(
"blockstore: block not found"
)
...
...
@@ -71,6 +72,12 @@ type blockstore struct {
lk
sync
.
RWMutex
gcreq
int32
gcreqlk
sync
.
Mutex
rehash
bool
}
func
(
bs
*
blockstore
)
RuntimeHashing
(
enabled
bool
)
{
bs
.
rehash
=
enabled
}
func
(
bs
*
blockstore
)
Get
(
k
key
.
Key
)
(
blocks
.
Block
,
error
)
{
...
...
@@ -90,7 +97,16 @@ func (bs *blockstore) Get(k key.Key) (blocks.Block, error) {
return
nil
,
ValueTypeMismatch
}
if
bs
.
rehash
{
rb
:=
blocks
.
NewBlock
(
bdata
)
if
rb
.
Key
()
!=
k
{
return
nil
,
ErrHashMismatch
}
else
{
return
rb
,
nil
}
}
else
{
return
blocks
.
NewBlockWithHash
(
bdata
,
mh
.
Multihash
(
k
))
}
}
func
(
bs
*
blockstore
)
Put
(
block
blocks
.
Block
)
error
{
...
...
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