Start writing a connection class for tracking active connections

This commit is contained in:
Lee Miller 2023-09-04 03:24:06 +03:00
parent eb447a92dc
commit abd7977471
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
1 changed files with 20 additions and 0 deletions

View File

@ -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