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
10eab98a
Commit
10eab98a
authored
Aug 24, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
basic implementation of bitswap, needs testing/verification that it works
parent
19745ca2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
44 deletions
+0
-44
blocks.go
blocks.go
+0
-44
No files found.
blocks.go
View file @
10eab98a
package
blocks
package
blocks
import
(
import
(
"fmt"
ds
"github.com/jbenet/datastore.go"
u
"github.com/jbenet/go-ipfs/util"
u
"github.com/jbenet/go-ipfs/util"
mh
"github.com/jbenet/go-multihash"
mh
"github.com/jbenet/go-multihash"
)
)
...
@@ -27,45 +25,3 @@ func NewBlock(data []byte) (*Block, error) {
...
@@ -27,45 +25,3 @@ func NewBlock(data []byte) (*Block, error) {
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
{
Datastore
ds
.
Datastore
// Remote *bitswap.BitSwap // eventually.
}
// NewBlockService creates a BlockService with given datastore instance.
func
NewBlockService
(
d
ds
.
Datastore
)
(
*
BlockService
,
error
)
{
if
d
==
nil
{
return
nil
,
fmt
.
Errorf
(
"BlockService requires valid datastore"
)
}
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
)
{
k
:=
b
.
Key
()
dsk
:=
ds
.
NewKey
(
string
(
k
))
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
)
{
dsk
:=
ds
.
NewKey
(
string
(
k
))
datai
,
err
:=
s
.
Datastore
.
Get
(
dsk
)
if
err
!=
nil
{
return
nil
,
err
}
data
,
ok
:=
datai
.
([]
byte
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"data associated with %s is not a []byte"
,
k
)
}
return
&
Block
{
Multihash
:
mh
.
Multihash
(
k
),
Data
:
data
,
},
nil
}
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