mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
remove unneeded packet number field from the unpackedPacket
This commit is contained in:
parent
7d827d515e
commit
fd1b3a23c4
4 changed files with 37 additions and 26 deletions
|
@ -982,11 +982,11 @@ func (s *connection) handleSinglePacket(p *receivedPacket, hdr *wire.Header) boo
|
|||
}
|
||||
|
||||
if s.logger.Debug() {
|
||||
s.logger.Debugf("<- Reading packet %d (%d bytes) for connection %s, %s", packet.packetNumber, p.Size(), hdr.DestConnectionID, packet.encryptionLevel)
|
||||
s.logger.Debugf("<- Reading packet %d (%d bytes) for connection %s, %s", packet.hdr.PacketNumber, p.Size(), hdr.DestConnectionID, packet.encryptionLevel)
|
||||
packet.hdr.Log(s.logger)
|
||||
}
|
||||
|
||||
if s.receivedPacketHandler.IsPotentiallyDuplicate(packet.packetNumber, packet.encryptionLevel) {
|
||||
if s.receivedPacketHandler.IsPotentiallyDuplicate(packet.hdr.PacketNumber, packet.encryptionLevel) {
|
||||
s.logger.Debugf("Dropping (potentially) duplicate packet.")
|
||||
if s.tracer != nil {
|
||||
s.tracer.DroppedPacket(logging.PacketTypeFromHeader(hdr), p.Size(), logging.PacketDropDuplicate)
|
||||
|
@ -1214,7 +1214,7 @@ func (s *connection) handleUnpackedPacket(
|
|||
}
|
||||
}
|
||||
|
||||
return s.receivedPacketHandler.ReceivedPacket(packet.packetNumber, ecn, packet.encryptionLevel, rcvTime, isAckEliciting)
|
||||
return s.receivedPacketHandler.ReceivedPacket(packet.hdr.PacketNumber, ecn, packet.encryptionLevel, rcvTime, isAckEliciting)
|
||||
}
|
||||
|
||||
func (s *connection) handleFrame(f wire.Frame, encLevel protocol.EncryptionLevel, destConnID protocol.ConnectionID) error {
|
||||
|
|
|
@ -731,13 +731,14 @@ var _ = Describe("Connection", func() {
|
|||
PacketNumber: 0x37,
|
||||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
}
|
||||
unpackedHdr := *hdr
|
||||
unpackedHdr.PacketNumber = 0x1337
|
||||
packet := getPacket(hdr, nil)
|
||||
packet.ecn = protocol.ECNCE
|
||||
rcvTime := time.Now().Add(-10 * time.Second)
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), rcvTime, gomock.Any()).Return(&unpackedPacket{
|
||||
packetNumber: 0x1337,
|
||||
encryptionLevel: protocol.EncryptionInitial,
|
||||
hdr: hdr,
|
||||
hdr: &unpackedHdr,
|
||||
data: []byte{0}, // one PADDING frame
|
||||
}, nil)
|
||||
rph := mockackhandler.NewMockReceivedPacketHandler(mockCtrl)
|
||||
|
@ -748,7 +749,7 @@ var _ = Describe("Connection", func() {
|
|||
conn.receivedPacketHandler = rph
|
||||
packet.rcvTime = rcvTime
|
||||
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
|
||||
tracer.EXPECT().ReceivedPacket(hdr, protocol.ByteCount(len(packet.data)), []logging.Frame{})
|
||||
tracer.EXPECT().ReceivedPacket(&unpackedHdr, protocol.ByteCount(len(packet.data)), []logging.Frame{})
|
||||
Expect(conn.handlePacketImpl(packet)).To(BeTrue())
|
||||
})
|
||||
|
||||
|
@ -758,15 +759,16 @@ var _ = Describe("Connection", func() {
|
|||
PacketNumber: 0x37,
|
||||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
}
|
||||
unpackedHdr := *hdr
|
||||
unpackedHdr.PacketNumber = 0x1337
|
||||
rcvTime := time.Now().Add(-10 * time.Second)
|
||||
b, err := (&wire.PingFrame{}).Append(nil, conn.version)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
packet := getPacket(hdr, nil)
|
||||
packet.ecn = protocol.ECT1
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), rcvTime, gomock.Any()).Return(&unpackedPacket{
|
||||
packetNumber: 0x1337,
|
||||
encryptionLevel: protocol.Encryption1RTT,
|
||||
hdr: hdr,
|
||||
hdr: &unpackedHdr,
|
||||
data: b,
|
||||
}, nil)
|
||||
rph := mockackhandler.NewMockReceivedPacketHandler(mockCtrl)
|
||||
|
@ -777,7 +779,7 @@ var _ = Describe("Connection", func() {
|
|||
conn.receivedPacketHandler = rph
|
||||
packet.rcvTime = rcvTime
|
||||
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
|
||||
tracer.EXPECT().ReceivedPacket(hdr, protocol.ByteCount(len(packet.data)), []logging.Frame{&logging.PingFrame{}})
|
||||
tracer.EXPECT().ReceivedPacket(&unpackedHdr, protocol.ByteCount(len(packet.data)), []logging.Frame{&logging.PingFrame{}})
|
||||
Expect(conn.handlePacketImpl(packet)).To(BeTrue())
|
||||
})
|
||||
|
||||
|
@ -788,12 +790,15 @@ var _ = Describe("Connection", func() {
|
|||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
}
|
||||
packet := getPacket(hdr, nil)
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(&unpackedPacket{
|
||||
packetNumber: 0x1337,
|
||||
encryptionLevel: protocol.Encryption1RTT,
|
||||
hdr: hdr,
|
||||
data: []byte("foobar"),
|
||||
}, nil)
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(*wire.Header, time.Time, []byte) (*unpackedPacket, error) {
|
||||
h := *hdr
|
||||
h.PacketNumber = 0x1337
|
||||
return &unpackedPacket{
|
||||
encryptionLevel: protocol.Encryption1RTT,
|
||||
hdr: &h,
|
||||
data: []byte("foobar"),
|
||||
}, nil
|
||||
})
|
||||
rph := mockackhandler.NewMockReceivedPacketHandler(mockCtrl)
|
||||
rph.EXPECT().IsPotentiallyDuplicate(protocol.PacketNumber(0x1337), protocol.Encryption1RTT).Return(true)
|
||||
conn.receivedPacketHandler = rph
|
||||
|
@ -842,8 +847,10 @@ var _ = Describe("Connection", func() {
|
|||
return &unpackedPacket{
|
||||
data: []byte{0}, // PADDING frame
|
||||
encryptionLevel: protocol.Encryption1RTT,
|
||||
packetNumber: pn,
|
||||
hdr: &wire.ExtendedHeader{Header: *hdr},
|
||||
hdr: &wire.ExtendedHeader{
|
||||
Header: *hdr,
|
||||
PacketNumber: pn,
|
||||
},
|
||||
}, nil
|
||||
}).Times(3)
|
||||
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
|
||||
|
@ -887,8 +894,10 @@ var _ = Describe("Connection", func() {
|
|||
return &unpackedPacket{
|
||||
data: []byte{0}, // PADDING frame
|
||||
encryptionLevel: protocol.Encryption1RTT,
|
||||
packetNumber: pn,
|
||||
hdr: &wire.ExtendedHeader{Header: *hdr},
|
||||
hdr: &wire.ExtendedHeader{
|
||||
Header: *hdr,
|
||||
PacketNumber: pn,
|
||||
},
|
||||
}, nil
|
||||
}).Times(3)
|
||||
tracer.EXPECT().StartedConnection(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
|
||||
|
@ -1160,8 +1169,10 @@ var _ = Describe("Connection", func() {
|
|||
return &unpackedPacket{
|
||||
encryptionLevel: protocol.EncryptionHandshake,
|
||||
data: []byte{0},
|
||||
packetNumber: 1,
|
||||
hdr: &wire.ExtendedHeader{Header: wire.Header{SrcConnectionID: destConnID}},
|
||||
hdr: &wire.ExtendedHeader{
|
||||
PacketNumber: 1,
|
||||
Header: wire.Header{SrcConnectionID: destConnID},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
hdrLen2, packet2 := getPacketWithLength(srcConnID, 123)
|
||||
|
@ -1170,8 +1181,10 @@ var _ = Describe("Connection", func() {
|
|||
return &unpackedPacket{
|
||||
encryptionLevel: protocol.EncryptionHandshake,
|
||||
data: []byte{0},
|
||||
packetNumber: 2,
|
||||
hdr: &wire.ExtendedHeader{Header: wire.Header{SrcConnectionID: destConnID}},
|
||||
hdr: &wire.ExtendedHeader{
|
||||
PacketNumber: 2,
|
||||
Header: wire.Header{SrcConnectionID: destConnID},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
gomock.InOrder(
|
||||
|
|
|
@ -27,7 +27,6 @@ func (e *headerParseError) Error() string {
|
|||
}
|
||||
|
||||
type unpackedPacket struct {
|
||||
packetNumber protocol.PacketNumber // the decoded packet number
|
||||
hdr *wire.ExtendedHeader
|
||||
encryptionLevel protocol.EncryptionLevel
|
||||
data []byte
|
||||
|
@ -105,7 +104,6 @@ func (u *packetUnpacker) Unpack(hdr *wire.Header, rcvTime time.Time, data []byte
|
|||
|
||||
return &unpackedPacket{
|
||||
hdr: extHdr,
|
||||
packetNumber: extHdr.PacketNumber,
|
||||
encryptionLevel: encLevel,
|
||||
data: decrypted,
|
||||
}, nil
|
||||
|
|
|
@ -287,6 +287,6 @@ var _ = Describe("Packet Unpacker", func() {
|
|||
}
|
||||
packet, err := unpacker.Unpack(hdr, time.Now(), data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.packetNumber).To(Equal(protocol.PacketNumber(0x7331)))
|
||||
Expect(packet.hdr.PacketNumber).To(Equal(protocol.PacketNumber(0x7331)))
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue