Change forwarding
parent: tbd commit: 2556801
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 | |
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 settings_backend: , |
182 | pub addr: SocketAddr, |
183 | pub instance: Instance, |
184 | pub handshaked: , |
185 | pub key_cache: , |
186 | pub instance_connections: , |
187 | pub config: Table, |
188 | |
189 | |
190 | |
191 | pub async |
192 | let payload = to_string?; |
193 | info!; |
194 | self.socket |
195 | .lock |
196 | .await |
197 | .send |
198 | .await?; |
199 | |
200 | Ok |
201 | |
202 | |
203 | pub async |
204 | let payload = to_string?; |
205 | info!; |
206 | self.socket |
207 | .lock |
208 | .await |
209 | .send |
210 | .await?; |
211 | |
212 | Ok |
213 | |
214 | |
215 | pub async |
216 | let mut keys = self.key_cache.lock .await; |
217 | keys.get .await |
218 | |
219 | |
220 |