net.rs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 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, 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. match prop_type {
  221. PropertyType::Null => {
  222. prop.set_null(Role::User, prop_i)?;
  223. }
  224. PropertyType::Bool => {
  225. let val = bool::decode(&mut cur).unwrap();
  226. prop.set_bool(Role::User, prop_i, val)?;
  227. }
  228. PropertyType::Uint32 => {
  229. let val = u32::decode(&mut cur).unwrap();
  230. prop.set_u32(Role::User, prop_i, val)?;
  231. }
  232. PropertyType::Float32 => {
  233. let val = f32::decode(&mut cur).unwrap();
  234. prop.set_f32(Role::User, prop_i, val)?;
  235. }
  236. PropertyType::Str => {
  237. let val = String::decode(&mut cur).unwrap();
  238. prop.set_str(Role::User, prop_i, val)?;
  239. }
  240. PropertyType::Enum => {
  241. let val = String::decode(&mut cur).unwrap();
  242. prop.set_enum(Role::User, prop_i, val)?;
  243. }
  244. PropertyType::SceneNodeId => {
  245. let val = SceneNodeId::decode(&mut cur).unwrap();
  246. prop.set_node_id(Role::User, prop_i, val)?;
  247. }
  248. PropertyType::SExpr => {
  249. let val = SExprCode::decode(&mut cur).unwrap();
  250. debug!(target: "req", " received code {:?}", val);
  251. prop.set_expr(Role::User, prop_i, val)?;
  252. }
  253. }
  254. }
  255. Command::AddNode => {
  256. /*
  257. let node_name = String::decode(&mut cur).unwrap();
  258. let node_type = SceneNodeType::decode(&mut cur).unwrap();
  259. debug!(target: "req", "{:?}({}, {:?})", cmd, node_name, node_type);
  260. let node_id = scene_graph.add_node(&node_name, node_type).id;
  261. node_id.encode(&mut reply).unwrap();
  262. */
  263. }
  264. Command::RemoveNode => {
  265. /*
  266. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  267. debug!(target: "req", "{:?}({})", cmd, node_id);
  268. scene_graph.remove_node(node_id)?;
  269. */
  270. }
  271. Command::RenameNode => {
  272. /*
  273. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  274. let node_name = String::decode(&mut cur).unwrap();
  275. debug!(target: "req", "{:?}({}, {})", cmd, node_id, node_name);
  276. scene_graph.rename_node(node_id, node_name)?;
  277. */
  278. }
  279. Command::ScanDangling => {
  280. /*
  281. let dangling = scene_graph.scan_dangling();
  282. dangling.encode(&mut reply).unwrap();
  283. */
  284. }
  285. Command::LookupNodeId => {
  286. /*
  287. let node_path: String = deserialize(&payload).unwrap();
  288. debug!(target: "req", "{:?}({})", cmd, node_path);
  289. let node_id = scene_graph.lookup_node_id(&node_path).ok_or(Error::NodeNotFound)?;
  290. node_id.encode(&mut reply).unwrap();
  291. */
  292. }
  293. Command::AddProperty => {
  294. /*
  295. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  296. let prop_name = String::decode(&mut cur).unwrap();
  297. let prop_type = PropertyType::decode(&mut cur).unwrap();
  298. let prop_subtype = PropertySubType::decode(&mut cur).unwrap();
  299. debug!(target: "req", "{:?}({}, {}, {:?}, {:?}, ...)", cmd, node_id, prop_name, prop_type, prop_subtype);
  300. let mut prop = Property::new(prop_name, prop_type, prop_subtype);
  301. let prop_array_len = u32::decode(&mut cur).unwrap();
  302. prop.set_array_len(prop_array_len as usize);
  303. let prop_defaults_is_some = bool::decode(&mut cur).unwrap();
  304. if prop_defaults_is_some {
  305. let prop_defaults_len = VarInt::decode(&mut cur).unwrap();
  306. match prop_type {
  307. PropertyType::Uint32 => {
  308. let mut prop_defaults = vec![];
  309. for _ in 0..prop_defaults_len.0 {
  310. prop_defaults.push(u32::decode(&mut cur).unwrap());
  311. }
  312. prop.set_defaults_u32(prop_defaults)?;
  313. }
  314. PropertyType::Float32 => {
  315. let mut prop_defaults = vec![];
  316. for _ in 0..prop_defaults_len.0 {
  317. prop_defaults.push(f32::decode(&mut cur).unwrap());
  318. }
  319. prop.set_defaults_f32(prop_defaults)?;
  320. }
  321. PropertyType::Str => {
  322. let mut prop_defaults = vec![];
  323. for _ in 0..prop_defaults_len.0 {
  324. prop_defaults.push(String::decode(&mut cur).unwrap());
  325. }
  326. prop.set_defaults_str(prop_defaults)?;
  327. }
  328. _ => return Err(Error::PropertyWrongType),
  329. }
  330. }
  331. let prop_ui_name = String::decode(&mut cur).unwrap();
  332. let prop_desc = String::decode(&mut cur).unwrap();
  333. let prop_is_null_allowed = bool::decode(&mut cur).unwrap();
  334. let prop_is_expr_allowed = bool::decode(&mut cur).unwrap();
  335. match prop_type {
  336. PropertyType::Uint32 => {
  337. let min_is_some = bool::decode(&mut cur).unwrap();
  338. let min = if min_is_some {
  339. let min = u32::decode(&mut cur).unwrap();
  340. Some(PropertyValue::Uint32(min))
  341. } else {
  342. None
  343. };
  344. let max_is_some = bool::decode(&mut cur).unwrap();
  345. let max = if max_is_some {
  346. let max = u32::decode(&mut cur).unwrap();
  347. Some(PropertyValue::Uint32(max))
  348. } else {
  349. None
  350. };
  351. prop.min_val = min;
  352. prop.max_val = max;
  353. }
  354. PropertyType::Float32 => {
  355. let min_is_some = bool::decode(&mut cur).unwrap();
  356. let min = if min_is_some {
  357. let min = f32::decode(&mut cur).unwrap();
  358. Some(PropertyValue::Float32(min))
  359. } else {
  360. None
  361. };
  362. let max_is_some = bool::decode(&mut cur).unwrap();
  363. let max = if max_is_some {
  364. let max = f32::decode(&mut cur).unwrap();
  365. Some(PropertyValue::Float32(max))
  366. } else {
  367. None
  368. };
  369. prop.min_val = min;
  370. prop.max_val = max;
  371. }
  372. _ => {
  373. let min_is_some = bool::decode(&mut cur).unwrap();
  374. if min_is_some {
  375. return Err(Error::PropertyWrongType)
  376. }
  377. let max_is_some = bool::decode(&mut cur).unwrap();
  378. if max_is_some {
  379. return Err(Error::PropertyWrongType)
  380. }
  381. }
  382. }
  383. let prop_enum_items = Vec::<String>::decode(&mut cur).unwrap();
  384. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  385. prop.set_ui_text(prop_ui_name, prop_desc);
  386. prop.is_null_allowed = prop_is_null_allowed;
  387. prop.is_expr_allowed = prop_is_expr_allowed;
  388. if !prop_enum_items.is_empty() {
  389. prop.set_enum_items(prop_enum_items)?;
  390. }
  391. node.add_property(prop)?;
  392. */
  393. }
  394. Command::LinkNode => {
  395. /*
  396. let child_id = SceneNodeId::decode(&mut cur).unwrap();
  397. let parent_id = SceneNodeId::decode(&mut cur).unwrap();
  398. debug!(target: "req", "{:?}({}, {})", cmd, child_id, parent_id);
  399. scene_graph.link(child_id, parent_id)?;
  400. */
  401. }
  402. Command::UnlinkNode => {
  403. /*
  404. let child_id = SceneNodeId::decode(&mut cur).unwrap();
  405. let parent_id = SceneNodeId::decode(&mut cur).unwrap();
  406. debug!(target: "req", "{:?}({}, {})", cmd, child_id, parent_id);
  407. scene_graph.unlink(child_id, parent_id)?;
  408. */
  409. }
  410. Command::GetSignals => {
  411. /*
  412. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  413. debug!(target: "req", "{:?}({})", cmd, node_id);
  414. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  415. let mut sigs = vec![];
  416. for sig in &node.sigs {
  417. sigs.push(sig.name.clone());
  418. }
  419. sigs.encode(&mut reply).unwrap();
  420. */
  421. }
  422. Command::RegisterSlot => {
  423. /*
  424. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  425. let sig_name = String::decode(&mut cur).unwrap();
  426. let slot_name = String::decode(&mut cur).unwrap();
  427. let user_data = Vec::<u8>::decode(&mut cur).unwrap();
  428. debug!(target: "req", "{:?}({}, {}, {}, {:?})", cmd, node_id, sig_name, slot_name, user_data);
  429. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  430. let (sendr, recvr) = async_channel::unbounded();
  431. let slot = Slot { name: slot_name, notify: sendr };
  432. // This task will auto-die when the slot is unregistered
  433. let self2 = self.clone();
  434. self.ex
  435. .spawn(async move {
  436. loop {
  437. let Ok(signal_data) = recvr.recv().await else {
  438. // Die
  439. break;
  440. };
  441. let mut m = zeromq::ZmqMessage::from(signal_data);
  442. m.push_back(user_data.clone().into());
  443. self2.zmq_pub.lock().await.send(m).await.unwrap();
  444. }
  445. })
  446. .detach();
  447. let slot_id = node.register(&sig_name, slot)?;
  448. slot_id.encode(&mut reply).unwrap();
  449. */
  450. }
  451. Command::UnregisterSlot => {
  452. /*
  453. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  454. let sig_name = String::decode(&mut cur).unwrap();
  455. let slot_id = SlotId::decode(&mut cur).unwrap();
  456. debug!(target: "req", "{:?}({}, {}, {})", cmd, node_id, sig_name, slot_id);
  457. let node = scene_graph.get_node_mut(node_id).ok_or(Error::NodeNotFound)?;
  458. node.unregister(&sig_name, slot_id)?;
  459. */
  460. }
  461. Command::LookupSlotId => {
  462. /*
  463. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  464. let sig_name = String::decode(&mut cur).unwrap();
  465. let slot_name = String::decode(&mut cur).unwrap();
  466. debug!(target: "req", "{:?}({}, {}, {})", cmd, node_id, sig_name, slot_name);
  467. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  468. let signal = node.get_signal(&sig_name).ok_or(Error::SignalNotFound)?;
  469. let slot_id = signal.lookup_slot_id(&slot_name).ok_or(Error::SlotNotFound)?;
  470. slot_id.encode(&mut reply).unwrap();
  471. */
  472. }
  473. Command::GetSlots => {
  474. /*
  475. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  476. let sig_name = String::decode(&mut cur).unwrap();
  477. debug!(target: "req", "{:?}({}, {})", cmd, node_id, sig_name);
  478. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  479. let signal = node.get_signal(&sig_name).ok_or(Error::SignalNotFound)?;
  480. let mut slots = vec![];
  481. for (slot_id, slot) in signal.get_slots() {
  482. slots.push((slot.name.clone(), slot_id));
  483. }
  484. slots.encode(&mut reply).unwrap();
  485. */
  486. }
  487. Command::GetMethods => {
  488. /*
  489. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  490. debug!(target: "req", "{:?}({})", cmd, node_id);
  491. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  492. let method_names: Vec<_> = node.methods.iter().map(|m| m.name.clone()).collect();
  493. method_names.encode(&mut reply).unwrap();
  494. */
  495. }
  496. Command::GetMethod => {
  497. /*
  498. let node_id = SceneNodeId::decode(&mut cur).unwrap();
  499. let method_name = String::decode(&mut cur).unwrap();
  500. debug!(target: "req", "{:?}({}, {})", cmd, node_id, method_name);
  501. let node = scene_graph.get_node(node_id).ok_or(Error::NodeNotFound)?;
  502. let method = node.get_method(&method_name).ok_or(Error::MethodNotFound)?;
  503. method.args.encode(&mut reply).unwrap();
  504. method.result.encode(&mut reply).unwrap();
  505. */
  506. }
  507. Command::CallMethod => {
  508. let node_path: ScenePath = String::decode(&mut cur).unwrap().parse()?;
  509. let method_name = String::decode(&mut cur).unwrap();
  510. let arg_data = Vec::<u8>::decode(&mut cur).unwrap();
  511. debug!(target: "req", "{cmd:?}({node_path}, {method_name}, ...)");
  512. let node =
  513. self.sg_root.clone().lookup_node(node_path).ok_or(Error::NodeNotFound)?;
  514. let result = node.call_method(&method_name, arg_data).await?;
  515. result.encode(&mut reply).unwrap();
  516. }
  517. }
  518. Ok(reply)
  519. }
  520. }