Add lease_time as parameter

This commit is contained in:
Philipp Homann 2020-12-20 14:48:55 +01:00
parent 5a3333c895
commit e436e5f483
No known key found for this signature in database
GPG key ID: 8405DC192C90CE71

View file

@ -107,7 +107,7 @@ class UPnP:
return await self.gateway.commands.GetExternalIPAddress() return await self.gateway.commands.GetExternalIPAddress()
async def add_port_mapping(self, external_port: int, protocol: str, internal_port: int, lan_address: str, async def add_port_mapping(self, external_port: int, protocol: str, internal_port: int, lan_address: str,
description: str) -> None: description: str, lease_time: int = 0) -> None:
""" """
Add a new port mapping Add a new port mapping
@ -116,12 +116,13 @@ class UPnP:
:param internal_port: (int) internal port :param internal_port: (int) internal port
:param lan_address: (str) internal lan address :param lan_address: (str) internal lan address
:param description: (str) mapping description :param description: (str) mapping description
:param lease_time: (int) lease time in seconds
:return: None :return: None
""" """
await self.gateway.commands.AddPortMapping( await self.gateway.commands.AddPortMapping(
NewRemoteHost='', NewExternalPort=external_port, NewProtocol=protocol, NewRemoteHost='', NewExternalPort=external_port, NewProtocol=protocol,
NewInternalPort=internal_port, NewInternalClient=lan_address, NewInternalPort=internal_port, NewInternalClient=lan_address,
NewEnabled=1, NewPortMappingDescription=description, NewLeaseDuration='0' NewEnabled=1, NewPortMappingDescription=description, NewLeaseDuration=lease_time
) )
return None return None
@ -208,7 +209,7 @@ class UPnP:
return None return None
async def get_next_mapping(self, port: int, protocol: str, description: str, async def get_next_mapping(self, port: int, protocol: str, description: str,
internal_port: Optional[int] = None) -> int: internal_port: Optional[int] = None, lease_time: int = 0) -> int:
""" """
Get a new port mapping. If the requested port is not available, increment until the next free port is mapped Get a new port mapping. If the requested port is not available, increment until the next free port is mapped
@ -216,6 +217,7 @@ class UPnP:
:param protocol: (str) UDP | TCP :param protocol: (str) UDP | TCP
:param description: (str) mapping description :param description: (str) mapping description
:param internal_port: (int) internal port :param internal_port: (int) internal port
:param lease_time: (int) lease time in seconds
:return: (int) mapped port :return: (int) mapped port
""" """
@ -235,7 +237,7 @@ class UPnP:
if int_host == self.lan_address and int_port == requested_port and desc == description: if int_host == self.lan_address and int_port == requested_port and desc == description:
return port return port
port += 1 port += 1
await self.add_port_mapping(port, protocol, _internal_port, self.lan_address, description) await self.add_port_mapping(port, protocol, _internal_port, self.lan_address, description, lease_time)
return port return port
async def gather_debug_info(self) -> str: # pragma: no cover async def gather_debug_info(self) -> str: # pragma: no cover