Unverified Commit ded67db8 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #185 from libp2p/fix/search-value-nits

don't double-validate values
parents f6a03cbb f5423a6a
......@@ -222,30 +222,24 @@ func (dht *IpfsDHT) SearchValue(ctx context.Context, key string, opts ...ropts.O
}
// Select best value
if best != nil {
if bytes.Equal(best.Val, v.Val) {
continue
}
sel, err := dht.Validator.Select(key, [][]byte{best.Val, v.Val})
if err != nil {
log.Warning("Failed to select dht key: ", err)
continue
}
if sel == 1 && !bytes.Equal(v.Val, best.Val) {
best = &v
select {
case out <- v.Val:
case <-ctx.Done():
return
}
}
} else {
// Output first valid value
if err := dht.Validator.Validate(key, v.Val); err == nil {
best = &v
select {
case out <- v.Val:
case <-ctx.Done():
return
}
if sel != 1 {
continue
}
}
best = &v
select {
case out <- v.Val:
case <-ctx.Done():
return
}
case <-ctx.Done():
return
}
......
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