Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
added discovery options to discovery based content routing
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Sep 6, 2019
1 parent 06d154c commit f3be296
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,26 @@ func nsToCid(ns string) (cid.Cid, error) {
return cid.NewCidV1(cid.Raw, h), nil
}

func NewDiscoveryRouting(disc discovery.Discovery) *DiscoveryRouting {
return &DiscoveryRouting{disc}
func NewDiscoveryRouting(disc discovery.Discovery, opts ...discovery.Option) *DiscoveryRouting {
return &DiscoveryRouting{disc, opts}
}

type DiscoveryRouting struct {
discovery.Discovery
opts []discovery.Option
}

func (r *DiscoveryRouting) Provide(ctx context.Context, c cid.Cid, bcast bool) error {
if !bcast {
return nil
}

_, err := r.Advertise(ctx, cidToNs(c))
_, err := r.Advertise(ctx, cidToNs(c), r.opts...)
return err
}

func (r *DiscoveryRouting) FindProvidersAsync(ctx context.Context, c cid.Cid, limit int) <-chan peer.AddrInfo {
ch, _ := r.FindPeers(ctx, cidToNs(c), discovery.Limit(limit))
ch, _ := r.FindPeers(ctx, cidToNs(c), append([]discovery.Option{discovery.Limit(limit)}, r.opts...)...)
return ch
}

Expand Down
4 changes: 2 additions & 2 deletions routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ func TestDiscoveryRouting(t *testing.T) {
d1 := &mockDiscoveryClient{h1, dserver}
d2 := &mockDiscoveryClient{h2, dserver}

r1 := NewDiscoveryRouting(d1)
r2 := NewDiscoveryRouting(d2)
r1 := NewDiscoveryRouting(d1, discovery.TTL(time.Hour))
r2 := NewDiscoveryRouting(d2, discovery.TTL(time.Hour))

c, err := nsToCid("/test")
if err != nil {
Expand Down

0 comments on commit f3be296

Please sign in to comment.