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-block-format
Commits
19745ca2
Commit
19745ca2
authored
Jul 21, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go lint
link errors left: - protocol buffers output is not lint-friendly
parent
0b506293
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
blocks.go
blocks.go
+9
-2
No files found.
blocks.go
View file @
19745ca2
...
@@ -7,14 +7,14 @@ import (
...
@@ -7,14 +7,14 @@ import (
mh
"github.com/jbenet/go-multihash"
mh
"github.com/jbenet/go-multihash"
)
)
// Block
s
is the ipfs blocks service. It is the way
// Block is the ipfs blocks service. It is the way
// to retrieve blocks by the higher level ipfs modules
// to retrieve blocks by the higher level ipfs modules
type
Block
struct
{
type
Block
struct
{
Multihash
mh
.
Multihash
Multihash
mh
.
Multihash
Data
[]
byte
Data
[]
byte
}
}
// NewBlock creates a Block object from opaque data. It will hash the data.
func
NewBlock
(
data
[]
byte
)
(
*
Block
,
error
)
{
func
NewBlock
(
data
[]
byte
)
(
*
Block
,
error
)
{
h
,
err
:=
u
.
Hash
(
data
)
h
,
err
:=
u
.
Hash
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -23,15 +23,19 @@ func NewBlock(data []byte) (*Block, error) {
...
@@ -23,15 +23,19 @@ func NewBlock(data []byte) (*Block, error) {
return
&
Block
{
Data
:
data
,
Multihash
:
h
},
nil
return
&
Block
{
Data
:
data
,
Multihash
:
h
},
nil
}
}
// Key returns the block's Multihash as a Key value.
func
(
b
*
Block
)
Key
()
u
.
Key
{
func
(
b
*
Block
)
Key
()
u
.
Key
{
return
u
.
Key
(
b
.
Multihash
)
return
u
.
Key
(
b
.
Multihash
)
}
}
// BlockService is a block datastore.
// It uses an internal `datastore.Datastore` instance to store values.
type
BlockService
struct
{
type
BlockService
struct
{
Datastore
ds
.
Datastore
Datastore
ds
.
Datastore
// Remote *bitswap.BitSwap // eventually.
// Remote *bitswap.BitSwap // eventually.
}
}
// NewBlockService creates a BlockService with given datastore instance.
func
NewBlockService
(
d
ds
.
Datastore
)
(
*
BlockService
,
error
)
{
func
NewBlockService
(
d
ds
.
Datastore
)
(
*
BlockService
,
error
)
{
if
d
==
nil
{
if
d
==
nil
{
return
nil
,
fmt
.
Errorf
(
"BlockService requires valid datastore"
)
return
nil
,
fmt
.
Errorf
(
"BlockService requires valid datastore"
)
...
@@ -39,12 +43,15 @@ func NewBlockService(d ds.Datastore) (*BlockService, error) {
...
@@ -39,12 +43,15 @@ func NewBlockService(d ds.Datastore) (*BlockService, error) {
return
&
BlockService
{
Datastore
:
d
},
nil
return
&
BlockService
{
Datastore
:
d
},
nil
}
}
// AddBlock adds a particular block to the service, Putting it into the datastore.
func
(
s
*
BlockService
)
AddBlock
(
b
*
Block
)
(
u
.
Key
,
error
)
{
func
(
s
*
BlockService
)
AddBlock
(
b
*
Block
)
(
u
.
Key
,
error
)
{
k
:=
b
.
Key
()
k
:=
b
.
Key
()
dsk
:=
ds
.
NewKey
(
string
(
k
))
dsk
:=
ds
.
NewKey
(
string
(
k
))
return
k
,
s
.
Datastore
.
Put
(
dsk
,
b
.
Data
)
return
k
,
s
.
Datastore
.
Put
(
dsk
,
b
.
Data
)
}
}
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func
(
s
*
BlockService
)
GetBlock
(
k
u
.
Key
)
(
*
Block
,
error
)
{
func
(
s
*
BlockService
)
GetBlock
(
k
u
.
Key
)
(
*
Block
,
error
)
{
dsk
:=
ds
.
NewKey
(
string
(
k
))
dsk
:=
ds
.
NewKey
(
string
(
k
))
datai
,
err
:=
s
.
Datastore
.
Get
(
dsk
)
datai
,
err
:=
s
.
Datastore
.
Get
(
dsk
)
...
...
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