Add Size2 option handling according to RFC7959

Signed-off-by: Hubert Miś <hubert.mis@gmail.com>
This commit is contained in:
Hubert Miś 2020-12-22 13:17:39 +01:00
parent 89d51737a9
commit 13039faf71
3 changed files with 37 additions and 0 deletions

View file

@ -124,6 +124,7 @@ class OptionRegistry(object):
LOCATION_QUERY = OptionItem(20,"Location-Query",STRING, True, None) LOCATION_QUERY = OptionItem(20,"Location-Query",STRING, True, None)
BLOCK2 = OptionItem(23, "Block2", INTEGER, False, None) BLOCK2 = OptionItem(23, "Block2", INTEGER, False, None)
BLOCK1 = OptionItem(27, "Block1", INTEGER, False, None) BLOCK1 = OptionItem(27, "Block1", INTEGER, False, None)
SIZE2 = OptionItem(28, "Size2", INTEGER, False, 0)
PROXY_URI = OptionItem(35, "Proxy-Uri", STRING, False, None) PROXY_URI = OptionItem(35, "Proxy-Uri", STRING, False, None)
PROXY_SCHEME = OptionItem(39, "Proxy-Schema", STRING, False, None) PROXY_SCHEME = OptionItem(39, "Proxy-Schema", STRING, False, None)
SIZE1 = OptionItem(60, "Size1", INTEGER, False, None) SIZE1 = OptionItem(60, "Size1", INTEGER, False, None)
@ -147,6 +148,7 @@ class OptionRegistry(object):
20: LOCATION_QUERY, 20: LOCATION_QUERY,
23: BLOCK2, 23: BLOCK2,
27: BLOCK1, 27: BLOCK1,
28: SIZE2,
35: PROXY_URI, 35: PROXY_URI,
39: PROXY_SCHEME, 39: PROXY_SCHEME,
60: SIZE1, 60: SIZE1,

View file

@ -225,6 +225,9 @@ class BlockLayer(object):
self._block2_receive[key_token] = BlockItem(byte, num, m, size) self._block2_receive[key_token] = BlockItem(byte, num, m, size)
if transaction.request.size2 is not None:
transaction.response.size2 = len(transaction.response.payload)
if len(transaction.response.payload) > (byte + size): if len(transaction.response.payload) > (byte + size):
m = 1 m = 1
else: else:

View file

@ -641,6 +641,38 @@ class Message(object):
""" """
self.del_option_by_number(defines.OptionRegistry.BLOCK2.number) self.del_option_by_number(defines.OptionRegistry.BLOCK2.number)
@property
def size2(self):
"""
Get the Size2 option.
:return: the Size2 value
"""
value = None
for option in self.options:
if option.number == defines.OptionRegistry.SIZE2.number:
value = option.value
return value
@size2.setter
def size2(self, value):
"""
Set the Size2 option.
:param value: the Block2 value
"""
option = Option()
option.number = defines.OptionRegistry.SIZE2.number
option.value = value
self.add_option(option)
@size2.deleter
def size2(self):
"""
Delete the Size2 option.
"""
self.del_option_by_number(defines.OptionRegistry.SIZE2.number)
@property @property
def line_print(self): def line_print(self):
""" """