Commit 59e07036 authored by Jeromy's avatar Jeromy

move util.Key into its own package under blocks

parent bb4eca86
......@@ -11,6 +11,7 @@ import (
blocks "github.com/ipfs/go-ipfs/blocks"
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil"
key "github.com/ipfs/go-ipfs/blocks/key"
offline "github.com/ipfs/go-ipfs/exchange/offline"
u "github.com/ipfs/go-ipfs/util"
)
......@@ -30,7 +31,7 @@ func TestBlocks(t *testing.T) {
t.Error("Block Multihash and data multihash not equal")
}
if b.Key() != u.Key(h) {
if b.Key() != key.Key(h) {
t.Error("Block key and data multihash key not equal")
}
......@@ -68,7 +69,7 @@ func TestGetBlocksSequential(t *testing.T) {
bg := blocksutil.NewBlockGenerator()
blks := bg.Blocks(50)
var keys []u.Key
var keys []key.Key
for _, blk := range blks {
keys = append(keys, blk.Key())
servs[0].AddBlock(blk)
......@@ -79,7 +80,7 @@ func TestGetBlocksSequential(t *testing.T) {
for i := 1; i < len(servs); i++ {
ctx, _ := context.WithTimeout(context.TODO(), time.Second*50)
out := servs[i].GetBlocks(ctx, keys)
gotten := make(map[u.Key]*blocks.Block)
gotten := make(map[key.Key]*blocks.Block)
for blk := range out {
if _, ok := gotten[blk.Key()]; ok {
t.Fatal("Got duplicate block!")
......
......@@ -10,6 +10,7 @@ import (
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
blocks "github.com/ipfs/go-ipfs/blocks"
"github.com/ipfs/go-ipfs/blocks/blockstore"
key "github.com/ipfs/go-ipfs/blocks/key"
worker "github.com/ipfs/go-ipfs/blockservice/worker"
exchange "github.com/ipfs/go-ipfs/exchange"
u "github.com/ipfs/go-ipfs/util"
......@@ -64,7 +65,7 @@ func New(bs blockstore.Blockstore, rem exchange.Interface) (*BlockService, error
// AddBlock adds a particular block to the service, Putting it into the datastore.
// TODO pass a context into this if the remote.HasBlock is going to remain here.
func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
func (s *BlockService) AddBlock(b *blocks.Block) (key.Key, error) {
k := b.Key()
err := s.Blockstore.Put(b)
if err != nil {
......@@ -78,7 +79,7 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, 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, k u.Key) (*blocks.Block, error) {
func (s *BlockService) GetBlock(ctx context.Context, k key.Key) (*blocks.Block, error) {
log.Debugf("BlockService GetBlock: '%s'", k)
block, err := s.Blockstore.Get(k)
if err == nil {
......@@ -101,11 +102,11 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
// 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 []u.Key) <-chan *blocks.Block {
func (s *BlockService) GetBlocks(ctx context.Context, ks []key.Key) <-chan *blocks.Block {
out := make(chan *blocks.Block, 0)
go func() {
defer close(out)
var misses []u.Key
var misses []key.Key
for _, k := range ks {
hit, err := s.Blockstore.Get(k)
if err != nil {
......@@ -138,7 +139,7 @@ func (s *BlockService) GetBlocks(ctx context.Context, ks []u.Key) <-chan *blocks
}
// DeleteBlock deletes a block in the blockservice from the datastore
func (s *BlockService) DeleteBlock(k u.Key) error {
func (s *BlockService) DeleteBlock(k key.Key) error {
return s.Blockstore.DeleteBlock(k)
}
......
......@@ -9,6 +9,7 @@ import (
process "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
ratelimit "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit"
blocks "github.com/ipfs/go-ipfs/blocks"
key "github.com/ipfs/go-ipfs/blocks/key"
exchange "github.com/ipfs/go-ipfs/exchange"
waitable "github.com/ipfs/go-ipfs/thirdparty/waitable"
util "github.com/ipfs/go-ipfs/util"
......@@ -141,12 +142,12 @@ func (w *Worker) start(c Config) {
type BlockList struct {
list list.List
uniques map[util.Key]*list.Element
uniques map[key.Key]*list.Element
}
func (s *BlockList) PushFront(b *blocks.Block) {
if s.uniques == nil {
s.uniques = make(map[util.Key]*list.Element)
s.uniques = make(map[key.Key]*list.Element)
}
_, ok := s.uniques[b.Key()]
if !ok {
......@@ -157,7 +158,7 @@ func (s *BlockList) PushFront(b *blocks.Block) {
func (s *BlockList) Push(b *blocks.Block) {
if s.uniques == nil {
s.uniques = make(map[util.Key]*list.Element)
s.uniques = make(map[key.Key]*list.Element)
}
_, ok := s.uniques[b.Key()]
if !ok {
......
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