Skip to content

Commit

Permalink
GH-728: send ConfigurationChangeMessage to other actors too
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshg6 committed Oct 25, 2023
1 parent 79b6b9a commit 8204b01
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 7 deletions.
10 changes: 10 additions & 0 deletions node/src/accountant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -163,6 +164,14 @@ impl Handler<BindMessage> for Accountant {
}
}

impl Handler<ConfigurationChangeMessage> for Accountant {
type Result = ();

fn handle(&mut self, msg: ConfigurationChangeMessage, ctx: &mut Self::Context) -> Self::Result {
todo!("handler for Accountant");
}
}

impl Handler<StartMessage> for Accountant {
type Result = ();

Expand Down Expand Up @@ -446,6 +455,7 @@ impl Accountant {
pub fn make_subs_from(addr: &Addr<Accountant>) -> 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),
Expand Down
5 changes: 4 additions & 1 deletion node/src/actor_system_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions node/src/blockchain/blockchain_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +107,14 @@ impl SkeletonOptHolder for RetrieveTransactions {
}
}

impl Handler<ConfigurationChangeMessage> for BlockchainBridge {
type Result = ();

fn handle(&mut self, msg: ConfigurationChangeMessage, ctx: &mut Self::Context) -> Self::Result {
todo!("handler for BlockchainBridge");
}
}

impl Handler<RetrieveTransactions> for BlockchainBridge {
type Result = ();

Expand Down Expand Up @@ -232,6 +241,7 @@ impl BlockchainBridge {
pub fn make_subs_from(addr: &Addr<BlockchainBridge>) -> 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),
Expand Down
49 changes: 43 additions & 6 deletions node/src/node_configurator/configurator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,26 @@ impl Handler<BindMessage> 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<ConfigurationChangeMessage> for Configurator {
type Result = ();

fn handle(&mut self, msg: ConfigurationChangeMessage, ctx: &mut Self::Context) -> Self::Result {
todo!("handler in configurator")
}
}

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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::<ConfigurationChangeMessage>(0),
&ConfigurationChangeMessage {
change: ConfigurationChange::UpdatePassword("new_password".to_string())
}
&expected_configuration_msg
);
assert_eq!(
configurator_recording.get_record::<ConfigurationChangeMessage>(0),
&expected_configuration_msg
);
assert_eq!(
blockchain_bridge_recording.get_record::<ConfigurationChangeMessage>(0),
&expected_configuration_msg
);
assert_eq!(
accountant_recording.get_record::<ConfigurationChangeMessage>(0),
&expected_configuration_msg
);
assert_eq!(neighborhood_recording.len(), 1);
}
Expand Down
2 changes: 2 additions & 0 deletions node/src/sub_lib/accountant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,6 +91,7 @@ impl Default for ScanIntervals {
#[derive(Clone, PartialEq, Eq)]
pub struct AccountantSubs {
pub bind: Recipient<BindMessage>,
pub configuration_change_msg_sub: Recipient<ConfigurationChangeMessage>,
pub start: Recipient<StartMessage>,
pub report_routing_service_provided: Recipient<ReportRoutingServiceProvidedMessage>,
pub report_exit_service_provided: Recipient<ReportExitServiceProvidedMessage>,
Expand Down
2 changes: 2 additions & 0 deletions node/src/sub_lib/blockchain_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ pub struct BlockchainBridgeConfig {
#[derive(Clone, PartialEq, Eq)]
pub struct BlockchainBridgeSubs {
pub bind: Recipient<BindMessage>,
pub configuration_change_msg_sub: Recipient<ConfigurationChangeMessage>,
pub outbound_payments_instructions: Recipient<OutboundPaymentsInstructions>,
pub qualified_payables: Recipient<QualifiedPayablesMessage>,
pub retrieve_transactions: Recipient<RetrieveTransactions>,
Expand Down
3 changes: 3 additions & 0 deletions node/src/sub_lib/configurator.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +17,7 @@ use std::fmt::{Debug, Formatter};
pub struct ConfiguratorSubs {
pub bind: Recipient<BindMessage>,
pub node_from_ui_sub: Recipient<NodeFromUiMessage>,
pub configuration_change_msg_sub: Recipient<ConfigurationChangeMessage>,
}

impl Debug for ConfiguratorSubs {
Expand All @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions node/src/test_utils/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ pub fn make_neighborhood_subs_from_recorder(addr: &Addr<Recorder>) -> Neighborho
pub fn make_accountant_subs_from_recorder(addr: &Addr<Recorder>) -> 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),
Expand All @@ -480,6 +481,7 @@ pub fn make_ui_gateway_subs_from_recorder(addr: &Addr<Recorder>) -> UiGatewaySub
pub fn make_blockchain_bridge_subs_from_recorder(addr: &Addr<Recorder>) -> 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),
Expand All @@ -492,6 +494,7 @@ pub fn make_configurator_subs_from_recorder(addr: &Addr<Recorder>) -> Configurat
ConfiguratorSubs {
bind: recipient!(addr, BindMessage),
node_from_ui_sub: recipient!(addr, NodeFromUiMessage),
configuration_change_msg_sub: recipient!(addr, ConfigurationChangeMessage),
}
}

Expand Down

0 comments on commit 8204b01

Please sign in to comment.