We were missing a logarithm... CodeToVarint would previously allocate
more bytes than necessary (exponentially) for the varint slice. This bug
was silent but deserves to be fixed nonetheless.
This method made implementing the manet.Listener interface annoying. Also, this
lets us drop the "use with caution" warning as we're now *wrapping* the listener
instead of exposing internal state.
Decapsulate currently allocates a lot and this appears to have been causing some
issues (hard to tell, pprof is misbehaving).
Note: I removed the TODO as this function now *only* checks if we're dealing
with a loopback address. Not sure what `OverIPLoopback` was supposed to mean.
Note 2: Decapsulate actually checked if the IP6 loopback addresses
appeared *anywhere* in the multiadder. However, as we weren't doing this for
IP4, I decided to simplify this and only check prefixes.
This was showing up on CPU profiles as a significant source of repeated
allocations. We don't really care about over allocation (don't keep these slices
around) and should rarely have more than 8 protocols in a single address.
1. Swap udt/utp.
2. Fix udp (17 is SHA1)
3. Change them to hex so it's easier to compare them with the official
multicodec table.
4. Remove the local protocols.csv table.
Fixes#49Fixesmultiformats/multicodec#51
Currently IsIPLoopback returns true for any multiaddr starting ip4/127, but only returns true on ip6 addresses that exactly equal ip6/::1. So /ip6/::1/tcp/4001 for example does not return true. Instead we should check whether ip6/::1 is contained in the multiaddr, and to do that I simply decapsulated and checked to see if the result is different. It seems this was not caught by tests as none are present specifically for this function.