holepunchto / hyperswarm

A distributed networking stack for connecting peers.
https://docs.holepunch.to
MIT License
1.04k stars 84 forks source link

Enforce 32-byte length on keys #73

Closed KyleMaas closed 3 years ago

KyleMaas commented 3 years ago

The docs say that both join() and leave() require keys to be 32 bytes, but it's buried in the docs and neither one complains if you give them a Buffer with a different length. They just aren't reliable. This enforces that 32 byte length, adds tests to make sure it's enforcing it, and gives a more helpful error message if you don't abide by that restriction.

I ran into a whole bunch of weird issues when trying to port multiserver-dht from discovery-swarm to Hyperswarm. Turns out a lot of the problems I was running into were due to Hyperswarm expecting a 32 byte key but not complaining if a shorter one was passed to it, which was quite unlike how discovery-swarm worked. Basically independently discovered and encountered the problem in #11.

mafintosh commented 3 years ago

Thanks! The test failure is unrelated

mafintosh commented 3 years ago

2.15.3