1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 05:52:20 +08:00

wire GetBlocks into blockservice

This commit is contained in:
Jeromy
2014-11-21 06:40:34 +00:00
parent ab201c15bb
commit d53deebada
15 changed files with 88 additions and 55 deletions

View File

@ -83,7 +83,7 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
if err := hasBlock.blockstore.Put(block); err != nil {
t.Fatal(err)
}
if err := hasBlock.exchange.HasBlock(context.Background(), *block); err != nil {
if err := hasBlock.exchange.HasBlock(context.Background(), block); err != nil {
t.Fatal(err)
}
@ -140,7 +140,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
first := instances[0]
for _, b := range blocks {
first.blockstore.Put(b)
first.exchange.HasBlock(context.Background(), *b)
first.exchange.HasBlock(context.Background(), b)
rs.Announce(first.peer, b.Key())
}
@ -212,7 +212,7 @@ func TestSendToWantingPeer(t *testing.T) {
beta := bg.Next()
t.Logf("Peer %v announes availability of %v\n", w.peer, beta.Key())
ctx, _ = context.WithTimeout(context.Background(), timeout)
if err := w.blockstore.Put(&beta); err != nil {
if err := w.blockstore.Put(beta); err != nil {
t.Fatal(err)
}
w.exchange.HasBlock(ctx, beta)
@ -225,7 +225,7 @@ func TestSendToWantingPeer(t *testing.T) {
t.Logf("%v announces availability of %v\n", o.peer, alpha.Key())
ctx, _ = context.WithTimeout(context.Background(), timeout)
if err := o.blockstore.Put(&alpha); err != nil {
if err := o.blockstore.Put(alpha); err != nil {
t.Fatal(err)
}
o.exchange.HasBlock(ctx, alpha)
@ -254,16 +254,16 @@ type BlockGenerator struct {
seq int
}
func (bg *BlockGenerator) Next() blocks.Block {
func (bg *BlockGenerator) Next() *blocks.Block {
bg.seq++
return *blocks.NewBlock([]byte(string(bg.seq)))
return blocks.NewBlock([]byte(string(bg.seq)))
}
func (bg *BlockGenerator) Blocks(n int) []*blocks.Block {
blocks := make([]*blocks.Block, 0)
for i := 0; i < n; i++ {
b := bg.Next()
blocks = append(blocks, &b)
blocks = append(blocks, b)
}
return blocks
}