Fix authenticated endpoints
parent: tbd commit: 1400b06
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 | HandshakeMessage | : ,
46 | State | : ,
47 | |
48 | info!; |
49 | connection_state |
50 | .send |
51 | identity: connection_state.instance.clone, |
52 | version: version, |
53 | |
54 | .await |
55 | .map_err?; |
56 | |
57 | Ok |
58 | // if !validate_version(&initiation.version) { |
59 | // error!( |
60 | // "Version compatibility failure! Our Version: {}, Their Version: {}", |
61 | // Version::from_str(&std::env::var("CARGO_PKG_VERSION").unwrap()).unwrap(), |
62 | // initiation.version |
63 | // ); |
64 | |
65 | // connection_state |
66 | // .send(HandshakeFinalize { success: false }) |
67 | // .await |
68 | // .map_err(|e| HandshakeError::SendError(e))?; |
69 | |
70 | // Ok(()) |
71 | // } else { |
72 | // connection_state |
73 | // .send(HandshakeResponse { |
74 | // identity: connection_state.instance.clone(), |
75 | // version: version(), |
76 | // }) |
77 | // .await |
78 | // .map_err(|e| HandshakeError::SendError(e))?; |
79 | |
80 | // Ok(()) |
81 | // } |
82 | |
83 | |
84 | async |
85 | HandshakeMessage | : ,
86 | State | : ,
87 | |
88 | connection_state |
89 | .send |
90 | .await |
91 | .map_err?; |
92 | |
93 | Ok |
94 | // if !validate_version(&response.version) { |
95 | // error!( |
96 | // "Version compatibility failure! Our Version: {}, Their Version: {}", |
97 | // Version::from_str(&std::env::var("CARGO_PKG_VERSION").unwrap()).unwrap(), |
98 | // response.version |
99 | // ); |
100 | |
101 | // connection_state |
102 | // .send(HandshakeFinalize { success: false }) |
103 | // .await |
104 | // .map_err(|e| HandshakeError::SendError(e))?; |
105 | |
106 | // Ok(()) |
107 | // } else { |
108 | // connection_state |
109 | // .send(HandshakeFinalize { success: true }) |
110 | // .await |
111 | // .map_err(|e| HandshakeError::SendError(e))?; |
112 | |
113 | // Ok(()) |
114 | // } |
115 | |
116 | |
117 | async |
118 | HandshakeMessage | : ,
119 | State | : ,
120 | |
121 | connection_state.handshaked.store; |
122 | |
123 | connection_state |
124 | .send |
125 | .await |
126 | .map_err?; |
127 | |
128 | Ok |
129 | // if !finalize.success { |
130 | // error!("Error during handshake, aborting connection"); |
131 | // return Err(Error::from(ConnectionError::Shutdown).into()); |
132 | // } else { |
133 | // connection_state.handshaked.store(true, Ordering::SeqCst); |
134 | |
135 | // connection_state |
136 | // .send(HandshakeFinalize { success: true }) |
137 | // .await |
138 | // .map_err(|e| HandshakeError::SendError(e))?; |
139 | |
140 | // Ok(()) |
141 | // } |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | VersionMismatch, |
148 | |
149 | SendError, |
150 | |
151 | Other, |
152 | |
153 |