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