refac(routing) replace timeout -> ctx
@jbenet oh hai there!
Brian Tiger Chow committed
Sep 18, 2014 at 19:15 UTC
0bd8f2092b488ebfe5f954ebcce65199d58df47a
3 files changed
+6
-6
exchange/bitswap/bitswap.go
+2
-2
@@ -22,7 +22,7 @@ import (
22
type Routing interface {
23
// FindProvidersAsync returns a channel of providers for the given key
24
// TODO replace with timeout with context
25
- FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer
25
+ FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer
26
27
// Provide provides the key to the network
28
Provide(key u.Key) error
@@ -74,7 +74,7 @@ func (bs *bitswap) Block(k u.Key, timeout time.Duration) (
74
// TODO replace timeout with ctx in routing interface
75
begin := time.Now()
76
tleft := timeout - time.Now().Sub(begin)
77
- provs_ch := bs.routing.FindProvidersAsync(k, 20, timeout)
77
+ provs_ch := bs.routing.FindProvidersAsync(ctx, k, 20)
78
79
blockChannel := make(chan blocks.Block)
80
after := time.After(tleft)
routing/dht/routing.go
+1
-3
@@ -121,9 +121,7 @@ func (dht *IpfsDHT) Provide(key u.Key) error {
121
}
122
123
// FindProvidersAsync runs FindProviders and sends back results over a channel
124
-func (dht *IpfsDHT) FindProvidersAsync(key u.Key, count int, timeout time.Duration) <-chan *peer.Peer {
125
- ctx, _ := context.WithTimeout(context.TODO(), timeout)
126
-
124
+func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int) <-chan *peer.Peer {
125
peerOut := make(chan *peer.Peer, count)
126
go func() {
127
ps := newPeerSet()
routing/routing.go
+3
-1
@@ -3,6 +3,8 @@ package routing
3
import (
4
"time"
5
6
+ context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
+
8
peer "github.com/jbenet/go-ipfs/peer"
9
u "github.com/jbenet/go-ipfs/util"
10
)
@@ -10,7 +12,7 @@ import (
12
// IpfsRouting is the routing module interface
13
// It is implemented by things like DHTs, etc.
14
type IpfsRouting interface {
13
- FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer
15
+ FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer
16
17
// Basic Put/Get
18