From 0bd8f2092b488ebfe5f954ebcce65199d58df47a Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow <brian.holderchow@gmail.com> Date: Thu, 18 Sep 2014 19:15:15 -0700 Subject: [PATCH] refac(routing) replace timeout -> ctx @jbenet oh hai there! --- exchange/bitswap/bitswap.go | 4 ++-- routing/dht/routing.go | 4 +--- routing/routing.go | 4 +++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 82d60317..9cd59af8 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -22,7 +22,7 @@ import ( type Routing interface { // FindProvidersAsync returns a channel of providers for the given key // TODO replace with timeout with context - FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer + FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer // Provide provides the key to the network Provide(key u.Key) error @@ -74,7 +74,7 @@ func (bs *bitswap) Block(k u.Key, timeout time.Duration) ( // TODO replace timeout with ctx in routing interface begin := time.Now() tleft := timeout - time.Now().Sub(begin) - provs_ch := bs.routing.FindProvidersAsync(k, 20, timeout) + provs_ch := bs.routing.FindProvidersAsync(ctx, k, 20) blockChannel := make(chan blocks.Block) after := time.After(tleft) diff --git a/routing/dht/routing.go b/routing/dht/routing.go index 4991a06f..9e6c5ff2 100644 --- a/routing/dht/routing.go +++ b/routing/dht/routing.go @@ -121,9 +121,7 @@ func (dht *IpfsDHT) Provide(key u.Key) error { } // FindProvidersAsync runs FindProviders and sends back results over a channel -func (dht *IpfsDHT) FindProvidersAsync(key u.Key, count int, timeout time.Duration) <-chan *peer.Peer { - ctx, _ := context.WithTimeout(context.TODO(), timeout) - +func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int) <-chan *peer.Peer { peerOut := make(chan *peer.Peer, count) go func() { ps := newPeerSet() diff --git a/routing/routing.go b/routing/routing.go index c8dc2772..872bad6f 100644 --- a/routing/routing.go +++ b/routing/routing.go @@ -3,6 +3,8 @@ package routing import ( "time" + context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" + peer "github.com/jbenet/go-ipfs/peer" u "github.com/jbenet/go-ipfs/util" ) @@ -10,7 +12,7 @@ import ( // IpfsRouting is the routing module interface // It is implemented by things like DHTs, etc. type IpfsRouting interface { - FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer + FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer // Basic Put/Get -- GitLab