net.rs 24 KB

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