Update for auth
parent: tbd commit: 3ef0383
1 | use |
2 | , | SocketAddr
3 | |
4 | , |
5 | Arc, |
6 | , |
7 | ; |
8 | |
9 | use Error; |
10 | use ; |
11 | use |
12 | , | ConnectionError
13 | , |
14 | ; |
15 | |
16 | use Serialize; |
17 | |
18 | use ; |
19 | use ; |
20 | use Table; |
21 | |
22 | use crate:: |
23 | , | AuthenticationTokenGranter
24 | , |
25 | , | wrap_forwarded
26 | , | InstanceConnections
27 | , | PublicKeyCache
28 | , | NetworkMessage
29 | ; |
30 | |
31 | use |
32 | , handshake_handle, | authentication_handle
33 | , user_handle, Connections, | repository_handle
34 | ; |
35 | |
36 | pub async |
37 | socket: , |
38 | connections: , |
39 | repository_backend: , |
40 | user_backend: , |
41 | auth_granter: , |
42 | settings_backend: , |
43 | addr: SocketAddr, |
44 | instance: impl , |
45 | instance_connections: , |
46 | config: Table, |
47 | |
48 | let connection_state = ConnectionState |
49 | socket: new, |
50 | connections, |
51 | repository_backend, |
52 | user_backend, |
53 | auth_granter, |
54 | settings_backend, |
55 | addr, |
56 | instance: instance.to_owned, |
57 | handshaked: new, |
58 | key_cache: default, |
59 | instance_connections: instance_connections.clone, |
60 | config, |
61 | ; |
62 | |
63 | let mut handshaked = false; |
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 | info!; |
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 | if connection_state.instance != *target_instance |
99 | // Forward request |
100 | info!; |
101 | let mut instance_connections = instance_connections.lock .await; |
102 | let pool = instance_connections.get_or_open .unwrap; |
103 | let pool_clone = pool.clone; |
104 | drop; |
105 | |
106 | let result = wrap_forwarded .await; |
107 | |
108 | let mut socket = connection_state.socket.lock .await; |
109 | let _ = socket.send .await; |
110 | |
111 | continue; |
112 | |
113 | |
114 | |
115 | let message_type = &raw.message_type; |
116 | |
117 | info!; |
118 | |
119 | match authentication_handle .await |
120 | Err => |
121 | let _ = connection_state |
122 | .send_raw |
123 | .await; |
124 | |
125 | Ok => continue, |
126 | Ok => |
127 | |
128 | |
129 | match repository_handle .await |
130 | Err => |
131 | let _ = connection_state |
132 | .send_raw |
133 | .await; |
134 | |
135 | Ok => continue, |
136 | Ok => |
137 | |
138 | |
139 | match user_handle .await |
140 | Err => |
141 | let _ = connection_state |
142 | .send_raw |
143 | .await; |
144 | |
145 | Ok => continue, |
146 | Ok => |
147 | |
148 | |
149 | match authentication_handle .await |
150 | Err => |
151 | let _ = connection_state |
152 | .send_raw |
153 | .await; |
154 | |
155 | Ok => continue, |
156 | Ok => |
157 | |
158 | |
159 | error! |
160 | "Message completely unhandled: {}", |
161 | unwrap | from_utf8 .
162 | ; |
163 | |
164 | |
165 | Some => |
166 | error!; |
167 | return; |
168 | |
169 | _ => |
170 | info!; |
171 | continue; |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | socket: , |
180 | pub connections: , |
181 | pub repository_backend: , |
182 | pub user_backend: , |
183 | pub auth_granter: , |
184 | pub settings_backend: , |
185 | pub addr: SocketAddr, |
186 | pub instance: Instance, |
187 | pub handshaked: , |
188 | pub key_cache: , |
189 | pub instance_connections: , |
190 | pub config: Table, |
191 | |
192 | |
193 | |
194 | pub async |
195 | let payload = to_string?; |
196 | info!; |
197 | self.socket |
198 | .lock |
199 | .await |
200 | .send |
201 | .await?; |
202 | |
203 | Ok |
204 | |
205 | |
206 | pub async |
207 | let payload = to_string?; |
208 | info!; |
209 | self.socket |
210 | .lock |
211 | .await |
212 | .send |
213 | .await?; |
214 | |
215 | Ok |
216 | |
217 | |
218 | pub async |
219 | let mut keys = self.key_cache.lock .await; |
220 | keys.get .await |
221 | |
222 | |
223 |