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
Hide 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)
...
@@ -17,13 +17,13 @@ type ToNetAddrFunc func(ma ma.Multiaddr) (net.Addr, error)
var
defaultCodecs
=
NewCodecMap
()
var
defaultCodecs
=
NewCodecMap
()
func
init
()
{
func
init
()
{
defaultCodecs
.
RegisterFromNetAddr
(
parseTCPNetAddr
,
"tcp"
,
"tcp4"
,
"tcp6"
)
RegisterFromNetAddr
(
parseTCPNetAddr
,
"tcp"
,
"tcp4"
,
"tcp6"
)
defaultCodecs
.
RegisterFromNetAddr
(
parseUDPNetAddr
,
"udp"
,
"udp4"
,
"udp6"
)
RegisterFromNetAddr
(
parseUDPNetAddr
,
"udp"
,
"udp4"
,
"udp6"
)
defaultCodecs
.
RegisterFromNetAddr
(
parseIPNetAddr
,
"ip"
,
"ip4"
,
"ip6"
)
RegisterFromNetAddr
(
parseIPNetAddr
,
"ip"
,
"ip4"
,
"ip6"
)
defaultCodecs
.
RegisterFromNetAddr
(
parseIPPlusNetAddr
,
"ip+net"
)
RegisterFromNetAddr
(
parseIPPlusNetAddr
,
"ip+net"
)
defaultCodecs
.
RegisterFromNetAddr
(
parseUnixNetAddr
,
"unix"
)
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
// CodecMap holds a map of NetCodecs indexed by their Protocol ID
...
@@ -77,6 +77,16 @@ func RegisterNetCodec(a *NetCodec) {
...
@@ -77,6 +77,16 @@ func RegisterNetCodec(a *NetCodec) {
defaultCodecs
.
RegisterNetCodec
(
a
)
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
// RegisterNetCodec adds a new NetCodec to the CodecMap. This function is
// thread safe.
// thread safe.
func
(
cm
*
CodecMap
)
RegisterNetCodec
(
a
*
NetCodec
)
{
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