Move user settings to user settings
parent: tbd commit: fd846f6
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 | , | NetworkMessage
34 | ; |
35 | |
36 | use |
37 | , handshake_handle, | authentication_handle
38 | , user_handle, Connections, | repository_handle
39 | ; |
40 | |
41 | pub async |
42 | socket: , |
43 | connections: , |
44 | repository_backend: , |
45 | user_backend: , |
46 | auth_granter: , |
47 | addr: SocketAddr, |
48 | instance: impl , |
49 | instance_connections: , |
50 | |
51 | let connection_state = ConnectionState |
52 | socket: new, |
53 | connections, |
54 | repository_backend, |
55 | user_backend, |
56 | auth_granter, |
57 | addr, |
58 | instance: instance.to_owned, |
59 | handshaked: new, |
60 | cached_keys: default, |
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 | |
84 | let message = NetworkMessage; |
85 | |
86 | if !handshaked |
87 | info!; |
88 | if handshake_handle .await.is_ok |
89 | if connection_state.handshaked.load |
90 | handshaked = true; |
91 | |
92 | |
93 | else |
94 | let raw = .unwrap; |
95 | |
96 | if let Some = &raw.target_instance |
97 | // Forward request |
98 | info!; |
99 | let mut instance_connections = instance_connections.lock .await; |
100 | let pool = instance_connections.get_or_open .unwrap; |
101 | let pool_clone = pool.clone; |
102 | drop; |
103 | |
104 | let result = wrap_forwarded .await; |
105 | |
106 | let mut socket = connection_state.socket.lock .await; |
107 | let _ = socket.send .await; |
108 | |
109 | continue; |
110 | |
111 | |
112 | let message_type = &raw.message_type; |
113 | |
114 | info!; |
115 | |
116 | match authentication_handle .await |
117 | Err => |
118 | let _ = connection_state |
119 | .send_raw |
120 | .await; |
121 | |
122 | Ok => continue, |
123 | Ok => |
124 | |
125 | |
126 | match repository_handle .await |
127 | Err => |
128 | let _ = connection_state |
129 | .send_raw |
130 | .await; |
131 | |
132 | Ok => continue, |
133 | Ok => |
134 | |
135 | |
136 | match user_handle .await |
137 | Err => |
138 | let _ = connection_state |
139 | .send_raw |
140 | .await; |
141 | |
142 | Ok => continue, |
143 | Ok => |
144 | |
145 | |
146 | match authentication_handle .await |
147 | Err => |
148 | let _ = connection_state |
149 | .send_raw |
150 | .await; |
151 | |
152 | Ok => continue, |
153 | Ok => |
154 | |
155 | |
156 | error! |
157 | "Message completely unhandled: {}", |
158 | unwrap | from_utf8 .
159 | ; |
160 | |
161 | |
162 | Some => |
163 | error!; |
164 | return; |
165 | |
166 | _ => |
167 | info!; |
168 | continue; |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | socket: , |
177 | pub connections: , |
178 | pub repository_backend: , |
179 | pub user_backend: , |
180 | pub auth_granter: , |
181 | pub addr: SocketAddr, |
182 | pub instance: Instance, |
183 | pub handshaked: , |
184 | pub cached_keys: , |
185 | |
186 | |
187 | |
188 | pub async |
189 | let payload = to_string?; |
190 | info!; |
191 | self.socket |
192 | .lock |
193 | .await |
194 | .send |
195 | .await?; |
196 | |
197 | Ok |
198 | |
199 | |
200 | pub async |
201 | let payload = to_string?; |
202 | info!; |
203 | self.socket |
204 | .lock |
205 | .await |
206 | .send |
207 | .await?; |
208 | |
209 | Ok |
210 | |
211 | |
212 |