Fixes
parent: tbd commit: 25c3410
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 | use RsaPublicKey; |
17 | use Serialize; |
18 | use Value; |
19 | use |
20 | , | TcpStream
21 | , |
22 | ; |
23 | use ; |
24 | |
25 | use crate:: |
26 | , | AuthenticationTokenGranter
27 | , |
28 | , | wrap_forwarded
29 | , | InstanceConnections
30 | , | NetworkMessage
31 | ; |
32 | |
33 | use |
34 | , handshake_handle, | authentication_handle
35 | , user_handle, Connections, | repository_handle
36 | ; |
37 | |
38 | pub async |
39 | socket: , |
40 | connections: , |
41 | repository_backend: , |
42 | user_backend: , |
43 | auth_granter: , |
44 | addr: SocketAddr, |
45 | instance: impl , |
46 | instance_connections: , |
47 | |
48 | let connection_state = ConnectionState |
49 | socket: new, |
50 | connections, |
51 | repository_backend, |
52 | user_backend, |
53 | auth_granter, |
54 | addr, |
55 | instance: instance.to_owned, |
56 | handshaked: new, |
57 | cached_keys: default, |
58 | ; |
59 | |
60 | let mut handshaked = false; |
61 | |
62 | loop |
63 | let mut socket = connection_state.socket.lock .await; |
64 | let message = socket.next .await; |
65 | drop; |
66 | |
67 | match message |
68 | Some => |
69 | let payload = match message |
70 | => payload, | Binary
71 | => | Ping
72 | let mut socket = connection_state.socket.lock .await; |
73 | let _ = socket.send .await; |
74 | drop; |
75 | continue; |
76 | |
77 | => return, | Close
78 | _ => continue, |
79 | ; |
80 | |
81 | info! |
82 | "Received payload: {}", |
83 | unwrap | from_utf8 .
84 | ; |
85 | |
86 | let message = NetworkMessage; |
87 | |
88 | if !handshaked |
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 | // Forward request |
99 | info!; |
100 | let mut instance_connections = instance_connections.lock .await; |
101 | let pool = instance_connections.get_or_open .unwrap; |
102 | let pool_clone = pool.clone; |
103 | drop; |
104 | |
105 | let result = wrap_forwarded .await; |
106 | |
107 | let mut socket = connection_state.socket.lock .await; |
108 | let _ = socket.send .await; |
109 | |
110 | continue; |
111 | |
112 | |
113 | let message_type = &raw.message_type; |
114 | |
115 | info!; |
116 | |
117 | match authentication_handle .await |
118 | Err => |
119 | let _ = connection_state.send .await; |
120 | |
121 | Ok => continue, |
122 | Ok => |
123 | |
124 | |
125 | match repository_handle .await |
126 | Err => |
127 | let _ = connection_state.send .await; |
128 | |
129 | Ok => continue, |
130 | Ok => |
131 | |
132 | |
133 | match user_handle .await |
134 | Err => |
135 | let _ = connection_state.send .await; |
136 | |
137 | Ok => continue, |
138 | Ok => |
139 | |
140 | |
141 | match authentication_handle .await |
142 | Err => |
143 | let _ = connection_state.send .await; |
144 | |
145 | Ok => continue, |
146 | Ok => |
147 | |
148 | |
149 | error! |
150 | "Message completely unhandled: {}", |
151 | unwrap | from_utf8 .
152 | ; |
153 | |
154 | |
155 | Some => |
156 | error!; |
157 | return; |
158 | |
159 | _ => |
160 | info!; |
161 | continue; |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | socket: , |
170 | pub connections: , |
171 | pub repository_backend: , |
172 | pub user_backend: , |
173 | pub auth_granter: , |
174 | pub addr: SocketAddr, |
175 | pub instance: Instance, |
176 | pub handshaked: , |
177 | pub cached_keys: , |
178 | |
179 | |
180 | |
181 | pub async |
182 | let payload = to_string?; |
183 | info!; |
184 | self.socket |
185 | .lock |
186 | .await |
187 | .send |
188 | .await?; |
189 | |
190 | Ok |
191 | |
192 | |
193 |