-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
320 additions
and
269 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 was deleted.
Oops, something went wrong.
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,11 @@ | ||
class DummyMDNS: | ||
def advertise_service( | ||
self, | ||
service_type, | ||
protocol, | ||
port, | ||
txt_records=[], | ||
subtypes=[], | ||
instance_name="", | ||
): | ||
print(f"Advertise service {service_type} {protocol} {port} {txt_records}") |
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,41 @@ | ||
import subprocess | ||
|
||
|
||
class Avahi: | ||
def __init__(self): | ||
self.active_services = {} | ||
self.publish_address = None | ||
|
||
def advertise_service( | ||
self, | ||
service_type, | ||
protocol, | ||
port, | ||
txt_records={}, | ||
subtypes=[], | ||
instance_name="", | ||
): | ||
subtypes = [f"--subtype={subtype}" for subtype in subtypes] | ||
txt_records = [f"{key}={value}" for key, value in txt_records.items()] | ||
command = [ | ||
"avahi-publish-service", | ||
*subtypes, | ||
instance_name, | ||
f"{service_type}.{protocol}", | ||
str(port), | ||
*txt_records, | ||
] | ||
self.active_services[service_type + instance_name] = subprocess.Popen(command) | ||
if self.publish_address is None: | ||
command = [ | ||
"avahi-publish-address", | ||
"dalinar.local", | ||
"fd98:bbab:bd61:8040:642:1aff:fe0c:9f2a", # "fe80::642:1aff:fe0c:9f2a", | ||
] | ||
self.publish_address = subprocess.Popen(command) | ||
|
||
def __del__(self): | ||
for active_service in self.active_services.values(): | ||
active_service.kill() | ||
if self.publish_address is not None: | ||
self.publish_address.kill() |
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,6 @@ | ||
import os | ||
import secrets | ||
|
||
urandom = os.urandom | ||
|
||
randbelow = secrets.randbelow |
Oops, something went wrong.