def register_peer(self, connection_id, endpoint): """Registers a connected connection_id. Args: connection_id (str): A unique identifier which identifies an connection on the network server socket. endpoint (str): The publically reachable endpoint of the new peer """ with self._lock: if len(self._peers) < self._maximum_peer_connectivity: self._peers[connection_id] = endpoint self._topology.set_connection_status(connection_id, PeerStatus.PEER) LOGGER.debug("Added connection_id %s with endpoint %s, " "connected identities are now %s", connection_id, endpoint, self._peers) else: raise PeeringException( "At maximum configured number of peers: {} " "Rejecting peering request from {}.".format( self._maximum_peer_connectivity, endpoint)) public_key = self.peer_to_public_key(connection_id) if public_key: self._consensus_notifier.notify_peer_connected(public_key)
def register_peer(self, connection_id, endpoint): """Registers a connected connection_id. Args: connection_id (str): A unique identifier which identifies an connection on the network server socket. endpoint (str): The publically reachable endpoint of the new peer """ with self._condition: if len(self._peers) < self._maximum_peer_connectivity: self._peers[connection_id] = endpoint LOGGER.debug( "Added connection_id %s with endpoint %s, " "connected identities are now %s", connection_id, endpoint, self._peers) else: LOGGER.debug( "At maximum configured number of peers: %s " "Rejecting peering request from %s.", self._maximum_peer_connectivity, endpoint) raise PeeringException()