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