diff --git a/hathor/metrics.py b/hathor/metrics.py index e1e61c81f..2c27955be 100644 --- a/hathor/metrics.py +++ b/hathor/metrics.py @@ -173,6 +173,7 @@ def subscribe(self) -> None: """ events = [ HathorEvents.NETWORK_NEW_TX_ACCEPTED, + HathorEvents.NETWORK_PEER_CONNECTING, HathorEvents.NETWORK_PEER_READY, HathorEvents.NETWORK_PEER_CONNECTED, HathorEvents.NETWORK_PEER_DISCONNECTED, @@ -196,6 +197,7 @@ def handle_publish(self, key: HathorEvents, args: EventArguments) -> None: self.transactions = self.tx_storage.get_tx_count() elif key in ( HathorEvents.NETWORK_PEER_READY, + HathorEvents.NETWORK_PEER_CONNECTING, HathorEvents.NETWORK_PEER_CONNECTED, HathorEvents.NETWORK_PEER_DISCONNECTED, HathorEvents.NETWORK_PEER_CONNECTION_FAILED diff --git a/hathor/p2p/manager.py b/hathor/p2p/manager.py index 8db007ba5..37a912897 100644 --- a/hathor/p2p/manager.py +++ b/hathor/p2p/manager.py @@ -572,6 +572,11 @@ def connect_to(self, description: str, peer: Optional[PeerId] = None, use_ssl: O deferred.addCallback(self._connect_to_callback, peer, endpoint, connection_string, peer_id) deferred.addErrback(self.on_connection_failure, peer, endpoint) self.log.info('connect to ', endpoint=description, peer=str(peer)) + self.pubsub.publish( + HathorEvents.NETWORK_PEER_CONNECTING, + peer=peer, + peers_count=self._get_peers_count() + ) def listen(self, description: str, use_ssl: Optional[bool] = None) -> IStreamServerEndpoint: """ Start to listen to new connection according to the description. diff --git a/hathor/pubsub.py b/hathor/pubsub.py index 10aaa6d9e..e410c3fac 100644 --- a/hathor/pubsub.py +++ b/hathor/pubsub.py @@ -30,6 +30,10 @@ class HathorEvents(Enum): Triggered when a new tx/block is accepted in the network Publishes a tx/block object + NETWORK_PEER_CONNECTING: + Triggered when a peer starts connecting to the network + Publishes the peer id and the peers count + NETWORK_PEER_CONNECTION_FAILURE: Triggered when a peer connection to the network fails Publishes the peer id and the peers count @@ -91,6 +95,8 @@ class HathorEvents(Enum): MANAGER_ON_START = 'manager:on_start' MANAGER_ON_STOP = 'manager:on_stop' + NETWORK_PEER_CONNECTING = 'network:peer_connecting' + NETWORK_PEER_CONNECTION_FAILED = 'network:peer_connection_failed' NETWORK_PEER_CONNECTED = 'network:peer_connected'