Esempio n. 1
0
    def message_new_data(self, message):
        data, hashes = self._unpack_update(message)
        uncompressed = syncdata._decode_data(data)
        h = syncdata.sha256(uncompressed)
        self.datasource.update_synced_time(self)
        self.command(b"synced", h)

        if self.datasource.hash_history[-1] in hashes:
            self.datasource.not_diverged(self)

            self.datasource.hash_history.append(h)
            self.remote_hashes.append(h)

            self.datasource.data = uncompressed
            self.delay_update_notification()
        elif self.remote_hashes[-1] == h:
            return
        elif not self.diverged:
            # TODO: big flashy warning somewhere!
            self.disconnect("bad state - runtime diverge")
            return
        else:
            assert self.remote_hashes[-1] in hashes
            self.remote_hashes.append(h)
            self.datasource.record_diverge(self, uncompressed)
Esempio n. 2
0
    def message_history_and_data(self, message):
        # this can use a lot of memory, careful
        data, hashes = self._unpack_update(message)
        uncompressed = syncdata._decode_data(data)

        h = syncdata.sha256(uncompressed)
        assert hashes[-1] == h, "the other end sent derped data"

        if not self.diverged:
            if hashes[0] != self.datasource.hash_history[-1]:
                assert 0, "what do we do here?"

            self.datasource.hash_history.extend(hashes[1:])
            self.init_finished()

            self.datasource.data = uncompressed
            self.delay_update_notification()
        else:
            self.init_finished(hashes)
            self.datasource.record_diverge(self, uncompressed)

        self.datasource.update_synced_time(self)
        self.command(b"synced", h)