Completely refactor project structure
parent: tbd commit: ae8ff44
1 | use |
2 | , | HashMap
3 | , | SocketAddr
4 | |
5 | , |
6 | Arc, |
7 | , |
8 | ; |
9 | |
10 | use Error; |
11 | use ; |
12 | use ; |
13 | use RsaPublicKey; |
14 | use Serialize; |
15 | use Value; |
16 | use |
17 | , | TcpStream
18 | , |
19 | ; |
20 | use ; |
21 | |
22 | use crate:: |
23 | , | AuthenticationTokenGranter
24 | , |
25 | , | NetworkMessage
26 | ; |
27 | |
28 | use |
29 | , handshake_handle, | authentication_handle
30 | , user_handle, Connections, | repository_handle
31 | ; |
32 | |
33 | pub async |
34 | socket: , |
35 | connections: , |
36 | repository_backend: , |
37 | user_backend: , |
38 | auth_granter: , |
39 | addr: SocketAddr, |
40 | instance: impl , |
41 | |
42 | let connection_state = ConnectionState |
43 | socket: new, |
44 | connections, |
45 | repository_backend, |
46 | user_backend, |
47 | auth_granter, |
48 | addr, |
49 | instance: instance.to_owned, |
50 | handshaked: new, |
51 | cached_keys: default, |
52 | ; |
53 | |
54 | let mut handshaked = false; |
55 | |
56 | loop |
57 | let mut socket = connection_state.socket.lock .await; |
58 | let message = socket.next .await; |
59 | drop; |
60 | |
61 | match message |
62 | Some => |
63 | let payload = match message |
64 | => payload, | Binary
65 | => | Ping
66 | let mut socket = connection_state.socket.lock .await; |
67 | let _ = socket.send .await; |
68 | drop; |
69 | continue; |
70 | |
71 | => return, | Close
72 | _ => continue, |
73 | ; |
74 | |
75 | let message = NetworkMessage; |
76 | |
77 | if !handshaked |
78 | if handshake_handle .await.is_ok |
79 | if connection_state.handshaked.load |
80 | handshaked = true; |
81 | |
82 | |
83 | else |
84 | let raw = .unwrap; |
85 | let message_type = raw.get .unwrap .as_str .unwrap; |
86 | |
87 | match authentication_handle .await |
88 | Err => |
89 | let _ = connection_state.send .await; |
90 | |
91 | Ok => continue, |
92 | Ok => |
93 | |
94 | |
95 | match repository_handle .await |
96 | Err => |
97 | let _ = connection_state.send .await; |
98 | |
99 | Ok => continue, |
100 | Ok => |
101 | |
102 | |
103 | match user_handle .await |
104 | Err => |
105 | let _ = connection_state.send .await; |
106 | |
107 | Ok => continue, |
108 | Ok => |
109 | |
110 | |
111 | match authentication_handle .await |
112 | Err => |
113 | let _ = connection_state.send .await; |
114 | |
115 | Ok => continue, |
116 | Ok => |
117 | |
118 | |
119 | error! |
120 | "Message completely unhandled: {}", |
121 | unwrap | from_utf8 .
122 | ; |
123 | |
124 | |
125 | Some => |
126 | error!; |
127 | return; |
128 | |
129 | _ => |
130 | info!; |
131 | continue; |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | socket: , |
140 | pub connections: , |
141 | pub repository_backend: , |
142 | pub user_backend: , |
143 | pub auth_granter: , |
144 | pub addr: SocketAddr, |
145 | pub instance: Instance, |
146 | pub handshaked: , |
147 | pub cached_keys: , |
148 | |
149 | |
150 | |
151 | pub async |
152 | let payload = to_string?; |
153 | info!; |
154 | self.socket |
155 | .lock |
156 | .await |
157 | .send |
158 | .await?; |
159 | |
160 | Ok |
161 | |
162 | |
163 |