Skip to content

Commit

Permalink
Fix link-local address pinging (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
agners authored Jun 10, 2024
1 parent a938271 commit 97a2c38
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ async def remove_node(self, node_id: int) -> None:

@api_command(APICommand.PING_NODE)
async def ping_node(self, node_id: int, attempts: int = 1) -> NodePingResult:
"""Ping node on the currently known IP-adress(es)."""
"""Ping node on the currently known IP-address(es)."""
result: NodePingResult = {}
if node_id >= TEST_NODE_START:
return {"0.0.0.0": True, "0000:1111:2222:3333:4444": True}
Expand Down Expand Up @@ -781,9 +781,8 @@ async def _do_ping(ip_address: str) -> None:
"Pinging address %s (using interface %s)", clean_ip, interface_idx
)
else:
clean_ip = ip_address
node_logger.debug("Pinging address %s", clean_ip)
result[clean_ip] = await ping_ip(ip_address, timeout, attempts=attempts)
node_logger.debug("Pinging address %s", ip_address)
result[ip_address] = await ping_ip(ip_address, timeout, attempts=attempts)

ip_addresses = await self.get_node_ip_addresses(
node_id, prefer_cache=False, scoped=True
Expand Down Expand Up @@ -814,10 +813,10 @@ async def get_node_ip_addresses(
prefer_cache: bool = False,
scoped: bool = False,
) -> list[str]:
"""Return the currently known (scoped) IP-adress(es)."""
"""Return the currently known (scoped) IP-address(es)."""
cached_info = self._last_known_ip_addresses.get(node_id, [])
if prefer_cache and cached_info:
return cached_info if scoped else [x.split("%")[0] for x in cached_info]
return cached_info
node = self._nodes.get(node_id)
if node is None:
raise NodeNotExists(
Expand All @@ -835,10 +834,10 @@ async def get_node_ip_addresses(
"Node could not be discovered on the network, returning cached IP's"
)
return cached_info
ip_adresses = info.parsed_scoped_addresses(IPVersion.All)
ip_addresses = info.parsed_scoped_addresses(IPVersion.All)
# cache this info for later use
self._last_known_ip_addresses[node_id] = ip_adresses
return ip_adresses if scoped else [x.split("%")[0] for x in ip_adresses]
self._last_known_ip_addresses[node_id] = ip_addresses
return ip_addresses

@api_command(APICommand.IMPORT_TEST_NODE)
async def import_test_node(self, dump: str) -> None:
Expand Down

0 comments on commit 97a2c38

Please sign in to comment.