create-sia-app 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +179 -0
  3. package/package.json +29 -0
  4. package/template/CLAUDE.md +160 -0
  5. package/template/README.md +102 -0
  6. package/template/_gitignore +5 -0
  7. package/template/biome.json +40 -0
  8. package/template/index.html +13 -0
  9. package/template/package.json +30 -0
  10. package/template/rust/README.md +16 -0
  11. package/template/rust/sia-sdk-rs/.changeset/added_cancel_function_to_cancel_inflight_packed_uploads.md +6 -0
  12. package/template/rust/sia-sdk-rs/.changeset/check_if_we_have_enough_hosts_prior_to_encoding_in_upload_slabs.md +16 -0
  13. package/template/rust/sia-sdk-rs/.changeset/fix_slab_length_in_packed_object.md +5 -0
  14. package/template/rust/sia-sdk-rs/.changeset/fix_upload_racing_race_conditon.md +13 -0
  15. package/template/rust/sia-sdk-rs/.changeset/improved_parallelism_of_packed_uploads.md +5 -0
  16. package/template/rust/sia-sdk-rs/.changeset/progress_callback_will_now_be_called_as_expected_for_packed_uploads.md +5 -0
  17. package/template/rust/sia-sdk-rs/.github/dependabot.yml +10 -0
  18. package/template/rust/sia-sdk-rs/.github/workflows/main.yml +36 -0
  19. package/template/rust/sia-sdk-rs/.github/workflows/prepare-release.yml +34 -0
  20. package/template/rust/sia-sdk-rs/.github/workflows/release.yml +30 -0
  21. package/template/rust/sia-sdk-rs/.rustfmt.toml +4 -0
  22. package/template/rust/sia-sdk-rs/Cargo.lock +4127 -0
  23. package/template/rust/sia-sdk-rs/Cargo.toml +3 -0
  24. package/template/rust/sia-sdk-rs/LICENSE +21 -0
  25. package/template/rust/sia-sdk-rs/README.md +30 -0
  26. package/template/rust/sia-sdk-rs/indexd/CHANGELOG.md +79 -0
  27. package/template/rust/sia-sdk-rs/indexd/Cargo.toml +79 -0
  28. package/template/rust/sia-sdk-rs/indexd/benches/upload.rs +258 -0
  29. package/template/rust/sia-sdk-rs/indexd/src/app_client.rs +1710 -0
  30. package/template/rust/sia-sdk-rs/indexd/src/builder.rs +354 -0
  31. package/template/rust/sia-sdk-rs/indexd/src/download.rs +379 -0
  32. package/template/rust/sia-sdk-rs/indexd/src/hosts.rs +659 -0
  33. package/template/rust/sia-sdk-rs/indexd/src/lib.rs +827 -0
  34. package/template/rust/sia-sdk-rs/indexd/src/mock.rs +162 -0
  35. package/template/rust/sia-sdk-rs/indexd/src/object_encryption.rs +125 -0
  36. package/template/rust/sia-sdk-rs/indexd/src/quic.rs +575 -0
  37. package/template/rust/sia-sdk-rs/indexd/src/rhp4.rs +52 -0
  38. package/template/rust/sia-sdk-rs/indexd/src/slabs.rs +497 -0
  39. package/template/rust/sia-sdk-rs/indexd/src/upload.rs +629 -0
  40. package/template/rust/sia-sdk-rs/indexd/src/wasm_time.rs +41 -0
  41. package/template/rust/sia-sdk-rs/indexd/src/web_transport.rs +398 -0
  42. package/template/rust/sia-sdk-rs/indexd_ffi/CHANGELOG.md +76 -0
  43. package/template/rust/sia-sdk-rs/indexd_ffi/Cargo.toml +47 -0
  44. package/template/rust/sia-sdk-rs/indexd_ffi/examples/python/README.md +10 -0
  45. package/template/rust/sia-sdk-rs/indexd_ffi/examples/python/example.py +130 -0
  46. package/template/rust/sia-sdk-rs/indexd_ffi/src/bin/uniffi-bindgen.rs +3 -0
  47. package/template/rust/sia-sdk-rs/indexd_ffi/src/builder.rs +377 -0
  48. package/template/rust/sia-sdk-rs/indexd_ffi/src/io.rs +155 -0
  49. package/template/rust/sia-sdk-rs/indexd_ffi/src/lib.rs +1039 -0
  50. package/template/rust/sia-sdk-rs/indexd_ffi/src/logging.rs +58 -0
  51. package/template/rust/sia-sdk-rs/indexd_ffi/src/tls.rs +23 -0
  52. package/template/rust/sia-sdk-rs/indexd_wasm/Cargo.toml +33 -0
  53. package/template/rust/sia-sdk-rs/indexd_wasm/src/lib.rs +818 -0
  54. package/template/rust/sia-sdk-rs/knope.toml +54 -0
  55. package/template/rust/sia-sdk-rs/sia_derive/CHANGELOG.md +38 -0
  56. package/template/rust/sia-sdk-rs/sia_derive/Cargo.toml +19 -0
  57. package/template/rust/sia-sdk-rs/sia_derive/src/lib.rs +278 -0
  58. package/template/rust/sia-sdk-rs/sia_sdk/CHANGELOG.md +91 -0
  59. package/template/rust/sia-sdk-rs/sia_sdk/Cargo.toml +59 -0
  60. package/template/rust/sia-sdk-rs/sia_sdk/benches/merkle_root.rs +12 -0
  61. package/template/rust/sia-sdk-rs/sia_sdk/src/blake2.rs +22 -0
  62. package/template/rust/sia-sdk-rs/sia_sdk/src/consensus.rs +767 -0
  63. package/template/rust/sia-sdk-rs/sia_sdk/src/encoding/v1.rs +257 -0
  64. package/template/rust/sia-sdk-rs/sia_sdk/src/encoding/v2.rs +291 -0
  65. package/template/rust/sia-sdk-rs/sia_sdk/src/encoding.rs +26 -0
  66. package/template/rust/sia-sdk-rs/sia_sdk/src/encoding_async/v2.rs +367 -0
  67. package/template/rust/sia-sdk-rs/sia_sdk/src/encoding_async.rs +6 -0
  68. package/template/rust/sia-sdk-rs/sia_sdk/src/encryption.rs +303 -0
  69. package/template/rust/sia-sdk-rs/sia_sdk/src/erasure_coding.rs +347 -0
  70. package/template/rust/sia-sdk-rs/sia_sdk/src/lib.rs +15 -0
  71. package/template/rust/sia-sdk-rs/sia_sdk/src/macros.rs +435 -0
  72. package/template/rust/sia-sdk-rs/sia_sdk/src/merkle.rs +112 -0
  73. package/template/rust/sia-sdk-rs/sia_sdk/src/rhp/merkle.rs +357 -0
  74. package/template/rust/sia-sdk-rs/sia_sdk/src/rhp/rpc.rs +1507 -0
  75. package/template/rust/sia-sdk-rs/sia_sdk/src/rhp/types.rs +146 -0
  76. package/template/rust/sia-sdk-rs/sia_sdk/src/rhp.rs +7 -0
  77. package/template/rust/sia-sdk-rs/sia_sdk/src/seed.rs +278 -0
  78. package/template/rust/sia-sdk-rs/sia_sdk/src/signing.rs +236 -0
  79. package/template/rust/sia-sdk-rs/sia_sdk/src/types/common.rs +677 -0
  80. package/template/rust/sia-sdk-rs/sia_sdk/src/types/currency.rs +450 -0
  81. package/template/rust/sia-sdk-rs/sia_sdk/src/types/specifier.rs +110 -0
  82. package/template/rust/sia-sdk-rs/sia_sdk/src/types/spendpolicy.rs +778 -0
  83. package/template/rust/sia-sdk-rs/sia_sdk/src/types/utils.rs +117 -0
  84. package/template/rust/sia-sdk-rs/sia_sdk/src/types/v1.rs +1737 -0
  85. package/template/rust/sia-sdk-rs/sia_sdk/src/types/v2.rs +1726 -0
  86. package/template/rust/sia-sdk-rs/sia_sdk/src/types/work.rs +59 -0
  87. package/template/rust/sia-sdk-rs/sia_sdk/src/types.rs +16 -0
  88. package/template/scripts/setup-rust.js +29 -0
  89. package/template/src/App.tsx +13 -0
  90. package/template/src/components/DevNote.tsx +21 -0
  91. package/template/src/components/auth/ApproveScreen.tsx +84 -0
  92. package/template/src/components/auth/AuthFlow.tsx +77 -0
  93. package/template/src/components/auth/ConnectScreen.tsx +214 -0
  94. package/template/src/components/auth/LoadingScreen.tsx +8 -0
  95. package/template/src/components/auth/RecoveryScreen.tsx +182 -0
  96. package/template/src/components/upload/UploadZone.tsx +314 -0
  97. package/template/src/index.css +9 -0
  98. package/template/src/lib/constants.ts +8 -0
  99. package/template/src/lib/format.ts +35 -0
  100. package/template/src/lib/hex.ts +13 -0
  101. package/template/src/lib/sdk.ts +25 -0
  102. package/template/src/lib/wasm-env.ts +5 -0
  103. package/template/src/main.tsx +12 -0
  104. package/template/src/stores/auth.ts +86 -0
  105. package/template/tsconfig.app.json +31 -0
  106. package/template/tsconfig.json +7 -0
  107. package/template/tsconfig.node.json +26 -0
  108. package/template/vite.config.ts +18 -0
  109. package/template/wasm/indexd_wasm/indexd_wasm.d.ts +309 -0
  110. package/template/wasm/indexd_wasm/indexd_wasm.js +1507 -0
  111. package/template/wasm/indexd_wasm/indexd_wasm_bg.wasm +0 -0
  112. package/template/wasm/indexd_wasm/package.json +31 -0
