@@ -39,8 +39,8 @@ use crate::{
3939 proto:: DeviceConfigResponse ,
4040 service:: {
4141 proto:: {
42- DeleteServiceLocationsRequest , RemoveInterfaceRequest , ResetServiceLocationRequest ,
43- SaveServiceLocationsRequest , ServiceLocation ,
42+ DeleteServiceLocationsRequest , RemoveInterfaceRequest , SaveServiceLocationsRequest ,
43+ ServiceLocation ,
4444 } ,
4545 utils:: DAEMON_CLIENT ,
4646 } ,
@@ -290,7 +290,7 @@ pub async fn save_device_config(
290290 transaction. commit ( ) . await ?;
291291 info ! ( "New instance {instance} created." ) ;
292292 trace ! ( "Created following instance: {instance:#?}" ) ;
293- let locations = Location :: find_by_instance_id ( & * DB_POOL , instance. id ) . await ?;
293+ let locations = Location :: find_by_instance_id ( & * DB_POOL , instance. id , true ) . await ?;
294294 trace ! ( "Created following locations: {locations:#?}" ) ;
295295
296296 let mut service_locations = Vec :: < ServiceLocation > :: new ( ) ;
@@ -332,36 +332,6 @@ pub async fn save_device_config(
332332 "Saved service locations to the daemon for instance {}({})." ,
333333 instance. name, instance. id,
334334 ) ;
335-
336- let locations_pubkeys = service_locations
337- . iter ( )
338- . map ( |loc| loc. pubkey . clone ( ) )
339- . collect :: < HashSet < String > > ( ) ;
340-
341- for location_pubkey in locations_pubkeys {
342- let restart_request = ResetServiceLocationRequest {
343- instance_id : instance. uuid . clone ( ) ,
344- pubkey : location_pubkey. clone ( ) ,
345- } ;
346- debug ! (
347- "Restarting service location with pubkey {} on instance {}." ,
348- restart_request. pubkey, restart_request. instance_id,
349- ) ;
350- DAEMON_CLIENT . clone ( )
351- . reset_service_location ( restart_request)
352- . await
353- . map_err ( |err| {
354- error ! (
355- "Error while restarting service location with pubkey {} on instance {}: {err}" ,
356- location_pubkey, instance. uuid,
357- ) ;
358- Error :: InternalError ( err. to_string ( ) )
359- } ) ?;
360- debug ! (
361- "Restarted service location with pubkey {} on instance {}." ,
362- location_pubkey, instance. uuid
363- ) ;
364- }
365335 }
366336
367337 handle. emit ( EventKey :: InstanceUpdate . into ( ) , ( ) ) ?;
@@ -386,7 +356,7 @@ pub async fn all_instances() -> Result<Vec<InstanceInfo<Id>>, Error> {
386356 let mut instance_info = Vec :: new ( ) ;
387357 let connection_ids = get_connection_id_by_type ( ConnectionType :: Location ) . await ;
388358 for instance in instances {
389- let locations = Location :: find_by_instance_id ( & * DB_POOL , instance. id ) . await ?;
359+ let locations = Location :: find_by_instance_id ( & * DB_POOL , instance. id , false ) . await ?;
390360 let location_ids: Vec < i64 > = locations. iter ( ) . map ( |location| location. id ) . collect ( ) ;
391361 let connected = connection_ids
392362 . iter ( )
@@ -460,24 +430,14 @@ pub async fn all_locations(instance_id: Id) -> Result<Vec<LocationInfo>, Error>
460430 "Getting information about all locations for instance {}." ,
461431 instance. name
462432 ) ;
463- let locations = Location :: find_by_instance_id ( & * DB_POOL , instance_id) . await ?;
433+ let locations = Location :: find_by_instance_id ( & * DB_POOL , instance_id, false ) . await ?;
464434 trace ! (
465435 "Found {} locations for instance {instance} to return information about." ,
466436 locations. len( )
467437 ) ;
468438 let active_locations_ids = get_connection_id_by_type ( ConnectionType :: Location ) . await ;
469439 let mut location_info = Vec :: new ( ) ;
470440 for location in locations {
471- // Skip service locations, those shouldn't be shown in the UI.
472- if location. is_service_location ( ) {
473- debug ! (
474- "Skipping service location {}({}) for instance {}({}) when returning \
475- locations to the frontend.",
476- location. name, location. id, instance. name, instance. id,
477- ) ;
478- continue ;
479- }
480-
481441 let info = LocationInfo {
482442 id : location. id ,
483443 instance_id : location. instance_id ,
@@ -560,7 +520,7 @@ pub(crate) async fn locations_changed(
560520 device_config : & DeviceConfigResponse ,
561521) -> Result < bool , Error > {
562522 let db_locations: HashSet < Location < NoId > > =
563- Location :: find_by_instance_id ( transaction. as_mut ( ) , instance. id )
523+ Location :: find_by_instance_id ( transaction. as_mut ( ) , instance. id , true )
564524 . await ?
565525 . into_iter ( )
566526 . map ( |location| {
@@ -633,14 +593,13 @@ pub(crate) async fn do_update_instance(
633593 ) ;
634594 // fetch existing locations for given instance
635595 let mut current_locations =
636- Location :: find_by_instance_id ( transaction. as_mut ( ) , instance. id ) . await ?;
596+ Location :: find_by_instance_id ( transaction. as_mut ( ) , instance. id , true ) . await ?;
637597 for dev_config in response. configs {
638598 // parse device config
639599 let new_location = dev_config. into_location ( instance. id ) ;
640- let saved_location: Location < Id > ;
641600
642601 // check if location is already present in current locations
643- if let Some ( position) = current_locations
602+ let saved_location = if let Some ( position) = current_locations
644603 . iter ( )
645604 . position ( |loc| loc. network_id == new_location. network_id )
646605 {
@@ -662,14 +621,14 @@ pub(crate) async fn do_update_instance(
662621 current_location. service_location_mode = new_location. service_location_mode ;
663622 current_location. save ( transaction. as_mut ( ) ) . await ?;
664623 info ! ( "Location {current_location} configuration updated for instance {instance}" ) ;
665- saved_location = current_location;
624+ current_location
666625 } else {
667626 // create new location
668627 debug ! ( "Creating new location {new_location} for instance instance {instance}" ) ;
669628 let new_location = new_location. save ( transaction. as_mut ( ) ) . await ?;
670629 info ! ( "New location {new_location} created for instance {instance}" ) ;
671- saved_location = new_location;
672- }
630+ new_location
631+ } ;
673632
674633 if saved_location. is_service_location ( ) {
675634 debug ! (
@@ -699,7 +658,12 @@ pub(crate) async fn do_update_instance(
699658 . ok_or ( Error :: NotFound ) ?
700659 . prvkey ;
701660
702- if !service_locations. is_empty ( ) {
661+ if service_locations. is_empty ( ) {
662+ debug ! (
663+ "No service locations to process for instance {}({})" ,
664+ instance. name, instance. id
665+ ) ;
666+ } else {
703667 debug ! (
704668 "Processing {} service location(s) for instance {}({})" ,
705669 service_locations. len( ) ,
@@ -739,49 +703,10 @@ pub(crate) async fn do_update_instance(
739703 instance. id
740704 ) ;
741705
742- let service_locations_pubkeys = service_locations
743- . iter ( )
744- . map ( |loc| loc. pubkey . clone ( ) )
745- . collect :: < HashSet < String > > ( ) ;
746-
747- let instance_id = instance. uuid . clone ( ) ;
748-
749- for pubkey in service_locations_pubkeys {
750- debug ! (
751- "Sending state reset request for service location with pubkey {} on instance {}" ,
752- pubkey, instance_id
753- ) ;
754-
755- DAEMON_CLIENT
756- . clone ( )
757- . reset_service_location ( ResetServiceLocationRequest {
758- instance_id : instance_id. clone ( ) ,
759- pubkey : pubkey. clone ( ) ,
760- } )
761- . await
762- . map_err ( |err| {
763- error ! (
764- "Error while restarting service location with pubkey {} on instance {}: {err}" ,
765- pubkey, instance_id,
766- ) ;
767- Error :: InternalError ( err. to_string ( ) )
768- } ) ?;
769-
770- info ! (
771- "Successfully reset the state of service location with pubkey {} on instance {}" ,
772- pubkey, instance_id
773- ) ;
774- }
775-
776706 debug ! (
777707 "Completed processing all service locations for instance {}({})" ,
778708 instance. name, instance. id
779709 ) ;
780- } else {
781- debug ! (
782- "No service locations to process for instance {}({})" ,
783- instance. name, instance. id
784- ) ;
785710 }
786711
787712 Ok ( ( ) )
@@ -1007,7 +932,8 @@ pub async fn delete_instance(instance_id: Id, handle: AppHandle) -> Result<(), E
1007932 } ;
1008933 debug ! ( "The instance that is being deleted has been identified as {instance}" ) ;
1009934
1010- let instance_locations = Location :: find_by_instance_id ( & mut * transaction, instance_id) . await ?;
935+ let instance_locations =
936+ Location :: find_by_instance_id ( & mut * transaction, instance_id, false ) . await ?;
1011937 if !instance_locations. is_empty ( ) {
1012938 debug ! (
1013939 "Found locations associated with the instance {instance}, closing their connections."
0 commit comments