Commit dbebd417 authored by Jeromy's avatar Jeromy

cid: integrate cid into bitswap and blockstores

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>
parent 67ad3923
......@@ -2,15 +2,15 @@
package merkledag
import (
"context"
"fmt"
"strings"
"sync"
blocks "github.com/ipfs/go-ipfs/blocks"
bserv "github.com/ipfs/go-ipfs/blockservice"
offline "github.com/ipfs/go-ipfs/exchange/offline"
key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
"context"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/go-cid"
)
......@@ -60,7 +60,7 @@ func (n *dagService) Add(nd *Node) (*cid.Cid, error) {
return nil, fmt.Errorf("dagService is nil")
}
return n.Blocks.AddObject(nd)
return n.Blocks.AddBlock(nd)
}
func (n *dagService) Batch() *Batch {
......@@ -122,7 +122,7 @@ func (n *dagService) GetOfflineLinkService() LinkService {
}
func (n *dagService) Remove(nd *Node) error {
return n.Blocks.DeleteObject(nd)
return n.Blocks.DeleteBlock(nd)
}
// FetchGraph fetches all nodes that are children of the given node
......@@ -147,27 +147,11 @@ type NodeOption struct {
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 {
out := make(chan *NodeOption, len(keys))
blocks := ds.Blocks.GetBlocks(ctx, keys)
var count int
mapping := cidsToKeyMapping(keys)
go func() {
defer close(out)
for {
......@@ -180,7 +164,7 @@ func (ds *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *Node
return
}
c := mapping[b.Key()]
c := b.Cid()
var nd *Node
switch c.Type() {
......@@ -361,7 +345,7 @@ func (np *nodePromise) Get(ctx context.Context) (*Node, error) {
type Batch struct {
ds *dagService
objects []bserv.Object
blocks []blocks.Block
size int
MaxSize int
}
......@@ -372,7 +356,7 @@ func (t *Batch) Add(nd *Node) (*cid.Cid, error) {
return nil, err
}
t.objects = append(t.objects, nd)
t.blocks = append(t.blocks, nd)
t.size += len(d)
if t.size > t.MaxSize {
return nd.Cid(), t.Commit()
......@@ -381,8 +365,8 @@ func (t *Batch) Add(nd *Node) (*cid.Cid, error) {
}
func (t *Batch) Commit() error {
_, err := t.ds.Blocks.AddObjects(t.objects)
t.objects = nil
_, err := t.ds.Blocks.AddBlocks(t.blocks)
t.blocks = nil
t.size = 0
return err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment