-
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.
Fix "IPv6 connection unreliable from external PC"
Avahi workaround Jira-Id: SECO-7551 Signed-off-by: Mika Joenpera <[email protected]>
- Loading branch information
Showing
3 changed files
with
94 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
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
""" | ||
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) | ||
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() | ||
|
||
if __name__ == "__main__": | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger("CommsServiceRefresh") | ||
comms_service_refresh = CommsServiceRefresh("mika-battlestation", logger) | ||
comms_service_refresh.dns_service_refresh() | ||
time.sleep(100) | ||
# Wait for the service to be registered | ||
comms_service_refresh.shutdown_service() |