Refactor handshake messages
parent: tbd commit: 6c50283
1 | use ; |
2 | |
3 | use Error; |
4 | use Version; |
5 | |
6 | use crate:: |
7 | , | ConnectionError
8 | , |
9 | , |
10 | validate_version, |
11 | ; |
12 | |
13 | use ; |
14 | |
15 | pub async |
16 | message: &NetworkMessage, |
17 | state: &ConnectionState, |
18 | |
19 | if initiate_handshake |
20 | .handle_message |
21 | .await |
22 | .is_ok |
23 | |
24 | Ok |
25 | else if handshake_response |
26 | .handle_message |
27 | .await |
28 | .is_ok |
29 | |
30 | Ok |
31 | else if handshake_finalize |
32 | .handle_message |
33 | .await |
34 | .is_ok |
35 | |
36 | Ok |
37 | else |
38 | Err |
39 | |
40 | |
41 | |
42 | async |
43 | Message | : ,
44 | State | : ,
45 | _instance: AuthenticatedInstance, |
46 | |
47 | if !validate_version |
48 | error! |
49 | "Version compatibility failure! Our Version: {}, Their Version: {}", |
50 | unwrap, | from_str .
51 | initiation.version |
52 | ; |
53 | |
54 | connection_state |
55 | .send |
56 | .await |
57 | .map_err?; |
58 | |
59 | Ok |
60 | else |
61 | connection_state |
62 | .send |
63 | .await |
64 | .map_err?; |
65 | |
66 | Ok |
67 | |
68 | |
69 | |
70 | async |
71 | Message | : ,
72 | State | : ,
73 | _instance: AuthenticatedInstance, |
74 | |
75 | if !validate_version |
76 | error! |
77 | "Version compatibility failure! Our Version: {}, Their Version: {}", |
78 | unwrap, | from_str .
79 | response.version |
80 | ; |
81 | |
82 | connection_state |
83 | .send |
84 | .await |
85 | .map_err?; |
86 | |
87 | Ok |
88 | else |
89 | connection_state |
90 | .send |
91 | .await |
92 | .map_err?; |
93 | |
94 | Ok |
95 | |
96 | |
97 | |
98 | async |
99 | Message | : ,
100 | State | : ,
101 | _instance: AuthenticatedInstance, |
102 | |
103 | if !finalize.success |
104 | error!; |
105 | return Err; |
106 | else |
107 | connection_state.handshaked.store; |
108 | |
109 | connection_state |
110 | .send |
111 | .await |
112 | .map_err?; |
113 | |
114 | Ok |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | VersionMismatch, |
122 | |
123 | SendError, |
124 | |
125 | Other, |
126 | |
127 |