2023-10-12 20:12:39 +02:00
|
|
|
import cython
|
|
|
|
|
2023-11-16 19:24:50 +01:00
|
|
|
from ..connection cimport APIConnection
|
2023-10-12 20:12:39 +02:00
|
|
|
from .base cimport APIFrameHelper
|
|
|
|
|
|
|
|
|
2023-10-13 03:17:46 +02:00
|
|
|
cdef bint TYPE_CHECKING
|
2023-10-12 20:12:39 +02:00
|
|
|
|
2023-11-17 00:50:54 +01:00
|
|
|
cdef unsigned int NOISE_STATE_HELLO
|
|
|
|
cdef unsigned int NOISE_STATE_HANDSHAKE
|
|
|
|
cdef unsigned int NOISE_STATE_READY
|
|
|
|
cdef unsigned int NOISE_STATE_CLOSED
|
|
|
|
|
2023-11-24 19:12:32 +01:00
|
|
|
cdef bytes NOISE_HELLO
|
|
|
|
|
2023-10-12 20:12:39 +02:00
|
|
|
cdef class APINoiseFrameHelper(APIFrameHelper):
|
|
|
|
|
|
|
|
cdef object _noise_psk
|
2023-11-24 19:12:32 +01:00
|
|
|
cdef str _expected_name
|
2023-11-17 00:50:54 +01:00
|
|
|
cdef unsigned int _state
|
2023-10-12 20:12:39 +02:00
|
|
|
cdef object _server_name
|
|
|
|
cdef object _proto
|
|
|
|
cdef object _decrypt
|
|
|
|
cdef object _encrypt
|
|
|
|
|
|
|
|
@cython.locals(
|
2023-10-13 03:17:46 +02:00
|
|
|
header=bytes,
|
2023-11-24 19:04:12 +01:00
|
|
|
preamble="unsigned char",
|
|
|
|
msg_size_high="unsigned char",
|
|
|
|
msg_size_low="unsigned char",
|
2023-10-20 02:00:36 +02:00
|
|
|
)
|
2023-11-26 20:25:55 +01:00
|
|
|
cpdef void data_received(self, object data)
|
2023-10-13 03:17:46 +02:00
|
|
|
|
|
|
|
@cython.locals(
|
2023-11-24 19:04:12 +01:00
|
|
|
msg=bytes,
|
|
|
|
type_high="unsigned char",
|
|
|
|
type_low="unsigned char"
|
2023-10-13 03:17:46 +02:00
|
|
|
)
|
2023-11-24 19:40:33 +01:00
|
|
|
cdef void _handle_frame(self, bytes frame)
|
2023-11-17 00:50:54 +01:00
|
|
|
|
2023-11-24 19:12:32 +01:00
|
|
|
@cython.locals(
|
|
|
|
chosen_proto=char,
|
2023-11-24 19:35:58 +01:00
|
|
|
server_name_i=int
|
2023-11-24 19:12:32 +01:00
|
|
|
)
|
2023-11-24 19:40:33 +01:00
|
|
|
cdef void _handle_hello(self, bytes server_hello)
|
2023-11-17 00:50:54 +01:00
|
|
|
|
2023-11-24 19:40:33 +01:00
|
|
|
cdef void _handle_handshake(self, bytes msg)
|
2023-11-17 00:50:54 +01:00
|
|
|
|
2023-11-24 19:40:33 +01:00
|
|
|
cdef void _handle_closed(self, bytes frame)
|
2023-11-09 18:28:18 +01:00
|
|
|
|
2023-11-24 19:12:32 +01:00
|
|
|
@cython.locals(handshake_frame=bytearray, frame_len="unsigned int")
|
2023-11-24 19:40:33 +01:00
|
|
|
cdef void _send_hello_handshake(self)
|
2023-11-24 19:12:32 +01:00
|
|
|
|
2023-11-24 19:40:33 +01:00
|
|
|
cdef void _setup_proto(self)
|
2023-11-24 19:12:32 +01:00
|
|
|
|
|
|
|
@cython.locals(psk_bytes=bytes)
|
|
|
|
cdef _decode_noise_psk(self)
|
|
|
|
|
2023-11-09 18:28:18 +01:00
|
|
|
@cython.locals(
|
2023-11-16 17:31:02 +01:00
|
|
|
type_="unsigned int",
|
|
|
|
data=bytes,
|
|
|
|
packet=tuple,
|
2023-11-09 18:28:18 +01:00
|
|
|
data_len=cython.uint,
|
2023-11-16 17:31:02 +01:00
|
|
|
frame=bytes,
|
2023-11-18 22:10:40 +01:00
|
|
|
frame_len=cython.uint,
|
2023-11-09 18:28:18 +01:00
|
|
|
)
|
2023-11-26 20:25:55 +01:00
|
|
|
cpdef void write_packets(self, list packets, bint debug_enabled)
|
2023-11-18 22:10:40 +01:00
|
|
|
|
|
|
|
cdef _error_on_incorrect_preamble(self, bytes msg)
|