From 44562d9b3dccd14fff17c4cf356280391a13a36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 11 Sep 2023 14:33:32 +0200 Subject: [PATCH] Guard _peer_count value (#205) --- setup.py | 2 +- snitun/server/worker.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index aaa79205..65d7858a 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -VERSION = "0.36.1" +VERSION = "0.36.2" setup( name="snitun", diff --git a/snitun/server/worker.py b/snitun/server/worker.py index 77299cf8..268b9670 100644 --- a/snitun/server/worker.py +++ b/snitun/server/worker.py @@ -65,11 +65,13 @@ async def _async_init(self) -> None: def _event_stream(self, peer: Peer, event: PeerManagerEvent) -> None: """Event stream peer connection data.""" if event == PeerManagerEvent.CONNECTED: - self._peer_count.set(self._peer_count.value + 1) + if peer.hostname not in self._sync: + self._peer_count.set(self._peer_count.value + 1) for hostname in peer.all_hostnames: self._sync[hostname] = None else: - self._peer_count.set(self._peer_count.value - 1) + if peer.hostname in self._sync: + self._peer_count.set(self._peer_count.value - 1) for hostname in peer.all_hostnames: self._sync.pop(hostname, None)