@@ -5,7 +5,7 @@ use std::{collections::HashMap, num::NonZeroU64};
55use serde:: { Deserialize , Serialize } ;
66use tracing:: warn;
77
8- use super :: db :: { BlobId , DownloadProgress } ;
8+ use super :: Stats ;
99use crate :: { protocol:: RangeSpec , store:: BaoBlobSize , Hash } ;
1010
1111/// The identifier for progress events.
@@ -183,3 +183,90 @@ impl TransferState {
183183 }
184184 }
185185}
186+
187+ /// Progress updates for the get operation.
188+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
189+ pub enum DownloadProgress {
190+ /// Initial state if subscribing to a running or queued transfer.
191+ InitialState ( TransferState ) ,
192+ /// Data was found locally.
193+ FoundLocal {
194+ /// child offset
195+ child : BlobId ,
196+ /// The hash of the entry.
197+ hash : Hash ,
198+ /// The size of the entry in bytes.
199+ size : BaoBlobSize ,
200+ /// The ranges that are available locally.
201+ valid_ranges : RangeSpec ,
202+ } ,
203+ /// A new connection was established.
204+ Connected ,
205+ /// An item was found with hash `hash`, from now on referred to via `id`.
206+ Found {
207+ /// A new unique progress id for this entry.
208+ id : u64 ,
209+ /// Identifier for this blob within this download.
210+ ///
211+ /// Will always be [`BlobId::Root`] unless a hashseq is downloaded, in which case this
212+ /// allows to identify the children by their offset in the hashseq.
213+ child : BlobId ,
214+ /// The hash of the entry.
215+ hash : Hash ,
216+ /// The size of the entry in bytes.
217+ size : u64 ,
218+ } ,
219+ /// An item was found with hash `hash`, from now on referred to via `id`.
220+ FoundHashSeq {
221+ /// The name of the entry.
222+ hash : Hash ,
223+ /// Number of children in the collection, if known.
224+ children : u64 ,
225+ } ,
226+ /// We got progress ingesting item `id`.
227+ Progress {
228+ /// The unique id of the entry.
229+ id : u64 ,
230+ /// The offset of the progress, in bytes.
231+ offset : u64 ,
232+ } ,
233+ /// We are done with `id`.
234+ Done {
235+ /// The unique id of the entry.
236+ id : u64 ,
237+ } ,
238+ /// All operations finished.
239+ ///
240+ /// This will be the last message in the stream.
241+ AllDone ( Stats ) ,
242+ /// We got an error and need to abort.
243+ ///
244+ /// This will be the last message in the stream.
245+ Abort ( serde_error:: Error ) ,
246+ }
247+
248+ /// The id of a blob in a transfer
249+ #[ derive(
250+ Debug , Copy , Clone , Ord , PartialOrd , Eq , PartialEq , std:: hash:: Hash , Serialize , Deserialize ,
251+ ) ]
252+ pub enum BlobId {
253+ /// The root blob (child id 0)
254+ Root ,
255+ /// A child blob (child id > 0)
256+ Child ( NonZeroU64 ) ,
257+ }
258+
259+ impl BlobId {
260+ pub ( crate ) fn from_offset ( id : u64 ) -> Self {
261+ NonZeroU64 :: new ( id) . map ( Self :: Child ) . unwrap_or ( Self :: Root )
262+ }
263+ }
264+
265+ impl From < BlobId > for u64 {
266+ fn from ( value : BlobId ) -> Self {
267+ match value {
268+ BlobId :: Root => 0 ,
269+ BlobId :: Child ( id) => id. into ( ) ,
270+ }
271+ }
272+ }
0 commit comments