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
use prost::Message;
use super::Rpc;
use crate::utilities::filelogger::FileLogger;
use crate::storage::Storage;
use crate::storage::configuration::Configuration;
pub mod proto { include!("qaul.rpc.debug.rs"); }
pub struct Debug {
}
impl Debug {
pub fn rpc(data: Vec<u8>, _user_id: Vec<u8>) {
match proto::Debug::decode(&data[..]) {
Ok(debug) => {
match debug.message {
Some(proto::debug::Message::HeartbeatRequest(_heartbeat_request)) => {
let proto_message = proto::Debug {
message: Some(
proto::debug::Message::HeartbeatResponse(proto::HeartbeatResponse {})
),
};
let mut buf = Vec::with_capacity(proto_message.encoded_len());
proto_message.encode(&mut buf).expect("Vec<u8> provides capacity as needed");
Rpc::send_message(buf, crate::rpc::proto::Modules::Debug.into(), "".to_string(), Vec::new() );
},
Some(proto::debug::Message::Panic(_panic)) => {
log::error!("Libqaul will panic");
panic!("Libqaul panics for debugging reasons");
},
Some(proto::debug::Message::LogToFile(log_to_file)) => {
if log_to_file.enable {
FileLogger::enable(true);
if Configuration::get_debug_log() == false{
Configuration::enable_debug_log(true);
Configuration::save();
log::error!("starting debug log..");
}
}else {
if Configuration::get_debug_log() == true{
Configuration::enable_debug_log(false);
Configuration::save();
log::error!("stop debug log..");
}
FileLogger::enable(false);
}
},
Some(proto::debug::Message::StoragePathRequest(_storage_path_request)) => {
let path = Storage::get_path();
let proto_message = proto::Debug {
message: Some(
proto::debug::Message::StoragePathResponse(proto::StoragePathResponse {storage_path: path})
),
};
let mut buf = Vec::with_capacity(proto_message.encoded_len());
proto_message.encode(&mut buf).expect("Vec<u8> provides capacity as needed");
Rpc::send_message(buf, crate::rpc::proto::Modules::Debug.into(), "".to_string(), Vec::new() );
},
_ => {
log::error!("Unhandled RPC Debug Message");
},
}
},
Err(e) => {
log::error!("{:?}", e);
},
}
}
}