mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
fix(routing:dht) implement FindProvidersAsync in terms of FindProviders
until construction is complete on the actual async method
reverts changes from ec50703395098f75946f0bad01816cc54ab18a58
ec50703395
This commit is contained in:
@ -115,8 +115,26 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindProvidersAsync runs FindProviders and sends back results over a channel
|
// NB: not actually async. Used to keep the interface consistent while the
|
||||||
|
// actual async method, FindProvidersAsync2 is under construction
|
||||||
func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int) <-chan *peer.Peer {
|
func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int) <-chan *peer.Peer {
|
||||||
|
ch := make(chan *peer.Peer)
|
||||||
|
providers, err := dht.FindProviders(ctx, key)
|
||||||
|
if err != nil {
|
||||||
|
close(ch)
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
defer close(ch)
|
||||||
|
for _, p := range providers {
|
||||||
|
ch <- p
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: there's a bug here!
|
||||||
|
func (dht *IpfsDHT) FindProvidersAsync2(ctx context.Context, key u.Key, count int) <-chan *peer.Peer {
|
||||||
peerOut := make(chan *peer.Peer, count)
|
peerOut := make(chan *peer.Peer, count)
|
||||||
go func() {
|
go func() {
|
||||||
ps := newPeerSet()
|
ps := newPeerSet()
|
||||||
|
Reference in New Issue
Block a user