| 1 | |
|---|
| 2 | def upload_immutable(storage_server, storage_index, renew_secret, cancel_secret, shares): |
|---|
| 3 | """ |
|---|
| 4 | Synchronously upload some immutable shares to a ``StorageServer``. |
|---|
| 5 | |
|---|
| 6 | :param allmydata.storage.server.StorageServer storage_server: The storage |
|---|
| 7 | server object to use to perform the upload. |
|---|
| 8 | |
|---|
| 9 | :param bytes storage_index: The storage index for the immutable shares. |
|---|
| 10 | |
|---|
| 11 | :param bytes renew_secret: The renew secret for the implicitly created lease. |
|---|
| 12 | :param bytes cancel_secret: The cancel secret for the implicitly created lease. |
|---|
| 13 | |
|---|
| 14 | :param dict[int, bytes] shares: A mapping from share numbers to share data |
|---|
| 15 | to upload. The data for all shares must be of the same length. |
|---|
| 16 | |
|---|
| 17 | :return: ``None`` |
|---|
| 18 | """ |
|---|
| 19 | already, writers = storage_server.allocate_buckets( |
|---|
| 20 | storage_index, |
|---|
| 21 | renew_secret, |
|---|
| 22 | cancel_secret, |
|---|
| 23 | shares.keys(), |
|---|
| 24 | len(next(iter(shares.values()))), |
|---|
| 25 | ) |
|---|
| 26 | for shnum, writer in writers.items(): |
|---|
| 27 | writer.write(0, shares[shnum]) |
|---|
| 28 | writer.close() |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | def upload_mutable(storage_server, storage_index, secrets, shares): |
|---|
| 32 | """ |
|---|
| 33 | Synchronously upload some mutable shares to a ``StorageServer``. |
|---|
| 34 | |
|---|
| 35 | :param allmydata.storage.server.StorageServer storage_server: The storage |
|---|
| 36 | server object to use to perform the upload. |
|---|
| 37 | |
|---|
| 38 | :param bytes storage_index: The storage index for the immutable shares. |
|---|
| 39 | |
|---|
| 40 | :param secrets: A three-tuple of a write enabler, renew secret, and cancel |
|---|
| 41 | secret. |
|---|
| 42 | |
|---|
| 43 | :param dict[int, bytes] shares: A mapping from share numbers to share data |
|---|
| 44 | to upload. |
|---|
| 45 | |
|---|
| 46 | :return: ``None`` |
|---|
| 47 | """ |
|---|
| 48 | test_and_write_vectors = { |
|---|
| 49 | sharenum: ([], [(0, data)], None) |
|---|
| 50 | for sharenum, data |
|---|
| 51 | in shares.items() |
|---|
| 52 | } |
|---|
| 53 | read_vector = [] |
|---|
| 54 | |
|---|
| 55 | storage_server.slot_testv_and_readv_and_writev( |
|---|
| 56 | storage_index, |
|---|
| 57 | secrets, |
|---|
| 58 | test_and_write_vectors, |
|---|
| 59 | read_vector, |
|---|
| 60 | ) |
|---|