2023-10-14 06:01:34 +02:00
|
|
|
import cython
|
|
|
|
|
2023-11-16 17:31:02 +01:00
|
|
|
from ._frame_helper.base cimport APIFrameHelper
|
|
|
|
|
2023-10-14 06:01:34 +02:00
|
|
|
|
|
|
|
cdef dict MESSAGE_TYPE_TO_PROTO
|
|
|
|
cdef dict PROTO_TO_MESSAGE_TYPE
|
|
|
|
|
|
|
|
cdef set OPEN_STATES
|
|
|
|
|
|
|
|
cdef float KEEP_ALIVE_TIMEOUT_RATIO
|
|
|
|
|
|
|
|
cdef bint TYPE_CHECKING
|
|
|
|
|
|
|
|
cdef object DISCONNECT_REQUEST_MESSAGE
|
2023-10-16 00:01:00 +02:00
|
|
|
cdef object DISCONNECT_RESPONSE_MESSAGE
|
2023-10-14 06:01:34 +02:00
|
|
|
cdef object PING_REQUEST_MESSAGE
|
|
|
|
cdef object PING_RESPONSE_MESSAGE
|
|
|
|
|
2023-10-16 00:01:00 +02:00
|
|
|
cdef object asyncio_timeout
|
|
|
|
cdef object CancelledError
|
|
|
|
cdef object asyncio_TimeoutError
|
|
|
|
|
|
|
|
cdef object ConnectResponse
|
2023-10-14 06:01:34 +02:00
|
|
|
cdef object DisconnectRequest
|
|
|
|
cdef object PingRequest
|
2023-10-16 00:01:00 +02:00
|
|
|
cdef object GetTimeRequest, GetTimeResponse
|
|
|
|
|
|
|
|
cdef object APIVersion
|
|
|
|
|
2023-10-14 06:25:27 +02:00
|
|
|
cdef object partial
|
2023-10-14 06:01:34 +02:00
|
|
|
|
2023-10-16 00:01:00 +02:00
|
|
|
cdef object hr
|
|
|
|
|
|
|
|
cdef object RESOLVE_TIMEOUT
|
2023-11-21 13:08:48 +01:00
|
|
|
cdef object CONNECT_AND_SETUP_TIMEOUT, CONNECT_REQUEST_TIMEOUT
|
2023-10-16 00:01:00 +02:00
|
|
|
|
|
|
|
cdef object APIConnectionError
|
|
|
|
cdef object BadNameAPIError
|
|
|
|
cdef object HandshakeAPIError
|
|
|
|
cdef object PingFailedAPIError
|
|
|
|
cdef object ReadFailedAPIError
|
|
|
|
cdef object TimeoutAPIError
|
|
|
|
|
2023-11-21 13:08:48 +01:00
|
|
|
cdef object in_do_connect, astuple
|
|
|
|
|
|
|
|
|
|
|
|
@cython.dataclasses.dataclass
|
|
|
|
cdef class ConnectionParams:
|
|
|
|
cdef public str address
|
|
|
|
cdef public object port
|
|
|
|
cdef public object password
|
|
|
|
cdef public object client_info
|
|
|
|
cdef public object keepalive
|
|
|
|
cdef public object zeroconf_manager
|
|
|
|
cdef public object noise_psk
|
|
|
|
cdef public object expected_name
|
2023-10-16 00:01:00 +02:00
|
|
|
|
2023-10-14 06:01:34 +02:00
|
|
|
cdef class APIConnection:
|
|
|
|
|
2023-11-21 13:08:48 +01:00
|
|
|
cdef ConnectionParams _params
|
2023-10-14 06:01:34 +02:00
|
|
|
cdef public object on_stop
|
|
|
|
cdef object _on_stop_task
|
|
|
|
cdef public object _socket
|
2023-11-16 17:31:02 +01:00
|
|
|
cdef public APIFrameHelper _frame_helper
|
2023-10-14 06:01:34 +02:00
|
|
|
cdef public object api_version
|
2023-10-15 04:03:12 +02:00
|
|
|
cdef public object connection_state
|
2023-10-14 06:01:34 +02:00
|
|
|
cdef dict _message_handlers
|
|
|
|
cdef public str log_name
|
|
|
|
cdef set _read_exception_futures
|
|
|
|
cdef object _ping_timer
|
|
|
|
cdef object _pong_timer
|
|
|
|
cdef float _keep_alive_interval
|
|
|
|
cdef float _keep_alive_timeout
|
2023-10-15 04:03:12 +02:00
|
|
|
cdef object _start_connect_task
|
|
|
|
cdef object _finish_connect_task
|
2023-10-14 06:01:34 +02:00
|
|
|
cdef object _fatal_exception
|
|
|
|
cdef bint _expected_disconnect
|
|
|
|
cdef object _loop
|
|
|
|
cdef bint _send_pending_ping
|
|
|
|
cdef public bint is_connected
|
2023-10-15 04:03:12 +02:00
|
|
|
cdef bint _handshake_complete
|
2023-10-14 06:01:34 +02:00
|
|
|
cdef object _debug_enabled
|
2023-11-17 20:11:36 +01:00
|
|
|
cdef public str received_name
|
|
|
|
cdef public object resolved_addr_info
|
2023-10-14 06:01:34 +02:00
|
|
|
|
|
|
|
cpdef send_message(self, object msg)
|
|
|
|
|
2023-11-16 17:31:02 +01:00
|
|
|
cdef send_messages(self, tuple messages)
|
|
|
|
|
2023-10-14 06:01:34 +02:00
|
|
|
@cython.locals(handlers=set, handlers_copy=set)
|
2023-11-16 19:24:50 +01:00
|
|
|
cpdef process_packet(self, object msg_type_proto, object data)
|
2023-10-14 06:01:34 +02:00
|
|
|
|
|
|
|
cpdef _async_cancel_pong_timer(self)
|
|
|
|
|
|
|
|
cpdef _async_schedule_keep_alive(self, object now)
|
|
|
|
|
|
|
|
cpdef _cleanup(self)
|
|
|
|
|
|
|
|
cpdef _set_connection_state(self, object state)
|
|
|
|
|
2023-11-16 19:24:50 +01:00
|
|
|
cpdef report_fatal_error(self, Exception err)
|
2023-10-14 06:01:34 +02:00
|
|
|
|
|
|
|
@cython.locals(handlers=set)
|
2023-10-14 06:25:27 +02:00
|
|
|
cpdef _add_message_callback_without_remove(self, object on_message, tuple msg_types)
|
2023-10-14 06:01:34 +02:00
|
|
|
|
2023-10-14 06:25:27 +02:00
|
|
|
cpdef add_message_callback(self, object on_message, tuple msg_types)
|
2023-10-14 06:01:34 +02:00
|
|
|
|
|
|
|
@cython.locals(handlers=set)
|
2023-10-20 02:00:36 +02:00
|
|
|
cpdef _remove_message_callback(self, object on_message, tuple msg_types)
|
2023-11-21 13:08:48 +01:00
|
|
|
|
|
|
|
cpdef _handle_disconnect_request_internal(self, object msg)
|
|
|
|
|
|
|
|
cpdef _handle_ping_request_internal(self, object msg)
|
|
|
|
|
|
|
|
cpdef _handle_get_time_request_internal(self, object msg)
|