intercept failing query events when finding providers

parent 278c3ea7
...@@ -97,8 +97,9 @@ func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) error { ...@@ -97,8 +97,9 @@ func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) error {
func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo { func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo {
reqCtx, cancel := context.WithCancel(ctx) reqCtx, cancel := context.WithCancel(ctx)
outCh := make(chan peer.AddrInfo) outCh := make(chan peer.AddrInfo)
wanCh := dht.WAN.FindProvidersAsync(reqCtx, key, count) subCtx, errCh := routing.RegisterForQueryEvents(reqCtx)
lanCh := dht.LAN.FindProvidersAsync(reqCtx, key, count) wanCh := dht.WAN.FindProvidersAsync(subCtx, key, count)
lanCh := dht.LAN.FindProvidersAsync(subCtx, key, count)
zeroCount := (count == 0) zeroCount := (count == 0)
go func() { go func() {
defer cancel() defer cancel()
...@@ -106,9 +107,15 @@ func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) ...@@ -106,9 +107,15 @@ func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int)
found := make(map[peer.ID]struct{}, count) found := make(map[peer.ID]struct{}, count)
var pi peer.AddrInfo var pi peer.AddrInfo
var qEv *routing.QueryEvent
for (zeroCount || count > 0) && (wanCh != nil || lanCh != nil) { for (zeroCount || count > 0) && (wanCh != nil || lanCh != nil) {
var ok bool var ok bool
select { select {
case qEv, ok = <-errCh:
if ok && qEv != nil && qEv.Type != routing.QueryError {
routing.PublishQueryEvent(reqCtx, qEv)
}
continue
case pi, ok = <-wanCh: case pi, ok = <-wanCh:
if !ok { if !ok {
wanCh = nil wanCh = nil
...@@ -133,6 +140,9 @@ func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) ...@@ -133,6 +140,9 @@ func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int)
return return
} }
} }
if qEv != nil && qEv.Type == routing.QueryError && len(found) == 0 {
routing.PublishQueryEvent(reqCtx, qEv)
}
}() }()
return outCh return outCh
} }
......
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