def send_peers(self, connection_id): """Sends a message containing our peers to the connection identified by connection_id. Args: connection_id (str): A unique identifier which identifies an connection on the network server socket. """ with self._lock: # Needs to actually be the list of advertised endpoints of # our peers peer_endpoints = list(self._peers.values()) if self._endpoint: peer_endpoints.append(self._endpoint) peers_response = GetPeersResponse(peer_endpoints=peer_endpoints) try: # Send a one_way message because the connection will be closed # if this is a temp connection. self._network.send( validator_pb2.Message.GOSSIP_GET_PEERS_RESPONSE, peers_response.SerializeToString(), connection_id, one_way=True) except ValueError: LOGGER.debug("Connection disconnected: %s", connection_id)
def handle(self, connection_id, message_content): response = GetPeersResponse() response.ParseFromString(message_content) LOGGER.debug("Got peers response message from %s. Endpoints: %s", connection_id, response.peer_endpoints) self._gossip.add_candidate_peer_endpoints(response.peer_endpoints) return HandlerResult(HandlerStatus.PASS)
def handle(self, connection_id, message_content): response = GetPeersResponse() response.ParseFromString(message_content) LOGGER.debug("got peers response message " "from %s. sending ack", connection_id) LOGGER.debug("PEERS RESPONSE ENDPOINTS: %s", response.peer_endpoints) self._gossip.add_candidate_peer_endpoints(response.peer_endpoints) return HandlerResult(HandlerStatus.PASS)
def handle(self, connection_id, message_content): response = GetPeersResponse() response.ParseFromString(message_content) LOGGER.debug("got peers response message " "from %s. sending ack", connection_id) LOGGER.debug("PEERS RESPONSE ENDPOINTS: %s", response.peer_endpoints) self._gossip.add_candidate_peer_endpoints(response.peer_endpoints) ack = NetworkAcknowledgement() ack.status = ack.OK return HandlerResult(HandlerStatus.RETURN, message_out=ack, message_type=validator_pb2.Message.NETWORK_ACK)
def send_peers(self, connection_id): """Sends a message containing our peers to the connection identified by connection_id. Args: connection_id (str): A unique identifier which identifies an connection on the network server socket. """ with self._condition: # Needs to actually be the list of advertised endpoints of # our peers peer_endpoints = list(self._peers.values()) if self._endpoint: peer_endpoints.append(self._endpoint) peers_response = GetPeersResponse(peer_endpoints=peer_endpoints) self._network.send(validator_pb2.Message.GOSSIP_GET_PEERS_RESPONSE, peers_response.SerializeToString(), connection_id)