Start writing a connection class for tracking active connections
This commit is contained in:
parent
eb447a92dc
commit
abd7977471
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue