mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 15:42:21 +08:00
refac(routing) replace timeout -> ctx
@jbenet oh hai there!
This commit is contained in:
@ -22,7 +22,7 @@ import (
|
|||||||
type Routing interface {
|
type Routing interface {
|
||||||
// FindProvidersAsync returns a channel of providers for the given key
|
// FindProvidersAsync returns a channel of providers for the given key
|
||||||
// TODO replace with timeout with context
|
// 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 provides the key to the network
|
||||||
Provide(key u.Key) error
|
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
|
// TODO replace timeout with ctx in routing interface
|
||||||
begin := time.Now()
|
begin := time.Now()
|
||||||
tleft := timeout - time.Now().Sub(begin)
|
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)
|
blockChannel := make(chan blocks.Block)
|
||||||
after := time.After(tleft)
|
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
|
// 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 {
|
func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int) <-chan *peer.Peer {
|
||||||
ctx, _ := context.WithTimeout(context.TODO(), timeout)
|
|
||||||
|
|
||||||
peerOut := make(chan *peer.Peer, count)
|
peerOut := make(chan *peer.Peer, count)
|
||||||
go func() {
|
go func() {
|
||||||
ps := newPeerSet()
|
ps := newPeerSet()
|
||||||
|
@ -3,6 +3,8 @@ package routing
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||||
|
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
)
|
)
|
||||||
@ -10,7 +12,7 @@ import (
|
|||||||
// IpfsRouting is the routing module interface
|
// IpfsRouting is the routing module interface
|
||||||
// It is implemented by things like DHTs, etc.
|
// It is implemented by things like DHTs, etc.
|
||||||
type IpfsRouting interface {
|
type IpfsRouting interface {
|
||||||
FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer
|
FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer
|
||||||
|
|
||||||
// Basic Put/Get
|
// Basic Put/Get
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user