1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_util::codec::Framed;
use blather::Telegram;
use crate::err::Error;
use crate::types;
#[derive(Debug)]
pub struct DDLinkInfo {
pub engine: String,
pub protocol: types::node::ddlnk::Protocol,
pub protimpl: types::node::ddlnk::ProtImpl
}
#[derive(Debug)]
pub struct NodeInfo {
pub version: String,
pub os_name: String,
pub nodetype: types::node::Type,
pub ddlnk: DDLinkInfo
}
pub async fn get_nodeinfo<T: AsyncRead + AsyncWrite + Unpin>(
conn: &mut Framed<T, blather::Codec>
) -> Result<NodeInfo, Error> {
let mut tg = Telegram::new();
tg.set_topic("GetNodeInfo")?;
let params = crate::sendrecv(conn, &tg).await?;
let nodetype = params.get_str("ddmw.node").map_or_else(
|| Err(Error::miss_data("ddmw.node not found")),
|s| s.parse::<types::node::Type>()
)?;
let version = params.get_str("ddmw.version").map_or_else(
|| Err(Error::miss_data("ddmw.version not found")),
|s| Ok(s.to_string())
)?;
let os_name = params.get_str("os.name").map_or_else(
|| Err(Error::miss_data("os.name not found")),
|s| Ok(s.to_string())
)?;
let engine = params.get_str("ddmw.ddlnk.engine").map_or_else(
|| Err(Error::miss_data("ddmw.ddlnk.engine not found")),
|s| Ok(s.to_string())
)?;
let protocol = params.get_str("ddmw.ddlink.protocol").map_or_else(
|| Err(Error::miss_data("ddmw.ddlink.protocol not found")),
|s| s.parse::<types::node::ddlnk::Protocol>()
)?;
let protimpl = params.get_str("ddmw.ddlink.protimpl").map_or_else(
|| Err(Error::miss_data("ddmw.ddlink.protimpl not found")),
|s| s.parse::<types::node::ddlnk::ProtImpl>()
)?;
Ok(NodeInfo {
version,
os_name,
nodetype,
ddlnk: DDLinkInfo {
engine,
protocol,
protimpl
}
})
}