Commit 0bd8f209 authored by Brian Tiger Chow's avatar Brian Tiger Chow

refac(routing) replace timeout -> ctx

@jbenet oh hai there!
parent 81da645e
......@@ -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)
......
......@@ -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()
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment