def _get_peers_of_endpoints(self, peers, endpoints): get_peers_request = GetPeersRequest() for endpoint in endpoints: conn_id = None try: conn_id = self._network.get_connection_id_by_endpoint(endpoint) except KeyError: # If the connection does not exist, send a connection request with self._lock: if endpoint in self._temp_endpoints: del self._temp_endpoints[endpoint] self._network.add_outbound_connection(endpoint) self._temp_endpoints[endpoint] = EndpointInfo( EndpointStatus.TOPOLOGY, time.time(), INITIAL_RETRY_FREQUENCY) # If the connection does exist, request peers. if conn_id is not None: if conn_id in peers: # connected and peered - we've already sent peer request continue else: # connected but not peered if endpoint in self._temp_endpoints: # Endpoint is not yet authorized, do not request peers continue self._network.send( validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST, get_peers_request.SerializeToString(), conn_id)
def _connect_success_topology_callback(self, connection_id): LOGGER.debug("Connection to %s succeeded for topology request", connection_id) get_peers_request = GetPeersRequest() self._network.send(validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST, get_peers_request.SerializeToString(), connection_id)
def _get_peers_of_peers(self, peers): get_peers_request = GetPeersRequest() for conn_id in peers: try: self._network.send( validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST, get_peers_request.SerializeToString(), conn_id) except ValueError: LOGGER.debug("Peer disconnected: %s", conn_id)
def _connect_success_topology_callback(self, connection_id): LOGGER.debug("Connection to %s succeeded for topology request", connection_id) self._connection_statuses[connection_id] = "temp" get_peers_request = GetPeersRequest() self._network.send(validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST, get_peers_request.SerializeToString(), connection_id, callback=partial(self._remove_temporary_connection, connection_id))
def _get_peers_of_endpoints(self, peers, endpoints): get_peers_request = GetPeersRequest() LOGGER.debug("gossip:_get_peers_of_endpoints endpoints=%d ", len(endpoints)) for endpoint in endpoints: conn_id = None try: conn_id = self._network.get_connection_id_by_endpoint(endpoint) except KeyError: # If the connection does not exist, send a connection request with self._lock: if endpoint in self._temp_endpoints: del self._temp_endpoints[endpoint] self._temp_endpoints[endpoint] = EndpointInfo( EndpointStatus.TOPOLOGY, time.time(), INITIAL_RETRY_FREQUENCY) self._network.add_outbound_connection(endpoint) # If the connection does exist, request peers. if conn_id is not None: if not self._network.is_connection_handshake_complete(conn_id): # has not finished the authorization (trust/challenge) # process yet. LOGGER.debug( "gossip:_get_peers_of_endpoints has not finished the authorization " ) continue elif conn_id in peers: # connected and peered - we've already sent peer request continue else: # connected but not peered if endpoint in self._temp_endpoints: # Endpoint is not yet authorized, do not request peers LOGGER.debug( "gossip:Endpoint %s is not yet authorized, do not request peers %d ", endpoint, len(peers)) continue try: LOGGER.debug( "gossip:Endpoint %s send GOSSIP_GET_PEERS_REQUEST", endpoint) self._network.send( validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST, get_peers_request.SerializeToString(), conn_id) except ValueError: LOGGER.debug("Connection disconnected: %s", conn_id)
def _connect_success_topology_callback(self, connection_id): LOGGER.debug("Connection to %s succeeded for topology request", connection_id) self._connection_statuses[connection_id] = "temp" get_peers_request = GetPeersRequest() def callback(request, result): # request, result are ignored, but required by the callback self._remove_temporary_connection(connection_id) self._network.send(validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST, get_peers_request.SerializeToString(), connection_id, callback=callback)
def _get_peers_of_endpoints(self, peers, endpoints): get_peers_request = GetPeersRequest() for endpoint in endpoints: try: conn_id = self._network.get_connection_id_by_endpoint(endpoint) if conn_id in peers: # connected and peered - we've already sent continue else: # connected but not peered self._network.send( validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST, get_peers_request.SerializeToString(), conn_id) except KeyError: self._network.add_outbound_connection( endpoint, success_callback=self._connect_success_topology_callback, failure_callback=self._connect_failure_topology_callback)
def _get_peers_of_peers(self, peers): get_peers_request = GetPeersRequest() for conn_id in peers: self._network.send(validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST, get_peers_request.SerializeToString(), conn_id)