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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use libqaul;
use prost::Message;
pub mod proto {
include!("../../../libqaul/src/rpc/protobuf_generated/rust/qaul.rpc.rs");
}
pub struct Rpc {}
impl Rpc {
pub fn send_message(data: Vec<u8>, module: i32, request_id: String) {
let my_user_id = super::user_accounts::UserAccounts::get_user_id();
if my_user_id == None {
if module == proto::Modules::Node as i32 {
println!("Operation not permitted");
println!("No user account set yet");
println!("Please create a user account");
println!("");
println!(" account create {{Your User Name}}");
println!("");
return;
}
}
let user_id;
if let Some(data) = my_user_id {
user_id = data;
} else {
user_id = Vec::new();
}
let proto_message = proto::QaulRpc {
module,
request_id,
user_id,
data,
};
let mut buf = Vec::with_capacity(proto_message.encoded_len());
proto_message
.encode(&mut buf)
.expect("Vec<u8> provides capacity as needed");
libqaul::api::send_rpc(buf);
}
pub fn received_message(data: Vec<u8>) {
match proto::QaulRpc::decode(&data[..]) {
Ok(message) => {
log::trace!("qaul rpc message received");
match proto::Modules::from_i32(message.module) {
Some(proto::Modules::Node) => {
super::node::Node::rpc(message.data);
}
Some(proto::Modules::Rpc) => {
}
Some(proto::Modules::Useraccounts) => {
super::user_accounts::UserAccounts::rpc(message.data);
}
Some(proto::Modules::Users) => {
super::users::Users::rpc(message.data);
}
Some(proto::Modules::Router) => {
super::router::Router::rpc(message.data);
}
Some(proto::Modules::Feed) => {
super::feed::Feed::rpc(message.data);
}
Some(proto::Modules::Chat) => {
super::chat::Chat::rpc(message.data);
}
Some(proto::Modules::Connections) => {
super::connections::Connections::rpc(message.data);
}
Some(proto::Modules::Ble) => {
super::ble::Ble::rpc(message.data);
}
Some(proto::Modules::Debug) => {
super::debug::Debug::rpc(message.data);
}
Some(proto::Modules::Chatfile) => {
super::chatfile::ChatFile::rpc(message.data);
}
Some(proto::Modules::Group) => {
super::group::Group::rpc(message.data);
}
Some(proto::Modules::Rtc) => {
super::rtc::Rtc::rpc(message.data);
}
Some(proto::Modules::Dtn) => {
super::dtn::Dtn::rpc(message.data);
}
Some(proto::Modules::None) => {}
None => {}
}
}
Err(error) => {
log::error!("{:?}", error);
}
}
}
}