From 9fd0fd55c135c0a77dde27ce84eef4a1d014e0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Tue, 1 Aug 2023 10:57:10 -0300 Subject: [PATCH 1/2] core: services: beacon: Fix V2->V3 settings migration --- core/services/beacon/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/services/beacon/settings.py b/core/services/beacon/settings.py index 004a49b0e4..df924769a5 100644 --- a/core/services/beacon/settings.py +++ b/core/services/beacon/settings.py @@ -172,7 +172,7 @@ def migrate(self, data: Dict[str, Any]) -> None: try: if not any(interface["name"] == "uap0" for interface in data["interfaces"]): data["interfaces"].append( - Interface(name="uap0", domain_names=["blueos-hotspot"], advertise=["_http"], ip="ips[0]").as_dict() + Interface(name="uap0", domain_names=["blueos-hotspot"], advertise=["_http"], ip="ips[0]")._data ) except Exception as e: logger.error(f"unable to update SettingsV2 to SettingsV3: {e}") From a9e1ddd6383a1c4c9882295d2844857d07aa5eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ant=C3=B4nio=20Cardoso?= Date: Tue, 1 Aug 2023 12:06:42 -0300 Subject: [PATCH 2/2] core: services: beacon: Improve documentation --- core/services/beacon/settings.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/services/beacon/settings.py b/core/services/beacon/settings.py index df924769a5..286c5fdbe4 100644 --- a/core/services/beacon/settings.py +++ b/core/services/beacon/settings.py @@ -41,7 +41,11 @@ def get_phys(self) -> List[psutil._common.snicaddr]: def get_ip_strs(self) -> List[str]: """ - get ip as a string. this also translates 'ips[n]' to the n-th ip in that interface + returns a list of the interface IPs (IPv4 only) as a list of strings: + - if self.ip is "ips[*]", it returns all ips of that interface + - if self.ip is "ips[n]", it returns the n-th ip of that interface + - if self.ip is a single ipv4 (like "192.168.2.2"), it returns that ip as a string + - if self.ip is (mistakenly) an IPv6 or any other non-IPv4 format, it raises an InvalidIpAddress error """ address = str(self.ip) # Check for 'ips[n]' @@ -71,7 +75,7 @@ def get_ip_strs(self) -> List[str]: def get_ips(self) -> List[bytes]: """ - returns the ip as 4 bytes + returns a list of the interface IPs (IPv4 only) as a list of 4 bytes """ return [socket.inet_aton(ip) for ip in self.get_ip_strs()]