Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gx update and fix code to use new Cid type #7

Merged
merged 2 commits into from
Sep 12, 2018
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 .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.11: QmUy9RAnhX9LBEUbhg8mvrouMRsoF27ycvT2iZsSG8V7Sv
0.3.0: QmSFHnkFwayfnRKK1Z8jBUauMYMkHrZpQyvbxkFoPYb1VQ
4 changes: 2 additions & 2 deletions composed.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ func (cr *Compose) GetValue(ctx context.Context, key string, opts ...ropts.Optio
// Provide adds the given cid to the content routing system. If 'true' is
// passed, it also announces it, otherwise it is just kept in the local
// accounting of which objects are being provided.
func (cr *Compose) Provide(ctx context.Context, c *cid.Cid, local bool) error {
func (cr *Compose) Provide(ctx context.Context, c cid.Cid, local bool) error {
if cr.ContentRouting == nil {
return routing.ErrNotSupported
}
return cr.ContentRouting.Provide(ctx, c, local)
}

// FindProvidersAsync searches for peers who are able to provide a given key
func (cr *Compose) FindProvidersAsync(ctx context.Context, c *cid.Cid, count int) <-chan pstore.PeerInfo {
func (cr *Compose) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan pstore.PeerInfo {
if cr.ContentRouting == nil {
ch := make(chan pstore.PeerInfo)
close(ch)
Expand Down
10 changes: 5 additions & 5 deletions dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (d *dummyValueStore) GetValue(ctx context.Context, key string, opts ...ropt

type dummyProvider map[string][]peer.ID

func (d dummyProvider) FindProvidersAsync(ctx context.Context, c *cid.Cid, count int) <-chan pstore.PeerInfo {
func (d dummyProvider) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan pstore.PeerInfo {
peers := d[c.KeyString()]
if len(peers) > count {
peers = peers[:count]
Expand All @@ -68,17 +68,17 @@ func (d dummyProvider) FindProvidersAsync(ctx context.Context, c *cid.Cid, count
return out
}

func (d dummyProvider) Provide(ctx context.Context, c *cid.Cid, local bool) error {
func (d dummyProvider) Provide(ctx context.Context, c cid.Cid, local bool) error {
return routing.ErrNotSupported
}

type cbProvider func(c *cid.Cid, local bool) error
type cbProvider func(c cid.Cid, local bool) error

func (d cbProvider) Provide(ctx context.Context, c *cid.Cid, local bool) error {
func (d cbProvider) Provide(ctx context.Context, c cid.Cid, local bool) error {
return d(c, local)
}

func (d cbProvider) FindProvidersAsync(ctx context.Context, c *cid.Cid, count int) <-chan pstore.PeerInfo {
func (d cbProvider) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan pstore.PeerInfo {
ch := make(chan pstore.PeerInfo)
close(ch)
return ch
Expand Down
4 changes: 2 additions & 2 deletions null.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func (nr Null) GetValue(context.Context, string, ...ropts.Option) ([]byte, error
}

// Provide always returns ErrNotSupported
func (nr Null) Provide(context.Context, *cid.Cid, bool) error {
func (nr Null) Provide(context.Context, cid.Cid, bool) error {
return routing.ErrNotSupported
}

// FindProvidersAsync always returns a closed channel
func (nr Null) FindProvidersAsync(context.Context, *cid.Cid, int) <-chan pstore.PeerInfo {
func (nr Null) FindProvidersAsync(context.Context, cid.Cid, int) <-chan pstore.PeerInfo {
ch := make(chan pstore.PeerInfo)
close(ch)
return ch
Expand Down
5 changes: 3 additions & 2 deletions null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

cid "github.com/ipfs/go-cid"
peer "github.com/libp2p/go-libp2p-peer"
routing "github.com/libp2p/go-libp2p-routing"
)
Expand All @@ -17,10 +18,10 @@ func TestNull(t *testing.T) {
if _, err := n.GetValue(ctx, "anything", nil); err != routing.ErrNotFound {
t.Fatal(err)
}
if err := n.Provide(ctx, nil, false); err != routing.ErrNotSupported {
if err := n.Provide(ctx, cid.Cid{}, false); err != routing.ErrNotSupported {
t.Fatal(err)
}
if _, ok := <-n.FindProvidersAsync(ctx, nil, 10); ok {
if _, ok := <-n.FindProvidersAsync(ctx, cid.Cid{}, 10); ok {
t.Fatal("expected no values")
}
if _, err := n.FindPeer(ctx, peer.ID("thing")); err != routing.ErrNotFound {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"gxDependencies": [
{
"author": "whyrusleeping",
"hash": "QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb",
"hash": "QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7",
"name": "go-cid",
"version": "0.8.0"
"version": "0.9.0"
},
{
"author": "whyrusleeping",
Expand All @@ -38,9 +38,9 @@
"version": "2.0.0"
},
{
"hash": "QmY9JUvS8kbgao3XbPh6WAV3ChE2nxGKhcGTHiwMC4gmcU",
"hash": "QmdKS5YtmuSWKuLLgbHG176mS3VX3AKiyVmaaiAfvgcuch",
"name": "go-libp2p-routing",
"version": "2.4.10"
"version": "2.5.0"
},
{
"author": "hashicorp",
Expand All @@ -60,6 +60,6 @@
"license": "MIT",
"name": "go-libp2p-routing-helpers",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "0.2.11"
"version": "0.3.0"
}

4 changes: 2 additions & 2 deletions parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ func (r Parallel) FindPeer(ctx context.Context, p peer.ID) (pstore.PeerInfo, err
return pi, err
}

func (r Parallel) Provide(ctx context.Context, c *cid.Cid, local bool) error {
func (r Parallel) Provide(ctx context.Context, c cid.Cid, local bool) error {
return r.filter(func(ri routing.IpfsRouting) bool {
return supportsContent(ri)
}).put(func(ri routing.IpfsRouting) error {
return ri.Provide(ctx, c, local)
})
}

func (r Parallel) FindProvidersAsync(ctx context.Context, c *cid.Cid, count int) <-chan pstore.PeerInfo {
func (r Parallel) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan pstore.PeerInfo {
routers := r.filter(func(ri routing.IpfsRouting) bool {
return supportsContent(ri)
})
Expand Down
6 changes: 3 additions & 3 deletions parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestParallelFindProviders(t *testing.T) {
for i := 0; i < 2; i++ {

for i, tc := range []struct {
cid *cid.Cid
cid cid.Cid
providers []peer.ID
}{
{
Expand Down Expand Up @@ -370,12 +370,12 @@ func TestParallelProvide(t *testing.T) {
d := Parallel{
Parallel{
&Compose{
ContentRouting: cbProvider(func(c *cid.Cid, local bool) error {
ContentRouting: cbProvider(func(c cid.Cid, local bool) error {
return routing.ErrNotSupported
}),
},
&Compose{
ContentRouting: cbProvider(func(c *cid.Cid, local bool) error {
ContentRouting: cbProvider(func(c cid.Cid, local bool) error {
return errors.New(c.String())
}),
},
Expand Down
4 changes: 2 additions & 2 deletions tiered.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func (r Tiered) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)
return val, err
}

func (r Tiered) Provide(ctx context.Context, c *cid.Cid, local bool) error {
func (r Tiered) Provide(ctx context.Context, c cid.Cid, local bool) error {
return Parallel(r).Provide(ctx, c, local)
}

func (r Tiered) FindProvidersAsync(ctx context.Context, c *cid.Cid, count int) <-chan pstore.PeerInfo {
func (r Tiered) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan pstore.PeerInfo {
return Parallel(r).FindProvidersAsync(ctx, c, count)
}

Expand Down
3 changes: 2 additions & 1 deletion tiered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

errwrap "github.com/hashicorp/errwrap"
cid "github.com/ipfs/go-cid"
routing "github.com/libp2p/go-libp2p-routing"
)

Expand Down Expand Up @@ -85,7 +86,7 @@ func TestTieredGet(t *testing.T) {

func TestTieredNoSupport(t *testing.T) {
d := Tiered{Tiered{Null{}}}
if _, ok := <-d.FindProvidersAsync(context.Background(), nil, 0); ok {
if _, ok := <-d.FindProvidersAsync(context.Background(), cid.Cid{}, 0); ok {
t.Fatal("shouldn't have found a provider")
}
}