iroh_blobs/rpc/proto/blobs.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
//! RPC requests and responses for the blob service.
use std::path::PathBuf;
use bytes::Bytes;
use iroh::NodeAddr;
use nested_enum_utils::enum_conversions;
use quic_rpc_derive::rpc_requests;
use serde::{Deserialize, Serialize};
use super::{RpcError, RpcResult, RpcService};
pub use crate::get::progress::DownloadProgressEvent;
use crate::{
format::collection::Collection,
net_protocol::batches::BatchId,
rpc::client::blobs::{
BlobInfo, BlobStatus, DownloadMode, IncompleteBlobInfo, ReadAtLen, WrapOption,
},
store::{
BaoBlobSize, ConsistencyCheckProgress, ExportFormat, ExportMode, ExportProgress,
ImportMode, ValidateProgress,
},
util::SetTagOption,
BlobFormat, Hash, HashAndFormat, Tag,
};
#[allow(missing_docs)]
#[derive(strum::Display, Debug, Serialize, Deserialize)]
#[enum_conversions(super::Request)]
#[rpc_requests(RpcService)]
pub enum Request {
#[server_streaming(response = RpcResult<ReadAtResponse>)]
ReadAt(ReadAtRequest),
#[bidi_streaming(update = AddStreamUpdate, response = AddStreamResponse)]
AddStream(AddStreamRequest),
AddStreamUpdate(AddStreamUpdate),
#[server_streaming(response = AddPathResponse)]
AddPath(AddPathRequest),
#[server_streaming(response = DownloadResponse)]
Download(BlobDownloadRequest),
#[server_streaming(response = ExportResponse)]
Export(ExportRequest),
#[server_streaming(response = RpcResult<BlobInfo>)]
List(ListRequest),
#[server_streaming(response = RpcResult<IncompleteBlobInfo>)]
ListIncomplete(ListIncompleteRequest),
#[rpc(response = RpcResult<()>)]
Delete(DeleteRequest),
#[server_streaming(response = ValidateProgress)]
Validate(ValidateRequest),
#[server_streaming(response = ConsistencyCheckProgress)]
Fsck(ConsistencyCheckRequest),
#[rpc(response = RpcResult<CreateCollectionResponse>)]
CreateCollection(CreateCollectionRequest),
#[rpc(response = RpcResult<BlobStatusResponse>)]
BlobStatus(BlobStatusRequest),
#[bidi_streaming(update = BatchUpdate, response = BatchCreateResponse)]
BatchCreate(BatchCreateRequest),
BatchUpdate(BatchUpdate),
#[bidi_streaming(update = BatchAddStreamUpdate, response = BatchAddStreamResponse)]
BatchAddStream(BatchAddStreamRequest),
BatchAddStreamUpdate(BatchAddStreamUpdate),
#[server_streaming(response = BatchAddPathResponse)]
BatchAddPath(BatchAddPathRequest),
#[rpc(response = RpcResult<()>)]
BatchCreateTempTag(BatchCreateTempTagRequest),
}
#[allow(missing_docs)]
#[derive(strum::Display, Debug, Serialize, Deserialize)]
#[enum_conversions(super::Response)]
pub enum Response {
ReadAt(RpcResult<ReadAtResponse>),
AddStream(AddStreamResponse),
AddPath(AddPathResponse),
List(RpcResult<BlobInfo>),
ListIncomplete(RpcResult<IncompleteBlobInfo>),
Download(DownloadResponse),
Fsck(ConsistencyCheckProgress),
Export(ExportResponse),
Validate(ValidateProgress),
CreateCollection(RpcResult<CreateCollectionResponse>),
BlobStatus(RpcResult<BlobStatusResponse>),
BatchCreate(BatchCreateResponse),
BatchAddStream(BatchAddStreamResponse),
BatchAddPath(BatchAddPathResponse),
}
/// A request to the node to provide the data at the given path
///
/// Will produce a stream of [`AddProgressEvent`] messages.
#[derive(Debug, Serialize, Deserialize)]
pub struct AddPathRequest {
/// The path to the data to provide.
///
/// This should be an absolute path valid for the file system on which
/// the node runs. Usually the cli will run on the same machine as the
/// node, so this should be an absolute path on the cli machine.
pub path: PathBuf,
/// True if the provider can assume that the data will not change, so it
/// can be shared in place.
pub in_place: bool,
/// Tag to tag the data with.
pub tag: SetTagOption,
/// Whether to wrap the added data in a collection
pub wrap: WrapOption,
}
/// Wrapper around [`AddProgressEvent`].
#[derive(Debug, Serialize, Deserialize, derive_more::Into)]
pub struct AddPathResponse(pub AddProgressEvent);
/// Progress response for [`BlobDownloadRequest`]
#[derive(Debug, Clone, Serialize, Deserialize, derive_more::From, derive_more::Into)]
pub struct DownloadResponse(pub DownloadProgressEvent);
/// A request to the node to download and share the data specified by the hash.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExportRequest {
/// The hash of the blob to export.
pub hash: Hash,
/// The filepath to where the data should be saved
///
/// This should be an absolute path valid for the file system on which
/// the node runs.
pub path: PathBuf,
/// Set to [`ExportFormat::Collection`] if the `hash` refers to a [`Collection`] and you want
/// to export all children of the collection into individual files.
pub format: ExportFormat,
/// The mode of exporting.
///
/// The default is [`ExportMode::Copy`]. See [`ExportMode`] for details.
pub mode: ExportMode,
}
/// Progress response for [`ExportRequest`]
#[derive(Debug, Clone, Serialize, Deserialize, derive_more::From, derive_more::Into)]
pub struct ExportResponse(pub ExportProgress);
/// A request to the node to validate the integrity of all provided data
#[derive(Debug, Serialize, Deserialize)]
pub struct ConsistencyCheckRequest {
/// repair the store by dropping inconsistent blobs
pub repair: bool,
}
/// A request to the node to validate the integrity of all provided data
#[derive(Debug, Serialize, Deserialize)]
pub struct ValidateRequest {
/// repair the store by downgrading blobs from complete to partial
pub repair: bool,
}
/// List all blobs, including collections
#[derive(Debug, Serialize, Deserialize)]
pub struct ListRequest;
/// List all blobs, including collections
#[derive(Debug, Serialize, Deserialize)]
pub struct ListIncompleteRequest;
/// Get the bytes for a hash
#[derive(Serialize, Deserialize, Debug)]
pub struct ReadAtRequest {
/// Hash to get bytes for
pub hash: Hash,
/// Offset to start reading at
pub offset: u64,
/// Length of the data to get
pub len: ReadAtLen,
}
/// Response to [`ReadAtRequest`]
#[derive(Serialize, Deserialize, Debug)]
pub enum ReadAtResponse {
/// The entry header.
Entry {
/// The size of the blob
size: BaoBlobSize,
/// Whether the blob is complete
is_complete: bool,
},
/// Chunks of entry data.
Data {
/// The data chunk
chunk: Bytes,
},
}
/// Write a blob from a byte stream
#[derive(Serialize, Deserialize, Debug)]
pub struct AddStreamRequest {
/// Tag to tag the data with.
pub tag: SetTagOption,
}
/// Write a blob from a byte stream
#[derive(Serialize, Deserialize, Debug)]
pub enum AddStreamUpdate {
/// A chunk of stream data
Chunk(Bytes),
/// Abort the request due to an error on the client side
Abort,
}
/// Wrapper around [`AddProgressEvent`].
#[derive(Debug, Serialize, Deserialize, derive_more::Into)]
pub struct AddStreamResponse(pub AddProgressEvent);
/// Delete a blob
#[derive(Debug, Serialize, Deserialize)]
pub struct DeleteRequest {
/// Name of the tag
pub hash: Hash,
}
/// Create a collection.
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateCollectionRequest {
/// The collection
pub collection: Collection,
/// Tag option.
pub tag: SetTagOption,
/// Tags that should be deleted after creation.
pub tags_to_delete: Vec<Tag>,
}
/// A response to a create collection request
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateCollectionResponse {
/// The resulting hash.
pub hash: Hash,
/// The resulting tag.
pub tag: Tag,
}
/// Request to get the status of a blob
#[derive(Debug, Serialize, Deserialize)]
pub struct BlobStatusRequest {
/// The hash of the blob
pub hash: Hash,
}
/// The response to a status request
#[derive(Debug, Serialize, Deserialize, derive_more::From, derive_more::Into)]
pub struct BlobStatusResponse(pub BlobStatus);
/// Request to create a new scope for temp tags
#[derive(Debug, Serialize, Deserialize)]
pub struct BatchCreateRequest;
/// Update to a temp tag scope
#[derive(Debug, Serialize, Deserialize)]
pub enum BatchUpdate {
/// Drop of a remote temp tag
Drop(HashAndFormat),
/// Message to check that the connection is still alive
Ping,
}
/// Response to a temp tag scope request
#[derive(Debug, Serialize, Deserialize)]
pub enum BatchCreateResponse {
/// We got the id of the scope
Id(BatchId),
}
/// Create a temp tag with a given hash and format
#[derive(Debug, Serialize, Deserialize)]
pub struct BatchCreateTempTagRequest {
/// Content to protect
pub content: HashAndFormat,
/// Batch to create the temp tag in
pub batch: BatchId,
}
/// Write a blob from a byte stream
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchAddStreamRequest {
/// What format to use for the blob
pub format: BlobFormat,
/// Batch to create the temp tag in
pub batch: BatchId,
}
/// Write a blob from a byte stream
#[derive(Serialize, Deserialize, Debug)]
pub enum BatchAddStreamUpdate {
/// A chunk of stream data
Chunk(Bytes),
/// Abort the request due to an error on the client side
Abort,
}
/// Wrapper around [`AddProgressEvent`].
#[allow(missing_docs)]
#[derive(Debug, Serialize, Deserialize)]
pub enum BatchAddStreamResponse {
Abort(RpcError),
OutboardProgress { offset: u64 },
Result { hash: Hash },
}
/// Write a blob from a byte stream
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchAddPathRequest {
/// The path to the data to provide.
pub path: PathBuf,
/// Add the data in place
pub import_mode: ImportMode,
/// What format to use for the blob
pub format: BlobFormat,
/// Batch to create the temp tag in
pub batch: BatchId,
}
/// Response to a batch add path request
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchAddPathResponse(pub BatchAddPathProgressEvent);
/// A request to the node to download and share the data specified by the hash.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlobDownloadRequest {
/// This mandatory field contains the hash of the data to download and share.
pub hash: Hash,
/// If the format is [`BlobFormat::HashSeq`], all children are downloaded and shared as
/// well.
pub format: BlobFormat,
/// This mandatory field specifies the nodes to download the data from.
///
/// If set to more than a single node, they will all be tried. If `mode` is set to
/// [`DownloadMode::Direct`], they will be tried sequentially until a download succeeds.
/// If `mode` is set to [`DownloadMode::Queued`], the nodes may be dialed in parallel,
/// if the concurrency limits permit.
pub nodes: Vec<NodeAddr>,
/// Optional tag to tag the data with.
pub tag: SetTagOption,
/// Whether to directly start the download or add it to the download queue.
pub mode: DownloadMode,
}
/// Progress updates for the add operation.
#[derive(Debug, Serialize, Deserialize)]
pub enum AddProgressEvent {
/// An item was found with name `name`, from now on referred to via `id`
Found {
/// A new unique id for this entry.
id: u64,
/// The name of the entry.
name: String,
/// The size of the entry in bytes.
size: u64,
},
/// We got progress ingesting item `id`.
Progress {
/// The unique id of the entry.
id: u64,
/// The offset of the progress, in bytes.
offset: u64,
},
/// We are done with `id`, and the hash is `hash`.
Done {
/// The unique id of the entry.
id: u64,
/// The hash of the entry.
hash: Hash,
},
/// We are done with the whole operation.
AllDone {
/// The hash of the created data.
hash: Hash,
/// The format of the added data.
format: BlobFormat,
/// The tag of the added data.
tag: Tag,
},
/// We got an error and need to abort.
///
/// This will be the last message in the stream.
Abort(serde_error::Error),
}
/// Progress updates for the batch add operation.
#[derive(Debug, Serialize, Deserialize)]
pub enum BatchAddPathProgressEvent {
/// An item was found with the given size
Found {
/// The size of the entry in bytes.
size: u64,
},
/// We got progress ingesting the item.
Progress {
/// The offset of the progress, in bytes.
offset: u64,
},
/// We are done, and the hash is `hash`.
Done {
/// The hash of the entry.
hash: Hash,
},
/// We got an error and need to abort.
///
/// This will be the last message in the stream.
Abort(serde_error::Error),
}