@@ -5,11 +5,11 @@ use bao_tree::{ChunkNum, ChunkRanges};
5
5
use bytes:: Bytes ;
6
6
use iroh_blobs:: {
7
7
get:: {
8
- fsm:: { BlobContentNext , EndBlobNext } ,
8
+ fsm:: { BlobContentNext , EndBlobNext , RequestCounters } ,
9
9
Stats ,
10
10
} ,
11
11
hashseq:: HashSeq ,
12
- protocol:: { GetRequest , RangeSpecSeq } ,
12
+ protocol:: { ChunkRangesSeq , GetRequest } ,
13
13
Hash , HashAndFormat ,
14
14
} ;
15
15
use rand:: Rng ;
@@ -22,11 +22,17 @@ pub async fn unverified_size(
22
22
connection : & iroh:: endpoint:: Connection ,
23
23
hash : & Hash ,
24
24
) -> anyhow:: Result < ( u64 , Stats ) > {
25
- let request = iroh_blobs:: protocol:: GetRequest :: new (
26
- * hash,
27
- RangeSpecSeq :: from_ranges ( vec ! [ ChunkRanges :: from( ChunkNum ( u64 :: MAX ) ..) ] ) ,
25
+ let request = iroh_blobs:: protocol:: GetRequest :: new ( * hash, ChunkRangesSeq :: all ( ) ) ;
26
+ let request = iroh_blobs:: get:: fsm:: start (
27
+ connection. clone ( ) ,
28
+ request,
29
+ RequestCounters {
30
+ payload_bytes_written : 0 ,
31
+ other_bytes_written : 0 ,
32
+ payload_bytes_read : 0 ,
33
+ other_bytes_read : 0 ,
34
+ } ,
28
35
) ;
29
- let request = iroh_blobs:: get:: fsm:: start ( connection. clone ( ) , request) ;
30
36
let connected = request. next ( ) . await ?;
31
37
let iroh_blobs:: get:: fsm:: ConnectedNext :: StartRoot ( start) = connected. next ( ) . await ? else {
32
38
unreachable ! ( "expected start root" ) ;
@@ -46,11 +52,17 @@ pub async fn verified_size(
46
52
hash : & Hash ,
47
53
) -> anyhow:: Result < ( u64 , Stats ) > {
48
54
tracing:: debug!( "Getting verified size of {}" , hash. to_hex( ) ) ;
49
- let request = iroh_blobs:: protocol:: GetRequest :: new (
50
- * hash,
51
- RangeSpecSeq :: from_ranges ( vec ! [ ChunkRanges :: from( ChunkNum ( u64 :: MAX ) ..) ] ) ,
55
+ let request = iroh_blobs:: protocol:: GetRequest :: new ( * hash, ChunkRangesSeq :: verified_size ( ) ) ;
56
+ let request = iroh_blobs:: get:: fsm:: start (
57
+ connection. clone ( ) ,
58
+ request,
59
+ RequestCounters {
60
+ payload_bytes_written : 0 ,
61
+ other_bytes_written : 0 ,
62
+ payload_bytes_read : 0 ,
63
+ other_bytes_read : 0 ,
64
+ } ,
52
65
) ;
53
- let request = iroh_blobs:: get:: fsm:: start ( connection. clone ( ) , request) ;
54
66
let connected = request. next ( ) . await ?;
55
67
let iroh_blobs:: get:: fsm:: ConnectedNext :: StartRoot ( start) = connected. next ( ) . await ? else {
56
68
unreachable ! ( "expected start root" ) ;
@@ -89,12 +101,21 @@ pub async fn get_hash_seq_and_sizes(
89
101
tracing:: debug!( "Getting hash seq and children sizes of {}" , content) ;
90
102
let request = iroh_blobs:: protocol:: GetRequest :: new (
91
103
* hash,
92
- RangeSpecSeq :: from_ranges_infinite ( [
104
+ ChunkRangesSeq :: from_ranges_infinite ( [
93
105
ChunkRanges :: all ( ) ,
94
106
ChunkRanges :: from ( ChunkNum ( u64:: MAX ) ..) ,
95
107
] ) ,
96
108
) ;
97
- let at_start = iroh_blobs:: get:: fsm:: start ( connection. clone ( ) , request) ;
109
+ let at_start = iroh_blobs:: get:: fsm:: start (
110
+ connection. clone ( ) ,
111
+ request,
112
+ RequestCounters {
113
+ payload_bytes_written : 0 ,
114
+ other_bytes_written : 0 ,
115
+ payload_bytes_read : 0 ,
116
+ other_bytes_read : 0 ,
117
+ } ,
118
+ ) ;
98
119
let at_connected = at_start. next ( ) . await ?;
99
120
let iroh_blobs:: get:: fsm:: ConnectedNext :: StartRoot ( start) = at_connected. next ( ) . await ? else {
100
121
unreachable ! ( "query includes root" ) ;
@@ -140,9 +161,18 @@ pub async fn chunk_probe(
140
161
chunk : ChunkNum ,
141
162
) -> anyhow:: Result < Stats > {
142
163
let ranges = ChunkRanges :: from ( chunk..chunk + 1 ) ;
143
- let ranges = RangeSpecSeq :: from_ranges ( [ ranges] ) ;
164
+ let ranges = ChunkRangesSeq :: from_ranges ( [ ranges] ) ;
144
165
let request = GetRequest :: new ( * hash, ranges) ;
145
- let request = iroh_blobs:: get:: fsm:: start ( connection. clone ( ) , request) ;
166
+ let request = iroh_blobs:: get:: fsm:: start (
167
+ connection. clone ( ) ,
168
+ request,
169
+ RequestCounters {
170
+ payload_bytes_written : 0 ,
171
+ other_bytes_written : 0 ,
172
+ payload_bytes_read : 0 ,
173
+ other_bytes_read : 0 ,
174
+ } ,
175
+ ) ;
146
176
let connected = request. next ( ) . await ?;
147
177
let iroh_blobs:: get:: fsm:: ConnectedNext :: StartRoot ( start) = connected. next ( ) . await ? else {
148
178
unreachable ! ( "query includes root" ) ;
@@ -172,7 +202,7 @@ pub async fn chunk_probe(
172
202
///
173
203
/// The random chunk is chosen uniformly from the chunks of the children, so
174
204
/// larger children are more likely to be selected.
175
- pub fn random_hash_seq_ranges ( sizes : & [ u64 ] , mut rng : impl Rng ) -> RangeSpecSeq {
205
+ pub fn random_hash_seq_ranges ( sizes : & [ u64 ] , mut rng : impl Rng ) -> ChunkRangesSeq {
176
206
let total_chunks = sizes
177
207
. iter ( )
178
208
. map ( |size| ChunkNum :: full_chunks ( * size) . 0 )
@@ -193,5 +223,5 @@ pub fn random_hash_seq_ranges(sizes: &[u64], mut rng: impl Rng) -> RangeSpecSeq
193
223
ranges. push ( ChunkRanges :: empty ( ) ) ;
194
224
}
195
225
}
196
- RangeSpecSeq :: from_ranges ( ranges)
226
+ ChunkRangesSeq :: from_ranges ( ranges)
197
227
}
0 commit comments