Skip to content

Commit 4cbb4f8

Browse files
remove ConnectionID.Equal function
Connection IDs can now be compared with ==.
1 parent 1aced95 commit 4cbb4f8

File tree

9 files changed

+17
-34
lines changed

9 files changed

+17
-34
lines changed

conn_id_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (m *connIDGenerator) Retire(seq uint64, sentWithDestConnID protocol.Connect
8484
if !ok {
8585
return nil
8686
}
87-
if connID.Equal(sentWithDestConnID) {
87+
if connID == sentWithDestConnID {
8888
return &qerr.TransportError{
8989
ErrorCode: qerr.ProtocolViolation,
9090
ErrorMessage: fmt.Sprintf("retired connection ID %d (%s), which was used as the Destination Connection ID on this packet", seq, connID),

conn_id_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (h *connIDManager) addConnectionID(seq uint64, connID protocol.ConnectionID
121121
// insert a new element somewhere in the middle
122122
for el := h.queue.Front(); el != nil; el = el.Next() {
123123
if el.Value.SequenceNumber == seq {
124-
if !el.Value.ConnectionID.Equal(connID) {
124+
if el.Value.ConnectionID != connID {
125125
return fmt.Errorf("received conflicting connection IDs for sequence number %d", seq)
126126
}
127127
if el.Value.StatelessResetToken != resetToken {

conn_id_manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ var _ = Describe("Connection ID Manager", func() {
278278
m.SentPacket()
279279

280280
connID := m.Get()
281-
if !connID.Equal(lastConnID) {
281+
if connID != lastConnID {
282282
counter++
283283
lastConnID = connID
284284
Expect(removedTokens).To(HaveLen(1))
@@ -306,7 +306,7 @@ var _ = Describe("Connection ID Manager", func() {
306306
Expect(m.Get()).To(Equal(protocol.ParseConnectionID([]byte{10, 10, 10, 10})))
307307
for {
308308
m.SentPacket()
309-
if m.Get().Equal(protocol.ParseConnectionID([]byte{11, 11, 11, 11})) {
309+
if m.Get() == protocol.ParseConnectionID([]byte{11, 11, 11, 11}) {
310310
break
311311
}
312312
}

connection.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ func (s *connection) handlePacketImpl(rp *receivedPacket) bool {
881881
break
882882
}
883883

884-
if counter > 0 && !hdr.DestConnectionID.Equal(lastConnID) {
884+
if counter > 0 && hdr.DestConnectionID != lastConnID {
885885
if s.tracer != nil {
886886
s.tracer.DroppedPacket(logging.PacketTypeFromHeader(hdr), protocol.ByteCount(len(data)), logging.PacketDropUnknownConnectionID)
887887
}
@@ -925,7 +925,7 @@ func (s *connection) handleSinglePacket(p *receivedPacket, hdr *wire.Header) boo
925925

926926
// The server can change the source connection ID with the first Handshake packet.
927927
// After this, all packets with a different source connection have to be ignored.
928-
if s.receivedFirstPacket && hdr.IsLongHeader && hdr.Type == protocol.PacketTypeInitial && !hdr.SrcConnectionID.Equal(s.handshakeDestConnID) {
928+
if s.receivedFirstPacket && hdr.IsLongHeader && hdr.Type == protocol.PacketTypeInitial && hdr.SrcConnectionID != s.handshakeDestConnID {
929929
if s.tracer != nil {
930930
s.tracer.DroppedPacket(logging.PacketTypeInitial, p.Size(), logging.PacketDropUnknownConnectionID)
931931
}
@@ -1017,7 +1017,7 @@ func (s *connection) handleRetryPacket(hdr *wire.Header, data []byte) bool /* wa
10171017
return false
10181018
}
10191019
destConnID := s.connIDManager.Get()
1020-
if hdr.SrcConnectionID.Equal(destConnID) {
1020+
if hdr.SrcConnectionID == destConnID {
10211021
if s.tracer != nil {
10221022
s.tracer.DroppedPacket(logging.PacketTypeRetry, protocol.ByteCount(len(data)), logging.PacketDropUnexpectedPacket)
10231023
}
@@ -1143,7 +1143,7 @@ func (s *connection) handleUnpackedPacket(
11431143
s.tracer.NegotiatedVersion(s.version, clientVersions, serverVersions)
11441144
}
11451145
// The server can change the source connection ID with the first Handshake packet.
1146-
if s.perspective == protocol.PerspectiveClient && packet.hdr.IsLongHeader && !packet.hdr.SrcConnectionID.Equal(s.handshakeDestConnID) {
1146+
if s.perspective == protocol.PerspectiveClient && packet.hdr.IsLongHeader && packet.hdr.SrcConnectionID != s.handshakeDestConnID {
11471147
cid := packet.hdr.SrcConnectionID
11481148
s.logger.Debugf("Received first packet. Switching destination connection ID to: %s", cid)
11491149
s.handshakeDestConnID = cid
@@ -1155,7 +1155,7 @@ func (s *connection) handleUnpackedPacket(
11551155
// we might have create a connection with an incorrect source connection ID.
11561156
// Once we authenticate the first packet, we need to update it.
11571157
if s.perspective == protocol.PerspectiveServer {
1158-
if !packet.hdr.SrcConnectionID.Equal(s.handshakeDestConnID) {
1158+
if packet.hdr.SrcConnectionID != s.handshakeDestConnID {
11591159
s.handshakeDestConnID = packet.hdr.SrcConnectionID
11601160
s.connIDManager.ChangeInitialConnID(packet.hdr.SrcConnectionID)
11611161
}
@@ -1601,22 +1601,22 @@ func (s *connection) checkTransportParameters(params *wire.TransportParameters)
16011601
}
16021602

16031603
// check the initial_source_connection_id
1604-
if !params.InitialSourceConnectionID.Equal(s.handshakeDestConnID) {
1604+
if params.InitialSourceConnectionID != s.handshakeDestConnID {
16051605
return fmt.Errorf("expected initial_source_connection_id to equal %s, is %s", s.handshakeDestConnID, params.InitialSourceConnectionID)
16061606
}
16071607

16081608
if s.perspective == protocol.PerspectiveServer {
16091609
return nil
16101610
}
16111611
// check the original_destination_connection_id
1612-
if !params.OriginalDestinationConnectionID.Equal(s.origDestConnID) {
1612+
if params.OriginalDestinationConnectionID != s.origDestConnID {
16131613
return fmt.Errorf("expected original_destination_connection_id to equal %s, is %s", s.origDestConnID, params.OriginalDestinationConnectionID)
16141614
}
16151615
if s.retrySrcConnID != nil { // a Retry was performed
16161616
if params.RetrySourceConnectionID == nil {
16171617
return errors.New("missing retry_source_connection_id")
16181618
}
1619-
if !(*params.RetrySourceConnectionID).Equal(*s.retrySrcConnID) {
1619+
if *params.RetrySourceConnectionID != *s.retrySrcConnID {
16201620
return fmt.Errorf("expected retry_source_connection_id to equal %s, is %s", s.retrySrcConnID, *params.RetrySourceConnectionID)
16211621
}
16221622
} else if params.RetrySourceConnectionID != nil {

fuzzing/header/fuzz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Fuzz(data []byte) int {
3535
if err != nil {
3636
return 0
3737
}
38-
if !hdr.DestConnectionID.Equal(connID) {
38+
if hdr.DestConnectionID != connID {
3939
panic(fmt.Sprintf("Expected connection IDs to match: %s vs %s", hdr.DestConnectionID, connID))
4040
}
4141
if (hdr.Type == protocol.PacketType0RTT) != is0RTTPacket {

fuzzing/tokens/fuzz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ func newRetryToken(tg *handshake.TokenGenerator, data []byte) int {
132132
if token.SentTime.Before(start) || token.SentTime.After(time.Now()) {
133133
panic("incorrect send time")
134134
}
135-
if !token.OriginalDestConnectionID.Equal(origDestConnID) {
135+
if token.OriginalDestConnectionID != origDestConnID {
136136
panic("orig dest conn ID doesn't match")
137137
}
138-
if !token.RetrySrcConnectionID.Equal(retrySrcConnID) {
138+
if token.RetrySrcConnectionID != retrySrcConnID {
139139
panic("retry src conn ID doesn't match")
140140
}
141141
return 1

integrationtests/self/zero_rtt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,13 @@ var _ = Describe("0-RTT", func() {
417417
if firstConnID == nil {
418418
firstConnID = &connID
419419
firstCounter += zeroRTTBytes
420-
} else if firstConnID != nil && firstConnID.Equal(connID) {
420+
} else if firstConnID != nil && *firstConnID == connID {
421421
Expect(secondConnID).To(BeNil())
422422
firstCounter += zeroRTTBytes
423423
} else if secondConnID == nil {
424424
secondConnID = &connID
425425
secondCounter += zeroRTTBytes
426-
} else if secondConnID != nil && secondConnID.Equal(connID) {
426+
} else if secondConnID != nil && *secondConnID == connID {
427427
secondCounter += zeroRTTBytes
428428
} else {
429429
Fail("received 3 connection IDs on 0-RTT packets")

internal/protocol/connection_id.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ func ReadConnectionID(r io.Reader, l int) (ConnectionID, error) {
8686
return c, err
8787
}
8888

89-
// Equal says if two connection IDs are equal
90-
func (c ConnectionID) Equal(other ConnectionID) bool {
91-
return c == other
92-
}
93-
9489
// Len returns the length of the connection ID in bytes
9590
func (c ConnectionID) Len() int {
9691
return int(c.l)

internal/protocol/connection_id_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ var _ = Describe("Connection ID generation", func() {
4343
Expect(has20ByteConnID).To(BeTrue())
4444
})
4545

46-
It("says if connection IDs are equal", func() {
47-
c1 := ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8})
48-
c2 := ParseConnectionID([]byte{8, 7, 6, 5, 4, 3, 2, 1})
49-
c3 := ParseConnectionID([]byte{1, 2, 3, 4, 5, 6, 7, 8})
50-
Expect(c1.Equal(c1)).To(BeTrue())
51-
Expect(c1.Equal(c3)).To(BeTrue())
52-
Expect(c2.Equal(c2)).To(BeTrue())
53-
Expect(c2.Equal(c3)).To(BeFalse())
54-
Expect(c1.Equal(c2)).To(BeFalse())
55-
Expect(c2.Equal(c1)).To(BeFalse())
56-
})
57-
5846
It("reads the connection ID", func() {
5947
buf := bytes.NewBuffer([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9})
6048
c, err := ReadConnectionID(buf, 9)

0 commit comments

Comments
 (0)