Giterated stack changeover, refactor still incomplete
parent: tbd commit: 8d40dfe
1 | use |
2 | , | SocketAddr
3 | , |
4 | ; |
5 | |
6 | use Error; |
7 | use ; |
8 | |
9 | use ; |
10 | |
11 | use ObjectBackend; |
12 | |
13 | use |
14 | , GiteratedMessage, AnyObject, | AuthenticatedPayload
15 | , | AnyOperation
16 | ; |
17 | use Serialize; |
18 | |
19 | use ; |
20 | use ; |
21 | use Table; |
22 | |
23 | use crate:: |
24 | , | AuthenticationTokenGranter
25 | , |
26 | , | DatabaseBackend
27 | , | InstanceConnections
28 | , | PublicKeyCache
29 | ; |
30 | |
31 | use Connections; |
32 | |
33 | pub async |
34 | socket: , |
35 | connections: , |
36 | repository_backend: , |
37 | user_backend: , |
38 | auth_granter: , |
39 | settings_backend: , |
40 | addr: SocketAddr, |
41 | instance: impl , |
42 | instance_connections: , |
43 | config: Table, |
44 | backend: DatabaseBackend, |
45 | |
46 | let connection_state = ConnectionState |
47 | socket: new, |
48 | connections, |
49 | repository_backend, |
50 | user_backend, |
51 | auth_granter, |
52 | settings_backend, |
53 | addr, |
54 | instance: instance.to_owned, |
55 | handshaked: new, |
56 | key_cache: default, |
57 | instance_connections: instance_connections.clone, |
58 | config, |
59 | ; |
60 | |
61 | let _handshaked = false; |
62 | |
63 | let backend = backend.into_backend; |
64 | |
65 | loop |
66 | let mut socket = connection_state.socket.lock .await; |
67 | let message = socket.next .await; |
68 | drop; |
69 | |
70 | match message |
71 | Some => |
72 | let payload = match message |
73 | => payload, | Binary
74 | => | Ping
75 | let mut socket = connection_state.socket.lock .await; |
76 | let _ = socket.send .await; |
77 | drop; |
78 | continue; |
79 | |
80 | => return, | Close
81 | _ => continue, |
82 | ; |
83 | |
84 | let message: AuthenticatedPayload = deserialize .unwrap; |
85 | |
86 | let message: = message.into_message; |
87 | |
88 | let result = backend |
89 | .object_operation |
90 | .await; |
91 | |
92 | // Map result to Vec<u8> on both |
93 | let result = match result |
94 | Ok => Ok, |
95 | Err => Err |
96 | => | Operation
97 | Operation |
98 | |
99 | => Internal, | Internal
100 | => Unhandled, | Unhandled
101 | , |
102 | ; |
103 | |
104 | let mut socket = connection_state.socket.lock .await; |
105 | let _ = socket |
106 | .send |
107 | .await; |
108 | |
109 | drop; |
110 | |
111 | _ => |
112 | return; |
113 | |
114 | |
115 | |
116 | |
117 | // loop { |
118 | // let mut socket = connection_state.socket.lock().await; |
119 | // let message = socket.next().await; |
120 | // drop(socket); |
121 | |
122 | // match message { |
123 | // Some(Ok(message)) => { |
124 | // let payload = match message { |
125 | // Message::Binary(payload) => payload, |
126 | // Message::Ping(_) => { |
127 | // let mut socket = connection_state.socket.lock().await; |
128 | // let _ = socket.send(Message::Pong(vec![])).await; |
129 | // drop(socket); |
130 | // continue; |
131 | // } |
132 | // Message::Close(_) => return, |
133 | // _ => continue, |
134 | // }; |
135 | |
136 | // let message = NetworkMessage(payload.clone()); |
137 | |
138 | // if !handshaked { |
139 | // if handshake_handle(&message, &connection_state).await.is_ok() { |
140 | // if connection_state.handshaked.load(Ordering::SeqCst) { |
141 | // handshaked = true; |
142 | // } |
143 | // } |
144 | // } else { |
145 | // let raw = serde_json::from_slice::<AuthenticatedPayload>(&payload).unwrap(); |
146 | |
147 | // if let Some(target_instance) = &raw.target_instance { |
148 | // if connection_state.instance != *target_instance { |
149 | // // Forward request |
150 | // info!("Forwarding message to {}", target_instance.url); |
151 | // let mut instance_connections = instance_connections.lock().await; |
152 | // let pool = instance_connections.get_or_open(&target_instance).unwrap(); |
153 | // let pool_clone = pool.clone(); |
154 | // drop(pool); |
155 | |
156 | // let result = wrap_forwarded(&pool_clone, raw).await; |
157 | |
158 | // let mut socket = connection_state.socket.lock().await; |
159 | // let _ = socket.send(result).await; |
160 | |
161 | // continue; |
162 | // } |
163 | // } |
164 | |
165 | // let message_type = &raw.message_type; |
166 | |
167 | // match authentication_handle(message_type, &message, &connection_state).await { |
168 | // Err(e) => { |
169 | // let _ = connection_state |
170 | // .send_raw(ConnectionError(e.to_string())) |
171 | // .await; |
172 | // } |
173 | // Ok(true) => continue, |
174 | // Ok(false) => {} |
175 | // } |
176 | |
177 | // match repository_handle(message_type, &message, &connection_state).await { |
178 | // Err(e) => { |
179 | // let _ = connection_state |
180 | // .send_raw(ConnectionError(e.to_string())) |
181 | // .await; |
182 | // } |
183 | // Ok(true) => continue, |
184 | // Ok(false) => {} |
185 | // } |
186 | |
187 | // match user_handle(message_type, &message, &connection_state).await { |
188 | // Err(e) => { |
189 | // let _ = connection_state |
190 | // .send_raw(ConnectionError(e.to_string())) |
191 | // .await; |
192 | // } |
193 | // Ok(true) => continue, |
194 | // Ok(false) => {} |
195 | // } |
196 | |
197 | // match authentication_handle(message_type, &message, &connection_state).await { |
198 | // Err(e) => { |
199 | // let _ = connection_state |
200 | // .send_raw(ConnectionError(e.to_string())) |
201 | // .await; |
202 | // } |
203 | // Ok(true) => continue, |
204 | // Ok(false) => {} |
205 | // } |
206 | |
207 | // error!( |
208 | // "Message completely unhandled: {}", |
209 | // std::str::from_utf8(&payload).unwrap() |
210 | // ); |
211 | // } |
212 | // } |
213 | // Some(Err(e)) => { |
214 | // error!("Closing connection for {:?} for {}", e, addr); |
215 | // return; |
216 | // } |
217 | // _ => { |
218 | // continue; |
219 | // } |
220 | // } |
221 | // } |
222 | |
223 | |
224 | |
225 | |
226 | socket: , |
227 | pub connections: , |
228 | pub repository_backend: , |
229 | pub user_backend: , |
230 | pub auth_granter: , |
231 | pub settings_backend: , |
232 | pub addr: SocketAddr, |
233 | pub instance: Instance, |
234 | pub handshaked: , |
235 | pub key_cache: , |
236 | pub instance_connections: , |
237 | pub config: Table, |
238 | |
239 | |
240 | |
241 | pub async |
242 | let payload = to_string?; |
243 | self.socket |
244 | .lock |
245 | .await |
246 | .send |
247 | .await?; |
248 | |
249 | Ok |
250 | |
251 | |
252 | pub async |
253 | let payload = to_string?; |
254 | self.socket |
255 | .lock |
256 | .await |
257 | .send |
258 | .await?; |
259 | |
260 | Ok |
261 | |
262 | |
263 | pub async |
264 | let mut keys = self.key_cache.lock .await; |
265 | keys.get .await |
266 | |
267 | |
268 |