Ejemplo n.º 1
0
    def update(self, event: shard_events.MemberChunkEvent) -> None:
        if self.missing_chunk_indexes is None:
            self.average_chunk_size = len(event.members)
            self.chunk_count = event.chunk_count
            self.missing_chunk_indexes = list(range(event.chunk_count))

        self.not_found_ids.extend(event.not_found)
        self.missing_chunk_indexes.remove(event.chunk_index)
        self._mono_last_received = time.monotonic_ns()
        self.last_received = time.utc_datetime()
Ejemplo n.º 2
0
def _fixed_size_nonce() -> str:
    # This generates nonces of length 28 for use in member chunking.
    head = time.monotonic_ns().to_bytes(8, "big")
    tail = random.getrandbits(92).to_bytes(12, "big")
    return base64.b64encode(head + tail).decode("ascii")
Ejemplo n.º 3
0
def _random_nonce() -> str:
    head = time.monotonic_ns().to_bytes(8, "big")
    tail = random.getrandbits(92).to_bytes(12, "big")
    return base64.b64encode(head + tail).decode("ascii")
Ejemplo n.º 4
0
    def is_complete(self) -> bool:
        if self.received_chunks == self.chunk_count:
            return True

        return self._mono_last_received is not None and time.monotonic_ns(
        ) - self._mono_last_received > EXPIRY_TIME