Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
buf = builder.start_frame(QuicFrameType.CRYPTO)
buf.push_bytes(bytes(100))
self.assertFalse(builder.packet_is_empty)
# INITIAL, empty
builder.start_packet(PACKET_TYPE_INITIAL, crypto)
self.assertTrue(builder.packet_is_empty)
# check datagrams
datagrams, packets = builder.flush()
self.assertEqual(len(datagrams), 1)
self.assertEqual(len(datagrams[0]), 145)
self.assertEqual(
packets,
[
QuicSentPacket(
epoch=Epoch.INITIAL,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=0,
packet_type=PACKET_TYPE_INITIAL,
sent_bytes=145,
)
],
)
# check builder
self.assertEqual(builder.packet_number, 1)
self.assertEqual(builder.remaining_flight_space, 773)
buf = builder.start_frame(QuicFrameType.CRYPTO)
buf.push_bytes(bytes(builder.remaining_flight_space))
self.assertFalse(builder.packet_is_empty)
with self.assertRaises(QuicPacketBuilderStop):
builder.start_packet(PACKET_TYPE_ONE_RTT, crypto)
# check datagrams
datagrams, packets = builder.flush()
self.assertEqual(len(datagrams), 1)
self.assertEqual(len(datagrams[0]), 800)
self.assertEqual(
packets,
[
QuicSentPacket(
epoch=Epoch.ONE_RTT,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=0,
packet_type=PACKET_TYPE_ONE_RTT,
sent_bytes=800,
)
],
)
# check builder
self.assertEqual(builder.packet_number, 1)
buf = builder.start_frame(QuicFrameType.CRYPTO)
buf.push_bytes(bytes(builder.remaining_flight_space))
self.assertFalse(builder.packet_is_empty)
with self.assertRaises(QuicPacketBuilderStop):
builder.start_packet(PACKET_TYPE_ONE_RTT, crypto)
# check datagrams
datagrams, packets = builder.flush()
self.assertEqual(len(datagrams), 2)
self.assertEqual(len(datagrams[0]), 1280)
self.assertEqual(len(datagrams[1]), 720)
self.assertEqual(
packets,
[
QuicSentPacket(
epoch=Epoch.ONE_RTT,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=0,
packet_type=PACKET_TYPE_ONE_RTT,
sent_bytes=1280,
),
QuicSentPacket(
epoch=Epoch.ONE_RTT,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=1,
packet_type=PACKET_TYPE_ONE_RTT,
sent_bytes=720,
buf = builder.start_frame(QuicFrameType.CRYPTO)
buf.push_bytes(bytes(100))
self.assertFalse(builder.packet_is_empty)
# INITIAL, empty
builder.start_packet(PACKET_TYPE_INITIAL, crypto)
self.assertTrue(builder.packet_is_empty)
# check datagrams
datagrams, packets = builder.flush()
self.assertEqual(len(datagrams), 1)
self.assertEqual(len(datagrams[0]), 1280)
self.assertEqual(
packets,
[
QuicSentPacket(
epoch=Epoch.INITIAL,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=0,
packet_type=PACKET_TYPE_INITIAL,
sent_bytes=1280,
)
],
)
# check builder
self.assertEqual(builder.packet_number, 1)
buf = builder.start_frame(QuicFrameType.CRYPTO)
buf.push_bytes(bytes(builder.remaining_flight_space))
self.assertFalse(builder.packet_is_empty)
with self.assertRaises(QuicPacketBuilderStop):
builder.start_packet(PACKET_TYPE_ONE_RTT, crypto)
builder.start_frame(QuicFrameType.CRYPTO)
# check datagrams
datagrams, packets = builder.flush()
self.assertEqual(len(datagrams), 1)
self.assertEqual(len(datagrams[0]), 1000)
self.assertEqual(
packets,
[
QuicSentPacket(
epoch=Epoch.ONE_RTT,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=0,
packet_type=PACKET_TYPE_ONE_RTT,
sent_bytes=1000,
),
],
)
# check builder
self.assertEqual(builder.packet_number, 1)
buf.push_bytes(bytes(builder.remaining_flight_space))
self.assertFalse(builder.packet_is_empty)
# ONE_RTT, empty
builder.start_packet(PACKET_TYPE_ONE_RTT, crypto)
self.assertTrue(builder.packet_is_empty)
# check datagrams
datagrams, packets = builder.flush()
self.assertEqual(len(datagrams), 2)
self.assertEqual(len(datagrams[0]), 1280)
self.assertEqual(len(datagrams[1]), 1280)
self.assertEqual(
packets,
[
QuicSentPacket(
epoch=Epoch.INITIAL,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=0,
packet_type=PACKET_TYPE_INITIAL,
sent_bytes=1280,
),
QuicSentPacket(
epoch=Epoch.ONE_RTT,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=False,
packet_number=1,
packet_type=PACKET_TYPE_ONE_RTT,
sent_bytes=1280,
def test_on_packet_lost_crypto(self):
packet = QuicSentPacket(
epoch=tls.Epoch.INITIAL,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=0,
packet_type=PACKET_TYPE_INITIAL,
sent_bytes=1280,
sent_time=123.45,
)
space = self.INITIAL_SPACE
self.recovery.on_packet_sent(packet, space)
self.assertEqual(self.recovery.bytes_in_flight, 1280)
self.assertEqual(space.ack_eliciting_in_flight, 1)
self.assertEqual(len(space.sent_packets), 1)
builder.start_packet(PACKET_TYPE_ONE_RTT, crypto)
buf = builder.start_frame(QuicFrameType.ACK)
buf.push_bytes(bytes(64))
with self.assertRaises(QuicPacketBuilderStop):
builder.start_packet(PACKET_TYPE_ONE_RTT, crypto)
builder.start_frame(QuicFrameType.CRYPTO)
# check datagrams
datagrams, packets = builder.flush()
self.assertEqual(len(datagrams), 1)
self.assertEqual(len(datagrams[0]), 92)
self.assertEqual(
packets,
[
QuicSentPacket(
epoch=Epoch.ONE_RTT,
in_flight=False,
is_ack_eliciting=False,
is_crypto_packet=False,
packet_number=0,
packet_type=PACKET_TYPE_ONE_RTT,
sent_bytes=92,
),
],
)
# check builder
self.assertEqual(builder.packet_number, 1)
buf.push_bytes(bytes(100))
self.assertFalse(builder.packet_is_empty)
# INITIAL, empty
builder.start_packet(PACKET_TYPE_INITIAL, crypto)
self.assertTrue(builder.packet_is_empty)
# check datagrams
datagrams, packets = builder.flush()
self.assertEqual(len(datagrams), 2)
self.assertEqual(len(datagrams[0]), 1280)
self.assertEqual(len(datagrams[1]), 1280)
self.assertEqual(
packets,
[
QuicSentPacket(
epoch=Epoch.INITIAL,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=0,
packet_type=PACKET_TYPE_INITIAL,
sent_bytes=1280,
),
QuicSentPacket(
epoch=Epoch.INITIAL,
in_flight=True,
is_ack_eliciting=True,
is_crypto_packet=True,
packet_number=1,
packet_type=PACKET_TYPE_INITIAL,
sent_bytes=1280,
def test_on_ack_received_non_ack_eliciting(self):
packet = QuicSentPacket(
epoch=tls.Epoch.ONE_RTT,
in_flight=True,
is_ack_eliciting=False,
is_crypto_packet=False,
packet_number=0,
packet_type=PACKET_TYPE_ONE_RTT,
sent_bytes=1280,
sent_time=123.45,
)
space = self.ONE_RTT_SPACE
# Â packet sent
self.recovery.on_packet_sent(packet, space)
self.assertEqual(self.recovery.bytes_in_flight, 1280)
self.assertEqual(space.ack_eliciting_in_flight, 0)
self.assertEqual(len(space.sent_packets), 1)