Commit f5423a6a authored by Steven Allen's avatar Steven Allen

don't double-validate values

Also, de-duplicate some logic.
parent f6a03cbb
......@@ -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