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