2019-06-29 14:43:10 +03:00
use std ::io ::Write ;
2021-10-08 12:19:37 +03:00
use anyhow ::Error ;
2019-08-28 16:30:25 +03:00
2022-04-21 16:04:59 +03:00
use pbs_api_types ::{ Authid , BackupNamespace , BackupType } ;
2022-04-10 18:44:34 +03:00
use pbs_client ::{ BackupReader , HttpClient , HttpClientOptions } ;
2019-06-29 14:43:10 +03:00
pub struct DummyWriter {
bytes : usize ,
}
impl Write for DummyWriter {
fn write ( & mut self , data : & [ u8 ] ) -> Result < usize , std ::io ::Error > {
self . bytes + = data . len ( ) ;
Ok ( data . len ( ) )
}
fn flush ( & mut self ) -> Result < ( ) , std ::io ::Error > {
Ok ( ( ) )
}
}
2019-08-28 16:30:25 +03:00
async fn run ( ) -> Result < ( ) , Error > {
2019-06-29 14:43:10 +03:00
let host = " localhost " ;
2020-10-08 16:19:39 +03:00
let auth_id = Authid ::root_auth_id ( ) ;
2019-06-29 14:43:10 +03:00
2021-01-25 16:42:57 +03:00
let options = HttpClientOptions ::default ( )
2020-01-25 14:18:00 +03:00
. interactive ( true )
. ticket_cache ( true ) ;
2020-10-08 16:19:39 +03:00
let client = HttpClient ::new ( host , 8007 , auth_id , options ) ? ;
2019-06-29 14:43:10 +03:00
2021-10-08 12:19:37 +03:00
let backup_time = proxmox_time ::parse_rfc3339 ( " 2019-06-28T10:49:48Z " ) ? ;
2019-06-29 14:43:10 +03:00
2022-04-14 16:05:58 +03:00
let client = BackupReader ::start (
2023-11-21 17:31:50 +03:00
& client ,
2022-04-14 16:05:58 +03:00
None ,
" store2 " ,
2022-05-09 16:39:29 +03:00
& BackupNamespace ::root ( ) ,
& ( BackupType ::Host , " elsa " . to_string ( ) , backup_time ) . into ( ) ,
2022-04-14 16:05:58 +03:00
true ,
)
. await ? ;
2019-06-29 14:43:10 +03:00
let start = std ::time ::SystemTime ::now ( ) ;
2019-08-28 16:30:25 +03:00
let mut bytes = 0 ;
for _ in 0 .. 100 {
2020-06-12 12:46:42 +03:00
let mut writer = DummyWriter { bytes : 0 } ;
client . speedtest ( & mut writer ) . await ? ;
2019-08-28 16:30:25 +03:00
println! ( " Received {} bytes " , writer . bytes ) ;
bytes + = writer . bytes ;
}
2019-06-29 14:43:10 +03:00
2019-08-28 16:30:25 +03:00
let elapsed = start . elapsed ( ) . unwrap ( ) ;
2022-04-10 18:44:34 +03:00
let elapsed = ( elapsed . as_secs ( ) as f64 ) + ( elapsed . subsec_millis ( ) as f64 ) / 1000.0 ;
2019-06-29 14:43:10 +03:00
2022-04-10 18:44:34 +03:00
println! (
" Downloaded {} bytes, {} MB/s " ,
bytes ,
( bytes as f64 ) / ( elapsed * 1024.0 * 1024.0 )
) ;
2019-06-29 14:43:10 +03:00
2019-08-28 16:30:25 +03:00
Ok ( ( ) )
}
2019-06-29 14:43:10 +03:00
2020-06-22 17:44:14 +03:00
fn main ( ) {
2021-11-19 19:36:06 +03:00
if let Err ( err ) = proxmox_async ::runtime ::main ( run ( ) ) {
2019-08-28 16:30:25 +03:00
eprintln! ( " ERROR: {} " , err ) ;
}
println! ( " DONE " ) ;
2019-06-29 14:43:10 +03:00
}