@@ -33,7 +33,7 @@ use api::AccessMethodEvent;
33
33
use device:: { AccountEvent , PrivateAccountAndDevice , PrivateDeviceEvent } ;
34
34
use futures:: {
35
35
channel:: { mpsc, oneshot} ,
36
- future:: { abortable, AbortHandle , Future , LocalBoxFuture } ,
36
+ future:: { abortable, AbortHandle , Future } ,
37
37
StreamExt ,
38
38
} ;
39
39
use geoip:: GeoIpHandler ;
@@ -467,7 +467,7 @@ impl DaemonCommandChannel {
467
467
}
468
468
}
469
469
470
- #[ derive( Clone ) ]
470
+ #[ derive( Debug , Clone ) ]
471
471
pub struct DaemonCommandSender ( Arc < mpsc:: UnboundedSender < InternalDaemonEvent > > ) ;
472
472
473
473
impl DaemonCommandSender {
@@ -540,7 +540,7 @@ where
540
540
}
541
541
542
542
/// Trait representing something that can broadcast daemon events.
543
- pub trait EventListener {
543
+ pub trait EventListener : Clone + Send + Sync + ' static {
544
544
/// Notify that the tunnel state changed.
545
545
fn notify_new_state ( & self , new_state : TunnelState ) ;
546
546
@@ -585,7 +585,7 @@ pub struct Daemon<L: EventListener> {
585
585
relay_selector : RelaySelector ,
586
586
relay_list_updater : RelayListUpdaterHandle ,
587
587
parameters_generator : tunnel:: ParametersGenerator ,
588
- shutdown_tasks : Vec < Pin < Box < dyn Future < Output = ( ) > > > > ,
588
+ shutdown_tasks : Vec < Pin < Box < dyn Future < Output = ( ) > + Send + Sync > > > ,
589
589
tunnel_state_machine_handle : TunnelStateMachineHandle ,
590
590
#[ cfg( target_os = "windows" ) ]
591
591
volume_update_tx : mpsc:: UnboundedSender < ( ) > ,
@@ -594,7 +594,7 @@ pub struct Daemon<L: EventListener> {
594
594
595
595
impl < L > Daemon < L >
596
596
where
597
- L : EventListener + Clone + Send + ' static ,
597
+ L : EventListener ,
598
598
{
599
599
pub async fn start (
600
600
log_dir : Option < PathBuf > ,
@@ -897,46 +897,27 @@ where
897
897
/// Destroy daemon safely, by dropping all objects in the correct order, waiting for them to
898
898
/// be destroyed, and executing shutdown tasks
899
899
async fn finalize ( self ) {
900
- let ( event_listener, shutdown_tasks, api_runtime, tunnel_state_machine_handle) =
901
- self . shutdown ( ) ;
902
- for future in shutdown_tasks {
903
- future. await ;
904
- }
905
-
906
- tunnel_state_machine_handle. try_join ( ) . await ;
907
-
908
- drop ( event_listener) ;
909
- drop ( api_runtime) ;
910
- }
911
-
912
- /// Shuts down the daemon without shutting down the underlying event listener and the shutdown
913
- /// callbacks
914
- fn shutdown < ' a > (
915
- self ,
916
- ) -> (
917
- L ,
918
- Vec < LocalBoxFuture < ' a , ( ) > > ,
919
- mullvad_api:: Runtime ,
920
- TunnelStateMachineHandle ,
921
- ) {
922
900
let Daemon {
923
901
event_listener,
924
- mut shutdown_tasks,
902
+ shutdown_tasks,
925
903
api_runtime,
926
904
tunnel_state_machine_handle,
927
905
target_state,
928
906
account_manager,
929
907
..
930
908
} = self ;
931
- shutdown_tasks. push ( Box :: pin ( target_state. finalize ( ) ) ) ;
932
- shutdown_tasks. push ( Box :: pin ( account_manager. shutdown ( ) ) ) ;
933
909
934
- (
935
- event_listener,
936
- shutdown_tasks,
937
- api_runtime,
938
- tunnel_state_machine_handle,
939
- )
910
+ for future in shutdown_tasks {
911
+ future. await ;
912
+ }
913
+
914
+ target_state. finalize ( ) . await ;
915
+ account_manager. shutdown ( ) . await ;
916
+
917
+ tunnel_state_machine_handle. try_join ( ) . await ;
918
+
919
+ drop ( event_listener) ;
920
+ drop ( api_runtime) ;
940
921
}
941
922
942
923
async fn handle_event ( & mut self , event : InternalDaemonEvent ) -> bool {
@@ -1686,7 +1667,7 @@ where
1686
1667
1687
1668
#[ cfg( not( target_os = "android" ) ) ]
1688
1669
async fn on_factory_reset ( & mut self , tx : ResponseTx < ( ) , Error > ) {
1689
- let mut last_error = Ok ( ( ) ) ;
1670
+ let mut last_error = None ;
1690
1671
1691
1672
if let Err ( error) = self . account_manager . logout ( ) . await {
1692
1673
log:: error!(
@@ -1700,12 +1681,12 @@ where
1700
1681
"{}" ,
1701
1682
error. display_chain_with_msg( "Failed to clear account history" )
1702
1683
) ;
1703
- last_error = Err ( Error :: FactoryResetError ( "Failed to clear account history" ) ) ;
1684
+ last_error = Some ( "Failed to clear account history" ) ;
1704
1685
}
1705
1686
1706
1687
if let Err ( e) = self . settings . reset ( ) . await {
1707
1688
log:: error!( "Failed to reset settings: {}" , e) ;
1708
- last_error = Err ( Error :: FactoryResetError ( "Failed to reset settings" ) ) ;
1689
+ last_error = Some ( "Failed to reset settings" ) ;
1709
1690
}
1710
1691
1711
1692
// Shut the daemon down.
@@ -1717,11 +1698,12 @@ where
1717
1698
"{}" ,
1718
1699
e. display_chain_with_msg( "Failed to clear cache and log directories" )
1719
1700
) ;
1720
- last_error = Err ( Error :: FactoryResetError (
1721
- "Failed to clear cache and log directories" ,
1722
- ) ) ;
1701
+ last_error = Some ( "Failed to clear cache and log directories" ) ;
1723
1702
}
1724
- Self :: oneshot_send ( tx, last_error, "factory_reset response" ) ;
1703
+ let result = last_error
1704
+ . map ( |error| Err ( Error :: FactoryResetError ( error) ) )
1705
+ . unwrap_or ( Ok ( ( ) ) ) ;
1706
+ Self :: oneshot_send ( tx, result, "factory_reset response" ) ;
1725
1707
} ) ) ;
1726
1708
}
1727
1709
0 commit comments