Skip to content

Commit

Permalink
fix(saemubox): flag to disable src ip check (#537)
Browse files Browse the repository at this point in the history
This is due to the fact that the virtual saemubox will have a new IP on each restart when scheduled with podman.
  • Loading branch information
hairmare authored Nov 13, 2023
1 parent ebe87e8 commit 8a1d31d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion nowplaying/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def __init__(self, options):
self.options = options

self.event_queue = Queue()
self.saemubox = SaemuBox(self.options.saemubox_ip)
self.saemubox = SaemuBox(
self.options.saemubox_ip, self.options.check_saemubox_sender
)

def main(self): # pragma: no cover
# TODO test once there is not saemubox in the loop
Expand Down
7 changes: 5 additions & 2 deletions nowplaying/misc/saemubox.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SaemuBox:
6: "Studio Live",
}

def __init__(self, saemubox_ip):
def __init__(self, saemubox_ip, check_sender=True):
warnings.warn(
"Saemubox will be replaced with Pathfinder", PendingDeprecationWarning
)
Expand All @@ -49,6 +49,9 @@ def __init__(self, saemubox_ip):
# allowed sender ip addresses
self.senders = {saemubox_ip}

# check self.senders for validity
self.check_sender = check_sender

# valid saemubox ids
self.valid_ids = [str(i) for i in self.output_mapping]

Expand Down Expand Up @@ -79,7 +82,7 @@ def __update(self): # pragma: no cover
# read from socket while there is something to read (non-blocking)
while select.select([self.sock], [], [], 0)[0]:
data, addr = self.sock.recvfrom(1024)
if addr[0] not in self.senders:
if self.check_sender and addr[0] not in self.senders:
logger.warn("SaemuBox: receiving data from invalid host: %s " % addr[0])
continue

Expand Down
8 changes: 8 additions & 0 deletions nowplaying/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ def __init__(self):
self.__args = configargparse.ArgParser(
default_config_files=["/etc/nowplaying/conf.d/*.conf", "~/.nowplayingrc"]
)
# TODO v3 remove this option
self.__args.add_argument(
"-b",
"--saemubox-ip",
dest="saemubox_ip",
help="IP address of SAEMUBOX",
default="",
)
# TODO v3 remove this option
self.__args.add_argument(
"--check-saemubox-sender",
dest="check_saemubox_sender",
help="Check SRC SAEMUBOX IP",
default=True,
)
IcecastTrackObserver.Options.args(self.__args)
DabAudioCompanionTrackObserver.Options.args(self.__args)
TickerTrackObserver.Options.args(self.__args)
Expand Down
1 change: 1 addition & 0 deletions tests/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def fixture_options():
class _Options:
def __init__(self):
self.saemubox_ip = ""
self.check_saemubox_sender = True

return _Options()

Expand Down

0 comments on commit 8a1d31d

Please sign in to comment.