-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from tiiuae/fix_avahi
Fix "IPv6 connection unreliable from external PC"
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
modules/sc-mesh-secure-deployment/src/nats/src/comms_service_refresh.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Refresher class for the comms service registration | ||
""" | ||
import logging | ||
import threading | ||
import time | ||
import subprocess | ||
|
||
class CommsServiceRefresh: | ||
""" | ||
Comms service publisher class | ||
""" | ||
DNS_SERVICE_EVENT_LOOP_TIMEOUT: int = 5 | ||
|
||
def __init__(self, __hostname, __logger: logging.Logger) -> None: | ||
|
||
self.logger: logging.Logger = __logger.getChild("CommsServicePublisher") | ||
self.logger.setLevel(logging.INFO) | ||
self.__event: threading.Event = threading.Event() | ||
self.__hostname: str = __hostname | ||
|
||
|
||
def __refresh_hostname(self) -> None: | ||
""" | ||
Refresh the hostname with avahi-resolve-host-name | ||
""" | ||
try: | ||
subprocess.run(["avahi-resolve-host-name", self.__hostname + ".local"], | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE) | ||
except subprocess.CalledProcessError: | ||
self.logger.exception("Error refreshing hostname") | ||
|
||
def dns_service_refresh(self) -> None: | ||
""" | ||
Register and re-announce service periodically | ||
""" | ||
self.logger.info("Refresh start") | ||
while not self.__event.is_set(): | ||
time.sleep(self.DNS_SERVICE_EVENT_LOOP_TIMEOUT) | ||
self.__refresh_hostname() | ||
self.logger.info("Refresh stopped") | ||
|
||
|
||
def shutdown_service(self) -> None: | ||
""" | ||
Shutdown the service | ||
""" | ||
self.__event.set() |