@@ -0,0 +1,3 @@
1
+ [workspace]
2
+ resolver = "2"
3
+ members = ["sia_sdk", "sia_derive", "indexd", "indexd_ffi", "indexd_wasm"]
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 The Sia Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Sia Core RS
2
+
3
+ This is a Rust implementation of core Sia types. It is intended to be used as a
4
+ library for projects that need to interact with Sia at a low level. It is not
5
+ intended to be a full Sia node implementation.
6
+
7
+ This project is currently in the early stages of development and is not yet ready
8
+ for production use. The API will have breaking changes.
9
+
10
+ ## Features
11
+ - [x] BIP-39 Seeds
12
+ - [x] Addresses
13
+ - [x] Sia binary encoding
14
+ - [ ] Sector roots
15
+ - [ ] Merkle proofs
16
+
17
+ ### v1
18
+ - [x] Unlock conditions
19
+ - [x] Transaction signing
20
+
21
+ ### v2
22
+ - [x] Spend policies
23
+ - [ ] Transaction signing
24
+ - [ ] RHP4
25
+ - [ ] State tree verification
26
+
27
+ ## License
28
+ This project makes use of the `webpki-roots` crate which contains data from
29
+ Common CA Database (CCADB) and is used under the CDLA-2.0-Permissive license.
30
+ The remaining code in this project is licensed under the MIT License.
@@ -0,0 +1,79 @@
1
+ ## 0.2.0 (2026-01-28)
2
+
3
+ ### Breaking Changes
4
+
5
+ - Added missing SDK functionality.
6
+ - Changed download function to borrow the writer.
7
+ - Implemented new `indexd` authentication.
8
+ - Merge SlabSlice and Slab types.
9
+ - Reduced size of signed urls by shortening query parameter names and using base64 URL encoding instead of hex.
10
+ - Renamed `key` to `id` in object event and cursor.
11
+
12
+ ### Features
13
+
14
+ - Add optional host filters (offset/limit/service-account/protocol/country) plus distance sort
15
+ - Exposed `Hosts` struct to deduplicate host selection and performance tracking for scenarios that can not use the QUIC client.
16
+ - Implement upload packing
17
+ - Track RPC failure rate when selecting hosts rather than raw RPCs.
18
+ - Update the insufficient shard check in download_slab_shards.
19
+
20
+ ### Fixes
21
+
22
+ - Fix decoding failing when encrypted metadata is null or missing
23
+ - Fixed an issue with uploads stalling after resuming on some platforms.
24
+ - Fixed progress callback not being called immediately leading to incorrect reporting.
25
+ - Fixed signing when URLs have port number.
26
+ - Improved upload performance by 75%.
27
+ - Make use of goodForUpload field
28
+ - Refactor the uploader and downloader to be transport agnostic to make it easier to add regression testing and benchmarks.
29
+ - Remove service account fields
30
+ - Remove SlabFetcher now that we have the full slab info in the object.
31
+ - Update object listing endpoints to use events
32
+
33
+ ## 0.1.2 (2025-10-04)
34
+
35
+ ### Features
36
+
37
+ - Add JSON serialization to ChainState
38
+
39
+ ## 0.1.1 (2025-10-04)
40
+
41
+ ### Features
42
+
43
+ - Add JSON serialization to ChainState
44
+
45
+ ### Fixes
46
+
47
+ - Fix path dependency versions.
48
+
49
+ ## 0.1.0 (2025-10-04)
50
+
51
+ ### Breaking Changes
52
+
53
+ - Publish to cargo
54
+
55
+ ### Features
56
+
57
+ - Add JSON serialization to ChainState
58
+
59
+ ## 0.0.2 (2025-10-04)
60
+
61
+ ### Features
62
+
63
+ - Add JSON serialization to ChainState
64
+ - Add account API endpoint to app_client and FFI implementation.
65
+ - Add objects API to SDK and app client.
66
+ - Add pin_slab and unpin_slab to FFI.
67
+ - Add progress callback.
68
+ - Add slab pruning
69
+ - Encrypt object metadata.
70
+ - Remove separate range methods.
71
+ - Use randomly generated encryption keys.
72
+ - Validate object key when fetching objects from indexd.
73
+ - Add method for pinning multiple slabs
74
+
75
+ ### Fixes
76
+
77
+ - Make upload progress more responsive.
78
+ - Swap out 'time' dependency for 'chrono'.
79
+ - Use PublicKey for account key type.
@@ -0,0 +1,79 @@
1
+ [package]
2
+ name = "indexd"
3
+ version = "0.2.0"
4
+ edition = "2024"
5
+ repository = "https://github.com/SiaFoundation/sia-sdk-rs"
6
+ license = "MIT"
7
+ description = "SDK for interacting with a Sia network indexer"
8
+ authors = ["The Sia Foundation"]
9
+ categories = ["cryptography::cryptocurrencies"]
10
+ keywords = ["sia", "decentralized", "blockchain", "depin", "storage"]
11
+
12
+ [lib]
13
+ name = "indexd"
14
+ path = "src/lib.rs"
15
+ crate-type = ["cdylib", "rlib"] # cdylib for wasm-pack, rlib for normal use
16
+
17
+ [dependencies]
18
+ serde = "1.0.228"
19
+ serde_json = "1.0.149"
20
+ thiserror = "2.0.18"
21
+ sia_sdk = { path = "../sia_sdk", version = "0.2.0" }
22
+ rand = "0.10.0"
23
+ blake2b_simd = "1.0.4"
24
+ url = { version = "2.5.8", features = ["serde"] }
25
+ log = "0.4.29"
26
+ bytes = "1.11.1"
27
+ tokio-util = { version = "0.7.18", features = ["rt"] }
28
+ priority-queue = "2.7.0"
29
+ serde_with = {version = "3.16.1", features = ["base64"]}
30
+ hex = "0.4.3"
31
+ chacha20poly1305 = "0.10.1"
32
+ chrono = { version = "0.4.43", features = ["serde"] }
33
+ blake2 = "0.10.6"
34
+ hkdf = "0.12.4"
35
+ base64 = "0.22.1"
36
+ async-trait = "0.1.89"
37
+
38
+ # Native-only dependencies
39
+ [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
40
+ tokio = { version = "1.49.0", features = ["fs", "sync", "io-util", "macros", "rt"] }
41
+ # avoid rustls-platform-verifier until https://github.com/rustls/rustls-platform-verifier/issues/115 is resolved
42
+ quinn = { version = "0.11.9", default-features = false, features = ["bloom", "log", "runtime-tokio", "rustls-ring"] }
43
+ reqwest = { version = "0.12.28", default-features = false, features = ["charset", "http2", "json", "rustls-tls"] }
44
+ rustls = { version = "0.23.36", default-features = false, features = ["ring", "logging", "std", "tls12"] }
45
+
46
+ # WASM-only dependencies
47
+ [target.'cfg(target_arch = "wasm32")'.dependencies]
48
+ tokio = { version = "1.49.0", features = ["sync", "io-util", "macros", "rt"] }
49
+ wasm-bindgen = "0.2"
50
+ wasm-bindgen-futures = "0.4"
51
+ js-sys = "0.3"
52
+ web-sys = { version = "0.3", features = [
53
+ "WebTransport",
54
+ "WebTransportOptions",
55
+ "WebTransportBidirectionalStream",
56
+ "WebTransportReceiveStream",
57
+ "WebTransportSendStream",
58
+ "ReadableStream",
59
+ "ReadableStreamDefaultReader",
60
+ "WritableStream",
61
+ "WritableStreamDefaultWriter",
62
+ ] }
63
+ getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
64
+ getrandom = { version = "0.4", features = ["wasm_js"] }
65
+ reqwest = { version = "0.12.28", default-features = false, features = ["json"] }
66
+
67
+ [dev-dependencies]
68
+ criterion = { version = "0.8.2", features = ["async_tokio"] }
69
+ httptest = "0.16.4"
70
+ rustls-platform-verifier = "0.6.2"
71
+ tokio = { version = "1.49.0", features = ["macros"] }
72
+
73
+ [features]
74
+ mock = []
75
+
76
+ [[bench]]
77
+ name = "upload"
78
+ harness = false
79
+ required-features = ["mock"]
@@ -0,0 +1,258 @@
1
+ use bytes::{Bytes, BytesMut};
2
+ use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
3
+ use indexd::mock::{MockDownloader, MockRHP4Client, MockUploader};
4
+ use indexd::{DownloadOptions, Hosts, Object, UploadOptions};
5
+ use rand::Rng;
6
+ use sia::rhp::{Host, SECTOR_SIZE};
7
+ use sia::signing::PrivateKey;
8
+ use sia::types::v2::NetAddress;
9
+ use std::io::Cursor;
10
+ use std::sync::Arc;
11
+ use tokio::io::{AsyncWrite, sink};
12
+ use tokio::runtime;
13
+
14
+ struct TtfbWriter {
15
+ start: std::time::Instant,
16
+ ttfb: Option<std::time::Duration>,
17
+ }
18
+
19
+ impl TtfbWriter {
20
+ fn new(start: std::time::Instant) -> Self {
21
+ Self { start, ttfb: None }
22
+ }
23
+
24
+ fn ttfb(&self) -> Option<std::time::Duration> {
25
+ self.ttfb
26
+ }
27
+ }
28
+
29
+ impl AsyncWrite for TtfbWriter {
30
+ fn poll_write(
31
+ mut self: std::pin::Pin<&mut Self>,
32
+ _: &mut std::task::Context<'_>,
33
+ buf: &[u8],
34
+ ) -> std::task::Poll<std::io::Result<usize>> {
35
+ if self.ttfb.is_none() {
36
+ self.ttfb = Some(self.start.elapsed());
37
+ }
38
+ std::task::Poll::Ready(Ok(buf.len()))
39
+ }
40
+
41
+ fn poll_flush(
42
+ self: std::pin::Pin<&mut Self>,
43
+ _: &mut std::task::Context<'_>,
44
+ ) -> std::task::Poll<std::io::Result<()>> {
45
+ std::task::Poll::Ready(Ok(()))
46
+ }
47
+
48
+ fn poll_shutdown(
49
+ self: std::pin::Pin<&mut Self>,
50
+ _: &mut std::task::Context<'_>,
51
+ ) -> std::task::Poll<std::io::Result<()>> {
52
+ std::task::Poll::Ready(Ok(()))
53
+ }
54
+ }
55
+
56
+ async fn upload_object(uploader: Arc<MockUploader>, input: Bytes, opts: UploadOptions) -> Object {
57
+ let r = Cursor::new(input);
58
+ uploader.upload(r, opts).await.expect("upload failed")
59
+ }
60
+
61
+ fn upload_benchmark(c: &mut Criterion) {
62
+ let app_key = Arc::new(PrivateKey::from_seed(&rand::random()));
63
+ let transport = Arc::new(MockRHP4Client::new());
64
+ let hosts = Hosts::new();
65
+ hosts.update(
66
+ (0..90)
67
+ .map(|_| Host {
68
+ public_key: PrivateKey::from_seed(&rand::random()).public_key(),
69
+ addresses: vec![NetAddress {
70
+ protocol: sia::types::v2::Protocol::QUIC,
71
+ address: "localhost:1234".to_string(),
72
+ }],
73
+ country_code: "US".to_string(),
74
+ latitude: 0.0,
75
+ longitude: 0.0,
76
+ good_for_upload: true,
77
+ })
78
+ .collect(),
79
+ );
80
+
81
+ let uploader = Arc::new(MockUploader::new(
82
+ hosts.clone(),
83
+ transport.clone(),
84
+ app_key.clone(),
85
+ ));
86
+ let downloader = Arc::new(MockDownloader::new(
87
+ hosts.clone(),
88
+ transport.clone(),
89
+ app_key.clone(),
90
+ ));
91
+ let mut input = BytesMut::zeroed(SECTOR_SIZE * 30); // 3 full slabs
92
+ rand::rng().fill_bytes(&mut input);
93
+ let input = input.freeze();
94
+
95
+ let mut large_group = c.benchmark_group("120MiB");
96
+ large_group.throughput(Throughput::Bytes(input.len() as u64));
97
+
98
+ let runtime = runtime::Builder::new_multi_thread()
99
+ .enable_all()
100
+ .build()
101
+ .expect("failed to create global runtime");
102
+
103
+ // all shards in flight
104
+ large_group.bench_with_input(
105
+ BenchmarkId::new("upload", "90 inflight"),
106
+ &input,
107
+ |b, input| {
108
+ b.to_async(&runtime).iter(|| async {
109
+ upload_object(
110
+ uploader.clone(),
111
+ input.clone(),
112
+ UploadOptions {
113
+ max_inflight: 90,
114
+ ..Default::default()
115
+ },
116
+ )
117
+ .await;
118
+ });
119
+ transport.clear();
120
+ },
121
+ );
122
+
123
+ large_group.bench_with_input(
124
+ BenchmarkId::new("upload", "10 inflight"),
125
+ &input,
126
+ |b, input| {
127
+ b.to_async(&runtime).iter(|| async {
128
+ upload_object(
129
+ uploader.clone(),
130
+ input.clone(),
131
+ UploadOptions {
132
+ max_inflight: 10,
133
+ ..Default::default()
134
+ },
135
+ )
136
+ .await;
137
+ });
138
+ transport.clear();
139
+ },
140
+ );
141
+
142
+ large_group.bench_with_input(BenchmarkId::new("upload", "default"), &input, |b, input| {
143
+ b.to_async(&runtime).iter(|| async {
144
+ upload_object(uploader.clone(), input.clone(), UploadOptions::default()).await;
145
+ });
146
+ transport.clear();
147
+ });
148
+
149
+ let object = runtime.block_on(async {
150
+ upload_object(uploader.clone(), input.clone(), UploadOptions::default()).await
151
+ });
152
+
153
+ large_group.bench_with_input(
154
+ BenchmarkId::new("download", "30 inflight"),
155
+ &object,
156
+ |b, object| {
157
+ b.to_async(&runtime).iter(|| async {
158
+ downloader
159
+ .download(
160
+ &mut sink(),
161
+ object,
162
+ DownloadOptions {
163
+ max_inflight: 30,
164
+ ..Default::default()
165
+ },
166
+ )
167
+ .await
168
+ .expect("download to complete");
169
+ });
170
+ },
171
+ );
172
+
173
+ large_group.bench_with_input(
174
+ BenchmarkId::new("download", "10 inflight"),
175
+ &object,
176
+ |b, object| {
177
+ b.to_async(&runtime).iter(|| async {
178
+ downloader
179
+ .download(
180
+ &mut sink(),
181
+ object,
182
+ DownloadOptions {
183
+ max_inflight: 10,
184
+ ..Default::default()
185
+ },
186
+ )
187
+ .await
188
+ .expect("download to complete");
189
+ });
190
+ },
191
+ );
192
+
193
+ large_group.bench_with_input(
194
+ BenchmarkId::new("download", "default"),
195
+ &object,
196
+ |b, object| {
197
+ b.to_async(&runtime).iter(|| async {
198
+ downloader
199
+ .download(&mut sink(), object, DownloadOptions::default())
200
+ .await
201
+ .expect("download to complete");
202
+ });
203
+ },
204
+ );
205
+
206
+ large_group.finish();
207
+
208
+ let mut ttfb_group = c.benchmark_group("ttfb");
209
+
210
+ ttfb_group.bench_function("120MiB", |b| {
211
+ b.to_async(&runtime).iter_custom(|iters| {
212
+ let downloader = downloader.clone();
213
+ let object = object.clone();
214
+ async move {
215
+ let mut total = std::time::Duration::ZERO;
216
+ for _ in 0..iters {
217
+ let mut w = TtfbWriter::new(std::time::Instant::now());
218
+ downloader
219
+ .download(&mut w, &object, DownloadOptions::default())
220
+ .await
221
+ .expect("download to complete");
222
+ total += w.ttfb().unwrap_or_else(|| w.start.elapsed());
223
+ }
224
+ total
225
+ }
226
+ });
227
+ });
228
+
229
+ ttfb_group.bench_function("64B", |b| {
230
+ b.to_async(&runtime).iter_custom(|iters| {
231
+ let downloader = downloader.clone();
232
+ let object = object.clone();
233
+ async move {
234
+ let mut total = std::time::Duration::ZERO;
235
+ for _ in 0..iters {
236
+ let mut w = TtfbWriter::new(std::time::Instant::now());
237
+ downloader
238
+ .download(
239
+ &mut w,
240
+ &object,
241
+ DownloadOptions {
242
+ length: Some(64),
243
+ ..Default::default()
244
+ },
245
+ )
246
+ .await
247
+ .expect("download to complete");
248
+ total += w.ttfb().unwrap_or_else(|| w.start.elapsed());
249
+ }
250
+ total
251
+ }
252
+ });
253
+ });
254
+ ttfb_group.finish();
255
+ }
256
+
257
+ criterion_group!(benches, upload_benchmark);
258
+ criterion_main!(benches);