diff --git a/RNS/Buffer.py b/RNS/Buffer.py index c9a89a9..bf0207a 100644 --- a/RNS/Buffer.py +++ b/RNS/Buffer.py @@ -45,7 +45,8 @@ class StreamDataMessage(MessageBase): The stream id is limited to 2 bytes - 2 bit """ - MAX_DATA_LEN = RNS.Link.MDU - 2 - 6 # 2 for stream data message header, 6 for channel envelope + OVERHEAD = 2 + 6 # 2 for stream data message header, 6 for channel envelope + MAX_DATA_LEN = RNS.Link.MDU - OVERHEAD """ When the Buffer package is imported, this value is calculcated based on the value of OVERHEAD @@ -215,6 +216,7 @@ class RawChannelWriter(RawIOBase, AbstractContextManager): self._stream_id = stream_id self._channel = channel self._eof = False + self._mdu = channel.mdu - StreamDataMessage.OVERHEAD def write(self, __b: bytes) -> int | None: try: diff --git a/RNS/Channel.py b/RNS/Channel.py index 47c11f6..fa80855 100644 --- a/RNS/Channel.py +++ b/RNS/Channel.py @@ -602,7 +602,7 @@ class Channel(contextlib.AbstractContextManager): return envelope @property - def MDU(self): + def mdu(self): """ Maximum Data Unit: the number of bytes available for a message to consume in a single send. This @@ -611,7 +611,10 @@ class Channel(contextlib.AbstractContextManager): :return: number of bytes available """ - return self._outlet.mdu - 6 # sizeof(msgtype) + sizeof(length) + sizeof(sequence) + mdu = self._outlet.mdu - 6 # sizeof(msgtype) + sizeof(length) + sizeof(sequence) + if mdu > 0xFFFF: + mdu = 0xFFFF + return mdu class LinkChannelOutlet(ChannelOutletBase): @@ -639,7 +642,7 @@ class LinkChannelOutlet(ChannelOutletBase): @property def mdu(self): - return self.link.MDU + return self.link.mdu @property def rtt(self): diff --git a/RNS/Link.py b/RNS/Link.py index 9b85648..dd6d1e0 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -423,7 +423,7 @@ class Link: if timeout == None: timeout = self.rtt * self.traffic_timeout_factor + RNS.Resource.RESPONSE_MAX_GRACE_TIME*1.125 - if len(packed_request) <= Link.MDU: + if len(packed_request) <= self.mdu: request_packet = RNS.Packet(self, packed_request, RNS.Packet.DATA, context = RNS.Packet.REQUEST) packet_receipt = request_packet.send() @@ -775,7 +775,7 @@ class Link: if response != None: packed_response = umsgpack.packb([request_id, response]) - if len(packed_response) <= Link.MDU: + if len(packed_response) <= self.mdu: RNS.Packet(self, packed_response, RNS.Packet.DATA, context = RNS.Packet.RESPONSE).send() else: response_resource = RNS.Resource(packed_response, self, request_id = request_id, is_response = True)