Ejemplo n.º 1
0
def encode_frame(frame_type: int, frame_data: bytes) -> bytes:
    frame_length = len(frame_data)
    buf = Buffer(capacity=frame_length + 16)
    buf.push_uint_var(frame_type)
    buf.push_uint_var(frame_length)
    buf.push_bytes(frame_data)
    return buf.data
Ejemplo n.º 2
0
 def encode(self) -> bytes:
     """
     Encodes this H3Capsule and return the bytes.
     """
     buffer = Buffer(capacity=len(self.data) + 2 * UINT_VAR_MAX_SIZE)
     buffer.push_uint_var(self.type)
     buffer.push_uint_var(len(self.data))
     buffer.push_bytes(self.data)
     return buffer.data
Ejemplo n.º 3
0
    def close(self, close_info: Optional[Tuple[int, bytes]]) -> None:
        """
        Close the session.

        :param close_info The close information to send.
        """
        self._protocol._allow_calling_session_closed = False
        assert self._protocol._session_stream_id is not None
        session_stream_id = self._protocol._session_stream_id
        if close_info is not None:
            code = close_info[0]
            reason = close_info[1]
            buffer = Buffer(capacity=len(reason) + 4)
            buffer.push_uint32(code)
            buffer.push_bytes(reason)
            capsule =\
                H3Capsule(CapsuleType.CLOSE_WEBTRANSPORT_SESSION, buffer.data)
            self._http.send_data(session_stream_id, capsule.encode(), end_stream=False)

        self._http.send_data(session_stream_id, b'', end_stream=True)
Ejemplo n.º 4
0
 def create_packet(key_phase, packet_number):
     buf = Buffer(capacity=100)
     buf.push_uint8(PACKET_FIXED_BIT | key_phase << 2 | 1)
     buf.push_bytes(binascii.unhexlify("8394c8f03e515708"))
     buf.push_uint16(packet_number)
     return buf.data, b"\x00\x01\x02\x03"
Ejemplo n.º 5
0
 def test_push_bytes_zero(self):
     buf = Buffer(capacity=3)
     buf.push_bytes(b"")
     self.assertEqual(buf.data, b"")
     self.assertEqual(buf.tell(), 0)
Ejemplo n.º 6
0
 def test_push_bytes_truncated(self):
     buf = Buffer(capacity=3)
     with self.assertRaises(BufferWriteError):
         buf.push_bytes(b"\x08\x07\x06\x05")
     self.assertEqual(buf.tell(), 0)
Ejemplo n.º 7
0
 def test_push_bytes(self):
     buf = Buffer(capacity=3)
     buf.push_bytes(b"\x08\x07\x06")
     self.assertEqual(buf.data, b"\x08\x07\x06")
     self.assertEqual(buf.tell(), 3)