Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
1617759f
Commit
1617759f
authored
May 24, 2021
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(net): export new net.Addr conversion registration functions
fixes #151
parent
32974f6a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
net/registry.go
net/registry.go
+16
-6
No files found.
net/registry.go
View file @
1617759f
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment