From abd7977471b5e615fe2a4354bca32432d55b3d7e Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Mon, 4 Sep 2023 03:24:06 +0300 Subject: [PATCH] Start writing a connection class for tracking active connections --- minode/connection.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/minode/connection.py b/minode/connection.py index 2d057bb..405c010 100644 --- a/minode/connection.py +++ b/minode/connection.py @@ -491,4 +491,24 @@ class Connection(ConnectionBase): self.vectors_to_send.update(getdata.vectors) +class TrackingConnection(Connection): + """A helper to track number of servers in the network""" + def __init__(self, *args): + super().__init__(*args) + self.connected_time = None + self.active = False + + def _on_connection_fully_established(self): + self.connected_time = time.time() + super()._on_connection_fully_established() + + def _process_message(self, m): + super()._process_message(m) + if not self.active and m.command in (b'object', b'getdata'): + self.active = True + + # def run(self): + # super().run() + + shared.connection = Connection