mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-07 23:43:10 +00:00
parent
a80cfc331f
commit
41068aa69c
@ -451,6 +451,7 @@ func TestBinaryRepresentation(t *testing.T) {
|
|||||||
func TestRoundTrip(t *testing.T) {
|
func TestRoundTrip(t *testing.T) {
|
||||||
for _, s := range []string{
|
for _, s := range []string{
|
||||||
"/unix/a/b/c/d",
|
"/unix/a/b/c/d",
|
||||||
|
"/ip6/::ffff:127.0.0.1/tcp/111",
|
||||||
"/ip4/127.0.0.1/tcp/123",
|
"/ip4/127.0.0.1/tcp/123",
|
||||||
"/ip4/127.0.0.1/udp/123",
|
"/ip4/127.0.0.1/udp/123",
|
||||||
"/ip4/127.0.0.1/udp/123/ip6/::",
|
"/ip4/127.0.0.1/udp/123/ip6/::",
|
||||||
|
|||||||
@ -46,8 +46,8 @@ func (t twrp) ValidateBytes(b []byte) error {
|
|||||||
return t.validbyte(b)
|
return t.validbyte(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
var TranscoderIP4 = NewTranscoderFromFunctions(ip4StB, ipBtS, nil)
|
var TranscoderIP4 = NewTranscoderFromFunctions(ip4StB, ip4BtS, nil)
|
||||||
var TranscoderIP6 = NewTranscoderFromFunctions(ip6StB, ipBtS, nil)
|
var TranscoderIP6 = NewTranscoderFromFunctions(ip6StB, ip6BtS, nil)
|
||||||
var TranscoderIP6Zone = NewTranscoderFromFunctions(ip6zoneStB, ip6zoneBtS, ip6zoneVal)
|
var TranscoderIP6Zone = NewTranscoderFromFunctions(ip6zoneStB, ip6zoneBtS, ip6zoneVal)
|
||||||
|
|
||||||
func ip4StB(s string) ([]byte, error) {
|
func ip4StB(s string) ([]byte, error) {
|
||||||
@ -88,7 +88,16 @@ func ip6StB(s string) ([]byte, error) {
|
|||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ipBtS(b []byte) (string, error) {
|
func ip6BtS(b []byte) (string, error) {
|
||||||
|
ip := net.IP(b)
|
||||||
|
if ip4 := ip.To4(); ip4 != nil {
|
||||||
|
// Go fails to prepend the `::ffff:` part.
|
||||||
|
return "::ffff:" + ip4.String(), nil
|
||||||
|
}
|
||||||
|
return ip.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ip4BtS(b []byte) (string, error) {
|
||||||
return net.IP(b).String(), nil
|
return net.IP(b).String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user