Skip to content

Commit

Permalink
Reset site info and module on stun connection loss
Browse files Browse the repository at this point in the history
  • Loading branch information
yozik04 committed Nov 11, 2023
1 parent aae7384 commit 05e3885
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions paradox/connections/ip/stun_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, site_id, email, panel_serial):

async def connect(self) -> None:
self.connection_timestamp = 0
logger.info("Connecting to Site: {}".format(self.site_id))
logger.info("Connecting to Site: %s", self.site_id)
if self.site_info is None:
self.site_info = await self._get_site_info(
siteid=self.site_id, email=self.email
Expand All @@ -36,7 +36,7 @@ async def connect(self) -> None:
if self.site_info is None:
raise ConnectToSiteFailed("Unable to get site info")

logger.debug("Site Info: {}".format(json.dumps(self.site_info, indent=4)))
logger.debug("Site Info: %s", json.dumps(self.site_info, indent=4))
self.module = self._select_module()

if self.module is None:
Expand All @@ -63,7 +63,7 @@ async def connect(self) -> None:
f"STUN Connection Bind Request error: {stun.get_error(stun_r)}"
)

logger.info("Connected to Site: {}".format(self.site_id))
logger.info("Connected to Site: %s", self.site_id)

async def _stun_connect(self, xoraddr):
logger.debug("STUN Connect Request")
Expand Down Expand Up @@ -102,9 +102,7 @@ def _select_module(self):
continue

logger.debug(
"Found module with panel serial: {}".format(
module["panelSerial"]
)
"Found module with panel serial: %s", module["panelSerial"]
)

if not self.panel_serial: # Pick first available
Expand Down Expand Up @@ -133,18 +131,15 @@ def refresh_session_if_required(self) -> None:
self.connection_timestamp = time.time()

def close(self):
self.site_info = None
self.module = None

if self.stun_control:
try:
self.stun_control.close()
self.stun_control = None
except:
logger.exception("stun_control socket close failed")
self.stun_control.close()
self.stun_control = None
if self.stun_tunnel:
try:
self.stun_tunnel.close()
self.stun_tunnel = None
except:
logger.exception("stun_tunnel socket close failed")
self.stun_tunnel.close()
self.stun_tunnel = None

self.connection_timestamp = 0

Expand Down

0 comments on commit 05e3885

Please sign in to comment.