@@ -392,7 +392,7 @@ pub use range_spec::{ChunkRangesSeq, NonEmptyRequestRangeSpecIter, RangeSpec};
392
392
use snafu:: { GenerateImplicitData , Snafu } ;
393
393
use tokio:: io:: AsyncReadExt ;
394
394
395
- use crate :: { api:: blobs:: Bitfield , provider:: CountingReader , BlobFormat , Hash , HashAndFormat } ;
395
+ use crate :: { api:: blobs:: Bitfield , provider:: RecvStreamExt , BlobFormat , Hash , HashAndFormat } ;
396
396
397
397
/// Maximum message size is limited to 100MiB for now.
398
398
pub const MAX_MESSAGE_SIZE : usize = 1024 * 1024 ;
@@ -441,9 +441,7 @@ pub enum RequestType {
441
441
}
442
442
443
443
impl Request {
444
- pub async fn read_async (
445
- reader : & mut CountingReader < & mut iroh:: endpoint:: RecvStream > ,
446
- ) -> io:: Result < Self > {
444
+ pub async fn read_async ( reader : & mut iroh:: endpoint:: RecvStream ) -> io:: Result < ( Self , usize ) > {
447
445
let request_type = reader. read_u8 ( ) . await ?;
448
446
let request_type: RequestType = postcard:: from_bytes ( std:: slice:: from_ref ( & request_type) )
449
447
. map_err ( |_| {
@@ -453,22 +451,31 @@ impl Request {
453
451
)
454
452
} ) ?;
455
453
Ok ( match request_type {
456
- RequestType :: Get => reader
457
- . read_to_end_as :: < GetRequest > ( MAX_MESSAGE_SIZE )
458
- . await ?
459
- . into ( ) ,
460
- RequestType :: GetMany => reader
461
- . read_to_end_as :: < GetManyRequest > ( MAX_MESSAGE_SIZE )
462
- . await ?
463
- . into ( ) ,
464
- RequestType :: Observe => reader
465
- . read_to_end_as :: < ObserveRequest > ( MAX_MESSAGE_SIZE )
466
- . await ?
467
- . into ( ) ,
468
- RequestType :: Push => reader
469
- . read_length_prefixed :: < PushRequest > ( MAX_MESSAGE_SIZE )
470
- . await ?
471
- . into ( ) ,
454
+ RequestType :: Get => {
455
+ let ( r, size) = reader
456
+ . read_to_end_as :: < GetRequest > ( MAX_MESSAGE_SIZE )
457
+ . await ?;
458
+ ( r. into ( ) , size)
459
+ }
460
+ RequestType :: GetMany => {
461
+ let ( r, size) = reader
462
+ . read_to_end_as :: < GetManyRequest > ( MAX_MESSAGE_SIZE )
463
+ . await ?;
464
+ ( r. into ( ) , size)
465
+ }
466
+ RequestType :: Observe => {
467
+ let ( r, size) = reader
468
+ . read_to_end_as :: < ObserveRequest > ( MAX_MESSAGE_SIZE )
469
+ . await ?;
470
+ ( r. into ( ) , size)
471
+ }
472
+ RequestType :: Push => {
473
+ let r = reader
474
+ . read_length_prefixed :: < PushRequest > ( MAX_MESSAGE_SIZE )
475
+ . await ?;
476
+ let size = postcard:: experimental:: serialized_size ( & r) . unwrap ( ) ;
477
+ ( r. into ( ) , size)
478
+ }
472
479
_ => {
473
480
return Err ( io:: Error :: new (
474
481
io:: ErrorKind :: InvalidData ,
0 commit comments