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-blockservice
Commits
be6f25b0
Commit
be6f25b0
authored
Aug 19, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
blockservice: don't store blocks we already have
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
63cbf6e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
3 deletions
+25
-3
blockservice.go
blockservice.go
+25
-3
No files found.
blockservice.go
View file @
be6f25b0
...
...
@@ -43,7 +43,15 @@ func New(bs blockstore.Blockstore, rem exchange.Interface) *BlockService {
// TODO pass a context into this if the remote.HasBlock is going to remain here.
func
(
s
*
BlockService
)
AddBlock
(
b
blocks
.
Block
)
(
key
.
Key
,
error
)
{
k
:=
b
.
Key
()
err
:=
s
.
Blockstore
.
Put
(
b
)
has
,
err
:=
s
.
Blockstore
.
Has
(
k
)
if
err
!=
nil
{
return
k
,
err
}
if
has
{
return
k
,
nil
}
err
=
s
.
Blockstore
.
Put
(
b
)
if
err
!=
nil
{
return
k
,
err
}
...
...
@@ -54,13 +62,27 @@ func (s *BlockService) AddBlock(b blocks.Block) (key.Key, error) {
}
func
(
s
*
BlockService
)
AddBlocks
(
bs
[]
blocks
.
Block
)
([]
key
.
Key
,
error
)
{
err
:=
s
.
Blockstore
.
PutMany
(
bs
)
var
toput
[]
blocks
.
Block
for
_
,
b
:=
range
bs
{
has
,
err
:=
s
.
Blockstore
.
Has
(
b
.
Key
())
if
err
!=
nil
{
return
nil
,
err
}
if
has
{
continue
}
toput
=
append
(
toput
,
b
)
}
err
:=
s
.
Blockstore
.
PutMany
(
toput
)
if
err
!=
nil
{
return
nil
,
err
}
var
ks
[]
key
.
Key
for
_
,
b
:=
range
bs
{
for
_
,
b
:=
range
toput
{
if
err
:=
s
.
Exchange
.
HasBlock
(
b
);
err
!=
nil
{
return
nil
,
errors
.
New
(
"blockservice is closed"
)
}
...
...
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