mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-02 13:03:11 +00:00
remove wrong (and redundant) IsIpv6LinkLocal
This commit is contained in:
parent
114704e81f
commit
dff7fed63c
12
net/ip.go
12
net/ip.go
@ -95,18 +95,6 @@ func IsIPUnspecified(m ma.Multiaddr) bool {
|
||||
return net.IP(c.RawValue()).IsUnspecified()
|
||||
}
|
||||
|
||||
// IsIpv6LinkLocal returns whether the addr uses a non-local ip link
|
||||
func IsIpv6LinkLocal(a ma.Multiaddr) bool {
|
||||
split := ma.Split(a)
|
||||
if len(split) < 1 {
|
||||
return false
|
||||
}
|
||||
if IsIP6LinkLocal(split[0]) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// If m matches [zone,ip6,...], return [ip6,...]
|
||||
// else if m matches [], [zone], or [zone,...], return nil
|
||||
// else return m
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func newMultiaddr(t *testing.T, m string) ma.Multiaddr {
|
||||
@ -449,7 +450,7 @@ func TestIPUnspecified(t *testing.T) {
|
||||
|
||||
func TestIP6LinkLocal(t *testing.T) {
|
||||
for a := 0; a < 65536; a++ {
|
||||
isLinkLocal := (a&0xffc0 == 0xfe80 || a&0xff0f == 0xff02)
|
||||
isLinkLocal := a&0xffc0 == 0xfe80 || a&0xff0f == 0xff02
|
||||
m := newMultiaddr(t, fmt.Sprintf("/ip6/%x::1", a))
|
||||
if IsIP6LinkLocal(m) != isLinkLocal {
|
||||
t.Errorf("IsIP6LinkLocal failed (%s != %v)", m, isLinkLocal)
|
||||
@ -459,6 +460,22 @@ func TestIP6LinkLocal(t *testing.T) {
|
||||
if !IsIP6LinkLocal(newMultiaddr(t, "/ip6zone/hello/ip6/fe80::9999")) {
|
||||
t.Error("IsIP6LinkLocal failed (/ip6/fe80::9999)")
|
||||
}
|
||||
|
||||
bad := []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip6/fe80::1/tcp/1234"), // link local
|
||||
newMultiaddr(t, "/ip6/fe80::100/tcp/1234"), // link local
|
||||
}
|
||||
good := []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip4/127.0.0.1/tcp/1234"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/udp/1234/utp"),
|
||||
}
|
||||
for _, addr := range bad {
|
||||
require.True(t, IsIP6LinkLocal(addr), "%s is a link local addr", addr)
|
||||
}
|
||||
for _, addr := range good {
|
||||
require.False(t, IsIP6LinkLocal(addr), "%s is not a link local addr", addr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertNetAddr(t *testing.T) {
|
||||
|
||||
@ -74,7 +74,7 @@ func interfaceAddresses() ([]ma.Multiaddr, error) {
|
||||
|
||||
var out []ma.Multiaddr
|
||||
for _, a := range maddrs {
|
||||
if !IsIpv6LinkLocal(a) {
|
||||
if IsIP6LinkLocal(a) {
|
||||
continue
|
||||
}
|
||||
out = append(out, a)
|
||||
|
||||
@ -55,21 +55,3 @@ func TestResolvingAddrs(t *testing.T) {
|
||||
t.Fatal("should have failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddrOverNonLocalIP(t *testing.T) {
|
||||
bad := []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip6/fe80::1/tcp/1234"), // link local
|
||||
newMultiaddr(t, "/ip6/fe80::100/tcp/1234"), // link local
|
||||
}
|
||||
good := []ma.Multiaddr{
|
||||
newMultiaddr(t, "/ip4/127.0.0.1/tcp/1234"),
|
||||
newMultiaddr(t, "/ip6/::1/tcp/1234"),
|
||||
newMultiaddr(t, "/ip4/1.2.3.4/udp/1234/utp"),
|
||||
}
|
||||
for _, addr := range bad {
|
||||
require.Falsef(t, IsIpv6LinkLocal(addr), "%s is a link local addr", addr)
|
||||
}
|
||||
for _, addr := range good {
|
||||
require.Truef(t, IsIpv6LinkLocal(addr), "%s is not a link local addr", addr)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user