コード例 #1
0
ファイル: gossip.py プロジェクト: cclauss/sawtooth-core
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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))
コード例 #5
0
    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)
コード例 #6
0
    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)
コード例 #7
0
    def handle(self, connection_id, message_content):
        request = GetPeersRequest()
        request.ParseFromString(message_content)
        LOGGER.debug("got peers request message "
                     "from %s. sending ack", connection_id)

        self._gossip.send_peers(connection_id)

        ack = NetworkAcknowledgement()
        ack.status = ack.OK

        return HandlerResult(HandlerStatus.RETURN,
                             message_out=ack,
                             message_type=validator_pb2.Message.NETWORK_ACK)
コード例 #8
0
    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)
コード例 #9
0
    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)