Ejemplo n.º 1
0
    def check_for_messages(self):
        try:
            data = self.socket.recv(4096)
        except ConnectionResetError:
            self.state = BitcoinNetworkPeer.STATE_DEAD
            return
        except socket.timeout:
            return

        if len(data) == 0:  # Have we lost connection?
            self.state = BitcoinNetworkPeer.STATE_DEAD
            return

        # TODO - unwrap_message should return a "required" length for the message to be successful
        # and we should wait until that length becomes available before calling unwrap_message again
        current_buffer = self.data_buffer + data
        self.recv_bytes += len(data)

        while True:
            command, payload, leftover_data = Bitcoin.unwrap_message(
                current_buffer, Bitcoin.NETWORK_DELIVERY)
            self.data_buffer = leftover_data

            if command is None:
                break

            self.got_peer_message(command, payload)
            current_buffer = self.data_buffer
Ejemplo n.º 2
0
    def check_for_messages(self):
        try:
            data = self.socket.recv(4096)
        except ConnectionResetError:
            self.state = BitcoinNetworkPeer.STATE_DEAD
            return
        except socket.timeout:
            return

        if len(data) == 0:  # Have we lost connection?
            self.state = BitcoinNetworkPeer.STATE_DEAD
            return

        # TODO - unwrap_message should return a "required" length for the message to be successful
        # and we should wait until that length becomes available before calling unwrap_message again
        current_buffer = self.data_buffer + data
        self.recv_bytes += len(data)

        while True:
            command, payload, leftover_data = Bitcoin.unwrap_message(current_buffer, Bitcoin.NETWORK_DELIVERY)
            self.data_buffer = leftover_data

            if command is None:
                break

            self.got_peer_message(command, payload)
            current_buffer = self.data_buffer