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
3df9fe4b
Commit
3df9fe4b
authored
Aug 29, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
integrate bitswap and blockservice into the core package
parent
1c51a522
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
0 deletions
+5
-0
blockservice.go
blockservice.go
+5
-0
No files found.
blockservice.go
View file @
3df9fe4b
...
@@ -48,24 +48,29 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
...
@@ -48,24 +48,29 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
// GetBlock retrieves a particular block from the service,
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
// Getting it from the datastore using the key (hash).
func
(
s
*
BlockService
)
GetBlock
(
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
func
(
s
*
BlockService
)
GetBlock
(
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
u
.
DOut
(
"BlockService GetBlock: '%s'
\n
"
,
k
.
Pretty
())
dsk
:=
ds
.
NewKey
(
string
(
k
))
dsk
:=
ds
.
NewKey
(
string
(
k
))
datai
,
err
:=
s
.
Datastore
.
Get
(
dsk
)
datai
,
err
:=
s
.
Datastore
.
Get
(
dsk
)
if
err
==
nil
{
if
err
==
nil
{
u
.
DOut
(
"Blockservice: Got data in datastore.
\n
"
)
bdata
,
ok
:=
datai
.
([]
byte
)
bdata
,
ok
:=
datai
.
([]
byte
)
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"data associated with %s is not a []byte"
,
k
)
return
nil
,
fmt
.
Errorf
(
"data associated with %s is not a []byte"
,
k
)
}
}
u
.
DOut
(
"Got data: %v
\n
"
,
bdata
)
return
&
blocks
.
Block
{
return
&
blocks
.
Block
{
Multihash
:
mh
.
Multihash
(
k
),
Multihash
:
mh
.
Multihash
(
k
),
Data
:
bdata
,
Data
:
bdata
,
},
nil
},
nil
}
else
if
err
==
ds
.
ErrNotFound
&&
s
.
Remote
!=
nil
{
}
else
if
err
==
ds
.
ErrNotFound
&&
s
.
Remote
!=
nil
{
u
.
DOut
(
"Blockservice: Searching bitswap.
\n
"
)
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
}
}
return
blk
,
nil
return
blk
,
nil
}
else
{
}
else
{
u
.
DOut
(
"Blockservice GetBlock: Not found.
\n
"
)
return
nil
,
u
.
ErrNotFound
return
nil
,
u
.
ErrNotFound
}
}
}
}
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