-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use xor-compare for finding closer peers #2538
Conversation
Switches from array compare to xor compare as this is how we're supposed to measure distance between two peers. Also stores `PeerInfo`s in peer distance list instead of `PeerId`s so to not lose the peers found in a query that are not in the peer store yet.
import { convertPeerId, getDistance } from '../utils.js' | ||
import type { PeerId } from '@libp2p/interface' | ||
import { xor as uint8ArrayXor } from 'uint8arrays/xor' | ||
import { xorCompare as uint8ArrayXorCompare } from 'uint8arrays/xor-compare' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for future reference, this was added in achingbrain/uint8arrays#89
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the change to XOR comparison overall but left some comments.
peerId: PeerId | ||
distance: bigint | ||
peer: PeerInfo | ||
distance: Uint8Array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this ends up getting converted to a bigint
what's the rationale behind changing these to Uint8Array
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're linking to main there - it no longer gets converted to a bigint, instead the Uint8Array
s are the xor distances that get compared using xorCompare
.
Co-authored-by: Chad Nehemiah <chad.nehemiah94@gmail.com>
Switches from array compare to xor compare as this is how we're supposed to measure distance between two peers.
Also stores
PeerInfo
s in peer distance list instead ofPeerId
s so to not lose the peers found in a query that are not in the peer store yet.Change checklist