Skip to content

Commit 5bd241d

Browse files
committed
use NewComponent in FromIP
This allows us to do less string-parsing.
1 parent 03e871b commit 5bd241d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

convert.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ func parseBasicNetMaddr(maddr ma.Multiaddr) (net.Addr, error) {
6868

6969
// FromIP converts a net.IP type to a Multiaddr.
7070
func FromIP(ip net.IP) (ma.Multiaddr, error) {
71+
var proto string
7172
switch {
7273
case ip.To4() != nil:
73-
return ma.NewMultiaddr("/ip4/" + ip.String())
74+
proto = "ip4"
7475
case ip.To16() != nil:
75-
return ma.NewMultiaddr("/ip6/" + ip.String())
76+
proto = "ip6"
7677
default:
7778
return nil, errIncorrectNetAddr
7879
}
80+
return ma.NewComponent(proto, ip.String())
7981
}
8082

8183
// DialArgs is a convenience function returning arguments for use in net.Dial

0 commit comments

Comments
 (0)