From e78417e4de550340c9e429bd5a884ed969d2b97e Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Wed, 18 Jan 2023 10:43:54 +0100 Subject: [PATCH] Move creation of new_limits into helper --- asyncua/common/connection.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/asyncua/common/connection.py b/asyncua/common/connection.py index 52e7630ed..08dc202f3 100644 --- a/asyncua/common/connection.py +++ b/asyncua/common/connection.py @@ -52,7 +52,13 @@ def is_chunk_count_within_limit(self, sz: int) -> bool: _logger.error("Number of message chunks: %s is > configured max chunk count: %s", sz, self.max_chunk_count) return within_limit - def _set_new_limits(self, new_limits: "TransportLimits", role: Literal["client", "server"]) -> None: + def _set_new_limits_from_ack(self, ack: ua.Acknowledge, role: Literal["client", "server"]) -> None: + new_limits = TransportLimits( + max_chunk_count=ack.MaxChunkCount, + max_recv_buffer=ack.SendBufferSize, + max_send_buffer=ack.ReceiveBufferSize, + max_message_size=ack.MaxMessageSize, + ) if new_limits != self: self.max_chunk_count = new_limits.max_chunk_count self.max_recv_buffer = new_limits.max_recv_buffer @@ -66,13 +72,7 @@ def create_acknowledge_and_set_limits(self, msg: ua.Hello) -> ua.Acknowledge: ack.SendBufferSize = min(msg.SendBufferSize, self.max_recv_buffer) ack.MaxChunkCount = self._select_limit(msg.MaxChunkCount, self.max_chunk_count) ack.MaxMessageSize = self._select_limit(msg.MaxMessageSize, self.max_message_size) - new_limits = TransportLimits( - max_chunk_count=ack.MaxChunkCount, - max_recv_buffer=ack.SendBufferSize, - max_send_buffer=ack.ReceiveBufferSize, - max_message_size=ack.MaxMessageSize, - ) - self._set_new_limits(new_limits, "server") + self._set_new_limits_from_ack(ack, "server") return ack def create_hello_limits(self, msg: ua.Hello) -> ua.Hello: @@ -83,13 +83,7 @@ def create_hello_limits(self, msg: ua.Hello) -> ua.Hello: return msg def update_client_limits(self, msg: ua.Acknowledge) -> None: - new_limits = TransportLimits( - max_chunk_count=msg.MaxChunkCount, - max_recv_buffer=msg.SendBufferSize, - max_send_buffer=msg.ReceiveBufferSize, - max_message_size=msg.MaxMessageSize, - ) - self._set_new_limits(new_limits, "client") + self._set_new_limits_from_ack(msg, "client") class MessageChunk: