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