Hacker News new | ask | show | jobs
by Retr0id 27 days ago
With IPv6 it's plausible that you can avoid collisions as long as you use an expensive hash function, but for v4 how do you avoid IP collisions?

With only 22 bits of entropy in your v4 addresses, you'll get accidental collisions with only ~2000 users.

1 comments

Indeed. So what we do is build your ipv4 using private key bits + collision_index. It is not perfect but it has worked in our tests. We'll keep improving it.

The collision_index is incremented when a collision happens on a network. Let's say you join network A, B, C. But when you join C, another peer has the same IP. The coordinator (which is a role anybody can have in the network) will not accept you in the network unless you change your IP. Which means you need to increase your collision index. Now that process is repeated N times until you don't collide with any other peer.

So I'd have a different IP on each network?

(I really hope "private key" was a typo of "public key"?)

Indeed, it is a typo of `public key`. What I mean is that your identity is your private key. And no, you won't have a new IP per network. Your IP is `fnv1a(ip || index) when index > 0`. Which changes your IP in all of the networks. That's why we also implemented MagicDNS. You can just use your `user.ray` name. The daemon handles IP changes.
So every time you join a new network, your IP in the others can change?
No, only once if there is a collision, which is 1/4M
That's a "yes"