Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

remove unused WAN functions #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,6 @@ func AddrInList(addr ma.Multiaddr, list []ma.Multiaddr) bool {
return false
}

// AddrIsShareableOnWAN returns whether the given address should be shareable on the
// wide area network (wide internet).
func AddrIsShareableOnWAN(addr ma.Multiaddr) bool {
s := ma.Split(addr)
if len(s) < 1 {
return false
}
a := s[0]
if manet.IsIPLoopback(a) || manet.IsIP6LinkLocal(a) || manet.IsIPUnspecified(a) {
return false
}
return manet.IsThinWaist(a)
}

// WANShareableAddrs filters addresses based on whether they're shareable on WAN
func WANShareableAddrs(inp []ma.Multiaddr) []ma.Multiaddr {
return FilterAddrs(inp, AddrIsShareableOnWAN)
}

// Subtract filters out all addrs in b from a
func Subtract(a, b []ma.Multiaddr) []ma.Multiaddr {
return FilterAddrs(a, func(m ma.Multiaddr) bool {
Expand Down
39 changes: 0 additions & 39 deletions addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,45 +137,6 @@ func TestResolvingAddrs(t *testing.T) {

}

func TestWANShareable(t *testing.T) {

wanok := []ma.Multiaddr{
newMultiaddr(t, "/ip4/1.2.3.4/tcp/1234"),
newMultiaddr(t, "/ip6/abcd::1/tcp/1234"),
}

wanbad := []ma.Multiaddr{
newMultiaddr(t, "/ip4/127.0.0.1/tcp/1234"),
newMultiaddr(t, "/ip4/0.0.0.0/tcp/1234"),
newMultiaddr(t, "/ip6/::1/tcp/1234"),
newMultiaddr(t, "/ip6/::/tcp/1234"),
newMultiaddr(t, "/ip6/fe80::1/tcp/1234"),
newMultiaddr(t, "/ip6/fe80::/tcp/1234"),
}

for _, a := range wanok {
if !AddrIsShareableOnWAN(a) {
t.Error("should be true", a)
}
}

for _, a := range wanbad {
if AddrIsShareableOnWAN(a) {
t.Error("should be false", a)
}
}

wanok2 := WANShareableAddrs(wanok)
if len(wanok) != len(wanok2) {
t.Error("should be the same")
}

wanbad2 := WANShareableAddrs(wanbad)
if len(wanbad2) != 0 {
t.Error("should be zero")
}
}

func TestSubtract(t *testing.T) {

a := []ma.Multiaddr{
Expand Down