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
6f1789fd
Commit
6f1789fd
authored
Sep 28, 2014
by
Jeromy
Committed by
Juan Batiz-Benet
Oct 01, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update logging in multiple packages
parent
29a24c8b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
blockservice.go
blockservice.go
+9
-6
No files found.
blockservice.go
View file @
6f1789fd
...
...
@@ -7,12 +7,15 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/op/go-logging"
blocks
"github.com/jbenet/go-ipfs/blocks"
exchange
"github.com/jbenet/go-ipfs/exchange"
u
"github.com/jbenet/go-ipfs/util"
)
var
log
=
logging
.
MustGetLogger
(
"blockservice"
)
// BlockService is a block datastore.
// It uses an internal `datastore.Datastore` instance to store values.
type
BlockService
struct
{
...
...
@@ -26,7 +29,7 @@ func NewBlockService(d ds.Datastore, rem exchange.Interface) (*BlockService, err
return
nil
,
fmt
.
Errorf
(
"BlockService requires valid datastore"
)
}
if
rem
==
nil
{
u
.
DErr
(
"Caution:
blockservice running in local (offline) mode.
\n
"
)
log
.
Warning
(
"
blockservice running in local (offline) mode."
)
}
return
&
BlockService
{
Datastore
:
d
,
Remote
:
rem
},
nil
}
...
...
@@ -35,7 +38,7 @@ func NewBlockService(d ds.Datastore, rem exchange.Interface) (*BlockService, err
func
(
s
*
BlockService
)
AddBlock
(
b
*
blocks
.
Block
)
(
u
.
Key
,
error
)
{
k
:=
b
.
Key
()
dsk
:=
ds
.
NewKey
(
string
(
k
))
u
.
DOut
(
"storing [%s] in datastore
\n
"
,
k
.
Pretty
())
log
.
Debug
(
"storing [%s] in datastore"
,
k
.
Pretty
())
// TODO(brian): define a block datastore with a Put method which accepts a
// block parameter
err
:=
s
.
Datastore
.
Put
(
dsk
,
b
.
Data
)
...
...
@@ -52,11 +55,11 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func
(
s
*
BlockService
)
GetBlock
(
k
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
u
.
DOut
(
"BlockService GetBlock: '%s'
\n
"
,
k
.
Pretty
())
log
.
Debug
(
"BlockService GetBlock: '%s'"
,
k
.
Pretty
())
dsk
:=
ds
.
NewKey
(
string
(
k
))
datai
,
err
:=
s
.
Datastore
.
Get
(
dsk
)
if
err
==
nil
{
u
.
DOut
(
"Blockservice: Got data in datastore.
\n
"
)
log
.
Debug
(
"Blockservice: Got data in datastore."
)
bdata
,
ok
:=
datai
.
([]
byte
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"data associated with %s is not a []byte"
,
k
)
...
...
@@ -66,7 +69,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
Data
:
bdata
,
},
nil
}
else
if
err
==
ds
.
ErrNotFound
&&
s
.
Remote
!=
nil
{
u
.
DOut
(
"Blockservice: Searching bitswap.
\n
"
)
log
.
Debug
(
"Blockservice: Searching bitswap."
)
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
5
*
time
.
Second
)
blk
,
err
:=
s
.
Remote
.
Block
(
ctx
,
k
)
if
err
!=
nil
{
...
...
@@ -74,7 +77,7 @@ func (s *BlockService) GetBlock(k u.Key) (*blocks.Block, error) {
}
return
blk
,
nil
}
else
{
u
.
DOut
(
"Blockservice GetBlock: Not found.
\n
"
)
log
.
Debug
(
"Blockservice GetBlock: Not found."
)
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