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
use libp2p::PeerId;
use state::Storage;
use std::collections::VecDeque;
use std::sync::RwLock;
pub static USERREQUESTER: Storage<RwLock<UserRequester>> = Storage::new();
pub static USERRESPONSER: Storage<RwLock<UserResponser>> = Storage::new();
pub struct UserRequest {
pub neighbour_id: PeerId,
pub user_ids: Vec<Vec<u8>>,
}
pub struct UserRequester {
pub to_send: VecDeque<UserRequest>,
}
impl UserRequester {
pub fn init() {
let user_requester = UserRequester {
to_send: VecDeque::new(),
};
USERREQUESTER.set(RwLock::new(user_requester));
}
pub fn add(neighbour_id: &PeerId, user_ids: &Vec<Vec<u8>>) {
let msg = UserRequest {
neighbour_id: neighbour_id.clone(),
user_ids: user_ids.clone(),
};
let mut user_requester = USERREQUESTER.get().write().unwrap();
user_requester.to_send.push_back(msg);
}
}
pub struct UserResponse {
pub neighbour_id: PeerId,
pub users: super::router_net_proto::UserInfoTable,
}
pub struct UserResponser {
pub to_send: VecDeque<UserResponse>,
}
impl UserResponser {
pub fn init() {
let user_responser = UserResponser {
to_send: VecDeque::new(),
};
USERRESPONSER.set(RwLock::new(user_responser));
}
pub fn add(neighbour_id: &PeerId, table: &super::router_net_proto::UserInfoTable) {
let msg = UserResponse {
neighbour_id: neighbour_id.clone(),
users: table.clone(),
};
let mut user_responser = USERRESPONSER.get().write().unwrap();
user_responser.to_send.push_back(msg);
}
}