Commit a7511437 authored by Jorropo's avatar Jorropo

Remove `IsFDCostlyTransport`

parent 60fd7d35
......@@ -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 {
......
......@@ -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)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment