Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Exchange don't add blocks on their own anymore #47

Merged
merged 3 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/ipfs/go-datastore v0.5.0
github.com/ipfs/go-ipfs-blockstore v1.2.0
github.com/ipfs/go-ipfs-blocksutil v0.0.1
github.com/ipfs/go-ipfs-exchange-interface v0.1.0
github.com/ipfs/go-ipfs-exchange-interface v0.2.0
github.com/ipfs/go-ipfs-util v0.0.2
github.com/ipfs/go-ipld-format v0.3.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/ipfs/go-ipfs-blocksutil v0.0.1/go.mod h1:Yq4M86uIOmxmGPUHv/uI7uKqZNtL
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
github.com/ipfs/go-ipfs-ds-help v1.1.0 h1:yLE2w9RAsl31LtfMt91tRZcrx+e61O5mDxFRR994w4Q=
github.com/ipfs/go-ipfs-ds-help v1.1.0/go.mod h1:YR5+6EaebOhfcqVCyqemItCLthrpVNot+rsOU/5IatU=
github.com/ipfs/go-ipfs-exchange-interface v0.1.0 h1:TiMekCrOGQuWYtZO3mf4YJXDIdNgnKWZ9IE3fGlnWfo=
github.com/ipfs/go-ipfs-exchange-interface v0.1.0/go.mod h1:ych7WPlyHqFvCi/uQI48zLZuAWVP5iTQPXEfVaw5WEI=
github.com/ipfs/go-ipfs-exchange-interface v0.2.0 h1:8lMSJmKogZYNo2jjhUs0izT+dck05pqUw4mWNW9Pw6Y=
github.com/ipfs/go-ipfs-exchange-interface v0.2.0/go.mod h1:z6+RhJuDQbqKguVyslSOuVDhqF9JtTrO3eptSAiW2/Y=
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8=
github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ=
Expand Down
11 changes: 4 additions & 7 deletions offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ func (e *offlineExchange) GetBlock(ctx context.Context, k cid.Cid) (blocks.Block
return blk, err
}

// HasBlock always returns nil.
func (e *offlineExchange) HasBlock(ctx context.Context, b blocks.Block) error {
return e.bs.Put(ctx, b)
// NotifyNewBlocks tells the exchange that new blocks are available and can be served.
func (e *offlineExchange) NotifyNewBlocks(ctx context.Context, blocks ...blocks.Block) error {
// as an offline exchange we have nothing to do
return nil
}

// Close always returns nil.
Expand Down Expand Up @@ -71,7 +72,3 @@ func (e *offlineExchange) GetBlocks(ctx context.Context, ks []cid.Cid) (<-chan b
}()
return out, nil
}

func (e *offlineExchange) IsOnline() bool {
return false
}
21 changes: 4 additions & 17 deletions offline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"testing"

blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
ds_sync "github.com/ipfs/go-datastore/sync"
Expand All @@ -23,21 +22,6 @@ func TestBlockReturnsErr(t *testing.T) {
t.Fail()
}

func TestHasBlockReturnsNil(t *testing.T) {
store := bstore()
ex := Exchange(store)
block := blocks.NewBlock([]byte("data"))

err := ex.HasBlock(context.Background(), block)
if err != nil {
t.Fail()
}

if _, err := store.Get(context.Background(), block.Cid()); err != nil {
t.Fatal(err)
}
}

func TestGetBlocks(t *testing.T) {
store := bstore()
ex := Exchange(store)
Expand All @@ -46,7 +30,10 @@ func TestGetBlocks(t *testing.T) {
expected := g.Blocks(2)

for _, b := range expected {
if err := ex.HasBlock(context.Background(), b); err != nil {
if err := store.Put(context.Background(), b); err != nil {
t.Fatal(err)
}
if err := ex.NotifyNewBlocks(context.Background(), b); err != nil {
t.Fail()
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.2.0"
"version": "v0.3.0"
}