mirror of
https://github.com/espressif/openthread.git
synced 2026-08-06 10:47:46 +00:00
[srp-client] new feature to allow lease and key lease per service (#8211)
This commit add a new feature in `Srp::Client` to allow user to specify the lease and/or key lease intervals explicitly per service. The lease intervals in a service can be left unspecified(set to zero) in which case the default lease intervals will be used. In an SRP Update message, the lease info is included in additional section in an Update Lease Option record. Therefore the lease values are applicable to the entire message and all its records. If we have services with different lease intervals, they need to be registered in separate messages. This commit updates `Srp::Client` to implement such a mechanism. When preparing an SRP message, we first determine the lease and key lease intervals and ensure the services using matching intervals are included in the message. This commit also updates and simplifies the "single service mode" functionality to use the newly added mechanism for tracking which services are included in the message. This commit adds `test_srp_register_services_diff_lease` which covers the behavior of the newly added mechanisms.
This commit is contained in:
@@ -1023,6 +1023,8 @@ class NodeImpl:
|
||||
'priority': '0',
|
||||
'weight': '0',
|
||||
'ttl': '7200',
|
||||
'lease': '7200',
|
||||
'key-lease': '7200',
|
||||
'TXT': ['abc=010203'],
|
||||
'host_fullname': 'my-host.default.service.arpa.',
|
||||
'host': 'my-host',
|
||||
@@ -1035,6 +1037,7 @@ class NodeImpl:
|
||||
cmd = 'srp server service'
|
||||
self.send_command(cmd)
|
||||
lines = self._expect_command_output()
|
||||
|
||||
service_list = []
|
||||
while lines:
|
||||
service = {}
|
||||
@@ -1049,8 +1052,8 @@ class NodeImpl:
|
||||
service_list.append(service)
|
||||
continue
|
||||
|
||||
# 'subtypes', port', 'priority', 'weight', 'ttl'
|
||||
for i in range(0, 5):
|
||||
# 'subtypes', port', 'priority', 'weight', 'ttl', 'lease', and 'key-lease'
|
||||
for i in range(0, 7):
|
||||
key_value = lines.pop(0).strip().split(':')
|
||||
service[key_value[0].strip()] = key_value[1].strip()
|
||||
|
||||
@@ -1163,11 +1166,22 @@ class NodeImpl:
|
||||
self.send_command(f'srp client host address')
|
||||
self._expect_done()
|
||||
|
||||
def srp_client_add_service(self, instance_name, service_name, port, priority=0, weight=0, txt_entries=[]):
|
||||
def srp_client_add_service(self,
|
||||
instance_name,
|
||||
service_name,
|
||||
port,
|
||||
priority=0,
|
||||
weight=0,
|
||||
txt_entries=[],
|
||||
lease=0,
|
||||
key_lease=0):
|
||||
txt_record = "".join(self._encode_txt_entry(entry) for entry in txt_entries)
|
||||
if txt_record == '':
|
||||
txt_record = '-'
|
||||
instance_name = self._escape_escapable(instance_name)
|
||||
self.send_command(
|
||||
f'srp client service add {instance_name} {service_name} {port} {priority} {weight} {txt_record}')
|
||||
f'srp client service add {instance_name} {service_name} {port} {priority} {weight} {txt_record} {lease} {key_lease}'
|
||||
)
|
||||
self._expect_done()
|
||||
|
||||
def srp_client_remove_service(self, instance_name, service_name):
|
||||
@@ -1194,6 +1208,16 @@ class NodeImpl:
|
||||
self.send_command(cmd)
|
||||
return int(self._expect_result('\d+'))
|
||||
|
||||
def srp_client_set_key_lease_interval(self, leaseinterval: int):
|
||||
cmd = f'srp client keyleaseinterval {leaseinterval}'
|
||||
self.send_command(cmd)
|
||||
self._expect_done()
|
||||
|
||||
def srp_client_get_key_lease_interval(self) -> int:
|
||||
cmd = 'srp client keyleaseinterval'
|
||||
self.send_command(cmd)
|
||||
return int(self._expect_result('\d+'))
|
||||
|
||||
def srp_client_set_ttl(self, ttl: int):
|
||||
cmd = f'srp client ttl {ttl}'
|
||||
self.send_command(cmd)
|
||||
|
||||
Reference in New Issue
Block a user