From ad490ae31de1b8fe9fc426ee150d4b4ab58b1aa8 Mon Sep 17 00:00:00 2001 From: Miguel Naveira <47919901+mrnaveira@users.noreply.github.com> Date: Fri, 31 May 2024 11:34:58 +0100 Subject: [PATCH] feat(tari_swarm_daemon): link up wallet daemon and signaling server (#1041) Description --- Links up wallet daemon and signaling server in the `tari_swam` application Motivation and Context --- `tari_swarm_daemon` is a very useful tool to spawn a local Tari network for development purposes. But currently the wallet daemon process is not spawn with the signaling server address, which means that webRTC communication between web pages and the wallet daemon is not possible. This PR makes the necessary changes to the `tari_swarm_daemon` to make this possible. How Has This Been Tested? --- Manually by running `tari_swarm_daemon` and connecting a site to the wallet daemon using `tari.js` What process can a PR reviewer use to test or verify this change? --- See previous section. Note that existing `tari_swarm` process directories (and config files) must be created fresh for this change to work. Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify --------- Co-authored-by: stringhandler --- applications/tari_swarm_daemon/src/main.rs | 20 +++++++++---------- .../src/process_definitions/context.rs | 5 +++++ .../src/process_definitions/wallet_daemon.rs | 15 ++++++++++++++ .../src/process_manager/instances/manager.rs | 14 +++++++++---- .../processes/signaling_server.rs | 2 -- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/applications/tari_swarm_daemon/src/main.rs b/applications/tari_swarm_daemon/src/main.rs index 8001a0213..e4da5bb8d 100644 --- a/applications/tari_swarm_daemon/src/main.rs +++ b/applications/tari_swarm_daemon/src/main.rs @@ -110,31 +110,31 @@ fn get_base_config(cli: &Cli) -> anyhow::Result { env: vec![], }, ExecutableConfig { - instance_type: InstanceType::TariWalletDaemon, - execuable_path: Some("target/release/tari_wallet_daemon".into()), + instance_type: InstanceType::TariIndexer, + execuable_path: Some("target/release/tari_indexer".into()), compile: Some(CompileConfig { working_dir: Some(".".into()), - package_name: "tari_dan_wallet_daemon".to_string(), + package_name: "tari_indexer".to_string(), target_dir: None, }), env: vec![], }, ExecutableConfig { - instance_type: InstanceType::TariIndexer, - execuable_path: Some("target/release/tari_indexer".into()), + instance_type: InstanceType::TariSignalingServer, + execuable_path: Some("target/release/tari_signaling_server".into()), compile: Some(CompileConfig { working_dir: Some(".".into()), - package_name: "tari_indexer".to_string(), + package_name: "tari_signaling_server".to_string(), target_dir: None, }), env: vec![], }, ExecutableConfig { - instance_type: InstanceType::TariSignalingServer, - execuable_path: Some("target/release/tari_signaling_server".into()), + instance_type: InstanceType::TariWalletDaemon, + execuable_path: Some("target/release/tari_wallet_daemon".into()), compile: Some(CompileConfig { working_dir: Some(".".into()), - package_name: "tari_signaling_server".to_string(), + package_name: "tari_dan_wallet_daemon".to_string(), target_dir: None, }), env: vec![], @@ -156,8 +156,8 @@ fn get_base_config(cli: &Cli) -> anyhow::Result { .with_name("Validator node") .with_num_instances(1), InstanceConfig::new(InstanceType::TariIndexer).with_name("Indexer"), - InstanceConfig::new(InstanceType::TariWalletDaemon).with_name("Wallet Daemon"), InstanceConfig::new(InstanceType::TariSignalingServer).with_name("Signaling server"), + InstanceConfig::new(InstanceType::TariWalletDaemon).with_name("Wallet Daemon"), ]; let base_dir = cli diff --git a/applications/tari_swarm_daemon/src/process_definitions/context.rs b/applications/tari_swarm_daemon/src/process_definitions/context.rs index 629ad7d35..c9f42173e 100644 --- a/applications/tari_swarm_daemon/src/process_definitions/context.rs +++ b/applications/tari_swarm_daemon/src/process_definitions/context.rs @@ -12,6 +12,7 @@ use crate::process_manager::{ InstanceManager, MinoTariNodeProcess, MinoTariWalletProcess, + SignalingServerProcess, }; pub struct ProcessContext<'a> { @@ -91,4 +92,8 @@ impl<'a> ProcessContext<'a> { pub fn indexers(&self) -> impl Iterator { self.instances.indexers() } + + pub fn signaling_servers(&self) -> impl Iterator { + self.instances.signaling_servers() + } } diff --git a/applications/tari_swarm_daemon/src/process_definitions/wallet_daemon.rs b/applications/tari_swarm_daemon/src/process_definitions/wallet_daemon.rs index d5896d4bd..aa0e02abf 100644 --- a/applications/tari_swarm_daemon/src/process_definitions/wallet_daemon.rs +++ b/applications/tari_swarm_daemon/src/process_definitions/wallet_daemon.rs @@ -52,6 +52,21 @@ impl ProcessDefinition for WalletDaemon { .arg(format!("--ui-connect-address={json_rpc_public_address}")) .arg(format!("-pdan_wallet_daemon.http_ui_address={web_ui_address}")); + // A signaling server is not required for startup of the wallet daemon, + // but if it is available we want to set it up + let maybe_signaling_server = context.signaling_servers().next(); + if let Some(signaling_server) = maybe_signaling_server { + let signaling_server_url = format!( + "{local_ip}:{}", + signaling_server + .instance() + .allocated_ports() + .get("jrpc") + .ok_or_else(|| anyhow!("Signaling server port not found"))? + ); + command.arg(format!("--signaling-server-address={signaling_server_url}")); + } + Ok(command) } } diff --git a/applications/tari_swarm_daemon/src/process_manager/instances/manager.rs b/applications/tari_swarm_daemon/src/process_manager/instances/manager.rs index fa43b2152..872a54b6b 100644 --- a/applications/tari_swarm_daemon/src/process_manager/instances/manager.rs +++ b/applications/tari_swarm_daemon/src/process_manager/instances/manager.rs @@ -211,14 +211,14 @@ impl InstanceManager { InstanceType::TariIndexer => { self.indexers.insert(instance_id, IndexerProcess::new(instance)); }, - InstanceType::TariWalletDaemon => { - self.wallet_daemons - .insert(instance_id, WalletDaemonProcess::new(instance)); - }, InstanceType::TariSignalingServer => { self.signaling_servers .insert(instance_id, SignalingServerProcess::new(instance)); }, + InstanceType::TariWalletDaemon => { + self.wallet_daemons + .insert(instance_id, WalletDaemonProcess::new(instance)); + }, } Ok(instance_id) @@ -252,6 +252,10 @@ impl InstanceManager { self.indexers.values() } + pub fn signaling_servers(&self) -> impl Iterator + Sized { + self.signaling_servers.values() + } + // pub fn wallet_daemons(&self) -> impl Iterator + Sized { // self.wallet_daemons.values() // } @@ -301,6 +305,7 @@ impl InstanceManager { .chain(self.minotari_miners.values_mut().map(|x| x.instance_mut())) .chain(self.validator_nodes.values_mut().map(|x| x.instance_mut())) .chain(self.indexers.values_mut().map(|x| x.instance_mut())) + .chain(self.signaling_servers.values_mut().map(|x| x.instance_mut())) .chain(self.wallet_daemons.values_mut().map(|x| x.instance_mut())) } @@ -312,6 +317,7 @@ impl InstanceManager { .chain(self.minotari_miners.values().map(|x| x.instance())) .chain(self.validator_nodes.values().map(|x| x.instance())) .chain(self.indexers.values().map(|x| x.instance())) + .chain(self.signaling_servers.values().map(|x| x.instance())) .chain(self.wallet_daemons.values().map(|x| x.instance())) } diff --git a/applications/tari_swarm_daemon/src/process_manager/processes/signaling_server.rs b/applications/tari_swarm_daemon/src/process_manager/processes/signaling_server.rs index b6ad60fe2..3c9bd123f 100644 --- a/applications/tari_swarm_daemon/src/process_manager/processes/signaling_server.rs +++ b/applications/tari_swarm_daemon/src/process_manager/processes/signaling_server.rs @@ -12,12 +12,10 @@ impl SignalingServerProcess { Self { instance } } - #[allow(dead_code)] pub fn instance(&self) -> &Instance { &self.instance } - #[allow(dead_code)] pub fn instance_mut(&mut self) -> &mut Instance { &mut self.instance }