From 8204b010e177427849f28515e5895aeb667e04a9 Mon Sep 17 00:00:00 2001 From: utkarshg6 Date: Wed, 25 Oct 2023 10:55:49 +0530 Subject: [PATCH] GH-728: send ConfigurationChangeMessage to other actors too --- node/src/accountant/mod.rs | 10 +++++ node/src/actor_system_factory.rs | 5 ++- node/src/blockchain/blockchain_bridge.rs | 10 +++++ node/src/node_configurator/configurator.rs | 49 +++++++++++++++++++--- node/src/sub_lib/accountant.rs | 2 + node/src/sub_lib/blockchain_bridge.rs | 2 + node/src/sub_lib/configurator.rs | 3 ++ node/src/test_utils/recorder.rs | 3 ++ 8 files changed, 77 insertions(+), 7 deletions(-) diff --git a/node/src/accountant/mod.rs b/node/src/accountant/mod.rs index 7937fefe3..95542e377 100644 --- a/node/src/accountant/mod.rs +++ b/node/src/accountant/mod.rs @@ -43,6 +43,7 @@ use crate::sub_lib::accountant::ReportRoutingServiceProvidedMessage; use crate::sub_lib::accountant::ReportServicesConsumedMessage; use crate::sub_lib::accountant::{MessageIdGenerator, MessageIdGeneratorReal}; use crate::sub_lib::blockchain_bridge::OutboundPaymentsInstructions; +use crate::sub_lib::neighborhood::ConfigurationChangeMessage; use crate::sub_lib::peer_actors::{BindMessage, StartMessage}; use crate::sub_lib::utils::{handle_ui_crash_request, NODE_MAILBOX_CAPACITY}; use crate::sub_lib::wallet::Wallet; @@ -163,6 +164,14 @@ impl Handler for Accountant { } } +impl Handler for Accountant { + type Result = (); + + fn handle(&mut self, msg: ConfigurationChangeMessage, ctx: &mut Self::Context) -> Self::Result { + todo!("handler for Accountant"); + } +} + impl Handler for Accountant { type Result = (); @@ -446,6 +455,7 @@ impl Accountant { pub fn make_subs_from(addr: &Addr) -> AccountantSubs { AccountantSubs { bind: recipient!(addr, BindMessage), + configuration_change_msg_sub: recipient!(addr, ConfigurationChangeMessage), start: recipient!(addr, StartMessage), report_routing_service_provided: recipient!(addr, ReportRoutingServiceProvidedMessage), report_exit_service_provided: recipient!(addr, ReportExitServiceProvidedMessage), diff --git a/node/src/actor_system_factory.rs b/node/src/actor_system_factory.rs index 870460dd1..02b4e1a7b 100644 --- a/node/src/actor_system_factory.rs +++ b/node/src/actor_system_factory.rs @@ -24,7 +24,9 @@ use crate::sub_lib::cryptde::CryptDE; use crate::sub_lib::dispatcher::DispatcherSubs; use crate::sub_lib::hopper::HopperConfig; use crate::sub_lib::hopper::HopperSubs; -use crate::sub_lib::neighborhood::{NeighborhoodMode, NeighborhoodSubs}; +use crate::sub_lib::neighborhood::{ + ConfigurationChangeMessage, NeighborhoodMode, NeighborhoodSubs, +}; use crate::sub_lib::peer_actors::{BindMessage, StartMessage}; use crate::sub_lib::peer_actors::{NewPublicIp, PeerActors}; use crate::sub_lib::proxy_client::ProxyClientConfig; @@ -534,6 +536,7 @@ impl ActorFactory for ActorFactoryReal { ConfiguratorSubs { bind: recipient!(addr, BindMessage), node_from_ui_sub: recipient!(addr, NodeFromUiMessage), + configuration_change_msg_sub: recipient!(addr, ConfigurationChangeMessage), } } } diff --git a/node/src/blockchain/blockchain_bridge.rs b/node/src/blockchain/blockchain_bridge.rs index 9b170709a..327348260 100644 --- a/node/src/blockchain/blockchain_bridge.rs +++ b/node/src/blockchain/blockchain_bridge.rs @@ -23,6 +23,7 @@ use crate::db_config::persistent_configuration::{ PersistentConfiguration, PersistentConfigurationReal, }; use crate::sub_lib::blockchain_bridge::{BlockchainBridgeSubs, OutboundPaymentsInstructions}; +use crate::sub_lib::neighborhood::ConfigurationChangeMessage; use crate::sub_lib::peer_actors::BindMessage; use crate::sub_lib::utils::{db_connection_launch_panic, handle_ui_crash_request}; use crate::sub_lib::wallet::Wallet; @@ -106,6 +107,14 @@ impl SkeletonOptHolder for RetrieveTransactions { } } +impl Handler for BlockchainBridge { + type Result = (); + + fn handle(&mut self, msg: ConfigurationChangeMessage, ctx: &mut Self::Context) -> Self::Result { + todo!("handler for BlockchainBridge"); + } +} + impl Handler for BlockchainBridge { type Result = (); @@ -232,6 +241,7 @@ impl BlockchainBridge { pub fn make_subs_from(addr: &Addr) -> BlockchainBridgeSubs { BlockchainBridgeSubs { bind: recipient!(addr, BindMessage), + configuration_change_msg_sub: recipient!(addr, ConfigurationChangeMessage), outbound_payments_instructions: recipient!(addr, OutboundPaymentsInstructions), qualified_payables: recipient!(addr, QualifiedPayablesMessage), retrieve_transactions: recipient!(addr, RetrieveTransactions), diff --git a/node/src/node_configurator/configurator.rs b/node/src/node_configurator/configurator.rs index f31522ff2..c1ffffb8a 100644 --- a/node/src/node_configurator/configurator.rs +++ b/node/src/node_configurator/configurator.rs @@ -65,11 +65,26 @@ impl Handler for Configurator { fn handle(&mut self, msg: BindMessage, _ctx: &mut Self::Context) -> Self::Result { self.node_to_ui_sub_opt = Some(msg.peer_actors.ui_gateway.node_to_ui_message_sub.clone()); // self.new_password_subs = Some(vec![msg.peer_actors.neighborhood.new_password_sub]); // GH-728 + self.update_min_hops_sub_opt = Some( + msg.peer_actors + .neighborhood + .configuration_change_msg_sub + .clone(), + ); self.update_password_subs = Some(hashmap!( - "neighborhood".to_string() => msg.peer_actors.neighborhood.configuration_change_msg_sub.clone(), + "neighborhood".to_string() => msg.peer_actors.neighborhood.configuration_change_msg_sub, + "configurator".to_string() => msg.peer_actors.configurator.configuration_change_msg_sub, + "blockchain_bridge".to_string() => msg.peer_actors.blockchain_bridge.configuration_change_msg_sub, + "accountant".to_string() => msg.peer_actors.accountant.configuration_change_msg_sub )); - self.update_min_hops_sub_opt = - Some(msg.peer_actors.neighborhood.configuration_change_msg_sub); + } +} + +impl Handler for Configurator { + type Result = (); + + fn handle(&mut self, msg: ConfigurationChangeMessage, ctx: &mut Self::Context) -> Self::Result { + todo!("handler in configurator") } } @@ -1086,9 +1101,15 @@ mod tests { let subject_addr = subject.start(); let (ui_gateway, _, ui_gateway_recording_arc) = make_recorder(); let (neighborhood, _, neighborhood_recording_arc) = make_recorder(); + let (configurator, _, configurator_recording_arc) = make_recorder(); + let (blockchain_bridge, _, blockchain_bridge_recording_arc) = make_recorder(); + let (accountant, _, accountant_recording_arc) = make_recorder(); let peer_actors = peer_actors_builder() .ui_gateway(ui_gateway) .neighborhood(neighborhood) + .configurator(configurator) + .blockchain_bridge(blockchain_bridge) + .accountant(accountant) .build(); subject_addr.try_send(BindMessage { peer_actors }).unwrap(); @@ -1126,11 +1147,27 @@ mod tests { } ); let neighborhood_recording = neighborhood_recording_arc.lock().unwrap(); + let configurator_recording = configurator_recording_arc.lock().unwrap(); + let blockchain_bridge_recording = blockchain_bridge_recording_arc.lock().unwrap(); + let accountant_recording = accountant_recording_arc.lock().unwrap(); + let expected_configuration_msg = ConfigurationChangeMessage { + change: ConfigurationChange::UpdatePassword("new_password".to_string()), + }; assert_eq!( neighborhood_recording.get_record::(0), - &ConfigurationChangeMessage { - change: ConfigurationChange::UpdatePassword("new_password".to_string()) - } + &expected_configuration_msg + ); + assert_eq!( + configurator_recording.get_record::(0), + &expected_configuration_msg + ); + assert_eq!( + blockchain_bridge_recording.get_record::(0), + &expected_configuration_msg + ); + assert_eq!( + accountant_recording.get_record::(0), + &expected_configuration_msg ); assert_eq!(neighborhood_recording.len(), 1); } diff --git a/node/src/sub_lib/accountant.rs b/node/src/sub_lib/accountant.rs index 15ceb0613..d3a3d7077 100644 --- a/node/src/sub_lib/accountant.rs +++ b/node/src/sub_lib/accountant.rs @@ -10,6 +10,7 @@ use crate::accountant::{ }; use crate::actor_system_factory::SubsFactory; use crate::blockchain::blockchain_bridge::PendingPayableFingerprintSeeds; +use crate::sub_lib::neighborhood::ConfigurationChangeMessage; use crate::sub_lib::peer_actors::{BindMessage, StartMessage}; use crate::sub_lib::wallet::Wallet; use actix::Recipient; @@ -90,6 +91,7 @@ impl Default for ScanIntervals { #[derive(Clone, PartialEq, Eq)] pub struct AccountantSubs { pub bind: Recipient, + pub configuration_change_msg_sub: Recipient, pub start: Recipient, pub report_routing_service_provided: Recipient, pub report_exit_service_provided: Recipient, diff --git a/node/src/sub_lib/blockchain_bridge.rs b/node/src/sub_lib/blockchain_bridge.rs index ff006fdaa..f6e03f2e6 100644 --- a/node/src/sub_lib/blockchain_bridge.rs +++ b/node/src/sub_lib/blockchain_bridge.rs @@ -5,6 +5,7 @@ use crate::accountant::scanners::mid_scan_msg_handling::payable_scanner::blockch use crate::accountant::scanners::mid_scan_msg_handling::payable_scanner::msgs::QualifiedPayablesMessage; use crate::accountant::{RequestTransactionReceipts, ResponseSkeleton, SkeletonOptHolder}; use crate::blockchain::blockchain_bridge::RetrieveTransactions; +use crate::sub_lib::neighborhood::ConfigurationChangeMessage; use crate::sub_lib::peer_actors::BindMessage; use actix::Message; use actix::Recipient; @@ -26,6 +27,7 @@ pub struct BlockchainBridgeConfig { #[derive(Clone, PartialEq, Eq)] pub struct BlockchainBridgeSubs { pub bind: Recipient, + pub configuration_change_msg_sub: Recipient, pub outbound_payments_instructions: Recipient, pub qualified_payables: Recipient, pub retrieve_transactions: Recipient, diff --git a/node/src/sub_lib/configurator.rs b/node/src/sub_lib/configurator.rs index 627818cce..877117187 100644 --- a/node/src/sub_lib/configurator.rs +++ b/node/src/sub_lib/configurator.rs @@ -1,5 +1,6 @@ // Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved. +use crate::sub_lib::neighborhood::ConfigurationChangeMessage; use crate::sub_lib::peer_actors::BindMessage; use actix::Recipient; use masq_lib::ui_gateway::NodeFromUiMessage; @@ -16,6 +17,7 @@ use std::fmt::{Debug, Formatter}; pub struct ConfiguratorSubs { pub bind: Recipient, pub node_from_ui_sub: Recipient, + pub configuration_change_msg_sub: Recipient, } impl Debug for ConfiguratorSubs { @@ -37,6 +39,7 @@ mod tests { let subject = ConfiguratorSubs { bind: recipient!(recorder, BindMessage), node_from_ui_sub: recipient!(recorder, NodeFromUiMessage), + configuration_change_msg_sub: recipient!(recorder, ConfigurationChangeMessage), }; assert_eq!(format!("{:?}", subject), "ConfiguratorSubs"); diff --git a/node/src/test_utils/recorder.rs b/node/src/test_utils/recorder.rs index bd656db03..405153faf 100644 --- a/node/src/test_utils/recorder.rs +++ b/node/src/test_utils/recorder.rs @@ -455,6 +455,7 @@ pub fn make_neighborhood_subs_from_recorder(addr: &Addr) -> Neighborho pub fn make_accountant_subs_from_recorder(addr: &Addr) -> AccountantSubs { AccountantSubs { bind: recipient!(addr, BindMessage), + configuration_change_msg_sub: recipient!(addr, ConfigurationChangeMessage), start: recipient!(addr, StartMessage), report_routing_service_provided: recipient!(addr, ReportRoutingServiceProvidedMessage), report_exit_service_provided: recipient!(addr, ReportExitServiceProvidedMessage), @@ -480,6 +481,7 @@ pub fn make_ui_gateway_subs_from_recorder(addr: &Addr) -> UiGatewaySub pub fn make_blockchain_bridge_subs_from_recorder(addr: &Addr) -> BlockchainBridgeSubs { BlockchainBridgeSubs { bind: recipient!(addr, BindMessage), + configuration_change_msg_sub: recipient!(addr, ConfigurationChangeMessage), outbound_payments_instructions: recipient!(addr, OutboundPaymentsInstructions), qualified_payables: recipient!(addr, QualifiedPayablesMessage), retrieve_transactions: recipient!(addr, RetrieveTransactions), @@ -492,6 +494,7 @@ pub fn make_configurator_subs_from_recorder(addr: &Addr) -> Configurat ConfiguratorSubs { bind: recipient!(addr, BindMessage), node_from_ui_sub: recipient!(addr, NodeFromUiMessage), + configuration_change_msg_sub: recipient!(addr, ConfigurationChangeMessage), } }