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

Remove IsFDCostlyTransport #31

Merged
merged 1 commit into from
Feb 12, 2021
Merged
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
15 changes: 0 additions & 15 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ func SubtractFilter(addrs ...ma.Multiaddr) func(ma.Multiaddr) bool {
}
}

// IsFDCostlyTransport returns true for transports that require a new file
// descriptor per connection created
func IsFDCostlyTransport(a ma.Multiaddr) bool {
res := false

ma.ForEach(a, func(c ma.Component) bool {
if c.Protocol().Code == ma.P_TCP {
res = true
return false
}
return true
})
return res
}

// FilterNeg returns a negated version of the passed in filter
func FilterNeg(f func(ma.Multiaddr) bool) func(ma.Multiaddr) bool {
return func(a ma.Multiaddr) bool {
Expand Down
58 changes: 0 additions & 58 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,3 @@ func TestSubtractAndNegFilter(t *testing.T) {
t.Errorf("Expected only one remaining address: %s", localhost.String())
}
}

func TestIsFDCostlyTransport(t *testing.T) {
tcpMa := newMultiaddr(t, "/ip4/127.0.0.1/tcp/1234")
if ok := IsFDCostlyTransport(tcpMa); !ok {
t.Errorf("Expected address %s to need a new file descriptor per new connection", tcpMa.String())
}
udpMa := newMultiaddr(t, "/ip4/127.0.0.1/udp/1234")
if ok := IsFDCostlyTransport(udpMa); ok {
t.Errorf("Expected address %s to not need a new file descriptor per new connection", udpMa.String())
}
}

func TestIsFDCostly(t *testing.T) {
good := []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"),
newMultiaddr(t, "/ip6/fe80::/tcp/1234/http"),
newMultiaddr(t, "/ip4/127.0.0.1/tcp/1234/http"),
}

bad := []ma.Multiaddr{
newMultiaddr(t, "/ip4/127.0.0.1/udp/1234"),
newMultiaddr(t, "/ip4/0.0.0.0/udp/1234/utp"),
newMultiaddr(t, "/ip6/::1/udp/1234"),
newMultiaddr(t, "/ip6/::/udp/1234"),
}

for _, a := range bad {
if IsFDCostlyTransport(a) {
t.Errorf("addr %s should not be fd costly", a)
}
}

for _, a := range good {
if !IsFDCostlyTransport(a) {
t.Errorf("addr %s should be fd costly", a)
}
}
}

func TestIsFdCostlyMalformed(t *testing.T) {
bad := []ma.Multiaddr{
newMultiaddr(t, "/ip4/127.0.0.1/"),
newMultiaddr(t, "/ip4/0.0.0.0/"),
newMultiaddr(t, "/ip6/::1/"),
newMultiaddr(t, "/ip6/::/"),
}

for _, a := range bad {
if IsFDCostlyTransport(a) {
t.Errorf("addr %s should not be fd costly", a)
}
}
}