summaryrefslogtreecommitdiff
path: root/kvmd/apps/janus/runner.py
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-09-16 23:07:38 +0300
committerMaxim Devaev <[email protected]>2024-09-16 23:07:38 +0300
commitc57334f214be1c31f52d486639d26c4fa1bd038f (patch)
tree5090d0a5d934a7bf0749aba57427c2996fa07e62 /kvmd/apps/janus/runner.py
parentb779c1853072297ca273ba3895141e821c0e722c (diff)
refactoring
Diffstat (limited to 'kvmd/apps/janus/runner.py')
-rw-r--r--kvmd/apps/janus/runner.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/kvmd/apps/janus/runner.py b/kvmd/apps/janus/runner.py
index e08fade0..cb46562a 100644
--- a/kvmd/apps/janus/runner.py
+++ b/kvmd/apps/janus/runner.py
@@ -11,15 +11,16 @@ from ... import aioproc
from ...logging import get_logger
+from .stun import StunNatType
from .stun import Stun
# =====
@dataclasses.dataclass(frozen=True)
class _Netcfg:
- nat_type: str = dataclasses.field(default="")
- src_ip: str = dataclasses.field(default="")
- ext_ip: str = dataclasses.field(default="")
+ nat_type: StunNatType = dataclasses.field(default=StunNatType.ERROR)
+ src_ip: str = dataclasses.field(default="")
+ ext_ip: str = dataclasses.field(default="")
stun_host: str = dataclasses.field(default="")
stun_port: int = dataclasses.field(default=0)
@@ -92,8 +93,9 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes
async def __get_netcfg(self) -> _Netcfg:
src_ip = (self.__get_default_ip() or "0.0.0.0")
- (stun, (nat_type, ext_ip)) = await self.__get_stun_info(src_ip)
- return _Netcfg(nat_type, src_ip, ext_ip, stun.host, stun.port)
+ info = await self.__stun.get_info(src_ip, 0)
+ # В текущей реализации _Netcfg() это копия StunInfo()
+ return _Netcfg(**dataclasses.asdict(info))
def __get_default_ip(self) -> str:
try:
@@ -115,13 +117,6 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes
get_logger().error("Can't get default IP: %s", tools.efmt(err))
return ""
- async def __get_stun_info(self, src_ip: str) -> tuple[Stun, tuple[str, str]]:
- try:
- return (self.__stun, (await self.__stun.get_info(src_ip, 0)))
- except Exception as err:
- get_logger().error("Can't get STUN info: %s", tools.efmt(err))
- return (self.__stun, ("", ""))
-
# =====
@aiotools.atomic_fg