Add more aggressive key caching
parent: tbd commit: 5bc92ad
1 | use |
2 | , | HashMap
3 | , | SocketAddr
4 | |
5 | , |
6 | Arc, |
7 | , |
8 | ; |
9 | |
10 | use Error; |
11 | use ; |
12 | use |
13 | , | ConnectionError
14 | |
15 | , |
16 | , | Instance
17 | , |
18 | ; |
19 | use RsaPublicKey; |
20 | use Serialize; |
21 | use Value; |
22 | use |
23 | , | TcpStream
24 | , |
25 | ; |
26 | use ; |
27 | |
28 | use crate:: |
29 | , | AuthenticationTokenGranter
30 | , |
31 | , | wrap_forwarded
32 | , | InstanceConnections
33 | , | PublicKeyCache
34 | , | NetworkMessage
35 | ; |
36 | |
37 | use |
38 | , handshake_handle, | authentication_handle
39 | , user_handle, Connections, | repository_handle
40 | ; |
41 | |
42 | pub async |
43 | socket: , |
44 | connections: , |
45 | repository_backend: , |
46 | user_backend: , |
47 | auth_granter: , |
48 | addr: SocketAddr, |
49 | instance: impl , |
50 | instance_connections: , |
51 | |
52 | let connection_state = ConnectionState |
53 | socket: new, |
54 | connections, |
55 | repository_backend, |
56 | user_backend, |
57 | auth_granter, |
58 | addr, |
59 | instance: instance.to_owned, |
60 | handshaked: new, |
61 | key_cache: default, |
62 | ; |
63 | |
64 | let mut handshaked = false; |
65 | |
66 | loop |
67 | let mut socket = connection_state.socket.lock .await; |
68 | let message = socket.next .await; |
69 | drop; |
70 | |
71 | match message |
72 | Some => |
73 | let payload = match message |
74 | => payload, | Binary
75 | => | Ping
76 | let mut socket = connection_state.socket.lock .await; |
77 | let _ = socket.send .await; |
78 | drop; |
79 | continue; |
80 | |
81 | => return, | Close
82 | _ => continue, |
83 | ; |
84 | |
85 | let message = NetworkMessage; |
86 | |
87 | if !handshaked |
88 | info!; |
89 | if handshake_handle .await.is_ok |
90 | if connection_state.handshaked.load |
91 | handshaked = true; |
92 | |
93 | |
94 | else |
95 | let raw = .unwrap; |
96 | |
97 | if let Some = &raw.target_instance |
98 | // Forward request |
99 | info!; |
100 | let mut instance_connections = instance_connections.lock .await; |
101 | let pool = instance_connections.get_or_open .unwrap; |
102 | let pool_clone = pool.clone; |
103 | drop; |
104 | |
105 | let result = wrap_forwarded .await; |
106 | |
107 | let mut socket = connection_state.socket.lock .await; |
108 | let _ = socket.send .await; |
109 | |
110 | continue; |
111 | |
112 | |
113 | let message_type = &raw.message_type; |
114 | |
115 | info!; |
116 | |
117 | match authentication_handle .await |
118 | Err => |
119 | let _ = connection_state |
120 | .send_raw |
121 | .await; |
122 | |
123 | Ok => continue, |
124 | Ok => |
125 | |
126 | |
127 | match repository_handle .await |
128 | Err => |
129 | let _ = connection_state |
130 | .send_raw |
131 | .await; |
132 | |
133 | Ok => continue, |
134 | Ok => |
135 | |
136 | |
137 | match user_handle .await |
138 | Err => |
139 | let _ = connection_state |
140 | .send_raw |
141 | .await; |
142 | |
143 | Ok => continue, |
144 | Ok => |
145 | |
146 | |
147 | match authentication_handle .await |
148 | Err => |
149 | let _ = connection_state |
150 | .send_raw |
151 | .await; |
152 | |
153 | Ok => continue, |
154 | Ok => |
155 | |
156 | |
157 | error! |
158 | "Message completely unhandled: {}", |
159 | unwrap | from_utf8 .
160 | ; |
161 | |
162 | |
163 | Some => |
164 | error!; |
165 | return; |
166 | |
167 | _ => |
168 | info!; |
169 | continue; |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | socket: , |
178 | pub connections: , |
179 | pub repository_backend: , |
180 | pub user_backend: , |
181 | pub auth_granter: , |
182 | pub addr: SocketAddr, |
183 | pub instance: Instance, |
184 | pub handshaked: , |
185 | pub key_cache: , |
186 | |
187 | |
188 | |
189 | pub async |
190 | let payload = to_string?; |
191 | info!; |
192 | self.socket |
193 | .lock |
194 | .await |
195 | .send |
196 | .await?; |
197 | |
198 | Ok |
199 | |
200 | |
201 | pub async |
202 | let payload = to_string?; |
203 | info!; |
204 | self.socket |
205 | .lock |
206 | .await |
207 | .send |
208 | .await?; |
209 | |
210 | Ok |
211 | |
212 | |
213 | pub async |
214 | let mut keys = self.key_cache.lock .await; |
215 | keys.get .await |
216 | |
217 | |
218 |