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
4ba51bde
Commit
4ba51bde
authored
6 years ago
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gx update and fix code to use new Cid type
parent
bbc2201e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
22 deletions
+22
-22
blockservice.go
blockservice.go
+11
-11
package.json
package.json
+10
-10
test/blocks_test.go
test/blocks_test.go
+1
-1
No files found.
blockservice.go
View file @
4ba51bde
...
...
@@ -25,7 +25,7 @@ var ErrNotFound = errors.New("blockservice: key not found")
// the blockservice.
type
BlockGetter
interface
{
// GetBlock gets the requested block.
GetBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
GetBlock
(
ctx
context
.
Context
,
c
cid
.
Cid
)
(
blocks
.
Block
,
error
)
// GetBlocks does a batch request for the given cids, returning blocks as
// they are found, in no particular order.
...
...
@@ -34,7 +34,7 @@ type BlockGetter interface {
// be canceled). In that case, it will close the channel early. It is up
// to the consumer to detect this situation and keep track which blocks
// it has received and which it hasn't.
GetBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
)
<-
chan
blocks
.
Block
GetBlocks
(
ctx
context
.
Context
,
ks
[]
cid
.
Cid
)
<-
chan
blocks
.
Block
}
// BlockService is a hybrid block datastore. It stores data in a local
...
...
@@ -58,7 +58,7 @@ type BlockService interface {
AddBlocks
(
bs
[]
blocks
.
Block
)
error
// DeleteBlock deletes the given block from the blockservice.
DeleteBlock
(
o
*
cid
.
Cid
)
error
DeleteBlock
(
o
cid
.
Cid
)
error
}
type
blockService
struct
{
...
...
@@ -196,7 +196,7 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
// GetBlock retrieves a particular block from the service,
// Getting it from the datastore using the key (hash).
func
(
s
*
blockService
)
GetBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
{
func
(
s
*
blockService
)
GetBlock
(
ctx
context
.
Context
,
c
cid
.
Cid
)
(
blocks
.
Block
,
error
)
{
log
.
Debugf
(
"BlockService GetBlock: '%s'"
,
c
)
var
f
exchange
.
Fetcher
...
...
@@ -207,7 +207,7 @@ func (s *blockService) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block,
return
getBlock
(
ctx
,
c
,
s
.
blockstore
,
f
)
// hash security
}
func
getBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
,
bs
blockstore
.
Blockstore
,
f
exchange
.
Fetcher
)
(
blocks
.
Block
,
error
)
{
func
getBlock
(
ctx
context
.
Context
,
c
cid
.
Cid
,
bs
blockstore
.
Blockstore
,
f
exchange
.
Fetcher
)
(
blocks
.
Block
,
error
)
{
err
:=
verifcid
.
ValidateCid
(
c
)
// hash security
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -244,11 +244,11 @@ func getBlock(ctx context.Context, c *cid.Cid, bs blockstore.Blockstore, f excha
// GetBlocks gets a list of blocks asynchronously and returns through
// the returned channel.
// NB: No guarantees are made about order.
func
(
s
*
blockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
)
<-
chan
blocks
.
Block
{
func
(
s
*
blockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
cid
.
Cid
)
<-
chan
blocks
.
Block
{
return
getBlocks
(
ctx
,
ks
,
s
.
blockstore
,
s
.
exchange
)
// hash security
}
func
getBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
,
bs
blockstore
.
Blockstore
,
f
exchange
.
Fetcher
)
<-
chan
blocks
.
Block
{
func
getBlocks
(
ctx
context
.
Context
,
ks
[]
cid
.
Cid
,
bs
blockstore
.
Blockstore
,
f
exchange
.
Fetcher
)
<-
chan
blocks
.
Block
{
out
:=
make
(
chan
blocks
.
Block
)
go
func
()
{
...
...
@@ -266,7 +266,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
}
ks
=
ks
[
:
k
]
var
misses
[]
*
cid
.
Cid
var
misses
[]
cid
.
Cid
for
_
,
c
:=
range
ks
{
hit
,
err
:=
bs
.
Get
(
c
)
if
err
!=
nil
{
...
...
@@ -303,7 +303,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
}
// DeleteBlock deletes a block in the blockservice from the datastore
func
(
s
*
blockService
)
DeleteBlock
(
c
*
cid
.
Cid
)
error
{
func
(
s
*
blockService
)
DeleteBlock
(
c
cid
.
Cid
)
error
{
err
:=
s
.
blockstore
.
DeleteBlock
(
c
)
if
err
==
nil
{
log
.
Event
(
context
.
TODO
(),
"BlockService.BlockDeleted"
,
c
)
...
...
@@ -323,12 +323,12 @@ type Session struct {
}
// GetBlock gets a block in the context of a request session
func
(
s
*
Session
)
GetBlock
(
ctx
context
.
Context
,
c
*
cid
.
Cid
)
(
blocks
.
Block
,
error
)
{
func
(
s
*
Session
)
GetBlock
(
ctx
context
.
Context
,
c
cid
.
Cid
)
(
blocks
.
Block
,
error
)
{
return
getBlock
(
ctx
,
c
,
s
.
bs
,
s
.
ses
)
// hash security
}
// GetBlocks gets blocks in the context of a request session
func
(
s
*
Session
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
*
cid
.
Cid
)
<-
chan
blocks
.
Block
{
func
(
s
*
Session
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
cid
.
Cid
)
<-
chan
blocks
.
Block
{
return
getBlocks
(
ctx
,
ks
,
s
.
bs
,
s
.
ses
)
// hash security
}
...
...
This diff is collapsed.
Click to expand it.
package.json
View file @
4ba51bde
...
...
@@ -9,15 +9,15 @@
"gxDependencies"
:
[
{
"author"
:
"why"
,
"hash"
:
"Qm
VDDgboX5nPUE4pBcK2xC1b9XbStA4t2KrUWBRMr9AiFd
"
,
"hash"
:
"Qm
QPWVDYeWvxN75cP4MGrbMVpADm2XqpM4KxgvbxkYk16u
"
,
"name"
:
"go-bitswap"
,
"version"
:
"1.
0.15
"
"version"
:
"1.
1.0
"
},
{
"author"
:
"hsanjuan"
,
"hash"
:
"Qm
PuLWvxK1vg6ckKUpT53Dow9VLCcQGdL5Trwxa8PTLp7r
"
,
"hash"
:
"Qm
XHsHBveZF6ueKzDJbUg476gmrbzoR1yijiyH5SZAEuDT
"
,
"name"
:
"go-ipfs-exchange-offline"
,
"version"
:
"0.
0.17
"
"version"
:
"0.
1.0
"
},
{
"author"
:
"jbenet"
,
...
...
@@ -27,21 +27,21 @@
},
{
"author"
:
"hsanjuan"
,
"hash"
:
"Qme
g56ecxRnVv7VWViMrDeEMoBHaNFMs4vQnyQrJ79Zz7i
"
,
"hash"
:
"Qme
MussyD8s3fQ3pM19ZsfbxvomEqPV9FvczLMWyBDYSnS
"
,
"name"
:
"go-ipfs-blockstore"
,
"version"
:
"0.
0.2
0"
"version"
:
"0.
1.
0"
},
{
"author"
:
"stebalien"
,
"hash"
:
"Qm
WAzSEoqZ6xU6pu8yL8e5WaMb7wtbfbhhN4p1DknUPtr3
"
,
"hash"
:
"Qm
RcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM
"
,
"name"
:
"go-block-format"
,
"version"
:
"0.
1.11
"
"version"
:
"0.
2.0
"
},
{
"author"
:
"why"
,
"hash"
:
"QmV
UhfewLZpSaAiBYCpw2krYMaiVmFuhr2iurQLuRoU6sD
"
,
"hash"
:
"QmV
kMRSkXrpjqrroEXWuYBvDBnXCdMMY6gsKicBGVGUqKT
"
,
"name"
:
"go-verifcid"
,
"version"
:
"0.
0.4
"
"version"
:
"0.
1.0
"
}
],
"gxVersion"
:
"0.12.1"
,
...
...
This diff is collapsed.
Click to expand it.
test/blocks_test.go
View file @
4ba51bde
...
...
@@ -71,7 +71,7 @@ func TestGetBlocksSequential(t *testing.T) {
}
objs
:=
makeObjects
(
50
)
var
cids
[]
*
cid
.
Cid
var
cids
[]
cid
.
Cid
for
_
,
o
:=
range
objs
{
cids
=
append
(
cids
,
o
.
Cid
())
servs
[
0
]
.
AddBlock
(
o
)
...
...
This diff is collapsed.
Click to expand it.
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