net.rs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2025 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use async_lock::Mutex;
  19. use darkfi_serial::{async_trait, deserialize, Decodable, Encodable, SerialDecodable, VarInt};
  20. use std::{
  21. io::Cursor,
  22. sync::{mpsc, Arc},
  23. };
  24. use zeromq::{Socket, SocketRecv, SocketSend};
  25. use crate::{
  26. error::{Error, Result},
  27. expr::SExprCode,
  28. prop::{Property, PropertyAtomicGuard, PropertySubType, PropertyType, PropertyValue, Role},
  29. scene::{SceneNodeId, SceneNodePtr, ScenePath},
  30. ExecutorPtr,
  31. };
  32. #[derive(Debug, SerialDecodable)]
  33. #[repr(u8)]
  34. enum Command {
  35. Hello = 0,
  36. AddNode = 1,
  37. RemoveNode = 9,
  38. RenameNode = 23,
  39. ScanDangling = 24,
  40. LookupNodeId = 12,
  41. AddProperty = 11,
  42. LinkNode = 2,
  43. UnlinkNode = 8,
  44. GetInfo = 19,
  45. GetChildren = 4,
  46. GetParents = 5,
  47. GetProperties = 3,
  48. GetPropertyValue = 6,
  49. SetPropertyValue = 7,
  50. GetSignals = 14,
  51. RegisterSlot = 15,
  52. UnregisterSlot = 16,
  53. LookupSlotId = 17,
  54. GetSlots = 18,
  55. GetMethods = 20,
  56. GetMethod = 21,
  57. CallMethod = 22,
  58. }
  59. // Missing calls todo:
  60. // GetPropLen
  61. // UnsetProperty
  62. // SetPropertyNull
  63. // PropertyPushNull
  64. // PropertyPush
  65. // PropertyIsUnset
  66. pub struct ZeroMQAdapter {
  67. /*
  68. // req-reply commands
  69. req_socket: zmq::Socket,
  70. // We cannot share zmq sockets across threads, and we cannot quickly spawn
  71. // pub sockets due to address reuse errors.
  72. slot_sender: mpsc::SyncSender<(Vec<u8>, Vec<u8>)>,
  73. slot_recvr: Option<mpsc::Receiver<(Vec<u8>, Vec<u8>)>>,
  74. */
  75. sg_root: SceneNodePtr,
  76. ex: ExecutorPtr,
  77. zmq_rep: Mutex<zeromq::RepSocket>,
  78. zmq_pub: Mutex<zeromq::PubSocket>,
  79. }
  80. impl ZeroMQAdapter {
  81. pub async fn new(sg_root: SceneNodePtr, ex: ExecutorPtr) -> Arc<Self> {
  82. let mut zmq_rep = zeromq::RepSocket::new();
  83. zmq_rep.bind("tcp://0.0.0.0:9484").await.unwrap();
  84. let mut zmq_pub = zeromq::PubSocket::new();
  85. zmq_pub.bind("tcp://0.0.0.0:9485").await.unwrap();
  86. Arc::new(Self { sg_root, ex, zmq_rep: Mutex::new(zmq_rep), zmq_pub: Mutex::new(zmq_pub) })
  87. }
  88. pub async fn run(self: Arc<Self>) {
  89. loop {
  90. let req = self.zmq_rep.lock().await.recv().await.unwrap();
  91. assert_eq!(req.len(), 2);
  92. let cmd = req.get(0).unwrap().to_vec();
  93. assert_eq!(cmd.len(), 1);
  94. let payload = req.get(1).unwrap().to_vec();
  95. let cmd = deserialize(&cmd).unwrap();
  96. debug!(target: "req", "zmq: {:?} {:?}", cmd, payload);
  97. let self2 = self.clone();
  98. match self2.process_request(cmd, payload).await {
  99. Ok(reply) => {
  100. let mut m = zeromq::ZmqMessage::from(vec![0u8]);
  101. m.push_back(reply.into());
  102. // [errc:1] [reply]
  103. self.zmq_rep.lock().await.send(m).await.unwrap();
  104. }
  105. Err(err) => {
  106. let errc = err as u8;
  107. warn!(target: "req", "errc {}: {}", errc, err);
  108. let mut m = zeromq::ZmqMessage::from(vec![errc]);
  109. m.push_back(vec![].into());
  110. // [errc:1] [reply]
  111. self.zmq_rep.lock().await.send(m).await.unwrap();
  112. }
  113. }
  114. }
  115. }
  116. async fn process_request(self: Arc<Self>, cmd: Command, payload: Vec<u8>) -> Result<Vec<u8>> {
  117. let mut cur = Cursor::new(&payload);
  118. let mut reply = vec![];
  119. match cmd {
  120. Command::Hello => {
  121. debug!(target: "req", "hello()");
  122. assert_eq!(payload.len(), 0);
  123. "hello".encode(&mut reply).unwrap();
  124. }
  125. Command::GetInfo => {
  126. /*
  127. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  128. debug!(target: "req", "{:?}({})", cmd, node_id);
  129. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  130. node.name.encode(&mut reply).unwrap();
  131. node.typ.encode(&mut reply).unwrap();
  132. */
  133. }
  134. Command::GetChildren => {
  135. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  136. debug!(target: "req", "{cmd:?}({node_path})");
  137. let node =
  138. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  139. let children: Vec<_> = node
  140. .get_children()
  141. .iter()
  142. .map(|node| (node.name.clone(), node.id, node.typ))
  143. .collect();
  144. children.encode(&mut reply).unwrap();
  145. }
  146. Command::GetParents => {
  147. /*
  148. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  149. debug!(target: "req", "{:?}({})", cmd, node_id);
  150. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  151. let parents: Vec<_> = node
  152. .parents
  153. .iter()
  154. .map(|node_inf| (node_inf.name.clone(), node_inf.id, node_inf.typ))
  155. .collect();
  156. parents.encode(&mut reply).unwrap();
  157. */
  158. }
  159. Command::GetProperties => {
  160. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  161. debug!(target: "req", "{cmd:?}({node_path})");
  162. let node =
  163. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  164. VarInt(node.props.len() as u64).encode(&mut reply).unwrap();
  165. for prop in &node.props {
  166. prop.name.encode(&mut reply).unwrap();
  167. prop.typ.encode(&mut reply).unwrap();
  168. prop.subtype.encode(&mut reply).unwrap();
  169. //prop.defaults.encode(&mut reply).unwrap();
  170. prop.ui_name.encode(&mut reply).unwrap();
  171. prop.desc.encode(&mut reply).unwrap();
  172. prop.is_null_allowed.encode(&mut reply).unwrap();
  173. prop.is_expr_allowed.encode(&mut reply).unwrap();
  174. (prop.array_len as u32).encode(&mut reply).unwrap();
  175. prop.min_val.encode(&mut reply).unwrap();
  176. prop.max_val.encode(&mut reply).unwrap();
  177. prop.enum_items.encode(&mut reply).unwrap();
  178. let depends: Vec<_> = prop
  179. .get_depends()
  180. .into_iter()
  181. .map(|d| (d.i as u32, d.local_name))
  182. .collect();
  183. depends.encode(&mut reply).unwrap();
  184. }
  185. }
  186. Command::GetPropertyValue => {
  187. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  188. let prop_name = String::decode(&mut cur).unwrap();
  189. debug!(target: "req", "{cmd:?}({node_path}, {prop_name})");
  190. let node =
  191. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  192. let prop = node.get_property(&prop_name).ok_or(Error::PropertyNotFound)?;
  193. prop.typ.encode(&mut reply).unwrap();
  194. VarInt(prop.get_len() as u64).encode(&mut reply).unwrap();
  195. for i in 0..prop.get_len() {
  196. let val = prop.get_value(i)?;
  197. if val.is_unset() {
  198. 1u8.encode(&mut reply).unwrap();
  199. let default = &prop.defaults[i];
  200. default.encode(&mut reply).unwrap();
  201. } else if val.is_null() {
  202. 2u8.encode(&mut reply).unwrap();
  203. } else if val.is_expr() {
  204. 3u8.encode(&mut reply).unwrap();
  205. } else {
  206. 0u8.encode(&mut reply).unwrap();
  207. val.encode(&mut reply).unwrap();
  208. }
  209. }
  210. }
  211. Command::SetPropertyValue => {
  212. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  213. let prop_name = String::decode(&mut cur).unwrap();
  214. let prop_i = u32::decode(&mut cur).unwrap() as usize;
  215. let prop_type = PropertyType::decode(&mut cur).unwrap();
  216. debug!(target: "req", "{cmd:?}({node_path}, {prop_name}, {prop_i}, {prop_type:?})");
  217. let node =
  218. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  219. let prop = node.get_property(&prop_name).ok_or(Error::PropertyNotFound)?;
  220. let atom = &mut PropertyAtomicGuard::new();
  221. match prop_type {
  222. PropertyType::Null => {
  223. prop.set_null(atom, Role::User, prop_i)?;
  224. }
  225. PropertyType::Bool => {
  226. let val = bool::decode(&mut cur).unwrap();
  227. prop.set_bool(atom, Role::User, prop_i, val)?;
  228. }
  229. PropertyType::Uint32 => {
  230. let val = u32::decode(&mut cur).unwrap();
  231. prop.set_u32(atom, Role::User, prop_i, val)?;
  232. }
  233. PropertyType::Float32 => {
  234. let val = f32::decode(&mut cur).unwrap();
  235. prop.set_f32(atom, Role::User, prop_i, val)?;
  236. }
  237. PropertyType::Str => {
  238. let val = String::decode(&mut cur).unwrap();
  239. prop.set_str(atom, Role::User, prop_i, val)?;
  240. }
  241. PropertyType::Enum => {
  242. let val = String::decode(&mut cur).unwrap();
  243. prop.set_enum(atom, Role::User, prop_i, val)?;
  244. }
  245. PropertyType::SceneNodeId => {
  246. let val = SceneNodeId::decode(&mut cur).unwrap();
  247. prop.set_node_id(atom, Role::User, prop_i, val)?;
  248. }
  249. PropertyType::SExpr => {
  250. let val = SExprCode::decode(&mut cur).unwrap();
  251. debug!(target: "req", " received code {:?}", val);
  252. prop.set_expr(atom, Role::User, prop_i, val)?;
  253. }
  254. }
  255. }
  256. Command::AddNode => {
  257. /*
  258. let node_name = String::decode(&mut cur).unwrap();
  259. let node_type = SceneNodeType::decode(&mut cur).unwrap();
  260. debug!(target: "req", "{:?}({}, {:?})", cmd, node_name, node_type);
  261. let node_id = scene_graph.add_node(&node_name, node_type).id;
  262. node_id.encode(&mut reply).unwrap();
  263. */
  264. }
  265. Command::RemoveNode => {
  266. /*
  267. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  268. debug!(target: "req", "{:?}({})", cmd, node_id);
  269. scene_graph.remove_node(node_id)?;
  270. */
  271. }
  272. Command::RenameNode => {
  273. /*
  274. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  275. let node_name = String::decode(&mut cur).unwrap();
  276. debug!(target: "req", "{:?}({}, {})", cmd, node_id, node_name);
  277. scene_graph.rename_node(node_id, node_name)?;
  278. */
  279. }
  280. Command::ScanDangling => {
  281. /*
  282. let dangling = scene_graph.scan_dangling();
  283. dangling.encode(&mut reply).unwrap();
  284. */
  285. }
  286. Command::LookupNodeId => {
  287. /*
  288. let node_path: String = deserialize(&payload).unwrap();
  289. debug!(target: "req", "{:?}({})", cmd, node_path);
  290. let node_id = scene_graph.lookup_node_id(&node_path).ok_or(Error::NodeNotFound)?;
  291. node_id.encode(&mut reply).unwrap();
  292. */
  293. }
  294. Command::AddProperty => {
  295. /*
  296. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  297. let prop_name = String::decode(&mut cur).unwrap();
  298. let prop_type = PropertyType::decode(&mut cur).unwrap();
  299. let prop_subtype = PropertySubType::decode(&mut cur).unwrap();
  300. debug!(target: "req", "{:?}({}, {}, {:?}, {:?}, ...)", cmd, node_id, prop_name, prop_type, prop_subtype);
  301. let mut prop = Property::new(prop_name, prop_type, prop_subtype);
  302. let prop_array_len = u32::decode(&mut cur).unwrap();
  303. prop.set_array_len(prop_array_len as usize);
  304. let prop_defaults_is_some = bool::decode(&mut cur).unwrap();
  305. if prop_defaults_is_some {
  306. let prop_defaults_len = VarInt::decode(&mut cur).unwrap();
  307. match prop_type {
  308. PropertyType::Uint32 => {
  309. let mut prop_defaults = vec![];
  310. for _ in 0..prop_defaults_len.0 {
  311. prop_defaults.push(u32::decode(&mut cur).unwrap());
  312. }
  313. prop.set_defaults_u32(prop_defaults)?;
  314. }
  315. PropertyType::Float32 => {
  316. let mut prop_defaults = vec![];
  317. for _ in 0..prop_defaults_len.0 {
  318. prop_defaults.push(f32::decode(&mut cur).unwrap());
  319. }
  320. prop.set_defaults_f32(prop_defaults)?;
  321. }
  322. PropertyType::Str => {
  323. let mut prop_defaults = vec![];
  324. for _ in 0..prop_defaults_len.0 {
  325. prop_defaults.push(String::decode(&mut cur).unwrap());
  326. }
  327. prop.set_defaults_str(prop_defaults)?;
  328. }
  329. _ => return Err(Error::PropertyWrongType),
  330. }
  331. }
  332. let prop_ui_name = String::decode(&mut cur).unwrap();
  333. let prop_desc = String::decode(&mut cur).unwrap();
  334. let prop_is_null_allowed = bool::decode(&mut cur).unwrap();
  335. let prop_is_expr_allowed = bool::decode(&mut cur).unwrap();
  336. match prop_type {
  337. PropertyType::Uint32 => {
  338. let min_is_some = bool::decode(&mut cur).unwrap();
  339. let min = if min_is_some {
  340. let min = u32::decode(&mut cur).unwrap();
  341. Some(PropertyValue::Uint32(min))
  342. } else {
  343. None
  344. };
  345. let max_is_some = bool::decode(&mut cur).unwrap();
  346. let max = if max_is_some {
  347. let max = u32::decode(&mut cur).unwrap();
  348. Some(PropertyValue::Uint32(max))
  349. } else {
  350. None
  351. };
  352. prop.min_val = min;
  353. prop.max_val = max;
  354. }
  355. PropertyType::Float32 => {
  356. let min_is_some = bool::decode(&mut cur).unwrap();
  357. let min = if min_is_some {
  358. let min = f32::decode(&mut cur).unwrap();
  359. Some(PropertyValue::Float32(min))
  360. } else {
  361. None
  362. };
  363. let max_is_some = bool::decode(&mut cur).unwrap();
  364. let max = if max_is_some {
  365. let max = f32::decode(&mut cur).unwrap();
  366. Some(PropertyValue::Float32(max))
  367. } else {
  368. None
  369. };
  370. prop.min_val = min;
  371. prop.max_val = max;
  372. }
  373. _ => {
  374. let min_is_some = bool::decode(&mut cur).unwrap();
  375. if min_is_some {
  376. return Err(Error::PropertyWrongType)
  377. }
  378. let max_is_some = bool::decode(&mut cur).unwrap();
  379. if max_is_some {
  380. return Err(Error::PropertyWrongType)
  381. }
  382. }
  383. }
  384. let prop_enum_items = Vec::<String>::decode(&mut cur).unwrap();
  385. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  386. prop.set_ui_text(prop_ui_name, prop_desc);
  387. prop.is_null_allowed = prop_is_null_allowed;
  388. prop.is_expr_allowed = prop_is_expr_allowed;
  389. if !prop_enum_items.is_empty() {
  390. prop.set_enum_items(prop_enum_items)?;
  391. }
  392. node.add_property(prop)?;
  393. */
  394. }
  395. Command::LinkNode => {
  396. /*
  397. let child_id = SceneNodeId::decode(&mut cur).unwrap();
  398. let parent_id = SceneNodeId::decode(&mut cur).unwrap();
  399. debug!(target: "req", "{:?}({}, {})", cmd, child_id, parent_id);
  400. scene_graph.link(child_id, parent_id)?;
  401. */
  402. }
  403. Command::UnlinkNode => {
  404. /*
  405. let child_id = SceneNodeId::decode(&mut cur).unwrap();
  406. let parent_id = SceneNodeId::decode(&mut cur).unwrap();
  407. debug!(target: "req", "{:?}({}, {})", cmd, child_id, parent_id);
  408. scene_graph.unlink(child_id, parent_id)?;
  409. */
  410. }
  411. Command::GetSignals => {
  412. /*
  413. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  414. debug!(target: "req", "{:?}({})", cmd, node_id);
  415. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  416. let mut sigs = vec![];
  417. for sig in &node.sigs {
  418. sigs.push(sig.name.clone());
  419. }
  420. sigs.encode(&mut reply).unwrap();
  421. */
  422. }
  423. Command::RegisterSlot => {
  424. /*
  425. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  426. let sig_name = String::decode(&mut cur).unwrap();
  427. let slot_name = String::decode(&mut cur).unwrap();
  428. let user_data = Vec::<u8>::decode(&mut cur).unwrap();
  429. debug!(target: "req", "{:?}({}, {}, {}, {:?})", cmd, node_id, sig_name, slot_name, user_data);
  430. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  431. let (sendr, recvr) = async_channel::unbounded();
  432. let slot = Slot { name: slot_name, notify: sendr };
  433. // This task will auto-die when the slot is unregistered
  434. let self2 = self.clone();
  435. self.ex
  436. .spawn(async move {
  437. loop {
  438. let Ok(signal_data) = recvr.recv().await else {
  439. // Die
  440. break
  441. };
  442. let mut m = zeromq::ZmqMessage::from(signal_data);
  443. m.push_back(user_data.clone().into());
  444. self2.zmq_pub.lock().await.send(m).await.unwrap();
  445. }
  446. })
  447. .detach();
  448. let slot_id = node.register(&sig_name, slot)?;
  449. slot_id.encode(&mut reply).unwrap();
  450. */
  451. }
  452. Command::UnregisterSlot => {
  453. /*
  454. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  455. let sig_name = String::decode(&mut cur).unwrap();
  456. let slot_id = SlotId::decode(&mut cur).unwrap();
  457. debug!(target: "req", "{:?}({}, {}, {})", cmd, node_id, sig_name, slot_id);
  458. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  459. node.unregister(&sig_name, slot_id)?;
  460. */
  461. }
  462. Command::LookupSlotId => {
  463. /*
  464. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  465. let sig_name = String::decode(&mut cur).unwrap();
  466. let slot_name = String::decode(&mut cur).unwrap();
  467. debug!(target: "req", "{:?}({}, {}, {})", cmd, node_id, sig_name, slot_name);
  468. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  469. let signal = node.get_signal(&sig_name).ok_or(Error::SignalNotFound)?;
  470. let slot_id = signal.lookup_slot_id(&slot_name).ok_or(Error::SlotNotFound)?;
  471. slot_id.encode(&mut reply).unwrap();
  472. */
  473. }
  474. Command::GetSlots => {
  475. /*
  476. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  477. let sig_name = String::decode(&mut cur).unwrap();
  478. debug!(target: "req", "{:?}({}, {})", cmd, node_id, sig_name);
  479. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  480. let signal = node.get_signal(&sig_name).ok_or(Error::SignalNotFound)?;
  481. let mut slots = vec![];
  482. for (slot_id, slot) in signal.get_slots() {
  483. slots.push((slot.name.clone(), slot_id));
  484. }
  485. slots.encode(&mut reply).unwrap();
  486. */
  487. }
  488. Command::GetMethods => {
  489. /*
  490. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  491. debug!(target: "req", "{:?}({})", cmd, node_id);
  492. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  493. let method_names: Vec<_> = node.methods.iter().map(|m| m.name.clone()).collect();
  494. method_names.encode(&mut reply).unwrap();
  495. */
  496. }
  497. Command::GetMethod => {
  498. /*
  499. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  500. let method_name = String::decode(&mut cur).unwrap();
  501. debug!(target: "req", "{:?}({}, {})", cmd, node_id, method_name);
  502. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  503. let method = node.get_method(&method_name).ok_or(Error::MethodNotFound)?;
  504. method.args.encode(&mut reply).unwrap();
  505. method.result.encode(&mut reply).unwrap();
  506. */
  507. }
  508. Command::CallMethod => {
  509. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  510. let method_name = String::decode(&mut cur).unwrap();
  511. let arg_data = Vec::<u8>::decode(&mut cur).unwrap();
  512. debug!(target: "req", "{cmd:?}({node_path}, {method_name}, ...)");
  513. let node =
  514. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  515. let result = node.call_method(&method_name, arg_data).await?;
  516. result.encode(&mut reply).unwrap();
  517. }
  518. }
  519. Ok(reply)
  520. }
  521. }