Skip to content

Commit 47e56e6

Browse files
committed
Hash zeroconf names that are too long
1 parent 9d85ea5 commit 47e56e6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/labthings/wsgi.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import signal
33
import socket
44
import threading
5+
import hashlib
56

67
from werkzeug.serving import run_simple
78
from werkzeug.debug import DebuggedApplication
@@ -46,7 +47,10 @@ def __init__(
4647

4748
def _register_zeroconf(self):
4849
if self.labthing:
49-
print(f"Registering zeroconf {self.labthing.safe_title}._labthing._tcp.local.")
50+
host = f"{self.labthing.safe_title}._labthing._tcp.local."
51+
if len(host) > 63:
52+
host = f"{hashlib.sha1(host.encode()).hexdigest()}._labthing._tcp.local."
53+
print(f"Registering zeroconf {host}")
5054
# Get list of host addresses
5155
mdns_addresses = {
5256
socket.inet_aton(i)
@@ -57,7 +61,7 @@ def _register_zeroconf(self):
5761
self.service_infos.append(
5862
ServiceInfo(
5963
"_labthing._tcp.local.",
60-
f"{self.labthing.safe_title}._labthing._tcp.local.",
64+
host,
6165
port=self.port,
6266
properties={
6367
"path": self.labthing.url_prefix,

0 commit comments

Comments
 (0)