@@ -66,7 +66,8 @@ use masq_lib::exit_locations::ExitLocationSet;
6666use masq_lib:: logger:: Logger ;
6767use masq_lib:: messages:: {
6868 ExitLocation , FromMessageBody , ToMessageBody , UiConnectionStage , UiConnectionStatusRequest ,
69- UiSetExitLocationRequest , UiSetExitLocationResponse ,
69+ UiGetNeighborhoodGraphRequest , UiGetNeighborhoodGraphResponse , UiSetExitLocationRequest ,
70+ UiSetExitLocationResponse ,
7071} ;
7172use masq_lib:: messages:: { UiConnectionStatusResponse , UiShutdownRequest } ;
7273use masq_lib:: ui_gateway:: MessagePath :: Conversation ;
@@ -366,6 +367,8 @@ impl Handler<NodeFromUiMessage> for Neighborhood {
366367 self . handle_connection_status_message ( client_id, context_id) ;
367368 } else if let Ok ( ( body, _) ) = UiShutdownRequest :: fmb ( msg. body . clone ( ) ) {
368369 self . handle_shutdown_order ( client_id, body) ;
370+ } else if let Ok ( ( _, context_id) ) = UiGetNeighborhoodGraphRequest :: fmb ( msg. body . clone ( ) ) {
371+ self . handle_neighborhood_graph_message ( client_id, context_id) ;
369372 } else {
370373 handle_ui_crash_request ( msg, & self . logger , self . crashable , CRASH_KEY )
371374 }
@@ -1611,6 +1614,19 @@ impl Neighborhood {
16111614 undesirability + node_undesirability
16121615 }
16131616
1617+ fn handle_neighborhood_graph_message ( & self , client_id : u64 , context_id : u64 ) {
1618+ let graph = self . neighborhood_database . to_dot_graph ( ) ;
1619+ let message = NodeToUiMessage {
1620+ target : MessageTarget :: ClientId ( client_id) ,
1621+ body : UiGetNeighborhoodGraphResponse { graph } . tmb ( context_id) ,
1622+ } ;
1623+ self . node_to_ui_recipient_opt
1624+ . as_ref ( )
1625+ . expect ( "UI Gateway is unbound" )
1626+ . try_send ( message)
1627+ . expect ( "UiGateway is dead" ) ;
1628+ }
1629+
16141630 fn handle_exit_location_message (
16151631 & mut self ,
16161632 message : UiSetExitLocationRequest ,
@@ -3634,6 +3650,81 @@ mod tests {
36343650 assert_eq ! ( juicy_parts( result_1) , ( 1 , 1 ) ) ;
36353651 }
36363652
3653+ #[ test]
3654+ fn handle_neighborhood_graph_message_works ( ) {
3655+ let test_name = "handle_neighborhood_graph_message_works" ;
3656+ let system = System :: new ( test_name) ;
3657+ let ( ui_gateway, _recorder, arc_recorder) = make_recorder ( ) ;
3658+ let mut subject = make_standard_subject ( ) ;
3659+ let root_node_ch = subject. neighborhood_database . root ( ) . clone ( ) ;
3660+ let neighbor_one_au = make_node_record_cc ( 1234 , true , "AU" ) ;
3661+ let neighbor_two_fr = make_node_record_cc ( 2345 , true , "FR" ) ;
3662+ let neighbor_three_cn = make_node_record_cc ( 3456 , true , "CN" ) ;
3663+ let neighbor_four_us = make_node_record_cc ( 4567 , true , "US" ) ;
3664+ let root_pubkey = format ! ( "{}" , root_node_ch. public_key( ) ) ;
3665+ let neighbor_one_pubkey = format ! ( "{}" , neighbor_one_au. public_key( ) ) ;
3666+ let neighbor_two_pubkey = format ! ( "{}" , neighbor_two_fr. public_key( ) ) ;
3667+ let neighbor_three_pubkey = format ! ( "{}" , neighbor_three_cn. public_key( ) ) ;
3668+ let neighbor_four_pubkey = format ! ( "{}" , neighbor_four_us. public_key( ) ) ;
3669+ subject
3670+ . neighborhood_database
3671+ . add_node ( neighbor_one_au. clone ( ) )
3672+ . unwrap ( ) ;
3673+ subject
3674+ . neighborhood_database
3675+ . add_node ( neighbor_two_fr. clone ( ) )
3676+ . unwrap ( ) ;
3677+ subject
3678+ . neighborhood_database
3679+ . add_node ( neighbor_three_cn. clone ( ) )
3680+ . unwrap ( ) ;
3681+ subject
3682+ . neighborhood_database
3683+ . add_node ( neighbor_four_us. clone ( ) )
3684+ . unwrap ( ) ;
3685+ subject
3686+ . neighborhood_database
3687+ . add_arbitrary_full_neighbor ( root_node_ch. public_key ( ) , neighbor_one_au. public_key ( ) ) ;
3688+ subject. neighborhood_database . add_arbitrary_full_neighbor (
3689+ neighbor_one_au. public_key ( ) ,
3690+ neighbor_two_fr. public_key ( ) ,
3691+ ) ;
3692+ subject. neighborhood_database . add_arbitrary_full_neighbor (
3693+ neighbor_two_fr. public_key ( ) ,
3694+ neighbor_three_cn. public_key ( ) ,
3695+ ) ;
3696+ subject. neighborhood_database . add_arbitrary_full_neighbor (
3697+ neighbor_three_cn. public_key ( ) ,
3698+ neighbor_four_us. public_key ( ) ,
3699+ ) ;
3700+ let request = UiGetNeighborhoodGraphRequest { } ;
3701+ let message = NodeFromUiMessage {
3702+ client_id : 456 ,
3703+ body : request. tmb ( 465 ) ,
3704+ } ;
3705+ let subject_addr = subject. start ( ) ;
3706+ let peer_actors = peer_actors_builder ( ) . ui_gateway ( ui_gateway) . build ( ) ;
3707+ subject_addr. try_send ( BindMessage { peer_actors } ) . unwrap ( ) ;
3708+
3709+ subject_addr. try_send ( message) . unwrap ( ) ;
3710+ System :: current ( ) . stop ( ) ;
3711+ system. run ( ) ;
3712+
3713+ let recorder_result = arc_recorder. lock ( ) . unwrap ( ) ;
3714+ let result = recorder_result
3715+ . get_record :: < NodeToUiMessage > ( 0 )
3716+ . body
3717+ . clone ( )
3718+ . payload
3719+ . unwrap ( ) ;
3720+ let result_object: UiGetNeighborhoodGraphResponse = serde_json:: from_str ( & result) . unwrap ( ) ;
3721+ assert ! ( result_object. graph. contains( & root_pubkey) ) ;
3722+ assert ! ( result_object. graph. contains( & neighbor_one_pubkey) ) ;
3723+ assert ! ( result_object. graph. contains( & neighbor_two_pubkey) ) ;
3724+ assert ! ( result_object. graph. contains( & neighbor_three_pubkey) ) ;
3725+ assert ! ( result_object. graph. contains( & neighbor_four_pubkey) ) ;
3726+ }
3727+
36373728 #[ test]
36383729 fn min_hops_change_affects_db_countries_and_exit_location_settings ( ) {
36393730 let mut subject = make_standard_subject ( ) ;
0 commit comments