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-merkledag
Commits
dbebd417
Commit
dbebd417
authored
Oct 07, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cid: integrate cid into bitswap and blockstores
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
67ad3923
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
25 deletions
+9
-25
merkledag.go
merkledag.go
+9
-25
No files found.
merkledag.go
View file @
dbebd417
...
@@ -2,15 +2,15 @@
...
@@ -2,15 +2,15 @@
package
merkledag
package
merkledag
import
(
import
(
"context"
"fmt"
"fmt"
"strings"
"strings"
"sync"
"sync"
blocks
"github.com/ipfs/go-ipfs/blocks"
bserv
"github.com/ipfs/go-ipfs/blockservice"
bserv
"github.com/ipfs/go-ipfs/blockservice"
offline
"github.com/ipfs/go-ipfs/exchange/offline"
offline
"github.com/ipfs/go-ipfs/exchange/offline"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
"context"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid
"gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid"
cid
"gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid"
)
)
...
@@ -60,7 +60,7 @@ func (n *dagService) Add(nd *Node) (*cid.Cid, error) {
...
@@ -60,7 +60,7 @@ func (n *dagService) Add(nd *Node) (*cid.Cid, error) {
return
nil
,
fmt
.
Errorf
(
"dagService is nil"
)
return
nil
,
fmt
.
Errorf
(
"dagService is nil"
)
}
}
return
n
.
Blocks
.
Add
Object
(
nd
)
return
n
.
Blocks
.
Add
Block
(
nd
)
}
}
func
(
n
*
dagService
)
Batch
()
*
Batch
{
func
(
n
*
dagService
)
Batch
()
*
Batch
{
...
@@ -122,7 +122,7 @@ func (n *dagService) GetOfflineLinkService() LinkService {
...
@@ -122,7 +122,7 @@ func (n *dagService) GetOfflineLinkService() LinkService {
}
}
func
(
n
*
dagService
)
Remove
(
nd
*
Node
)
error
{
func
(
n
*
dagService
)
Remove
(
nd
*
Node
)
error
{
return
n
.
Blocks
.
Delete
Object
(
nd
)
return
n
.
Blocks
.
Delete
Block
(
nd
)
}
}
// FetchGraph fetches all nodes that are children of the given node
// FetchGraph fetches all nodes that are children of the given node
...
@@ -147,27 +147,11 @@ type NodeOption struct {
...
@@ -147,27 +147,11 @@ type NodeOption struct {
Err
error
Err
error
}
}
// TODO: this is a mid-term hack to get around the fact that blocks don't
// have full CIDs and potentially (though we don't know of any such scenario)
// may have the same block with multiple different encodings.
// We have discussed the possiblity of using CIDs as datastore keys
// in the future. This would be a much larger changeset than i want to make
// right now.
func
cidsToKeyMapping
(
cids
[]
*
cid
.
Cid
)
map
[
key
.
Key
]
*
cid
.
Cid
{
mapping
:=
make
(
map
[
key
.
Key
]
*
cid
.
Cid
)
for
_
,
c
:=
range
cids
{
mapping
[
key
.
Key
(
c
.
Hash
())]
=
c
}
return
mapping
}
func
(
ds
*
dagService
)
GetMany
(
ctx
context
.
Context
,
keys
[]
*
cid
.
Cid
)
<-
chan
*
NodeOption
{
func
(
ds
*
dagService
)
GetMany
(
ctx
context
.
Context
,
keys
[]
*
cid
.
Cid
)
<-
chan
*
NodeOption
{
out
:=
make
(
chan
*
NodeOption
,
len
(
keys
))
out
:=
make
(
chan
*
NodeOption
,
len
(
keys
))
blocks
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
keys
)
blocks
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
keys
)
var
count
int
var
count
int
mapping
:=
cidsToKeyMapping
(
keys
)
go
func
()
{
go
func
()
{
defer
close
(
out
)
defer
close
(
out
)
for
{
for
{
...
@@ -180,7 +164,7 @@ func (ds *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *Node
...
@@ -180,7 +164,7 @@ func (ds *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *Node
return
return
}
}
c
:=
mapping
[
b
.
Key
()
]
c
:=
b
.
Cid
()
var
nd
*
Node
var
nd
*
Node
switch
c
.
Type
()
{
switch
c
.
Type
()
{
...
@@ -361,7 +345,7 @@ func (np *nodePromise) Get(ctx context.Context) (*Node, error) {
...
@@ -361,7 +345,7 @@ func (np *nodePromise) Get(ctx context.Context) (*Node, error) {
type
Batch
struct
{
type
Batch
struct
{
ds
*
dagService
ds
*
dagService
objects
[]
bserv
.
Object
blocks
[]
blocks
.
Block
size
int
size
int
MaxSize
int
MaxSize
int
}
}
...
@@ -372,7 +356,7 @@ func (t *Batch) Add(nd *Node) (*cid.Cid, error) {
...
@@ -372,7 +356,7 @@ func (t *Batch) Add(nd *Node) (*cid.Cid, error) {
return
nil
,
err
return
nil
,
err
}
}
t
.
object
s
=
append
(
t
.
object
s
,
nd
)
t
.
block
s
=
append
(
t
.
block
s
,
nd
)
t
.
size
+=
len
(
d
)
t
.
size
+=
len
(
d
)
if
t
.
size
>
t
.
MaxSize
{
if
t
.
size
>
t
.
MaxSize
{
return
nd
.
Cid
(),
t
.
Commit
()
return
nd
.
Cid
(),
t
.
Commit
()
...
@@ -381,8 +365,8 @@ func (t *Batch) Add(nd *Node) (*cid.Cid, error) {
...
@@ -381,8 +365,8 @@ func (t *Batch) Add(nd *Node) (*cid.Cid, error) {
}
}
func
(
t
*
Batch
)
Commit
()
error
{
func
(
t
*
Batch
)
Commit
()
error
{
_
,
err
:=
t
.
ds
.
Blocks
.
Add
Objects
(
t
.
object
s
)
_
,
err
:=
t
.
ds
.
Blocks
.
Add
Blocks
(
t
.
block
s
)
t
.
object
s
=
nil
t
.
block
s
=
nil
t
.
size
=
0
t
.
size
=
0
return
err
return
err
}
}
...
...
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