Skip to content

Commit

Permalink
Guard _peer_count value (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Sep 11, 2023
1 parent bd5ac13 commit 44562d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "0.36.1"
VERSION = "0.36.2"

setup(
name="snitun",
Expand Down
6 changes: 4 additions & 2 deletions snitun/server/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 44562d9

Please sign in to comment.