| 1 | #ifndef AWS_S3_CLIENT_H |
| 2 | #define AWS_S3_CLIENT_H |
| 3 | |
| 4 | /** |
| 5 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 6 | * SPDX-License-Identifier: Apache-2.0. |
| 7 | */ |
| 8 | |
| 9 | #include <aws/auth/signing_config.h> |
| 10 | #include <aws/common/ref_count.h> |
| 11 | #include <aws/io/retry_strategy.h> |
| 12 | #include <aws/s3/s3.h> |
| 13 | #include <aws/s3/s3_buffer_pool.h> |
| 14 | |
| 15 | AWS_PUSH_SANE_WARNING_LEVEL |
| 16 | |
| 17 | struct aws_allocator; |
| 18 | |
| 19 | struct aws_http_stream; |
| 20 | struct aws_http_message; |
| 21 | struct aws_http_headers; |
| 22 | struct aws_tls_connection_options; |
| 23 | struct aws_input_stream; |
| 24 | struct aws_hash_table; |
| 25 | |
| 26 | struct aws_s3_client; |
| 27 | struct aws_s3_request; |
| 28 | struct aws_s3_meta_request; |
| 29 | struct aws_s3_meta_request_result; |
| 30 | struct aws_s3_meta_request_resume_token; |
| 31 | struct aws_uri; |
| 32 | struct aws_string; |
| 33 | |
| 34 | struct aws_s3_request_metrics; |
| 35 | struct aws_s3express_credentials_provider; |
| 36 | struct aws_credentials_properties_s3express; |
| 37 | |
| 38 | /** |
| 39 | * A Meta Request represents a group of generated requests that are being done on behalf of the |
| 40 | * original request. For example, one large GetObject request can be transformed into a series |
| 41 | * of ranged GetObject requests that are executed in parallel to improve throughput. |
| 42 | * |
| 43 | * The aws_s3_meta_request_type is a hint of transformation to be applied. |
| 44 | */ |
| 45 | enum aws_s3_meta_request_type { |
| 46 | |
| 47 | /** |
| 48 | * The Default meta request type sends any request to S3 as-is (with no transformation). For example, |
| 49 | * it can be used to pass a CreateBucket request. |
| 50 | */ |
| 51 | AWS_S3_META_REQUEST_TYPE_DEFAULT, |
| 52 | |
| 53 | /** |
| 54 | * The GetObject request will be split into a series of ranged GetObject requests that are |
| 55 | * executed in parallel to improve throughput, when possible. |
| 56 | */ |
| 57 | AWS_S3_META_REQUEST_TYPE_GET_OBJECT, |
| 58 | |
| 59 | /** |
| 60 | * The PutObject request will be split into MultiPart uploads that are executed in parallel |
| 61 | * to improve throughput, when possible. |
| 62 | * Note: put object supports both known and unknown body length. The client |
| 63 | * relies on Content-Length header to determine length of the body. |
| 64 | * Request with unknown content length are always sent using multipart |
| 65 | * upload regardless of final number of parts and do have the following limitations: |
| 66 | * - multipart threshold is ignored and all request are made through mpu, |
| 67 | * even if they only need one part |
| 68 | * - pause/resume is not supported |
| 69 | * - meta request will throw error if checksum header is provider (due to |
| 70 | * general limitation of checksum not being usable if meta request is |
| 71 | * getting split) |
| 72 | */ |
| 73 | AWS_S3_META_REQUEST_TYPE_PUT_OBJECT, |
| 74 | |
| 75 | /** |
| 76 | * The CopyObject meta request performs a multi-part copy |
| 77 | * using multiple S3 UploadPartCopy requests in parallel, or bypasses |
| 78 | * a CopyObject request to S3 if the object size is not large enough for |
| 79 | * a multipart upload. |
| 80 | * Note: copy support is still in development and has following limitations: |
| 81 | * 1. host header must use virtual host addressing style (path style is not |
| 82 | * supported) and both source and dest buckets must have dns compliant name |
| 83 | * 2. only {bucket}/{key} format is supported for source and passing arn as |
| 84 | * source will not work |
| 85 | * 3. source bucket is assumed to be in the same region as dest |
| 86 | * 4. source bucket and dest bucket must both be either directory buckets or regular buckets. |
| 87 | * 5. on the multipart copy path, metadata, tags, and annotations are not |
| 88 | * automatically copied from the source object. The caller must set |
| 89 | * `x-amz-metadata-directive: REPLACE` and include all desired metadata |
| 90 | * headers and `x-amz-tagging` on the request. Single-part copies (< 1GB) |
| 91 | * are not affected as S3 CopyObject natively handles COPY directives. |
| 92 | * |
| 93 | * Provide the `meta_request_options.copy_source_uri` to bypass limitation 1 & 2. |
| 94 | */ |
| 95 | AWS_S3_META_REQUEST_TYPE_COPY_OBJECT, |
| 96 | |
| 97 | AWS_S3_META_REQUEST_TYPE_MAX, |
| 98 | }; |
| 99 | |
| 100 | /** |
| 101 | * The type of a single S3 HTTP request. Used by metrics. |
| 102 | * A meta-request can make multiple S3 HTTP requests under the hood. |
| 103 | * |
| 104 | * For example, AWS_S3_META_REQUEST_TYPE_PUT_OBJECT for a large file will |
| 105 | * do multipart upload, resulting in 3+ HTTP requests: |
| 106 | * AWS_S3_REQUEST_TYPE_CREATE_MULTIPART_UPLOAD, one or more AWS_S3_REQUEST_TYPE_UPLOAD_PART, |
| 107 | * and finally AWS_S3_REQUEST_TYPE_COMPLETE_MULTIPART_UPLOAD. |
| 108 | * |
| 109 | * aws_s3_request_type_operation_name() returns the S3 operation name |
| 110 | * for types that map (e.g. AWS_S3_REQUEST_TYPE_HEAD_OBJECT -> "HeadObject"), |
| 111 | * or empty string for types that don't map (e.g. AWS_S3_REQUEST_TYPE_UNKNOWN -> ""). |
| 112 | */ |
| 113 | enum aws_s3_request_type { |
| 114 | /* The actual type of the single S3 HTTP request is unknown */ |
| 115 | AWS_S3_REQUEST_TYPE_UNKNOWN, |
| 116 | |
| 117 | /* S3 APIs */ |
| 118 | AWS_S3_REQUEST_TYPE_HEAD_OBJECT, |
| 119 | AWS_S3_REQUEST_TYPE_GET_OBJECT, |
| 120 | AWS_S3_REQUEST_TYPE_LIST_PARTS, |
| 121 | AWS_S3_REQUEST_TYPE_CREATE_MULTIPART_UPLOAD, |
| 122 | AWS_S3_REQUEST_TYPE_UPLOAD_PART, |
| 123 | AWS_S3_REQUEST_TYPE_ABORT_MULTIPART_UPLOAD, |
| 124 | AWS_S3_REQUEST_TYPE_COMPLETE_MULTIPART_UPLOAD, |
| 125 | AWS_S3_REQUEST_TYPE_UPLOAD_PART_COPY, |
| 126 | AWS_S3_REQUEST_TYPE_COPY_OBJECT, |
| 127 | AWS_S3_REQUEST_TYPE_PUT_OBJECT, |
| 128 | AWS_S3_REQUEST_TYPE_CREATE_SESSION, |
| 129 | |
| 130 | /* Max enum value */ |
| 131 | AWS_S3_REQUEST_TYPE_MAX, |
| 132 | |
| 133 | /** @deprecated Use AWS_S3_REQUEST_TYPE_UNKNOWN if the actual S3 HTTP request type is unknown */ |
| 134 | AWS_S3_REQUEST_TYPE_DEFAULT = AWS_S3_REQUEST_TYPE_UNKNOWN, |
| 135 | }; |
| 136 | |
| 137 | /** |
| 138 | * Invoked to provide response headers received during execution of the meta request, both for |
| 139 | * success and error HTTP status codes. |
| 140 | * |
| 141 | * Return AWS_OP_SUCCESS to continue processing the request. |
| 142 | * |
| 143 | * Return aws_raise_error(E) to cancel the request. |
| 144 | * The error you raise will be reflected in `aws_s3_meta_request_result.error_code`. |
| 145 | * If you're not sure which error to raise, use AWS_ERROR_S3_CANCELED. |
| 146 | */ |
| 147 | typedef int(aws_s3_meta_request_headers_callback_fn)( |
| 148 | struct aws_s3_meta_request *meta_request, |
| 149 | const struct aws_http_headers *headers, |
| 150 | int response_status, |
| 151 | void *user_data); |
| 152 | |
| 153 | /** |
| 154 | * Invoked to provide the response body as it is received. |
| 155 | * |
| 156 | * Note: If you set `enable_read_backpressure` true on the S3 client, |
| 157 | * you must maintain the flow-control window. |
| 158 | * The flow-control window shrinks as you receive body data via this callback. |
| 159 | * Whenever the flow-control window reaches 0 you will stop downloading data. |
| 160 | * Use aws_s3_meta_request_increment_read_window() to increment the window and keep data flowing. |
| 161 | * Maintain a larger window to keep up a high download throughput, |
| 162 | * parts cannot download in parallel unless the window is large enough to hold multiple parts. |
| 163 | * Maintain a smaller window to limit the amount of data buffered in memory. |
| 164 | * |
| 165 | * If `manual_window_management` is false, you do not need to maintain the flow-control window. |
| 166 | * No back-pressure is applied and data arrives as fast as possible. |
| 167 | * |
| 168 | * Return AWS_OP_SUCCESS to continue processing the request. |
| 169 | * |
| 170 | * Return aws_raise_error(E) to cancel the request. |
| 171 | * The error you raise will be reflected in `aws_s3_meta_request_result.error_code`. |
| 172 | * If you're not sure which error to raise, use AWS_ERROR_S3_CANCELED. |
| 173 | */ |
| 174 | typedef int(aws_s3_meta_request_receive_body_callback_fn)( |
| 175 | |
| 176 | /* The meta request that the callback is being issued for. */ |
| 177 | struct aws_s3_meta_request *meta_request, |
| 178 | |
| 179 | /* The body data for this chunk of the object. */ |
| 180 | const struct aws_byte_cursor *body, |
| 181 | |
| 182 | /* The byte index of the object that this refers to. For example, for an HTTP message that has a range header, the |
| 183 | first chunk received will have a range_start that matches the range header's range-start.*/ |
| 184 | uint64_t range_start, |
| 185 | |
| 186 | /* User data specified by aws_s3_meta_request_options.*/ |
| 187 | void *user_data); |
| 188 | |
| 189 | /** |
| 190 | * Invoked when the entire meta request execution is complete. |
| 191 | */ |
| 192 | typedef void(aws_s3_meta_request_finish_fn)( |
| 193 | struct aws_s3_meta_request *meta_request, |
| 194 | const struct aws_s3_meta_request_result *meta_request_result, |
| 195 | void *user_data); |
| 196 | |
| 197 | struct aws_s3_meta_request_receive_body_extra_info { |
| 198 | /* The byte index of the object that this refers to. For example, for an HTTP message that has a range header, the |
| 199 | first chunk received will have a range_start that matches the range header's range-start.*/ |
| 200 | uint64_t range_start; |
| 201 | |
| 202 | /* Associated buffer |
| 203 | */ |
| 204 | struct aws_s3_buffer_ticket *ticket; |
| 205 | }; |
| 206 | |
| 207 | typedef int(aws_s3_meta_request_receive_body_callback_ex_fn)( |
| 208 | |
| 209 | /* The meta request that the callback is being issued for. */ |
| 210 | struct aws_s3_meta_request *meta_request, |
| 211 | |
| 212 | /* The body data for this chunk of the object. */ |
| 213 | const struct aws_byte_cursor *body, |
| 214 | |
| 215 | /* Extra information associated with the delivered body */ |
| 216 | const struct aws_s3_meta_request_receive_body_extra_info info, |
| 217 | |
| 218 | /* User data specified by aws_s3_meta_request_options.*/ |
| 219 | void *user_data); |
| 220 | |
| 221 | /** |
| 222 | * Information sent in the meta_request progress callback. |
| 223 | */ |
| 224 | struct aws_s3_meta_request_progress { |
| 225 | |
| 226 | /* Bytes transferred since the previous progress update */ |
| 227 | uint64_t bytes_transferred; |
| 228 | |
| 229 | /* Length of the entire meta request operation */ |
| 230 | uint64_t content_length; |
| 231 | }; |
| 232 | |
| 233 | /** |
| 234 | * Invoked to report progress of a meta-request. |
| 235 | * For PutObject, progress refers to bytes uploaded. |
| 236 | * For CopyObject, progress refers to bytes copied. |
| 237 | * For GetObject, progress refers to bytes downloaded. |
| 238 | * For anything else, progress refers to response body bytes received. |
| 239 | */ |
| 240 | typedef void(aws_s3_meta_request_progress_fn)( |
| 241 | struct aws_s3_meta_request *meta_request, |
| 242 | const struct aws_s3_meta_request_progress *progress, |
| 243 | void *user_data); |
| 244 | |
| 245 | /** |
| 246 | * Invoked to report the telemetry of the meta request once a single request finishes. |
| 247 | * Note: *metrics is only valid for the duration of the callback. If you need to keep it around, use |
| 248 | * `aws_s3_request_metrics_acquire` |
| 249 | */ |
| 250 | typedef void(aws_s3_meta_request_telemetry_fn)( |
| 251 | struct aws_s3_meta_request *meta_request, |
| 252 | struct aws_s3_request_metrics *metrics, |
| 253 | void *user_data); |
| 254 | |
| 255 | typedef void(aws_s3_meta_request_shutdown_fn)(void *user_data); |
| 256 | |
| 257 | typedef void(aws_s3_client_shutdown_complete_callback_fn)(void *user_data); |
| 258 | |
| 259 | /** |
| 260 | * Optional callback, for you to provide the full object checksum after the object was read. |
| 261 | * Client will NOT check the checksum provided before sending it to the server. |
| 262 | * |
| 263 | * @param meta_request pointer to the aws_s3_meta_request of the upload. |
| 264 | * @param user_data pointer to the user_data set. |
| 265 | * |
| 266 | * @return A new string with the full object checksum, as it is sent in a PutObject request (base64-encoded): |
| 267 | * https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html#API_PutObject_RequestSyntax |
| 268 | * If an error occurs, call aws_raise_error(E) with a proper error code and return NULL. |
| 269 | */ |
| 270 | typedef struct aws_string *(aws_s3_meta_request_full_object_checksum_fn)(struct aws_s3_meta_request *meta_request, |
| 271 | void *user_data); |
| 272 | |
| 273 | enum aws_s3_meta_request_tls_mode { |
| 274 | AWS_MR_TLS_ENABLED, |
| 275 | AWS_MR_TLS_DISABLED, |
| 276 | }; |
| 277 | |
| 278 | enum aws_s3_meta_request_compute_content_md5 { |
| 279 | AWS_MR_CONTENT_MD5_DISABLED, |
| 280 | AWS_MR_CONTENT_MD5_ENABLED, |
| 281 | }; |
| 282 | |
| 283 | enum aws_s3_checksum_algorithm { |
| 284 | AWS_SCA_NONE = 0, |
| 285 | AWS_SCA_INIT, |
| 286 | AWS_SCA_CRC32C = AWS_SCA_INIT, |
| 287 | AWS_SCA_CRC32, |
| 288 | AWS_SCA_SHA1, |
| 289 | AWS_SCA_SHA256, |
| 290 | AWS_SCA_CRC64NVME, |
| 291 | AWS_SCA_SHA512, |
| 292 | AWS_SCA_XXHASH64, |
| 293 | AWS_SCA_XXHASH3_64, |
| 294 | AWS_SCA_XXHASH3_128, |
| 295 | AWS_SCA_END = AWS_SCA_XXHASH3_128, |
| 296 | AWS_SCA_UNKNOWN, /* special value for forwards compat to indicate checksum type that crt is not aware of */ |
| 297 | }; |
| 298 | |
| 299 | enum aws_s3_checksum_location { |
| 300 | AWS_SCL_NONE = 0, |
| 301 | AWS_SCL_HEADER, |
| 302 | AWS_SCL_TRAILER, |
| 303 | }; |
| 304 | |
| 305 | enum aws_s3_recv_file_options { |
| 306 | /** |
| 307 | * Create a new file if it doesn't exist, otherwise replace the existing file. |
| 308 | */ |
| 309 | AWS_S3_RECV_FILE_CREATE_OR_REPLACE = 0, |
| 310 | /** |
| 311 | * Always create a new file. If the file already exists, AWS_ERROR_S3_RECV_FILE_ALREADY_EXISTS will be raised. |
| 312 | */ |
| 313 | AWS_S3_RECV_FILE_CREATE_NEW, |
| 314 | /** |
| 315 | * Create a new file if it doesn't exist, otherwise append to the existing file. |
| 316 | */ |
| 317 | AWS_S3_RECV_FILE_CREATE_OR_APPEND, |
| 318 | |
| 319 | /** |
| 320 | * Write to an existing file at the specified position, defined by the `recv_file_position`. |
| 321 | * If the file does not exist, AWS_ERROR_S3_RECV_FILE_NOT_FOUND will be raised. |
| 322 | * If `recv_file_position` is not configured, start overwriting data at the beginning of the |
| 323 | * file (byte 0). |
| 324 | */ |
| 325 | AWS_S3_RECV_FILE_WRITE_TO_POSITION, |
| 326 | }; |
| 327 | |
| 328 | /** |
| 329 | * WARNING: experimental/unstable: |
| 330 | * Controls how client performance file I/O operations. Only applies to the file based workload. |
| 331 | **/ |
| 332 | struct aws_s3_file_io_options { |
| 333 | /** |
| 334 | * Skip buffering the part in memory before sending the request. |
| 335 | * |
| 336 | * Default to false on small objects, and true when the object size exceed a certain threshold |
| 337 | *`g_streaming_object_size_threshold`. |
| 338 | **/ |
| 339 | bool should_stream; |
| 340 | |
| 341 | /** |
| 342 | * The estimated disk throughput. Only be applied when `streaming_upload` is true. |
| 343 | * in gigabits per second (Gbps). |
| 344 | * |
| 345 | * Notes: There are possibilities that cannot reach the all available disk throughput: |
| 346 | * 1. Disk is busy with other applications |
| 347 | * 2. OS Cache may cap the throughput, use `direct_io` to get around this. |
| 348 | * |
| 349 | * Default to throughput_target_gbps. |
| 350 | **/ |
| 351 | double disk_throughput_gbps; |
| 352 | |
| 353 | /** |
| 354 | * Enable direct IO to bypass the OS cache. Helpful when the disk I/O outperforms the kernel cache. |
| 355 | * Notes: |
| 356 | * - Currently only Linux supports direct I/O. On unsupported platforms, the request transparently |
| 357 | * falls back to buffered I/O and a warning is logged. |
| 358 | * - Supported for both upload (send_filepath) and download (recv_filepath). |
| 359 | * - This is a BEST-EFFORT optimization. The request transparently falls back to |
| 360 | * buffered I/O (logging a warning) if any of the following preconditions are not met: |
| 361 | * - part_size is not page-aligned |
| 362 | * - For AWS_S3_RECV_FILE_WRITE_TO_POSITION, recv_file_position is not page-aligned |
| 363 | * - For AWS_S3_RECV_FILE_CREATE_OR_APPEND, the existing file size is not page-aligned |
| 364 | * - The last part of the download has an unaligned length |
| 365 | * - Buffer allocated is NOT page size aligned. |
| 366 | * - Check NOTES for O_DIRECT for additional info https://man7.org/linux/man-pages/man2/openat.2.html |
| 367 | * In summary, O_DIRECT is a potentially powerful tool that should be used with caution. |
| 368 | */ |
| 369 | bool direct_io; |
| 370 | }; |
| 371 | |
| 372 | /** |
| 373 | * Info about a single part, for you to review before the upload completes. |
| 374 | */ |
| 375 | struct aws_s3_upload_part_review { |
| 376 | /* Size in bytes of this part */ |
| 377 | uint64_t size; |
| 378 | |
| 379 | /* Checksum string, as sent in the UploadPart request (usually base64-encoded): |
| 380 | * https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPart.html#API_UploadPart_RequestSyntax |
| 381 | * This is empty if no checksum is used. */ |
| 382 | struct aws_byte_cursor checksum; |
| 383 | }; |
| 384 | |
| 385 | /** |
| 386 | * Info for you to review before an upload completes. |
| 387 | * |
| 388 | * WARNING: This feature is experimental/unstable. |
| 389 | * At this time, review is only available for multipart upload |
| 390 | * (when Content-Length is above the `multipart_upload_threshold`, |
| 391 | * or Content-Length not specified). |
| 392 | */ |
| 393 | struct aws_s3_upload_review { |
| 394 | /* The checksum algorithm used. */ |
| 395 | enum aws_s3_checksum_algorithm checksum_algorithm; |
| 396 | |
| 397 | /* Number of parts uploaded. */ |
| 398 | size_t part_count; |
| 399 | |
| 400 | /* Array of info about each part uploaded (array is `part_count` in length) */ |
| 401 | struct aws_s3_upload_part_review *part_array; |
| 402 | }; |
| 403 | |
| 404 | /** |
| 405 | * Optional callback, for you to review an upload before it completes. |
| 406 | * For example, you can review each part's checksum and fail the upload if |
| 407 | * you do not agree with them. |
| 408 | * |
| 409 | * @param meta_request pointer to the aws_s3_meta_request of the upload. |
| 410 | * @param info Detailed info about the upload. |
| 411 | * |
| 412 | * Return AWS_OP_SUCCESS to continue processing the request. |
| 413 | * |
| 414 | * Return aws_raise_error(E) to cancel the request. |
| 415 | * The error you raise will be reflected in `aws_s3_meta_request_result.error_code`. |
| 416 | * If you're not sure which error to raise, use AWS_ERROR_S3_CANCELED. |
| 417 | * |
| 418 | * WARNING: This feature is experimental/unstable. |
| 419 | * At this time, the callback is only invoked for multipart upload |
| 420 | * (when Content-Length is above the `multipart_upload_threshold`, |
| 421 | * or Content-Length not specified). |
| 422 | */ |
| 423 | typedef int(aws_s3_meta_request_upload_review_fn)( |
| 424 | struct aws_s3_meta_request *meta_request, |
| 425 | const struct aws_s3_upload_review *review, |
| 426 | void *user_data); |
| 427 | |
| 428 | /** |
| 429 | * The factory function for S3 client to create a S3 Express credentials provider. |
| 430 | * The S3 client will be the only owner of the S3 Express credentials provider. |
| 431 | * |
| 432 | * During S3 client destruction, S3 client will start the destruction of the provider, and wait the |
| 433 | * on_provider_shutdown_callback to be invoked before the S3 client finish destruction. |
| 434 | * |
| 435 | * Note to implement the factory properly: |
| 436 | * - Make sure `on_provider_shutdown_callback` will be invoked after the provider finish shutdown, otherwise, |
| 437 | * leak will happen. |
| 438 | * - The provider must not acquire a reference to the client; otherwise, a circular reference will cause a deadlock. |
| 439 | * - The `client` provided CANNOT be used within the factory function call or the destructor. |
| 440 | * |
| 441 | * @param allocator memory allocator to create the provider. |
| 442 | * @param client The S3 client uses and owns the provider. |
| 443 | * @param on_provider_shutdown_callback The callback to be invoked when the provider finishes shutdown. |
| 444 | * @param shutdown_user_data The user data to invoke shutdown callback with |
| 445 | * @param user_data The user data with the factory |
| 446 | * |
| 447 | * @return The aws_s3express_credentials_provider. |
| 448 | */ |
| 449 | typedef struct aws_s3express_credentials_provider *( |
| 450 | aws_s3express_provider_factory_fn)(struct aws_allocator *allocator, |
| 451 | struct aws_s3_client *client, |
| 452 | aws_simple_completion_callback on_provider_shutdown_callback, |
| 453 | void *shutdown_user_data, |
| 454 | void *factory_user_data); |
| 455 | |
| 456 | /* Keepalive properties are TCP only. |
| 457 | * If interval or timeout are zero, then default values are used. |
| 458 | */ |
| 459 | struct aws_s3_tcp_keep_alive_options { |
| 460 | |
| 461 | uint16_t keep_alive_interval_sec; |
| 462 | uint16_t keep_alive_timeout_sec; |
| 463 | |
| 464 | /* If set, sets the number of keep alive probes allowed to fail before the connection is considered |
| 465 | * lost. If zero OS defaults are used. On Windows, this option is meaningless until Windows 10 1703.*/ |
| 466 | uint16_t keep_alive_max_failed_probes; |
| 467 | }; |
| 468 | |
| 469 | /* Options for a new client. */ |
| 470 | struct aws_s3_client_config { |
| 471 | |
| 472 | /* When set, this will cap the number of active connections. When 0, the client will determine this value based on |
| 473 | * throughput_target_gbps. (Recommended) */ |
| 474 | uint32_t max_active_connections_override; |
| 475 | |
| 476 | /* Region that the client default to. */ |
| 477 | struct aws_byte_cursor region; |
| 478 | |
| 479 | /* Client bootstrap used for common staples such as event loop group, host resolver, etc.. s*/ |
| 480 | struct aws_client_bootstrap *client_bootstrap; |
| 481 | |
| 482 | /* How tls should be used while performing the request |
| 483 | * If this is ENABLED: |
| 484 | * If tls_connection_options is not-null, then those tls options will be used |
| 485 | * If tls_connection_options is NULL, then default tls options will be used |
| 486 | * If this is DISABLED: |
| 487 | * No tls options will be used, regardless of tls_connection_options value. |
| 488 | */ |
| 489 | enum aws_s3_meta_request_tls_mode tls_mode; |
| 490 | |
| 491 | /* TLS Options to be used for each connection, if tls_mode is ENABLED. When compiling with BYO_CRYPTO, and tls_mode |
| 492 | * is ENABLED, this is required. Otherwise, this is optional. |
| 493 | */ |
| 494 | const struct aws_tls_connection_options *tls_connection_options; |
| 495 | |
| 496 | /** |
| 497 | * Optional. |
| 498 | * If set, this controls how the client interact with file I/O. |
| 499 | * Read `aws_s3_file_io_options` for details. |
| 500 | * Notes: Only applies to meta requests with `send_filepath` set. |
| 501 | * TODO: adapt it to `recv_filepath`. |
| 502 | * |
| 503 | * eg: |
| 504 | * - When the file is too large to fit in the buffer, set `should_stream` to avoid buffering the whole parts in |
| 505 | * memory. |
| 506 | * - When the disk I/O is faster than OS cache, set `direct_io` to bypass the OS cache. |
| 507 | */ |
| 508 | struct aws_s3_file_io_options *fio_opts; |
| 509 | |
| 510 | /** |
| 511 | * Required. |
| 512 | * Configure the signing for the requests made from the client. |
| 513 | * - Credentials or credentials provider is required. Other configs are all optional, and will be default to what |
| 514 | * needs to sign the request for S3, only overrides when Non-zero/Not-empty is set. |
| 515 | * - To skip signing, you can config it with anonymous credentials. |
| 516 | * - S3 Client will derive the right config for signing process based on this. |
| 517 | * |
| 518 | * Notes: |
| 519 | * - For AWS_SIGNING_ALGORITHM_V4_S3EXPRESS, S3 client will use the credentials in the config to derive the |
| 520 | * S3 Express credentials that are used in the signing process. |
| 521 | * - For other auth algorithm, client may make modifications to signing config before passing it on to signer. |
| 522 | * |
| 523 | * TODO: deprecate this structure from auth, introduce a new S3 specific one. |
| 524 | */ |
| 525 | const struct aws_signing_config_aws *signing_config; |
| 526 | |
| 527 | /** |
| 528 | * Optional. |
| 529 | * Size of parts the object will be downloaded or uploaded in, in bytes. |
| 530 | * This only affects AWS_S3_META_REQUEST_TYPE_GET_OBJECT and AWS_S3_META_REQUEST_TYPE_PUT_OBJECT. |
| 531 | * |
| 532 | * If not set, a dynamic default part size will be used based on the throughput target, memory_limit_in_bytes. |
| 533 | * |
| 534 | * The client will adjust the part size for AWS_S3_META_REQUEST_TYPE_PUT_OBJECT if needed for service limits (max |
| 535 | * number of parts per upload is 10,000, minimum upload part size is 5 MiB). |
| 536 | * |
| 537 | * You can also set this per meta-request, via `aws_s3_meta_request_options.part_size`. |
| 538 | */ |
| 539 | uint64_t part_size; |
| 540 | |
| 541 | /* If the part size needs to be adjusted for service limits, this is the maximum size it will be adjusted to. */ |
| 542 | uint64_t max_part_size; |
| 543 | |
| 544 | /** |
| 545 | * Optional. |
| 546 | * The size threshold in bytes for when to use multipart uploads. |
| 547 | * Uploads larger than this will use the multipart upload strategy. |
| 548 | * Uploads smaller or equal to this will use a single HTTP request. |
| 549 | * This only affects AWS_S3_META_REQUEST_TYPE_PUT_OBJECT. |
| 550 | * If set, this should be at least `part_size`. |
| 551 | * If not set, maximal of `part_size` and 5 MiB will be used. |
| 552 | * |
| 553 | * You can also set this per meta-request, via `aws_s3_meta_request_options.multipart_upload_threshold`. |
| 554 | */ |
| 555 | uint64_t multipart_upload_threshold; |
| 556 | |
| 557 | /* Throughput target in gigabits per second (Gbps) that we are trying to reach. */ |
| 558 | double throughput_target_gbps; |
| 559 | |
| 560 | /* How much memory can we use. This will be capped to SIZE_MAX */ |
| 561 | uint64_t memory_limit_in_bytes; |
| 562 | |
| 563 | /* Retry strategy to use. If NULL, a default retry strategy will be used. */ |
| 564 | struct aws_retry_strategy *retry_strategy; |
| 565 | |
| 566 | /** |
| 567 | * TODO: move MD5 config to checksum config. |
| 568 | * For multi-part upload, content-md5 will be calculated if the AWS_MR_CONTENT_MD5_ENABLED is specified |
| 569 | * or initial request has content-md5 header. |
| 570 | * For single-part upload, keep the content-md5 in the initial request unchanged. */ |
| 571 | enum aws_s3_meta_request_compute_content_md5 compute_content_md5; |
| 572 | |
| 573 | /* Callback and associated user data for when the client has completed its shutdown process. */ |
| 574 | aws_s3_client_shutdown_complete_callback_fn *shutdown_callback; |
| 575 | void *shutdown_callback_user_data; |
| 576 | |
| 577 | /** |
| 578 | * Optional. |
| 579 | * Proxy configuration for http connection. |
| 580 | * If the connection_type is AWS_HPCT_HTTP_LEGACY, it will be converted to AWS_HPCT_HTTP_TUNNEL if tls_mode is |
| 581 | * ENABLED. Otherwise, it will be converted to AWS_HPCT_HTTP_FORWARD. |
| 582 | */ |
| 583 | const struct aws_http_proxy_options *proxy_options; |
| 584 | |
| 585 | /** |
| 586 | * Optional. |
| 587 | * Configuration for fetching proxy configuration from environment. |
| 588 | * By Default proxy_ev_settings.aws_http_proxy_env_var_type is set to AWS_HPEV_ENABLE which means read proxy |
| 589 | * configuration from environment. |
| 590 | * Only works when proxy_options is not set. If both are set, configuration from proxy_options is used. |
| 591 | */ |
| 592 | const struct proxy_env_var_settings *proxy_ev_settings; |
| 593 | |
| 594 | /** |
| 595 | * Optional. |
| 596 | * If set to 0, default value is used. |
| 597 | */ |
| 598 | uint32_t connect_timeout_ms; |
| 599 | |
| 600 | /** |
| 601 | * Optional. |
| 602 | * Set keepalive to periodically transmit messages for detecting a disconnected peer. |
| 603 | */ |
| 604 | const struct aws_s3_tcp_keep_alive_options *tcp_keep_alive_options; |
| 605 | |
| 606 | /** |
| 607 | * Optional. |
| 608 | * Configuration options for connection monitoring. |
| 609 | * If the transfer speed falls below the specified minimum_throughput_bytes_per_second, the operation is aborted. |
| 610 | * If set to NULL, default values are used. |
| 611 | */ |
| 612 | const struct aws_http_connection_monitoring_options *monitoring_options; |
| 613 | |
| 614 | /** |
| 615 | * Enable backpressure and prevent response data from downloading faster than you can handle it. |
| 616 | * |
| 617 | * If false (default), no backpressure is applied and data will download as fast as possible. |
| 618 | * |
| 619 | * If true, each meta request has a flow-control window that shrinks as |
| 620 | * response body data is downloaded (headers do not affect the window). |
| 621 | * `initial_read_window` determines the starting size of each meta request's window. |
| 622 | * |
| 623 | * - You will stop receiving response body data whenever the flow-control window reaches 0 |
| 624 | * - If the window size remaining is smaller than the part download, client will buffer the part until |
| 625 | * the window opens up to delivery the full part. |
| 626 | * - You must call aws_s3_meta_request_increment_read_window() to keep data flowing. |
| 627 | * |
| 628 | * WARNING: This feature is experimental. |
| 629 | * Currently, backpressure is only applied to GetObject requests which are split into multiple parts, |
| 630 | * - If you set body_callback, no more data will be delivered once the window reaches 0. |
| 631 | * - If you set body_callback_ex, you may still receive some data after the window reaches 0. TODO: fix it. |
| 632 | */ |
| 633 | bool enable_read_backpressure; |
| 634 | |
| 635 | /** |
| 636 | * The starting size of each meta request's flow-control window, in bytes. |
| 637 | * Ignored unless `enable_read_backpressure` is true. |
| 638 | */ |
| 639 | size_t initial_read_window; |
| 640 | |
| 641 | /** |
| 642 | * To enable S3 Express support or not. |
| 643 | */ |
| 644 | bool enable_s3express; |
| 645 | |
| 646 | /** |
| 647 | * Optional. |
| 648 | * Only used when `enable_s3express` is set. |
| 649 | * |
| 650 | * If set, client will invoke the factory to get the provider to use, when needed. |
| 651 | * |
| 652 | * If not set, client will create a default S3 Express provider under the hood. |
| 653 | * |
| 654 | * NOTE: THE FOLLOWING BEHAVIOR IS EXPERIMENTAL AND UNSTABLE |
| 655 | * Default S3 Express provider will pass the headers allowed in `g_s3_create_session_allowed_headers` to the |
| 656 | * CreateSession call. |
| 657 | */ |
| 658 | aws_s3express_provider_factory_fn *s3express_provider_override_factory; |
| 659 | void *factory_user_data; |
| 660 | |
| 661 | /** |
| 662 | * THIS IS AN EXPERIMENTAL AND UNSTABLE API |
| 663 | * (Optional) |
| 664 | * An array of network interface names. The client will distribute the |
| 665 | * connections across network interface names provided in this array. If any interface name is invalid, goes down, |
| 666 | * or has any issues like network access, you will see connection failures. |
| 667 | * |
| 668 | * This option is only supported on Linux, MacOS, and platforms that have either SO_BINDTODEVICE or IP_BOUND_IF. It |
| 669 | * is not supported on Windows. `AWS_ERROR_PLATFORM_NOT_SUPPORTED` will be raised on unsupported platforms. On |
| 670 | * Linux, SO_BINDTODEVICE is used and requires kernel version >= 5.7 or root privileges. |
| 671 | */ |
| 672 | const struct aws_byte_cursor *network_interface_names_array; |
| 673 | size_t num_network_interface_names; |
| 674 | |
| 675 | /** |
| 676 | * Experimental (touch at your own risk). |
| 677 | * (Optional) |
| 678 | * Factory function to create buffer pool. |
| 679 | * if not set creates default implementation of the buffer pool. |
| 680 | */ |
| 681 | aws_s3_buffer_pool_factory_fn *buffer_pool_factory_fn; |
| 682 | |
| 683 | /* User data thats passed into pool factory. */ |
| 684 | void *buffer_pool_user_data; |
| 685 | }; |
| 686 | |
| 687 | struct aws_s3_checksum_config { |
| 688 | |
| 689 | /****************************** PUT Object specific *******************************/ |
| 690 | /** |
| 691 | * The location of client added checksum header. |
| 692 | * |
| 693 | * If AWS_SCL_NONE. No request payload checksum will be added. |
| 694 | * |
| 695 | * If AWS_SCL_HEADER, the client will calculate the checksum and add it to the headers. |
| 696 | * |
| 697 | * If AWS_SCL_TRAILER, the payload will be aws_chunked encoded, The client will calculate the checksum and add it to |
| 698 | * the trailer. Note the payload of the original request cannot be aws-chunked encoded already, this will cause an |
| 699 | * error. |
| 700 | */ |
| 701 | enum aws_s3_checksum_location location; |
| 702 | |
| 703 | /** |
| 704 | * The checksum algorithm used. |
| 705 | * Must be set if location is not AWS_SCL_NONE. |
| 706 | */ |
| 707 | enum aws_s3_checksum_algorithm checksum_algorithm; |
| 708 | |
| 709 | /** |
| 710 | * Optional. |
| 711 | * Provide the full object checksum. This callback is invoked once, after the entire body has been read. |
| 712 | * sent. |
| 713 | * |
| 714 | * NOTE: |
| 715 | * - Do not set this callback if the HTTP message already has a checksum header (e.g. x-amz-checksum-crc32). Doing |
| 716 | * so will raise AWS_ERROR_INVALID_ARGUMENT. |
| 717 | * - checksum_algorithm must be set to the algorithm you will use. |
| 718 | * |
| 719 | * WARNING: This feature is experimental/unstable. |
| 720 | * At this time, full object checksum callback is only available for multipart upload |
| 721 | * (when Content-Length is above the `multipart_upload_threshold`, |
| 722 | * or Content-Length not specified). Otherwise, it will be ignored. |
| 723 | */ |
| 724 | aws_s3_meta_request_full_object_checksum_fn *full_object_checksum_callback; |
| 725 | void *user_data; |
| 726 | |
| 727 | /****************************** GET Object specific *******************************/ |
| 728 | /** |
| 729 | * Enable checksum mode header will be attached to GET requests, this will tell s3 to send back checksums headers if |
| 730 | * they exist. Calculate the corresponding checksum on the response bodies. The meta request will finish with a did |
| 731 | * validate field and set the error code to AWS_ERROR_S3_RESPONSE_CHECKSUM_MISMATCH if the calculated |
| 732 | * checksum, and checksum found in the response header do not match. |
| 733 | */ |
| 734 | bool validate_response_checksum; |
| 735 | |
| 736 | /** |
| 737 | * Optional array of `enum aws_s3_checksum_algorithm`. |
| 738 | * |
| 739 | * Ignored when validate_response_checksum is not set. |
| 740 | * If not set all the algorithms will be selected as default behavior. |
| 741 | * Owned by the caller. |
| 742 | * |
| 743 | * The list of algorithms for user to pick up when validate the checksum. Client will pick up the algorithm from the |
| 744 | * list with the priority based on performance, and the algorithm sent by server. The priority based on performance |
| 745 | * is [XXHASH3_128, XXHASH3_64, CRC64NVME, CRC32C, CRC32, XXHASH64, SHA512, SHA256, SHA1]. |
| 746 | * |
| 747 | * If the response checksum was validated by client, the result will indicate which algorithm was picked. |
| 748 | */ |
| 749 | const struct aws_array_list *validate_checksum_algorithms; |
| 750 | }; |
| 751 | |
| 752 | /** |
| 753 | * Options for a new meta request, ie, file transfer that will be handled by the high performance client. |
| 754 | * |
| 755 | * There are several ways to pass the request's body data: |
| 756 | * 1) If the data is already in memory, set the body-stream on `message`. |
| 757 | * 2) If the data is on disk, set `send_filepath` for best performance. |
| 758 | * 3) If the data is available, but copying each chunk is asynchronous, set `send_async_stream`. |
| 759 | * 4) If you're not sure when each chunk of data will be available, use `send_using_async_writes`. |
| 760 | * 5) If the data is already in memory and you want the client to upload it with no extra copy or |
| 761 | * allocation, set `request_body` (DEFAULT meta request only). |
| 762 | */ |
| 763 | struct aws_s3_meta_request_options { |
| 764 | /* The type of meta request we will be trying to accelerate. */ |
| 765 | enum aws_s3_meta_request_type type; |
| 766 | |
| 767 | /** |
| 768 | * The S3 operation name (e.g. "CreateBucket"). |
| 769 | * This MUST be set if type is AWS_S3_META_REQUEST_TYPE_DEFAULT; |
| 770 | * it is automatically populated for other meta-request types. |
| 771 | * The canonical operation names are listed here: |
| 772 | * https://docs.aws.amazon.com/AmazonS3/latest/API/API_Operations_Amazon_Simple_Storage_Service.html |
| 773 | * |
| 774 | * This name is used to fill out details in metrics and error reports. |
| 775 | * It also drives some operation-specific behavior. |
| 776 | * If you pass the wrong name, you risk getting the wrong behavior. |
| 777 | * |
| 778 | * For example, every operation except "GetObject" has its response checked |
| 779 | * for error, even if the HTTP status-code was 200 OK |
| 780 | * (see https://repost.aws/knowledge-center/s3-resolve-200-internalerror). |
| 781 | * If you used AWS_S3_META_REQUEST_TYPE_DEFAULT to do GetObject, but mis-named |
| 782 | * it "Download", and the object looked like XML with an error code, |
| 783 | * then the meta-request would fail. You may log the full response body, |
| 784 | * and leak sensitive data. |
| 785 | */ |
| 786 | struct aws_byte_cursor operation_name; |
| 787 | |
| 788 | /** |
| 789 | * Configure the signing for each request created for this meta request. If NULL, options in the client will be |
| 790 | * used. |
| 791 | * - The credentials will be obtained based on the precedence of: |
| 792 | * 1. `credentials` from `signing_config` in `aws_s3_meta_request_options` |
| 793 | * 2. `credentials_provider` from `signing_config` in `aws_s3_meta_request_options` |
| 794 | * 3. `credentials` from `signing_config` cached in the client |
| 795 | * 4. `credentials_provider` cached in the client |
| 796 | * - To skip signing, you can config it with anonymous credentials. |
| 797 | * - S3 Client will derive the right config for signing process based on this. |
| 798 | * |
| 799 | * Notes: |
| 800 | * - For AWS_SIGNING_ALGORITHM_V4_S3EXPRESS, S3 client will use the credentials in the config to derive the |
| 801 | * S3 Express credentials that are used in the signing process. |
| 802 | * - For other auth algorithm, client may make modifications to signing config before passing it on to signer. |
| 803 | **/ |
| 804 | const struct aws_signing_config_aws *signing_config; |
| 805 | |
| 806 | /* Initial HTTP message that defines what operation we are doing. |
| 807 | * Do not set the message's body-stream if the body is being passed by other means (see note above) */ |
| 808 | struct aws_http_message *message; |
| 809 | |
| 810 | /** |
| 811 | * Optional. |
| 812 | * If set, the received data will be written into this file. |
| 813 | * the `body_callback` will NOT be invoked. |
| 814 | * This gives a better performance when receiving data to write to a file. |
| 815 | * See `aws_s3_recv_file_options` for the configuration on the receive file. |
| 816 | */ |
| 817 | struct aws_byte_cursor recv_filepath; |
| 818 | |
| 819 | /** |
| 820 | * Optional. |
| 821 | * Default to AWS_S3_RECV_FILE_CREATE_OR_REPLACE. |
| 822 | * This only works with recv_filepath set. |
| 823 | * See `aws_s3_recv_file_options`. |
| 824 | */ |
| 825 | enum aws_s3_recv_file_options recv_file_option; |
| 826 | /** |
| 827 | * Optional. |
| 828 | * The specified position to start writing at for the recv file when `recv_file_option` is set to |
| 829 | * AWS_S3_RECV_FILE_WRITE_TO_POSITION, ignored otherwise. |
| 830 | */ |
| 831 | uint64_t recv_file_position; |
| 832 | /** |
| 833 | * Set it to be true to delete the receive file on failure, otherwise, the file will be left as-is. |
| 834 | * This only works with recv_filepath set. |
| 835 | */ |
| 836 | bool recv_file_delete_on_failure; |
| 837 | |
| 838 | /** |
| 839 | * Optional. |
| 840 | * If set, this file is sent as the request body. |
| 841 | * This gives the best performance when sending data from a file. |
| 842 | * Do not set if the body is being passed by other means (see note above). |
| 843 | */ |
| 844 | struct aws_byte_cursor send_filepath; |
| 845 | |
| 846 | /** |
| 847 | * Optional. |
| 848 | * Overrides the client config if set. |
| 849 | * If set, this controls how the meta request interact with file I/O. |
| 850 | * Read `aws_s3_file_io_options` for details. |
| 851 | * Notes: Only applies when `send_filepath` is set. |
| 852 | * TODO: adapt it to `recv_filepath`. |
| 853 | * |
| 854 | * Note: if both client and meta request don't set this, for objects larger than 2TiB, this will be set to a default |
| 855 | * options with `should_stream` to be True and others follow the default to avoid memory issues. |
| 856 | * |
| 857 | * eg: |
| 858 | * - When the file is too large to fit in the buffer, set `should_stream` to avoid buffering the whole parts in |
| 859 | * memory. |
| 860 | * - When the disk I/O is faster than OS cache, set `direct_io` to bypass the OS cache. |
| 861 | */ |
| 862 | struct aws_s3_file_io_options *fio_opts; |
| 863 | |
| 864 | /** |
| 865 | * Optional - EXPERIMENTAL/UNSTABLE |
| 866 | * If set, the request body comes from this async stream. |
| 867 | * Use this when outgoing data will be produced in asynchronous chunks. |
| 868 | * The S3 client will read from the stream whenever it's ready to upload another chunk. |
| 869 | * |
| 870 | * WARNING: The S3 client can deadlock if many async streams are "stalled", |
| 871 | * never completing their async read. If you're not sure when (if ever) |
| 872 | * data will be ready, use `send_using_async_writes` instead. |
| 873 | * |
| 874 | * Do not set if the body is being passed by other means (see note above). |
| 875 | */ |
| 876 | struct aws_async_input_stream *send_async_stream; |
| 877 | |
| 878 | /** |
| 879 | * Optional - EXPERIMENTAL/UNSTABLE |
| 880 | * Set this to send request body data using the async aws_s3_meta_request_poll_write() |
| 881 | * or aws_s3_meta_request_write() functions. |
| 882 | * Use this when outgoing data will be produced in asynchronous chunks, |
| 883 | * and you're not sure when (if ever) each chunk will be ready. |
| 884 | * |
| 885 | * This only works with AWS_S3_META_REQUEST_TYPE_PUT_OBJECT. |
| 886 | * |
| 887 | * Do not set if the body is being passed by other means (see note above). |
| 888 | */ |
| 889 | bool send_using_async_writes; |
| 890 | |
| 891 | /** |
| 892 | * Optional - EXPERIMENTAL/UNSTABLE |
| 893 | * If set, the request body is sent directly from this caller-owned memory, with no additional |
| 894 | * allocation or copy by the client. |
| 895 | * |
| 896 | * Use this when you already hold the entire fixed request body in memory (e.g. in a buffer from your |
| 897 | * own memory pool) and want to avoid the client allocating a new buffer and copying into it. |
| 898 | * |
| 899 | * Memory ownership / lifetime: |
| 900 | * - The client BORROWS this memory; it never copies, frees, or modifies it. |
| 901 | * - The memory MUST stay valid and unmodified until the meta request completes. The client |
| 902 | * re-reads it on every send attempt, so it must outlive all retries. To learn when it is safe |
| 903 | * to free or reuse the memory, use the meta request's shutdown callback (the `aws_s3_meta_request_shutdown_fn` |
| 904 | * passed when the meta request was created); it is invoked once the meta request is fully torn |
| 905 | * down, after the request and all its retries are done. |
| 906 | * |
| 907 | * This is currently only supported for an AWS_S3_META_REQUEST_TYPE_DEFAULT meta request, which |
| 908 | * sends the body as a single request. |
| 909 | * |
| 910 | * Do not set if the body is being passed by other means (i.e. the message body-stream, |
| 911 | * send_filepath, send_async_stream, or send_using_async_writes). |
| 912 | */ |
| 913 | struct aws_byte_cursor request_body; |
| 914 | |
| 915 | /** |
| 916 | * Optional. |
| 917 | * if set, the flexible checksum will be performed by client based on the config. |
| 918 | * |
| 919 | * Notes: checksum can also be added through the http message provided. |
| 920 | * The checksum in http header will override corresponding the checksum config. |
| 921 | */ |
| 922 | const struct aws_s3_checksum_config *checksum_config; |
| 923 | |
| 924 | /** |
| 925 | * Optional. |
| 926 | * Size of parts the object will be downloaded or uploaded in, in bytes. |
| 927 | * This only affects AWS_S3_META_REQUEST_TYPE_GET_OBJECT and AWS_S3_META_REQUEST_TYPE_PUT_OBJECT. |
| 928 | * |
| 929 | * If not set, the value from `aws_s3_client_config.part_size` is used, which defaults to a dynamic value based on |
| 930 | * the throughput target, memory_limit_in_bytes and the requested object size. |
| 931 | * |
| 932 | * The client will adjust the part size for AWS_S3_META_REQUEST_TYPE_PUT_OBJECT if needed for service limits (max |
| 933 | * number of parts per upload is 10,000, minimum upload part size is 5 MiB). |
| 934 | */ |
| 935 | uint64_t part_size; |
| 936 | |
| 937 | /** |
| 938 | * Optional - EXPERIMENTAL/UNSTABLE |
| 939 | * Set this to prefer for the dynamic default part_size over the part size set for both client and meta request for |
| 940 | * the best performance under the memory constrain, especially for getting large objects. |
| 941 | */ |
| 942 | bool force_dynamic_part_size; |
| 943 | |
| 944 | /** |
| 945 | * Optional. |
| 946 | * The size threshold in bytes for when to use multipart uploads. |
| 947 | * Uploads larger than this will use the multipart upload strategy. |
| 948 | * Uploads smaller or equal to this will use a single HTTP request. |
| 949 | * This only affects AWS_S3_META_REQUEST_TYPE_PUT_OBJECT. |
| 950 | * If set, this should be at least `part_size`. |
| 951 | * If not set, `part_size` adjusted by client will be used as the threshold. |
| 952 | * If both `part_size` and `multipart_upload_threshold` are not set, |
| 953 | * the values from `aws_s3_client_config` are used. |
| 954 | */ |
| 955 | uint64_t multipart_upload_threshold; |
| 956 | |
| 957 | /* User data for all callbacks. */ |
| 958 | void *user_data; |
| 959 | |
| 960 | /** |
| 961 | * Optional. |
| 962 | * Invoked to provide response headers received during execution of the meta request. |
| 963 | * Note: this callback will not be fired for cases when resuming an |
| 964 | * operation that was already completed (ex. pausing put object after it |
| 965 | * uploaded all data and then resuming it) |
| 966 | * See `aws_s3_meta_request_headers_callback_fn`. |
| 967 | */ |
| 968 | aws_s3_meta_request_headers_callback_fn *headers_callback; |
| 969 | |
| 970 | /** |
| 971 | * Invoked to provide the response body as it is received. |
| 972 | * See `aws_s3_meta_request_receive_body_callback_fn`. |
| 973 | */ |
| 974 | aws_s3_meta_request_receive_body_callback_fn *body_callback; |
| 975 | |
| 976 | /** |
| 977 | * Invoked to provide the response body as it is received. |
| 978 | * Provides extra information as compared to regular callback. |
| 979 | * Note: setting both body_callback and body_callback_ex is not |
| 980 | * considered valid and meta request creation will fail. |
| 981 | * See `aws_s3_meta_request_receive_body_callback_ex_fn`. |
| 982 | */ |
| 983 | aws_s3_meta_request_receive_body_callback_ex_fn *body_callback_ex; |
| 984 | |
| 985 | /** |
| 986 | * Invoked when the entire meta request execution is complete. |
| 987 | * See `aws_s3_meta_request_finish_fn`. |
| 988 | */ |
| 989 | aws_s3_meta_request_finish_fn *finish_callback; |
| 990 | |
| 991 | /* Callback for when the meta request has completely cleaned up. */ |
| 992 | aws_s3_meta_request_shutdown_fn *shutdown_callback; |
| 993 | |
| 994 | /** |
| 995 | * Invoked to report progress of the meta request execution. |
| 996 | * See `aws_s3_meta_request_progress_fn`. |
| 997 | */ |
| 998 | aws_s3_meta_request_progress_fn *progress_callback; |
| 999 | |
| 1000 | /** |
| 1001 | * Optional. |
| 1002 | * To get telemetry metrics when a single request finishes. |
| 1003 | * If set the request will keep track of the metrics from `aws_s3_request_metrics`, and fire the callback when the |
| 1004 | * request finishes receiving response. |
| 1005 | * See `aws_s3_meta_request_telemetry_fn` |
| 1006 | */ |
| 1007 | aws_s3_meta_request_telemetry_fn *telemetry_callback; |
| 1008 | |
| 1009 | /** |
| 1010 | * Optional. |
| 1011 | * Callback for reviewing an upload before it completes. |
| 1012 | * WARNING: experimental/unstable |
| 1013 | * See `aws_s3_meta_request_upload_review_fn` |
| 1014 | */ |
| 1015 | aws_s3_meta_request_upload_review_fn *upload_review_callback; |
| 1016 | |
| 1017 | /** |
| 1018 | * Optional. |
| 1019 | * Endpoint override for request. Can be used to override scheme and port of |
| 1020 | * the endpoint. |
| 1021 | * There is some overlap between Host header and Endpoint and corner cases |
| 1022 | * are handled as follows: |
| 1023 | * - Only Host header is set - Host is used to construct endpoint. https is |
| 1024 | * default with corresponding port |
| 1025 | * - Only endpoint is set - Host header is created from endpoint. Port and |
| 1026 | * Scheme from endpoint is used. |
| 1027 | * - Both Host and Endpoint is set - Host header must match Authority of |
| 1028 | * Endpoint uri. Port and Scheme from endpoint is used. |
| 1029 | */ |
| 1030 | const struct aws_uri *endpoint; |
| 1031 | |
| 1032 | /** |
| 1033 | * Optional. |
| 1034 | * For meta requests that support pause/resume (e.g. PutObject), serialized resume token returned by |
| 1035 | * aws_s3_meta_request_pause() can be provided here. |
| 1036 | * Note: If PutObject request specifies a checksum algorithm, client will calculate checksums while skipping parts |
| 1037 | * from the buffer and compare them them to previously uploaded part checksums. |
| 1038 | */ |
| 1039 | struct aws_s3_meta_request_resume_token *resume_token; |
| 1040 | |
| 1041 | /* |
| 1042 | * Optional. |
| 1043 | * Total object size hint, in bytes. |
| 1044 | * The optimal strategy for downloading a file depends on its size. |
| 1045 | * Set this hint to help the S3 client choose the best strategy for this particular file. |
| 1046 | * This is just used as an estimate, so it's okay to provide an approximate value if the exact size is unknown. |
| 1047 | */ |
| 1048 | const uint64_t *object_size_hint; |
| 1049 | |
| 1050 | /* |
| 1051 | * (Optional) |
| 1052 | * If performing a copy operation, provide the source URI here to bypass limitations 1 and 2 of the copy operation. |
| 1053 | * This will be ignored for other operations. |
| 1054 | */ |
| 1055 | struct aws_byte_cursor copy_source_uri; |
| 1056 | |
| 1057 | /* When set, this will cap the number of active connections for the meta request. When 0, the client will determine |
| 1058 | * it based on client side settings. (Recommended) */ |
| 1059 | uint32_t max_active_connections_override; |
| 1060 | }; |
| 1061 | |
| 1062 | /* Result details of a meta request. |
| 1063 | * |
| 1064 | * If error_code is AWS_ERROR_SUCCESS, then response_status will match the response_status passed earlier by the header |
| 1065 | * callback and error_response_headers and error_response_body will be NULL. |
| 1066 | * |
| 1067 | * If error_code is equal to AWS_ERROR_S3_INVALID_RESPONSE_STATUS, then error_response_headers, error_response_body, and |
| 1068 | * response_status will be populated by the failed request. |
| 1069 | * |
| 1070 | * For all other error codes, response_status will be 0, and the error_response variables will be NULL. |
| 1071 | */ |
| 1072 | struct aws_s3_meta_request_result { |
| 1073 | |
| 1074 | /* If meta request failed due to an HTTP error response from S3, these are the headers. |
| 1075 | * NULL if meta request failed for another reason. */ |
| 1076 | struct aws_http_headers *error_response_headers; |
| 1077 | |
| 1078 | /* If meta request failed due to an HTTP error response from S3, this the body. |
| 1079 | * NULL if meta request failed for another reason, or if the response had no body (such as a HEAD response). */ |
| 1080 | struct aws_byte_buf *error_response_body; |
| 1081 | |
| 1082 | /* If meta request failed due to an HTTP error response from S3, |
| 1083 | * this is the name of the S3 operation it was responding to. |
| 1084 | * For example, if a AWS_S3_META_REQUEST_TYPE_PUT_OBJECT fails this could be |
| 1085 | * "PutObject, "CreateMultipartUpload", "UploadPart", "CompleteMultipartUpload", or others. |
| 1086 | * For AWS_S3_META_REQUEST_TYPE_DEFAULT, this is the same value passed to |
| 1087 | * aws_s3_meta_request_options.operation_name. |
| 1088 | * NULL if the meta request failed for another reason. */ |
| 1089 | struct aws_string *error_response_operation_name; |
| 1090 | |
| 1091 | /* Response status of the failed request or of the entire meta request. */ |
| 1092 | int response_status; |
| 1093 | |
| 1094 | /* Only set for GET request. |
| 1095 | * Was the server side checksum compared against a calculated checksum of the response body. This may be false |
| 1096 | * even if validate_get_response_checksum was set because the object was uploaded without a checksum, or was |
| 1097 | * uploaded as a multipart object. |
| 1098 | * |
| 1099 | * If the object to get is multipart object, the part checksum MAY be validated if the part size to get matches the |
| 1100 | * part size uploaded. In that case, if any part mismatch the checksum received, the meta request will fail with |
| 1101 | * checksum mismatch. However, even if the parts checksum were validated, this will NOT be set to true, as the |
| 1102 | * checksum for the whole meta request was NOT validated. |
| 1103 | **/ |
| 1104 | bool did_validate; |
| 1105 | |
| 1106 | /* algorithm used to validate checksum */ |
| 1107 | enum aws_s3_checksum_algorithm validation_algorithm; |
| 1108 | |
| 1109 | /* Final error code of the meta request. */ |
| 1110 | int error_code; |
| 1111 | }; |
| 1112 | |
| 1113 | AWS_EXTERN_C_BEGIN |
| 1114 | |
| 1115 | AWS_S3_API |
| 1116 | struct aws_s3_client *aws_s3_client_new( |
| 1117 | struct aws_allocator *allocator, |
| 1118 | const struct aws_s3_client_config *client_config); |
| 1119 | |
| 1120 | /** |
| 1121 | * Add a reference, keeping this object alive. |
| 1122 | * The reference must be released when you are done with it, or it's memory will never be cleaned up. |
| 1123 | * You must not pass in NULL. |
| 1124 | * Always returns the same pointer that was passed in. |
| 1125 | */ |
| 1126 | AWS_S3_API |
| 1127 | struct aws_s3_client *aws_s3_client_acquire(struct aws_s3_client *client); |
| 1128 | |
| 1129 | /** |
| 1130 | * Release a reference. |
| 1131 | * When the reference count drops to 0, this object will be cleaned up. |
| 1132 | * It's OK to pass in NULL (nothing happens). |
| 1133 | * Always returns NULL. |
| 1134 | */ |
| 1135 | AWS_S3_API |
| 1136 | struct aws_s3_client *aws_s3_client_release(struct aws_s3_client *client); |
| 1137 | |
| 1138 | AWS_S3_API |
| 1139 | struct aws_s3_meta_request *aws_s3_client_make_meta_request( |
| 1140 | struct aws_s3_client *client, |
| 1141 | const struct aws_s3_meta_request_options *options); |
| 1142 | |
| 1143 | /** |
| 1144 | * The result of an `aws_s3_meta_request_poll_write()` call. |
| 1145 | * Think of this like Rust's `Poll<Result<size_t, int>>`, or C++'s `optional<expected<size_t, int>>`. |
| 1146 | */ |
| 1147 | struct aws_s3_meta_request_poll_write_result { |
| 1148 | bool is_pending; |
| 1149 | int error_code; |
| 1150 | size_t bytes_processed; |
| 1151 | }; |
| 1152 | |
| 1153 | /** |
| 1154 | * Attempt to write data. |
| 1155 | * |
| 1156 | * You must set `aws_s3_meta_request_options.send_using_async_writes` to use this function. |
| 1157 | * |
| 1158 | * This is a non-blocking poll-style async function, similar to Rust's: |
| 1159 | * https://docs.rs/futures/latest/futures/io/trait.AsyncWrite.html#tymethod.poll_write |
| 1160 | * If you prefer completion-style async functions, and your data can outlive |
| 1161 | * the callstack, use aws_s3_meta_request_write() instead. |
| 1162 | * |
| 1163 | * Check the returned `result` struct to see what happened: |
| 1164 | * 1) If `result.is_pending == true` then no work was done. |
| 1165 | * The waker callback will be invoked when you can call poll_write() again. |
| 1166 | * Do not call poll_write() again before the waker is invoked. |
| 1167 | * |
| 1168 | * 2) Else if `result.error_code != 0` then poll_write() did not succeed |
| 1169 | * and you should not call it again. The meta request is guaranteed to finish soon |
| 1170 | * (you don't need to worry about canceling the meta request yourself after a failed write). |
| 1171 | * A common error code is AWS_ERROR_S3_REQUEST_HAS_COMPLETED, indicating |
| 1172 | * the meta request completed for reasons unrelated to the poll_write() call |
| 1173 | * (e.g. CreateMultipartUpload received a 403 Forbidden response). |
| 1174 | * AWS_ERROR_INVALID_STATE usually indicates that you're calling poll_write() |
| 1175 | * incorrectly (e.g. not waiting for waker callback from previous poll_write() call). |
| 1176 | * |
| 1177 | * 3) Else `result.bytes_processed` tells you how much data was processed. |
| 1178 | * `bytes_processed` may be less than the `data.len` you passed in. |
| 1179 | * Continue calling poll_write() with the remaining data until everything is processed. |
| 1180 | * `result.bytes_processed` won't be 0 unless you passed in `data.len` of 0. |
| 1181 | * |
| 1182 | * @param meta_request Meta request |
| 1183 | * |
| 1184 | * @param data The data to send. The data can be any size. |
| 1185 | * `result.bytes_processed` indicates how many bytes were |
| 1186 | * processed by this call. |
| 1187 | * |
| 1188 | * @param eof Pass true to signal EOF (end of file). |
| 1189 | * If poll_write() doesn't process all your data |
| 1190 | * (`result.is_pending` or `result.byte_processed < data.len`) |
| 1191 | * then EOF was ignored, and you need to pass it again |
| 1192 | * to subsequent poll_write() calls. |
| 1193 | * |
| 1194 | * @param waker Waker callback. |
| 1195 | * If `result.is_pending == true`, then the waker will be called |
| 1196 | * exactly once when it's a good time to call poll_write() again. |
| 1197 | * If `result.is_pending == false`, the waker will never be called. |
| 1198 | * |
| 1199 | * @param user_data Pointer to be passed to the waker callback. |
| 1200 | * |
| 1201 | * WARNING: This feature is experimental. |
| 1202 | */ |
| 1203 | AWS_S3_API |
| 1204 | struct aws_s3_meta_request_poll_write_result aws_s3_meta_request_poll_write( |
| 1205 | struct aws_s3_meta_request *meta_request, |
| 1206 | struct aws_byte_cursor data, |
| 1207 | bool eof, |
| 1208 | aws_simple_completion_callback *waker, |
| 1209 | void *user_data); |
| 1210 | |
| 1211 | /** |
| 1212 | * Write the next chunk of data. |
| 1213 | * |
| 1214 | * You must set `aws_s3_meta_request_options.send_using_async_writes` to use this function. |
| 1215 | * |
| 1216 | * This function is asynchronous, and returns a future (see <aws/io/future.h>). |
| 1217 | * You may not call write() again until the future completes. |
| 1218 | * |
| 1219 | * If the future completes with an error code, then write() did not succeed |
| 1220 | * and you should not call it again. If the future contains any error code, |
| 1221 | * the meta request is guaranteed to finish soon (you don't need to worry about |
| 1222 | * canceling the meta request yourself after a failed write). |
| 1223 | * A common error code is AWS_ERROR_S3_REQUEST_HAS_COMPLETED, indicating |
| 1224 | * the meta request completed for reasons unrelated to the write() call |
| 1225 | * (e.g. CreateMultipartUpload received a 403 Forbidden response). |
| 1226 | * AWS_ERROR_INVALID_STATE usually indicates that you're calling write() |
| 1227 | * incorrectly (e.g. not waiting for previous write to complete). |
| 1228 | * |
| 1229 | * You MUST keep the data in memory until the future completes. |
| 1230 | * If you cannot do this, use aws_s3_meta_request_poll_write() instead. |
| 1231 | * |
| 1232 | * You can wait any length of time between calls to write(). |
| 1233 | * If there's not enough data to upload a part, the data will be copied |
| 1234 | * to a buffer and the future will immediately complete. |
| 1235 | * |
| 1236 | * @param meta_request Meta request |
| 1237 | * |
| 1238 | * @param data The data to send. The data can be any size. |
| 1239 | * |
| 1240 | * @param eof Pass true to signal EOF (end of file). |
| 1241 | * Do not call write() again after passing true. |
| 1242 | * |
| 1243 | * This function never returns NULL. |
| 1244 | * |
| 1245 | * WARNING: This feature is experimental. |
| 1246 | */ |
| 1247 | AWS_S3_API |
| 1248 | struct aws_future_void *aws_s3_meta_request_write( |
| 1249 | struct aws_s3_meta_request *meta_request, |
| 1250 | struct aws_byte_cursor data, |
| 1251 | bool eof); |
| 1252 | |
| 1253 | /** |
| 1254 | * Increment the flow-control window, so that response data continues downloading. |
| 1255 | * |
| 1256 | * If the client was created with `enable_read_backpressure` set true, |
| 1257 | * each meta request has a flow-control window that shrinks as response |
| 1258 | * body data is downloaded (headers do not affect the size of the window). |
| 1259 | * The client's `initial_read_window` determines the starting size of each meta request's window. |
| 1260 | * If a meta request's flow-control window reaches 0, no further data will be downloaded. |
| 1261 | * If the `initial_read_window` is 0, the request will not start until the window is incremented. |
| 1262 | * Maintain a larger window to keep up a high download throughput, |
| 1263 | * parts cannot download in parallel unless the window is large enough to hold multiple parts. |
| 1264 | * Maintain a smaller window to limit the amount of data buffered in memory. |
| 1265 | * |
| 1266 | * If `enable_read_backpressure` is false this call will have no effect, |
| 1267 | * no backpressure is being applied and data is being downloaded as fast as possible. |
| 1268 | * |
| 1269 | * WARNING: This feature is experimental. |
| 1270 | * Currently, backpressure is applied to GetObject requests, |
| 1271 | * - If you set body_callback, no more data will be delivered once the window reaches 0. |
| 1272 | * - If you set body_callback_ex, you may still receive some data after the window reaches 0. TODO: fix it. |
| 1273 | */ |
| 1274 | AWS_S3_API |
| 1275 | void aws_s3_meta_request_increment_read_window(struct aws_s3_meta_request *meta_request, uint64_t bytes); |
| 1276 | |
| 1277 | AWS_S3_API |
| 1278 | void aws_s3_meta_request_cancel(struct aws_s3_meta_request *meta_request); |
| 1279 | |
| 1280 | /** |
| 1281 | * Note: pause is currently only supported on upload requests. |
| 1282 | * In order to pause an ongoing upload, call aws_s3_meta_request_pause() that |
| 1283 | * will return resume token. Token can be used to query the state of operation |
| 1284 | * at the pausing time. |
| 1285 | * To resume an upload that was paused, supply resume token in the meta |
| 1286 | * request options structure member aws_s3_meta_request_options.resume_token. |
| 1287 | * The upload can be resumed either from the same client or a different one. |
| 1288 | * Corner cases for resume upload are as follows: |
| 1289 | * - upload is not MPU - fail with AWS_ERROR_UNSUPPORTED_OPERATION |
| 1290 | * - pausing before MPU is created - NULL resume token returned. NULL resume |
| 1291 | * token is equivalent to restarting upload |
| 1292 | * - pausing in the middle of part transfer - return resume token. scheduling of |
| 1293 | * new part uploads stops. |
| 1294 | * - pausing after completeMPU started - return resume token. if s3 cannot find |
| 1295 | * find associated MPU id when resuming with that token and num of parts |
| 1296 | * uploaded equals to total num parts, then operation is a no op. Otherwise |
| 1297 | * operation fails. |
| 1298 | * Note: for no op case the call will succeed and finish/shutdown request callbacks will |
| 1299 | * fire, but on headers callback will not fire. |
| 1300 | * Note: similar to cancel pause does not cancel requests already in flight and |
| 1301 | * and parts might complete after pause is requested. |
| 1302 | * @param meta_request pointer to the aws_s3_meta_request of the upload to be paused |
| 1303 | * @param resume_token resume token |
| 1304 | * @return either AWS_OP_ERR or AWS_OP_SUCCESS |
| 1305 | */ |
| 1306 | AWS_S3_API |
| 1307 | int aws_s3_meta_request_pause( |
| 1308 | struct aws_s3_meta_request *meta_request, |
| 1309 | struct aws_s3_meta_request_resume_token **out_resume_token); |
| 1310 | |
| 1311 | /* |
| 1312 | * Options to construct upload resume token. |
| 1313 | * Note: fields correspond to getters on the token below and it up to the caller |
| 1314 | * to persist those in whichever way they choose. |
| 1315 | */ |
| 1316 | struct aws_s3_upload_resume_token_options { |
| 1317 | struct aws_byte_cursor upload_id; /* Required */ |
| 1318 | uint64_t part_size; /* Required. Must be less than SIZE_MAX */ |
| 1319 | size_t total_num_parts; /* Required */ |
| 1320 | |
| 1321 | /** |
| 1322 | * Optional. |
| 1323 | * |
| 1324 | * Note: during resume num_parts_uploaded is used for sanity checking against |
| 1325 | * uploads on s3 side. |
| 1326 | * In cases where upload id does not exist (already resumed using this token |
| 1327 | * or pause called after upload completes, etc...) and num_parts_uploaded |
| 1328 | * equals to total num parts, resume will become a noop. |
| 1329 | */ |
| 1330 | size_t num_parts_completed; |
| 1331 | }; |
| 1332 | |
| 1333 | /** |
| 1334 | * Create upload resume token from persisted data. |
| 1335 | * Note: Data required for resume token varies per operation. |
| 1336 | */ |
| 1337 | AWS_S3_API |
| 1338 | struct aws_s3_meta_request_resume_token *aws_s3_meta_request_resume_token_new_upload( |
| 1339 | struct aws_allocator *allocator, |
| 1340 | const struct aws_s3_upload_resume_token_options *options); |
| 1341 | |
| 1342 | /* |
| 1343 | * Increment resume token ref count. |
| 1344 | */ |
| 1345 | AWS_S3_API |
| 1346 | struct aws_s3_meta_request_resume_token *aws_s3_meta_request_resume_token_acquire( |
| 1347 | struct aws_s3_meta_request_resume_token *resume_token); |
| 1348 | |
| 1349 | /* |
| 1350 | * Decrement resume token ref count. |
| 1351 | */ |
| 1352 | AWS_S3_API |
| 1353 | struct aws_s3_meta_request_resume_token *aws_s3_meta_request_resume_token_release( |
| 1354 | struct aws_s3_meta_request_resume_token *resume_token); |
| 1355 | |
| 1356 | /* |
| 1357 | * Type of resume token. |
| 1358 | */ |
| 1359 | AWS_S3_API |
| 1360 | enum aws_s3_meta_request_type aws_s3_meta_request_resume_token_type( |
| 1361 | struct aws_s3_meta_request_resume_token *resume_token); |
| 1362 | |
| 1363 | /* |
| 1364 | * Part size associated with operation. |
| 1365 | */ |
| 1366 | AWS_S3_API |
| 1367 | uint64_t aws_s3_meta_request_resume_token_part_size(struct aws_s3_meta_request_resume_token *resume_token); |
| 1368 | |
| 1369 | /* |
| 1370 | * Total num parts associated with operation. |
| 1371 | */ |
| 1372 | AWS_S3_API |
| 1373 | size_t aws_s3_meta_request_resume_token_total_num_parts(struct aws_s3_meta_request_resume_token *resume_token); |
| 1374 | |
| 1375 | /* |
| 1376 | * Num parts completed. |
| 1377 | */ |
| 1378 | AWS_S3_API |
| 1379 | size_t aws_s3_meta_request_resume_token_num_parts_completed(struct aws_s3_meta_request_resume_token *resume_token); |
| 1380 | |
| 1381 | /* |
| 1382 | * Upload id associated with operation. |
| 1383 | * Only valid for tokens returned from upload operation. For all other operations |
| 1384 | * this will return empty. |
| 1385 | */ |
| 1386 | AWS_S3_API |
| 1387 | struct aws_byte_cursor aws_s3_meta_request_resume_token_upload_id( |
| 1388 | struct aws_s3_meta_request_resume_token *resume_token); |
| 1389 | |
| 1390 | /** |
| 1391 | * Add a reference, keeping this object alive. |
| 1392 | * The reference must be released when you are done with it, or it's memory will never be cleaned up. |
| 1393 | * You must not pass in NULL. |
| 1394 | * Always returns the same pointer that was passed in. |
| 1395 | */ |
| 1396 | AWS_S3_API |
| 1397 | struct aws_s3_meta_request *aws_s3_meta_request_acquire(struct aws_s3_meta_request *meta_request); |
| 1398 | |
| 1399 | /** |
| 1400 | * Release a reference. |
| 1401 | * When the reference count drops to 0, this object will be cleaned up. |
| 1402 | * It's OK to pass in NULL (nothing happens). |
| 1403 | * Always returns NULL. |
| 1404 | */ |
| 1405 | AWS_S3_API |
| 1406 | struct aws_s3_meta_request *aws_s3_meta_request_release(struct aws_s3_meta_request *meta_request); |
| 1407 | |
| 1408 | /** |
| 1409 | * Initialize the configuration for a default S3 signing. |
| 1410 | */ |
| 1411 | AWS_S3_API |
| 1412 | void aws_s3_init_default_signing_config( |
| 1413 | struct aws_signing_config_aws *signing_config, |
| 1414 | const struct aws_byte_cursor region, |
| 1415 | struct aws_credentials_provider *credentials_provider); |
| 1416 | |
| 1417 | /** |
| 1418 | * Return operation name for aws_s3_request_type, |
| 1419 | * or empty string if the type doesn't map to an actual operation. |
| 1420 | * For example: |
| 1421 | * AWS_S3_REQUEST_TYPE_HEAD_OBJECT -> "HeadObject" |
| 1422 | * AWS_S3_REQUEST_TYPE_UNKNOWN -> "" |
| 1423 | * AWS_S3_REQUEST_TYPE_MAX -> "" |
| 1424 | */ |
| 1425 | AWS_S3_API |
| 1426 | const char *aws_s3_request_type_operation_name(enum aws_s3_request_type type); |
| 1427 | |
| 1428 | /** |
| 1429 | * Add a reference, keeping this object alive. |
| 1430 | * The reference must be released when you are done with it, or it's memory will never be cleaned up. |
| 1431 | * Always returns the same pointer that was passed in. |
| 1432 | */ |
| 1433 | AWS_S3_API |
| 1434 | struct aws_s3_request_metrics *aws_s3_request_metrics_acquire(struct aws_s3_request_metrics *metrics); |
| 1435 | |
| 1436 | /** |
| 1437 | * Release a reference. |
| 1438 | * When the reference count drops to 0, this object will be cleaned up. |
| 1439 | * It's OK to pass in NULL (nothing happens). |
| 1440 | * Always returns NULL. |
| 1441 | */ |
| 1442 | AWS_S3_API |
| 1443 | struct aws_s3_request_metrics *aws_s3_request_metrics_release(struct aws_s3_request_metrics *metrics); |
| 1444 | |
| 1445 | /************************************* Getters for s3 request metrics ************************************************/ |
| 1446 | /** |
| 1447 | * Get the request ID from aws_s3_request_metrics. |
| 1448 | * If unavailable, AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised. |
| 1449 | * If available, out_request_id will be set to a string. Be warned this string's lifetime is tied to the metrics |
| 1450 | * object. |
| 1451 | **/ |
| 1452 | AWS_S3_API |
| 1453 | int aws_s3_request_metrics_get_request_id( |
| 1454 | const struct aws_s3_request_metrics *metrics, |
| 1455 | const struct aws_string **out_request_id); |
| 1456 | |
| 1457 | /** |
| 1458 | * Get the extended request ID from aws_s3_request_metrics. |
| 1459 | * If unavailable, AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised. |
| 1460 | * If available, out_extended_request_id will be set to a string. Be warned this string's lifetime is tied to the |
| 1461 | * metrics object. |
| 1462 | **/ |
| 1463 | AWS_S3_API |
| 1464 | int aws_s3_request_metrics_get_extended_request_id( |
| 1465 | const struct aws_s3_request_metrics *metrics, |
| 1466 | const struct aws_string **out_extended_request_id); |
| 1467 | |
| 1468 | /* Get the start time from aws_s3_request_metrics, which is when S3 client prepare the request to be sent. Always |
| 1469 | * available. Timestamp are from `aws_high_res_clock_get_ticks` */ |
| 1470 | AWS_S3_API |
| 1471 | void aws_s3_request_metrics_get_start_timestamp_ns( |
| 1472 | const struct aws_s3_request_metrics *metrics, |
| 1473 | uint64_t *out_start_time); |
| 1474 | |
| 1475 | /* Get the end time from aws_s3_request_metrics. Always available */ |
| 1476 | AWS_S3_API |
| 1477 | void aws_s3_request_metrics_get_end_timestamp_ns(const struct aws_s3_request_metrics *metrics, uint64_t *out_end_time); |
| 1478 | |
| 1479 | /* Get the total duration time from aws_s3_request_metrics. Always available */ |
| 1480 | AWS_S3_API |
| 1481 | void aws_s3_request_metrics_get_total_duration_ns( |
| 1482 | const struct aws_s3_request_metrics *metrics, |
| 1483 | uint64_t *out_total_duration); |
| 1484 | |
| 1485 | /* Get the time stamp when the request started to be encoded. Timestamps are from `aws_high_res_clock_get_ticks` |
| 1486 | * AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if the request ended before it gets sent. */ |
| 1487 | AWS_S3_API |
| 1488 | int aws_s3_request_metrics_get_send_start_timestamp_ns( |
| 1489 | const struct aws_s3_request_metrics *metrics, |
| 1490 | uint64_t *out_send_start_time); |
| 1491 | |
| 1492 | /* Get the time stamp when the request finished to be encoded. Timestamps are from `aws_high_res_clock_get_ticks` |
| 1493 | * AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1494 | AWS_S3_API |
| 1495 | int aws_s3_request_metrics_get_send_end_timestamp_ns( |
| 1496 | const struct aws_s3_request_metrics *metrics, |
| 1497 | uint64_t *out_send_end_time); |
| 1498 | |
| 1499 | /* The time duration for the request from start encoding to finish encoding (send_end_timestamp_ns - |
| 1500 | * send_start_timestamp_ns). |
| 1501 | * AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1502 | AWS_S3_API |
| 1503 | int aws_s3_request_metrics_get_sending_duration_ns( |
| 1504 | const struct aws_s3_request_metrics *metrics, |
| 1505 | uint64_t *out_sending_duration); |
| 1506 | |
| 1507 | /* Get the time stamp when the response started to be received from the network channel. Timestamps are from |
| 1508 | * `aws_high_res_clock_get_ticks` AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1509 | AWS_S3_API |
| 1510 | int aws_s3_request_metrics_get_receive_start_timestamp_ns( |
| 1511 | const struct aws_s3_request_metrics *metrics, |
| 1512 | uint64_t *out_receive_start_time); |
| 1513 | |
| 1514 | /* Get the time stamp when the response finished to be received from the network channel. Timestamps are from |
| 1515 | * `aws_high_res_clock_get_ticks` AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1516 | AWS_S3_API |
| 1517 | int aws_s3_request_metrics_get_receive_end_timestamp_ns( |
| 1518 | const struct aws_s3_request_metrics *metrics, |
| 1519 | uint64_t *out_receive_end_time); |
| 1520 | |
| 1521 | /* Get the time stamp when the signing for the request started. Timestamps are from |
| 1522 | * `aws_high_res_clock_get_ticks` AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1523 | AWS_S3_API |
| 1524 | int aws_s3_request_metrics_get_sign_start_timestamp_ns( |
| 1525 | const struct aws_s3_request_metrics *metrics, |
| 1526 | uint64_t *out_signing_start_time); |
| 1527 | |
| 1528 | /* Get the time stamp when the signing for the request ended. Timestamps are from |
| 1529 | * `aws_high_res_clock_get_ticks` AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1530 | AWS_S3_API |
| 1531 | int aws_s3_request_metrics_get_sign_end_timestamp_ns( |
| 1532 | const struct aws_s3_request_metrics *metrics, |
| 1533 | uint64_t *out_signing_end_time); |
| 1534 | |
| 1535 | /* The time duration for the request singing (sign_end_timestamp_ns - |
| 1536 | * sign_start_timestamp_ns). |
| 1537 | * AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1538 | AWS_S3_API |
| 1539 | int aws_s3_request_metrics_get_signing_duration_ns( |
| 1540 | const struct aws_s3_request_metrics *metrics, |
| 1541 | uint64_t *out_signing_duration); |
| 1542 | |
| 1543 | /* Get the time stamp when the memory acquisition for the request started. Timestamps are from |
| 1544 | * `aws_high_res_clock_get_ticks` AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1545 | AWS_S3_API |
| 1546 | int aws_s3_request_metrics_get_mem_acquire_start_timestamp_ns( |
| 1547 | const struct aws_s3_request_metrics *metrics, |
| 1548 | uint64_t *out_mem_acquire_start_time); |
| 1549 | |
| 1550 | /* Get the time stamp when the memory acquisition for the request ended. Timestamps are from |
| 1551 | * `aws_high_res_clock_get_ticks` AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1552 | AWS_S3_API |
| 1553 | int aws_s3_request_metrics_get_mem_acquire_end_timestamp_ns( |
| 1554 | const struct aws_s3_request_metrics *metrics, |
| 1555 | uint64_t *out_mem_acquire_end_time); |
| 1556 | |
| 1557 | /* The time duration for the request memory acquisition (mem_acquire_end_timestamp_ns - |
| 1558 | * mem_acquire_start_timestamp_ns). |
| 1559 | * AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1560 | AWS_S3_API |
| 1561 | int aws_s3_request_metrics_get_mem_acquire_duration_ns( |
| 1562 | const struct aws_s3_request_metrics *metrics, |
| 1563 | uint64_t *out_mem_acquire_duration); |
| 1564 | |
| 1565 | /* Get the time stamp when the delivery of the request response started. Timestamps are from |
| 1566 | * `aws_high_res_clock_get_ticks` AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1567 | AWS_S3_API |
| 1568 | int aws_s3_request_metrics_get_delivery_start_timestamp_ns( |
| 1569 | const struct aws_s3_request_metrics *metrics, |
| 1570 | uint64_t *out_delivery_start_time); |
| 1571 | |
| 1572 | /* Get the time stamp when the delivery of the request response ended. Timestamps are from |
| 1573 | * `aws_high_res_clock_get_ticks` AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1574 | AWS_S3_API |
| 1575 | int aws_s3_request_metrics_get_delivery_end_timestamp_ns( |
| 1576 | const struct aws_s3_request_metrics *metrics, |
| 1577 | uint64_t *out_delivery_end_time); |
| 1578 | |
| 1579 | /* The time duration for the request delivery(delivery_end_timestamp_ns - |
| 1580 | * delivery_start_timestamp_ns). |
| 1581 | * AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1582 | AWS_S3_API |
| 1583 | int aws_s3_request_metrics_get_delivery_duration_ns( |
| 1584 | const struct aws_s3_request_metrics *metrics, |
| 1585 | uint64_t *out_delivery_duration); |
| 1586 | |
| 1587 | /* The time duration for the request from start receiving to finish receiving (receive_end_timestamp_ns - |
| 1588 | * receive_start_timestamp_ns). |
| 1589 | * AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1590 | AWS_S3_API |
| 1591 | int aws_s3_request_metrics_get_receiving_duration_ns( |
| 1592 | const struct aws_s3_request_metrics *metrics, |
| 1593 | uint64_t *out_receiving_duration); |
| 1594 | |
| 1595 | /* Get the response status code for the request. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not |
| 1596 | * available. */ |
| 1597 | AWS_S3_API |
| 1598 | int aws_s3_request_metrics_get_response_status_code( |
| 1599 | const struct aws_s3_request_metrics *metrics, |
| 1600 | int *out_response_status); |
| 1601 | |
| 1602 | /* Get the HTTP Headers of the response received for the request. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised |
| 1603 | * if data not available. */ |
| 1604 | AWS_S3_API |
| 1605 | int aws_s3_request_metrics_get_response_headers( |
| 1606 | const struct aws_s3_request_metrics *metrics, |
| 1607 | struct aws_http_headers **out_response_headers); |
| 1608 | |
| 1609 | /** |
| 1610 | * Get the path and query of the request. |
| 1611 | * If unavailable, AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised. |
| 1612 | * If available, out_request_path_query will be set to a string. Be warned this string's lifetime is tied to the metrics |
| 1613 | * object. |
| 1614 | */ |
| 1615 | AWS_S3_API |
| 1616 | void aws_s3_request_metrics_get_request_path_query( |
| 1617 | const struct aws_s3_request_metrics *metrics, |
| 1618 | const struct aws_string **out_request_path_query); |
| 1619 | |
| 1620 | /** |
| 1621 | * Get the host_address of the request. |
| 1622 | * If unavailable, AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised. |
| 1623 | * If available, out_host_address will be set to a string. Be warned this string's lifetime is tied to the metrics |
| 1624 | * object. |
| 1625 | */ |
| 1626 | AWS_S3_API |
| 1627 | void aws_s3_request_metrics_get_host_address( |
| 1628 | const struct aws_s3_request_metrics *metrics, |
| 1629 | const struct aws_string **out_host_address); |
| 1630 | |
| 1631 | /** |
| 1632 | * Get the IP address of the request connected to. |
| 1633 | * If unavailable, AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised. |
| 1634 | * If available, out_ip_address will be set to a string. Be warned this string's lifetime is tied to the metrics object. |
| 1635 | */ |
| 1636 | AWS_S3_API |
| 1637 | int aws_s3_request_metrics_get_ip_address( |
| 1638 | const struct aws_s3_request_metrics *metrics, |
| 1639 | const struct aws_string **out_ip_address); |
| 1640 | |
| 1641 | /* Get the ptr address of connection that request was made from. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised |
| 1642 | * if data not available */ |
| 1643 | AWS_S3_API |
| 1644 | int aws_s3_request_metrics_get_connection_id(const struct aws_s3_request_metrics *metrics, size_t *out_connection_ptr); |
| 1645 | |
| 1646 | /* Get the pointer to the request that attempt was made from. Always available. */ |
| 1647 | AWS_S3_API |
| 1648 | int aws_s3_request_metrics_get_request_ptr(const struct aws_s3_request_metrics *metrics, size_t *out_request_ptr); |
| 1649 | |
| 1650 | /* Get the thread ID of the thread that request was made from. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if |
| 1651 | * data not available */ |
| 1652 | AWS_S3_API |
| 1653 | int aws_s3_request_metrics_get_thread_id(const struct aws_s3_request_metrics *metrics, aws_thread_id_t *out_thread_id); |
| 1654 | |
| 1655 | /* Get the stream-id, which is the idex when the stream was activated. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be |
| 1656 | * raised if data not available */ |
| 1657 | AWS_S3_API |
| 1658 | int aws_s3_request_metrics_get_request_stream_id(const struct aws_s3_request_metrics *metrics, uint32_t *out_stream_id); |
| 1659 | |
| 1660 | /** |
| 1661 | * Get the S3 operation name of the request (e.g. "HeadObject"). |
| 1662 | * If unavailable, AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised. |
| 1663 | * If available, out_operation_name will be set to a string. |
| 1664 | * Be warned this string's lifetime is tied to the metrics object. |
| 1665 | */ |
| 1666 | AWS_S3_API |
| 1667 | int aws_s3_request_metrics_get_operation_name( |
| 1668 | const struct aws_s3_request_metrics *metrics, |
| 1669 | const struct aws_string **out_operation_name); |
| 1670 | |
| 1671 | /* Get the request type from request metrics. |
| 1672 | * If you just need a string, aws_s3_request_metrics_get_operation_name() is more reliable. */ |
| 1673 | AWS_S3_API |
| 1674 | void aws_s3_request_metrics_get_request_type( |
| 1675 | const struct aws_s3_request_metrics *metrics, |
| 1676 | enum aws_s3_request_type *out_request_type); |
| 1677 | |
| 1678 | /* Get the AWS CRT error code from request metrics. */ |
| 1679 | AWS_S3_API |
| 1680 | int aws_s3_request_metrics_get_error_code(const struct aws_s3_request_metrics *metrics); |
| 1681 | |
| 1682 | /* Get retry attempt from request metrics. */ |
| 1683 | AWS_S3_API |
| 1684 | uint32_t aws_s3_request_metrics_get_retry_attempt(const struct aws_s3_request_metrics *metrics); |
| 1685 | |
| 1686 | /* Get whether the memory for the request was allocated from the pool. Cannot fail */ |
| 1687 | AWS_S3_API |
| 1688 | bool aws_s3_request_metrics_get_memory_allocated_from_pool(const struct aws_s3_request_metrics *metrics); |
| 1689 | |
| 1690 | /* Get the beginning range of this part from request metrics. */ |
| 1691 | AWS_S3_API |
| 1692 | void aws_s3_request_metrics_get_part_range_start( |
| 1693 | const struct aws_s3_request_metrics *metrics, |
| 1694 | uint64_t *out_part_range_start); |
| 1695 | |
| 1696 | /* Get the last byte of this part from request metrics. */ |
| 1697 | AWS_S3_API |
| 1698 | void aws_s3_request_metrics_get_part_range_end( |
| 1699 | const struct aws_s3_request_metrics *metrics, |
| 1700 | uint64_t *out_part_range_end); |
| 1701 | |
| 1702 | /* Get the part number from request metrics. */ |
| 1703 | AWS_S3_API |
| 1704 | void aws_s3_request_metrics_get_part_number(const struct aws_s3_request_metrics *metrics, uint32_t *out_part_number); |
| 1705 | /* Get the request start timestamp from aws_s3_request_metrics. Always available. */ |
| 1706 | AWS_S3_API |
| 1707 | void aws_s3_request_metrics_get_s3_request_first_attempt_start_timestamp_ns( |
| 1708 | const struct aws_s3_request_metrics *metrics, |
| 1709 | uint64_t *out_s3_request_first_attempt_start_time); |
| 1710 | |
| 1711 | /* Get the request end timestamp. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not |
| 1712 | * available. */ |
| 1713 | AWS_S3_API |
| 1714 | int aws_s3_request_metrics_get_s3_request_last_attempt_end_timestamp_ns( |
| 1715 | const struct aws_s3_request_metrics *metrics, |
| 1716 | uint64_t *out_s3_request_last_attempt_end_time); |
| 1717 | |
| 1718 | /* Get the request duration. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not |
| 1719 | * available. */ |
| 1720 | AWS_S3_API |
| 1721 | int aws_s3_request_metrics_get_s3_request_total_duration_ns( |
| 1722 | const struct aws_s3_request_metrics *metrics, |
| 1723 | uint64_t *out_request_duration); |
| 1724 | |
| 1725 | /* Get the connection acquire start timestamp. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not |
| 1726 | * available. */ |
| 1727 | AWS_S3_API |
| 1728 | int aws_s3_request_metrics_get_conn_acquire_start_timestamp_ns( |
| 1729 | const struct aws_s3_request_metrics *metrics, |
| 1730 | uint64_t *out_conn_acquire_start_time); |
| 1731 | |
| 1732 | /* Get the connection acquire end timestamp. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not |
| 1733 | * available. */ |
| 1734 | AWS_S3_API |
| 1735 | int aws_s3_request_metrics_get_conn_acquire_end_timestamp_ns( |
| 1736 | const struct aws_s3_request_metrics *metrics, |
| 1737 | uint64_t *out_conn_acquire_end_time); |
| 1738 | |
| 1739 | /* Get the connection acquire duration. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1740 | AWS_S3_API |
| 1741 | int aws_s3_request_metrics_get_conn_acquire_duration_ns( |
| 1742 | const struct aws_s3_request_metrics *metrics, |
| 1743 | uint64_t *out_conn_acquire_duration); |
| 1744 | |
| 1745 | /* Get the retry delay start timestamp. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1746 | AWS_S3_API |
| 1747 | int aws_s3_request_metrics_get_retry_delay_start_timestamp_ns( |
| 1748 | const struct aws_s3_request_metrics *metrics, |
| 1749 | uint64_t *out_retry_delay_start_time); |
| 1750 | |
| 1751 | /* Get the retry delay end timestamp. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1752 | AWS_S3_API |
| 1753 | int aws_s3_request_metrics_get_retry_delay_end_timestamp_ns( |
| 1754 | const struct aws_s3_request_metrics *metrics, |
| 1755 | uint64_t *out_retry_delay_end_time); |
| 1756 | |
| 1757 | /* Get the retry delay duration. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1758 | AWS_S3_API |
| 1759 | int aws_s3_request_metrics_get_retry_delay_duration_ns( |
| 1760 | const struct aws_s3_request_metrics *metrics, |
| 1761 | uint64_t *out_retry_delay_duration); |
| 1762 | |
| 1763 | /* Get the service call duration. AWS_ERROR_S3_METRIC_DATA_NOT_AVAILABLE will be raised if data not available. */ |
| 1764 | AWS_S3_API |
| 1765 | int aws_s3_request_metrics_get_service_call_duration_ns( |
| 1766 | const struct aws_s3_request_metrics *metrics, |
| 1767 | uint64_t *out_service_call_duration); |
| 1768 | |
| 1769 | AWS_EXTERN_C_END |
| 1770 | AWS_POP_SANE_WARNING_LEVEL |
| 1771 | |
| 1772 | #endif /* AWS_S3_CLIENT_H */ |