mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-03 05:23:08 +00:00
commit
1cb9a0e8a6
@ -6,7 +6,7 @@ sudo: true
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.9.x
|
||||
- 1.11
|
||||
|
||||
install:
|
||||
- make deps
|
||||
|
||||
10
ip.go
10
ip.go
@ -14,8 +14,8 @@ var (
|
||||
// IP6Loopback is the ip6 loopback multiaddr
|
||||
IP6Loopback = ma.StringCast("/ip6/::1")
|
||||
|
||||
// IP6LinkLocalLoopback is the ip6 link-local loopback multiaddr
|
||||
IP6LinkLocalLoopback = ma.StringCast("/ip6/fe80::1")
|
||||
// IP4MappedIP6Loopback is the IPv4 Mapped IPv6 loopback address.
|
||||
IP4MappedIP6Loopback = ma.StringCast("/ip6/::ffff:127.0.0.1")
|
||||
)
|
||||
|
||||
// Unspecified Addresses (used for )
|
||||
@ -28,8 +28,8 @@ var (
|
||||
// following byte sequences is considered a loopback multiaddr.
|
||||
var loopbackPrefixes = [][]byte{
|
||||
{ma.P_IP4, 127}, // 127.*
|
||||
IP6LinkLocalLoopback.Bytes(),
|
||||
IP6Loopback.Bytes(),
|
||||
{ma.P_IP6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 127}, // ::ffff:127.*
|
||||
IP6Loopback.Bytes(), // ::1
|
||||
}
|
||||
|
||||
// IsThinWaist returns whether a Multiaddr starts with "Thin Waist" Protocols.
|
||||
@ -60,7 +60,7 @@ func IsThinWaist(m ma.Multiaddr) bool {
|
||||
}
|
||||
|
||||
// IsIPLoopback returns whether a Multiaddr is a "Loopback" IP address
|
||||
// This means either /ip4/127.*.*.*, /ip6/::1, or /ip6/fe80::1
|
||||
// This means either /ip4/127.*.*.*, /ip6/::1, or /ip6/::ffff:127.*.*.*.*
|
||||
func IsIPLoopback(m ma.Multiaddr) bool {
|
||||
b := m.Bytes()
|
||||
for _, prefix := range loopbackPrefixes {
|
||||
|
||||
20
net_test.go
20
net_test.go
@ -306,8 +306,8 @@ func TestIPLoopback(t *testing.T) {
|
||||
t.Error("IP6Loopback incorrect:", IP6Loopback)
|
||||
}
|
||||
|
||||
if IP6LinkLocalLoopback.String() != "/ip6/fe80::1" {
|
||||
t.Error("IP6LinkLocalLoopback incorrect:", IP6Loopback)
|
||||
if IP4MappedIP6Loopback.String() != "/ip6/127.0.0.1" {
|
||||
t.Error("IP4MappedIP6Loopback incorrect:", IP4MappedIP6Loopback)
|
||||
}
|
||||
|
||||
if !IsIPLoopback(IP4Loopback) {
|
||||
@ -330,8 +330,16 @@ func TestIPLoopback(t *testing.T) {
|
||||
t.Error("IsIPLoopback failed (IP6Loopback)")
|
||||
}
|
||||
|
||||
if !IsIPLoopback(IP6LinkLocalLoopback) {
|
||||
t.Error("IsIPLoopback failed (IP6LinkLocalLoopback)")
|
||||
if !IsIPLoopback(newMultiaddr(t, "/ip6/127.0.0.1")) {
|
||||
t.Error("IsIPLoopback failed (/ip6/127.0.0.1)")
|
||||
}
|
||||
|
||||
if !IsIPLoopback(newMultiaddr(t, "/ip6/127.99.3.2")) {
|
||||
t.Error("IsIPLoopback failed (/ip6/127.99.3.2)")
|
||||
}
|
||||
|
||||
if IsIPLoopback(newMultiaddr(t, "/ip6/::fffa:127.99.3.2")) {
|
||||
t.Error("IsIPLoopback false positive (/ip6/::fffa:127.99.3.2)")
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,10 +362,6 @@ func TestIPUnspecified(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIP6LinkLocal(t *testing.T) {
|
||||
if !IsIP6LinkLocal(IP6LinkLocalLoopback) {
|
||||
t.Error("IsIP6LinkLocal failed (IP6LinkLocalLoopback)")
|
||||
}
|
||||
|
||||
for a := 0; a < 65536; a++ {
|
||||
isLinkLocal := (a == 0xfe80)
|
||||
m := newMultiaddr(t, fmt.Sprintf("/ip6/%x::1", a))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user