Skip to content

Commit ef7ebf9

Browse files
committed
rename, comment, and move loopback prefixes
Helps readers understand what they're looking at.
1 parent d176203 commit ef7ebf9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ip.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ var (
2424
IP6Unspecified = ma.StringCast("/ip6/::")
2525
)
2626

27+
// Loopback multiaddr prefixes. Any multiaddr beginning with one of the
28+
// following byte sequences is considered a loopback multiaddr.
29+
var loopbackPrefixes = [][]byte{
30+
{ma.P_IP4, 127}, // 127.*
31+
IP6LinkLocalLoopback.Bytes(),
32+
IP6Loopback.Bytes(),
33+
}
34+
2735
// IsThinWaist returns whether a Multiaddr starts with "Thin Waist" Protocols.
2836
// This means: /{IP4, IP6}[/{TCP, UDP}]
2937
func IsThinWaist(m ma.Multiaddr) bool {
@@ -51,17 +59,11 @@ func IsThinWaist(m ma.Multiaddr) bool {
5159
}
5260
}
5361

54-
var localPrefixes = [][]byte{
55-
{ma.P_IP4, 127}, // 127.*
56-
IP6LinkLocalLoopback.Bytes(),
57-
IP6Loopback.Bytes(),
58-
}
59-
6062
// IsIPLoopback returns whether a Multiaddr is a "Loopback" IP address
6163
// This means either /ip4/127.*.*.*, /ip6/::1, or /ip6/fe80::1
6264
func IsIPLoopback(m ma.Multiaddr) bool {
6365
b := m.Bytes()
64-
for _, prefix := range localPrefixes {
66+
for _, prefix := range loopbackPrefixes {
6567
if bytes.HasPrefix(b, prefix) {
6668
return true
6769
}

0 commit comments

Comments
 (0)