Finish connection refactor!
parent: tbd commit: bd675cd
1 | use |
2 | , | SocketAddr
3 | |
4 | , |
5 | Arc, |
6 | , |
7 | ; |
8 | |
9 | use Error; |
10 | use ; |
11 | use Serialize; |
12 | use ; |
13 | use ; |
14 | |
15 | use crate:: |
16 | , | AuthenticationTokenGranter
17 | , |
18 | , | ConnectionError
19 | , | Listeners
20 | , |
21 | ; |
22 | |
23 | use |
24 | , connection_worker, handshake_handle, | authentication_handle
25 | , user_handle, Connections, | repository_handle
26 | ; |
27 | |
28 | pub async |
29 | mut socket: , |
30 | listeners: , |
31 | connections: , |
32 | repository_backend: , |
33 | user_backend: , |
34 | auth_granter: , |
35 | discovery_backend: , |
36 | addr: SocketAddr, |
37 | instance: impl , |
38 | |
39 | let mut connection_state = ConnectionState |
40 | socket: new, |
41 | listeners, |
42 | connections, |
43 | repository_backend, |
44 | user_backend, |
45 | auth_granter, |
46 | discovery_backend, |
47 | addr, |
48 | instance: instance.to_owned, |
49 | handshaked: new, |
50 | ; |
51 | |
52 | let mut handshaked = false; |
53 | |
54 | loop |
55 | let mut socket = connection_state.socket.lock .await; |
56 | let message = socket.next .await; |
57 | drop; |
58 | |
59 | match message |
60 | Some => |
61 | let payload = match message |
62 | => payload, | Binary
63 | => | Ping
64 | let mut socket = connection_state.socket.lock .await; |
65 | socket.send .await; |
66 | drop; |
67 | continue; |
68 | |
69 | => return, | Close
70 | _ => continue, |
71 | ; |
72 | |
73 | let message = NetworkMessage; |
74 | |
75 | if !handshaked |
76 | if handshake_handle .await.is_ok |
77 | if connection_state.handshaked.load |
78 | handshaked = true; |
79 | |
80 | |
81 | else |
82 | if authentication_handle |
83 | .await |
84 | .is_ok |
85 | |
86 | continue; |
87 | else if repository_handle .await.is_ok |
88 | continue; |
89 | else if user_handle .await.is_ok |
90 | continue; |
91 | else |
92 | error!; |
93 | continue; |
94 | |
95 | |
96 | |
97 | _ => |
98 | error!; |
99 | return; |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | socket: , |
108 | pub listeners: , |
109 | pub connections: , |
110 | pub repository_backend: , |
111 | pub user_backend: , |
112 | pub auth_granter: , |
113 | pub discovery_backend: , |
114 | pub addr: SocketAddr, |
115 | pub instance: Instance, |
116 | pub handshaked: , |
117 | |
118 | |
119 | |
120 | pub async |
121 | self.socket |
122 | .lock |
123 | .await |
124 | .send |
125 | .await?; |
126 | |
127 | Ok |
128 | |
129 | |
130 |