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
732b9a7e
Commit
732b9a7e
authored
Aug 28, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing up some bitswap stuff after the PR
parent
54ff6ea4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
9 deletions
+6
-9
blocks_test.go
blocks_test.go
+1
-6
blockservice.go
blockservice.go
+5
-3
No files found.
blocks_test.go
View file @
732b9a7e
...
@@ -2,7 +2,6 @@ package blockservice
...
@@ -2,7 +2,6 @@ package blockservice
import
(
import
(
"bytes"
"bytes"
"fmt"
"testing"
"testing"
ds
"github.com/jbenet/datastore.go"
ds
"github.com/jbenet/datastore.go"
...
@@ -11,9 +10,8 @@ import (
...
@@ -11,9 +10,8 @@ import (
)
)
func
TestBlocks
(
t
*
testing
.
T
)
{
func
TestBlocks
(
t
*
testing
.
T
)
{
d
:=
ds
.
NewMapDatastore
()
d
:=
ds
.
NewMapDatastore
()
bs
,
err
:=
NewBlockService
(
d
)
bs
,
err
:=
NewBlockService
(
d
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
"failed to construct block service"
,
err
)
t
.
Error
(
"failed to construct block service"
,
err
)
return
return
...
@@ -62,7 +60,4 @@ func TestBlocks(t *testing.T) {
...
@@ -62,7 +60,4 @@ func TestBlocks(t *testing.T) {
if
!
bytes
.
Equal
(
b
.
Data
,
b2
.
Data
)
{
if
!
bytes
.
Equal
(
b
.
Data
,
b2
.
Data
)
{
t
.
Error
(
"Block data is not equal."
)
t
.
Error
(
"Block data is not equal."
)
}
}
fmt
.
Printf
(
"key: %s
\n
"
,
b
.
Key
())
fmt
.
Printf
(
"data: %v
\n
"
,
b
.
Data
)
}
}
blockservice.go
View file @
732b9a7e
...
@@ -25,7 +25,7 @@ func NewBlockService(d ds.Datastore, rem *bitswap.BitSwap) (*BlockService, error
...
@@ -25,7 +25,7 @@ func NewBlockService(d ds.Datastore, rem *bitswap.BitSwap) (*BlockService, error
return
nil
,
fmt
.
Errorf
(
"BlockService requires valid datastore"
)
return
nil
,
fmt
.
Errorf
(
"BlockService requires valid datastore"
)
}
}
if
rem
==
nil
{
if
rem
==
nil
{
return
nil
,
fmt
.
Errorf
(
"B
lock
S
ervice r
equires a valid bitswap
"
)
u
.
PErr
(
"Caution: b
lock
s
ervice r
unning in local (offline) mode.
\n
"
)
}
}
return
&
BlockService
{
Datastore
:
d
,
Remote
:
rem
},
nil
return
&
BlockService
{
Datastore
:
d
,
Remote
:
rem
},
nil
}
}
...
@@ -39,7 +39,9 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
...
@@ -39,7 +39,9 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
k
,
err
return
k
,
err
}
}
err
=
s
.
Remote
.
HaveBlock
(
b
.
Key
())
if
s
.
Remote
!=
nil
{
err
=
s
.
Remote
.
HaveBlock
(
b
.
Key
())
}
return
k
,
err
return
k
,
err
}
}
...
@@ -57,7 +59,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
...
@@ -57,7 +59,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
Multihash
:
mh
.
Multihash
(
k
),
Multihash
:
mh
.
Multihash
(
k
),
Data
:
bdata
,
Data
:
bdata
,
},
nil
},
nil
}
else
if
err
==
ds
.
ErrNotFound
{
}
else
if
err
==
ds
.
ErrNotFound
&&
s
.
Remote
!=
nil
{
blk
,
err
:=
s
.
Remote
.
GetBlock
(
k
,
time
.
Second
*
5
)
blk
,
err
:=
s
.
Remote
.
GetBlock
(
k
,
time
.
Second
*
5
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
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