add timeout to response socket in updater

patch bump
This commit is contained in:
onyx-and-iris 2022-09-23 20:03:16 +01:00
parent 14e538dca6
commit 444f95a9d6
2 changed files with 36 additions and 30 deletions

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "vban-cmd" name = "vban-cmd"
version = "1.4.2" version = "1.4.3"
description = "Python interface for the VBAN RT Packet Service (Sendtext)" description = "Python interface for the VBAN RT Packet Service (Sendtext)"
authors = ["onyx-and-iris <code@onyxandiris.online>"] authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT" license = "MIT"

View File

@ -41,6 +41,7 @@ class Updater(threading.Thread):
def __init__(self, remote): def __init__(self, remote):
super().__init__(name="updater", target=self.update, daemon=True) super().__init__(name="updater", target=self.update, daemon=True)
self._remote = remote self._remote = remote
self._remote.socks[Socket.response].settimeout(5)
self._remote.socks[Socket.response].bind( self._remote.socks[Socket.response].bind(
(socket.gethostbyname(socket.gethostname()), self._remote.port) (socket.gethostbyname(socket.gethostname()), self._remote.port)
) )
@ -48,35 +49,40 @@ class Updater(threading.Thread):
self._remote._public_packet = self._get_rt() self._remote._public_packet = self._get_rt()
def _fetch_rt_packet(self) -> Optional[VbanRtPacket]: def _fetch_rt_packet(self) -> Optional[VbanRtPacket]:
data, _ = self._remote.socks[Socket.response].recvfrom(2048) try:
# check for packet data data, _ = self._remote.socks[Socket.response].recvfrom(2048)
if len(data) > HEADER_SIZE: # check for packet data
# check if packet is of type rt packet response if len(data) > HEADER_SIZE:
if self.packet_expected.header == data[: HEADER_SIZE - 4]: # check if packet is of type rt packet response
return VbanRtPacket( if self.packet_expected.header == data[: HEADER_SIZE - 4]:
_voicemeeterType=data[28:29], return VbanRtPacket(
_reserved=data[29:30], _voicemeeterType=data[28:29],
_buffersize=data[30:32], _reserved=data[29:30],
_voicemeeterVersion=data[32:36], _buffersize=data[30:32],
_optionBits=data[36:40], _voicemeeterVersion=data[32:36],
_samplerate=data[40:44], _optionBits=data[36:40],
_inputLeveldB100=data[44:112], _samplerate=data[40:44],
_outputLeveldB100=data[112:240], _inputLeveldB100=data[44:112],
_TransportBit=data[240:244], _outputLeveldB100=data[112:240],
_stripState=data[244:276], _TransportBit=data[240:244],
_busState=data[276:308], _stripState=data[244:276],
_stripGaindB100Layer1=data[308:324], _busState=data[276:308],
_stripGaindB100Layer2=data[324:340], _stripGaindB100Layer1=data[308:324],
_stripGaindB100Layer3=data[340:356], _stripGaindB100Layer2=data[324:340],
_stripGaindB100Layer4=data[356:372], _stripGaindB100Layer3=data[340:356],
_stripGaindB100Layer5=data[372:388], _stripGaindB100Layer4=data[356:372],
_stripGaindB100Layer6=data[388:404], _stripGaindB100Layer5=data[372:388],
_stripGaindB100Layer7=data[404:420], _stripGaindB100Layer6=data[388:404],
_stripGaindB100Layer8=data[420:436], _stripGaindB100Layer7=data[404:420],
_busGaindB100=data[436:452], _stripGaindB100Layer8=data[420:436],
_stripLabelUTF8c60=data[452:932], _busGaindB100=data[436:452],
_busLabelUTF8c60=data[932:1412], _stripLabelUTF8c60=data[452:932],
) _busLabelUTF8c60=data[932:1412],
)
except TimeoutError as e:
print(f"Unable to establish connection with {self._remote.ip}")
[sock.close() for sock in self._remote.socks]
raise e
def _get_rt(self) -> VbanRtPacket: def _get_rt(self) -> VbanRtPacket:
"""Attempt to fetch data packet until a valid one found""" """Attempt to fetch data packet until a valid one found"""