Browse code

daemon/libnetwork/types: remove TransportPort.Equal()

The `TransporPort` type is comparable; it doesn't have fields that
require special handling. It's defined as;

// TransportPort represents a local Layer 4 endpoint
type TransportPort struct {
Proto Protocol
Port uint16
}

where `Protocol` is an int (with a stringer interface);

type Protocol uint8

So we can remove the `Equal` method, and simplify places where it's
compared.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/08/11 02:58:46
Showing 3 changed files
... ...
@@ -158,15 +158,9 @@ func compareConnConfig(a, b *connectivityConfiguration) bool {
158 158
 	if a == nil || b == nil {
159 159
 		return false
160 160
 	}
161
-	if len(a.ExposedPorts) != len(b.ExposedPorts) ||
162
-		len(a.PortBindings) != len(b.PortBindings) {
161
+	if !slices.Equal(a.ExposedPorts, b.ExposedPorts) {
163 162
 		return false
164 163
 	}
165
-	for i := 0; i < len(a.ExposedPorts); i++ {
166
-		if !a.ExposedPorts[i].Equal(&b.ExposedPorts[i]) {
167
-			return false
168
-		}
169
-	}
170 164
 	for i := 0; i < len(a.PortBindings); i++ {
171 165
 		if !comparePortBinding(&a.PortBindings[i].PortBinding, &b.PortBindings[i].PortBinding) {
172 166
 			return false
... ...
@@ -154,7 +154,7 @@ func matchLink(l stubFirewallerLink, parentIP, childIP netip.Addr, ports []types
154 154
 		return false
155 155
 	}
156 156
 	for i, p := range l.ports {
157
-		if !p.Equal(&ports[i]) {
157
+		if p != ports[i] {
158 158
 			return false
159 159
 		}
160 160
 	}
... ...
@@ -43,23 +43,6 @@ type TransportPort struct {
43 43
 	Port  uint16
44 44
 }
45 45
 
46
-// Equal checks if this instance of TransportPort is equal to the passed one
47
-func (t *TransportPort) Equal(o *TransportPort) bool {
48
-	if t == o {
49
-		return true
50
-	}
51
-
52
-	if o == nil {
53
-		return false
54
-	}
55
-
56
-	if t.Proto != o.Proto || t.Port != o.Port {
57
-		return false
58
-	}
59
-
60
-	return true
61
-}
62
-
63 46
 // String returns the TransportPort structure in string form
64 47
 func (t *TransportPort) String() string {
65 48
 	return fmt.Sprintf("%s/%d", t.Proto.String(), t.Port)