Add repository settings
parent: tbd commit: f8eaf38
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 | |
21 | use crate:: |
22 | , | AuthenticationTokenGranter
23 | , |
24 | , | wrap_forwarded
25 | , | InstanceConnections
26 | , | PublicKeyCache
27 | , | NetworkMessage
28 | ; |
29 | |
30 | use |
31 | , handshake_handle, | authentication_handle
32 | , user_handle, Connections, | repository_handle
33 | ; |
34 | |
35 | pub async |
36 | socket: , |
37 | connections: , |
38 | repository_backend: , |
39 | user_backend: , |
40 | auth_granter: , |
41 | settings_backend: , |
42 | addr: SocketAddr, |
43 | instance: impl , |
44 | instance_connections: , |
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 | ; |
58 | |
59 | let mut handshaked = false; |
60 | |
61 | loop |
62 | let mut socket = connection_state.socket.lock .await; |
63 | let message = socket.next .await; |
64 | drop; |
65 | |
66 | match message |
67 | Some => |
68 | let payload = match message |
69 | => payload, | Binary
70 | => | Ping
71 | let mut socket = connection_state.socket.lock .await; |
72 | let _ = socket.send .await; |
73 | drop; |
74 | continue; |
75 | |
76 | => return, | Close
77 | _ => continue, |
78 | ; |
79 | |
80 | let message = NetworkMessage; |
81 | |
82 | if !handshaked |
83 | info!; |
84 | if handshake_handle .await.is_ok |
85 | if connection_state.handshaked.load |
86 | handshaked = true; |
87 | |
88 | |
89 | else |
90 | let raw = .unwrap; |
91 | |
92 | if let Some = &raw.target_instance |
93 | // Forward request |
94 | info!; |
95 | let mut instance_connections = instance_connections.lock .await; |
96 | let pool = instance_connections.get_or_open .unwrap; |
97 | let pool_clone = pool.clone; |
98 | drop; |
99 | |
100 | let result = wrap_forwarded .await; |
101 | |
102 | let mut socket = connection_state.socket.lock .await; |
103 | let _ = socket.send .await; |
104 | |
105 | continue; |
106 | |
107 | |
108 | let message_type = &raw.message_type; |
109 | |
110 | info!; |
111 | |
112 | match authentication_handle .await |
113 | Err => |
114 | let _ = connection_state |
115 | .send_raw |
116 | .await; |
117 | |
118 | Ok => continue, |
119 | Ok => |
120 | |
121 | |
122 | match repository_handle .await |
123 | Err => |
124 | let _ = connection_state |
125 | .send_raw |
126 | .await; |
127 | |
128 | Ok => continue, |
129 | Ok => |
130 | |
131 | |
132 | match user_handle .await |
133 | Err => |
134 | let _ = connection_state |
135 | .send_raw |
136 | .await; |
137 | |
138 | Ok => continue, |
139 | Ok => |
140 | |
141 | |
142 | match authentication_handle .await |
143 | Err => |
144 | let _ = connection_state |
145 | .send_raw |
146 | .await; |
147 | |
148 | Ok => continue, |
149 | Ok => |
150 | |
151 | |
152 | error! |
153 | "Message completely unhandled: {}", |
154 | unwrap | from_utf8 .
155 | ; |
156 | |
157 | |
158 | Some => |
159 | error!; |
160 | return; |
161 | |
162 | _ => |
163 | info!; |
164 | continue; |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | socket: , |
173 | pub connections: , |
174 | pub repository_backend: , |
175 | pub user_backend: , |
176 | pub auth_granter: , |
177 | pub settings_backend: , |
178 | pub addr: SocketAddr, |
179 | pub instance: Instance, |
180 | pub handshaked: , |
181 | pub key_cache: , |
182 | |
183 | |
184 | |
185 | pub async |
186 | let payload = to_string?; |
187 | info!; |
188 | self.socket |
189 | .lock |
190 | .await |
191 | .send |
192 | .await?; |
193 | |
194 | Ok |
195 | |
196 | |
197 | pub async |
198 | let payload = to_string?; |
199 | info!; |
200 | self.socket |
201 | .lock |
202 | .await |
203 | .send |
204 | .await?; |
205 | |
206 | Ok |
207 | |
208 | |
209 | pub async |
210 | let mut keys = self.key_cache.lock .await; |
211 | keys.get .await |
212 | |
213 | |
214 |