Releases: multiformats/go-multiaddr
v0.15.0
Breaking Changes
- There is no
Multiaddr
interface type. - Multiaddr is now a concrete type of
[]Component
. Not an interface. - Empty Multiaddrs should be checked
len(ma) == 0
, exactly how slices should be checked withlen(s) == 0
rather thans == nil
. - Components do not implement
Multiaddr
as there is noMultiaddr
to implement. The do implement aMultiaddrer
interface that lets them convert to Multiaddrs. Multiaddr
can no longer be a key in a Map. If you want unique Multiaddrs, usestring(Multiaddr.Bytes())
orMultiaddr.String()
as the key, otherwise you can use the pointer value*Multiaddr
.
Why?
This library has had multiple issues related to Multiaddr being an interface. Many methods use and return nil as the zero value, which behaves poorly when the user forgets to do a nil check on every returned value and attempts to call a method on the nil pointer. For example, using Split to split a Multiaddr and then using Join to rebuild the original Multiaddr historically would panic in case one side of the split was nil. Using an interface also leads to incorrect usages of == to check if two Multiaddrs were equal (would only work for pointer equality) and, likewise, incorrectly using Multiaddr as a key for a map.
Using an interface is typically done to provide a consistent API surface for multiple implementing types. In practice however, the Multiaddr interface was only implemented for multiaddr and component (with arguably some awkwardness when using a component as a Multiaddr).
The better approach is to use a concrete type for a Multiaddr. This lets pointer receiver methods work even if the pointer is nil, since the compiler already knows which function to call. Most methods now take a value rather than a pointer which avoids the issue of a nil pointer dereference completely.
What's changed
v0.15 refactors the codebase to make it much harder to hit nil pointer dereference panics.
It does so by taking a different approach to how we've treated multiaddrs in the past. Instead of attempting to make them a general datastructure, we focus on treating them as just an encoding scheme. Users of multiaddrs are expected to parse the multiaddr into some struct that is suitable for their use case, and use the multiaddr form when interoperating. By treating Multiaddrs as just an encoding scheme we can make a number of simplifications in the codebase. Specifically we now:
- Remove the Multiaddr interface.
- Make Multiaddr a concrete type of []Component
Migration
Refer to ./v015-MIGRATION.md for breaking changes and migration tips
Full Changelog: v0.14.0...v0.15.0
v0.14.0
What's Changed
- Make it safe to roundtrip Split... and Join by @MarcoPolo in #250
- check for nil interfaces by @MarcoPolo in #251
- nit: validate ipcidr by @MarcoPolo in #247
- ci: uci/update-go by @web3-bot in #253
- feat: memory multiaddrs by @pyropy in #256
New Contributors
Full Changelog: v0.13.0...v0.14.0
v0.13.0
v0.12.4
What's Changed
Improved classification of IPv6 public addresses. For details see:
Full Changelog: v0.12.3...v0.12.4
v0.12.3
What's Changed
- .Decapsulate by Components by @MarcoPolo in #239
- chore: Expand comment ForEach by @MarcoPolo in #238
Full Changelog: v0.12.2...v0.12.3
v0.12.2
What's Changed
- replace custom random tests with testing.F by @sukunrt in #227
- Small fixes to parsing ports by @0xTylerHolmes in #228
- add round trip equality check to fuzz tests by @sukunrt in #232
New Contributors
- @0xTylerHolmes made their first contribution in #228
Full Changelog: v0.12.1...v0.12.2
v0.12.1
What's Changed
- Bump gopkg.in/yaml.v3 from 3.0.0-20200313102051-9f266ea9e77c to 3.0.0 by @dependabot in #218
- build(deps): bump golang.org/x/crypto from 0.1.0 to 0.17.0 by @dependabot in #224
- manet: reduce allocations in resolve unspecified address by @sukunrt in #225
Full Changelog: v0.12.0...v0.12.1
v0.12.0
What's Changed
- ci: uci/delete-templates by @web3-bot in #215
- ci: uci/copy-templates by @web3-bot in #216
- ci: uci/copy-templates by @web3-bot in #217
- net: consider dns addresses as public by @sukunrt in #220
- net: consider /dns/localhost as private address by @sukunrt in #221
Full Changelog: v0.11.0...v0.12.0
v0.11.0
v0.10.1
What's Changed
Full Changelog: v0.10.0...v0.10.1