Fixes
parent: tbd commit: b87f0a3
1 | use |
2 | , | SocketAddr
3 | , |
4 | ; |
5 | |
6 | use Error; |
7 | use ; |
8 | |
9 | use Instance; |
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 | loop |
64 | let mut socket = connection_state.socket.lock .await; |
65 | let message = socket.next .await; |
66 | drop; |
67 | |
68 | match message |
69 | Some => |
70 | let payload = match message |
71 | => payload, | Binary
72 | => | Ping
73 | let mut socket = connection_state.socket.lock .await; |
74 | let _ = socket.send .await; |
75 | drop; |
76 | continue; |
77 | |
78 | => return, | Close
79 | _ => continue, |
80 | ; |
81 | |
82 | let message: AuthenticatedPayload = deserialize .unwrap; |
83 | |
84 | let message: = message.into_message; |
85 | |
86 | let result = backend |
87 | .object_operation |
88 | .await; |
89 | |
90 | let mut socket = connection_state.socket.lock .await; |
91 | let _ = socket |
92 | .send |
93 | .await; |
94 | |
95 | info!; |
96 | drop; |
97 | |
98 | _ => |
99 | return; |
100 | |
101 | |
102 | |
103 | |
104 | // loop { |
105 | // let mut socket = connection_state.socket.lock().await; |
106 | // let message = socket.next().await; |
107 | // drop(socket); |
108 | |
109 | // match message { |
110 | // Some(Ok(message)) => { |
111 | // let payload = match message { |
112 | // Message::Binary(payload) => payload, |
113 | // Message::Ping(_) => { |
114 | // let mut socket = connection_state.socket.lock().await; |
115 | // let _ = socket.send(Message::Pong(vec![])).await; |
116 | // drop(socket); |
117 | // continue; |
118 | // } |
119 | // Message::Close(_) => return, |
120 | // _ => continue, |
121 | // }; |
122 | // info!("one payload"); |
123 | |
124 | // let message = NetworkMessage(payload.clone()); |
125 | |
126 | // if !handshaked { |
127 | // info!("im foo baring"); |
128 | // if handshake_handle(&message, &connection_state).await.is_ok() { |
129 | // if connection_state.handshaked.load(Ordering::SeqCst) { |
130 | // handshaked = true; |
131 | // } |
132 | // } |
133 | // } else { |
134 | // let raw = serde_json::from_slice::<AuthenticatedPayload>(&payload).unwrap(); |
135 | |
136 | // if let Some(target_instance) = &raw.target_instance { |
137 | // if connection_state.instance != *target_instance { |
138 | // // Forward request |
139 | // info!("Forwarding message to {}", target_instance.url); |
140 | // let mut instance_connections = instance_connections.lock().await; |
141 | // let pool = instance_connections.get_or_open(&target_instance).unwrap(); |
142 | // let pool_clone = pool.clone(); |
143 | // drop(pool); |
144 | |
145 | // let result = wrap_forwarded(&pool_clone, raw).await; |
146 | |
147 | // let mut socket = connection_state.socket.lock().await; |
148 | // let _ = socket.send(result).await; |
149 | |
150 | // continue; |
151 | // } |
152 | // } |
153 | |
154 | // let message_type = &raw.message_type; |
155 | |
156 | // info!("Handling message with type: {}", message_type); |
157 | |
158 | // match authentication_handle(message_type, &message, &connection_state).await { |
159 | // Err(e) => { |
160 | // let _ = connection_state |
161 | // .send_raw(ConnectionError(e.to_string())) |
162 | // .await; |
163 | // } |
164 | // Ok(true) => continue, |
165 | // Ok(false) => {} |
166 | // } |
167 | |
168 | // match repository_handle(message_type, &message, &connection_state).await { |
169 | // Err(e) => { |
170 | // let _ = connection_state |
171 | // .send_raw(ConnectionError(e.to_string())) |
172 | // .await; |
173 | // } |
174 | // Ok(true) => continue, |
175 | // Ok(false) => {} |
176 | // } |
177 | |
178 | // match user_handle(message_type, &message, &connection_state).await { |
179 | // Err(e) => { |
180 | // let _ = connection_state |
181 | // .send_raw(ConnectionError(e.to_string())) |
182 | // .await; |
183 | // } |
184 | // Ok(true) => continue, |
185 | // Ok(false) => {} |
186 | // } |
187 | |
188 | // match authentication_handle(message_type, &message, &connection_state).await { |
189 | // Err(e) => { |
190 | // let _ = connection_state |
191 | // .send_raw(ConnectionError(e.to_string())) |
192 | // .await; |
193 | // } |
194 | // Ok(true) => continue, |
195 | // Ok(false) => {} |
196 | // } |
197 | |
198 | // error!( |
199 | // "Message completely unhandled: {}", |
200 | // std::str::from_utf8(&payload).unwrap() |
201 | // ); |
202 | // } |
203 | // } |
204 | // Some(Err(e)) => { |
205 | // error!("Closing connection for {:?} for {}", e, addr); |
206 | // return; |
207 | // } |
208 | // _ => { |
209 | // info!("Unhandled"); |
210 | // continue; |
211 | // } |
212 | // } |
213 | // } |
214 | |
215 | |
216 | |
217 | |
218 | socket: , |
219 | pub connections: , |
220 | pub repository_backend: , |
221 | pub user_backend: , |
222 | pub auth_granter: , |
223 | pub settings_backend: , |
224 | pub addr: SocketAddr, |
225 | pub instance: Instance, |
226 | pub handshaked: , |
227 | pub key_cache: , |
228 | pub instance_connections: , |
229 | pub config: Table, |
230 | |
231 | |
232 | |
233 | pub async |
234 | let payload = to_string?; |
235 | info!; |
236 | self.socket |
237 | .lock |
238 | .await |
239 | .send |
240 | .await?; |
241 | |
242 | Ok |
243 | |
244 | |
245 | pub async |
246 | let payload = to_string?; |
247 | info!; |
248 | self.socket |
249 | .lock |
250 | .await |
251 | .send |
252 | .await?; |
253 | |
254 | Ok |
255 | |
256 | |
257 | pub async |
258 | let mut keys = self.key_cache.lock .await; |
259 | keys.get .await |
260 | |
261 | |
262 |