Merge pull request #152 from multiformats/fix/export-register

fix(net): export new net.Addr conversion registration functions
This commit is contained in:
Steven Allen 2021-05-29 19:36:18 -07:00 committed by GitHub
commit 5c39a31660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -17,13 +17,13 @@ type ToNetAddrFunc func(ma ma.Multiaddr) (net.Addr, error)
var defaultCodecs = NewCodecMap()
func init() {
defaultCodecs.RegisterFromNetAddr(parseTCPNetAddr, "tcp", "tcp4", "tcp6")
defaultCodecs.RegisterFromNetAddr(parseUDPNetAddr, "udp", "udp4", "udp6")
defaultCodecs.RegisterFromNetAddr(parseIPNetAddr, "ip", "ip4", "ip6")
defaultCodecs.RegisterFromNetAddr(parseIPPlusNetAddr, "ip+net")
defaultCodecs.RegisterFromNetAddr(parseUnixNetAddr, "unix")
RegisterFromNetAddr(parseTCPNetAddr, "tcp", "tcp4", "tcp6")
RegisterFromNetAddr(parseUDPNetAddr, "udp", "udp4", "udp6")
RegisterFromNetAddr(parseIPNetAddr, "ip", "ip4", "ip6")
RegisterFromNetAddr(parseIPPlusNetAddr, "ip+net")
RegisterFromNetAddr(parseUnixNetAddr, "unix")
defaultCodecs.RegisterToNetAddr(parseBasicNetMaddr, "tcp", "udp", "ip6", "ip4", "unix")
RegisterToNetAddr(parseBasicNetMaddr, "tcp", "udp", "ip6", "ip4", "unix")
}
// CodecMap holds a map of NetCodecs indexed by their Protocol ID
@ -77,6 +77,16 @@ func RegisterNetCodec(a *NetCodec) {
defaultCodecs.RegisterNetCodec(a)
}
// RegisterFromNetAddr registers a conversion from net.Addr instances to multiaddrs.
func RegisterFromNetAddr(from FromNetAddrFunc, networks ...string) {
defaultCodecs.RegisterFromNetAddr(from, networks...)
}
// RegisterToNetAddr registers a conversion from multiaddrs to net.Addr instances.
func RegisterToNetAddr(to ToNetAddrFunc, protocols ...string) {
defaultCodecs.RegisterToNetAddr(to, protocols...)
}
// RegisterNetCodec adds a new NetCodec to the CodecMap. This function is
// thread safe.
func (cm *CodecMap) RegisterNetCodec(a *NetCodec) {