Git repository hosting, collaboration, and discovery for the Fediverse.
begin new protocol refactor
parent: tbd commit: 2091700
1 | use FromStr; |
2 | |
3 | use StreamExt; |
4 | use ; |
5 | use Version; |
6 | use Serialize; |
7 | use Message; |
8 | |
9 | use crate Socket; |
10 | |
11 | ; |
12 | |
13 | |
14 | |
15 | Self |
16 | |
17 | |
18 | pub async |
19 | let mut socket = self.0; |
20 | |
21 | // Send handshake initiation |
22 | Self send_raw_message |
23 | &mut socket, |
24 | &InitiateHandshake |
25 | version: from_str .unwrap, |
26 | , |
27 | |
28 | .await?; |
29 | |
30 | while let Some = socket.next .await |
31 | let message = match message |
32 | Ok => message, |
33 | Err => |
34 | error!; |
35 | continue; |
36 | |
37 | ; |
38 | |
39 | let payload = match message |
40 | => text.into_bytes, | Text
41 | => bytes, | Binary
42 | => continue, | Ping
43 | => continue, | Pong
44 | => | Close
45 | socket.close .await?; |
46 | |
47 | return Err; |
48 | |
49 | _ => unreachable!, |
50 | ; |
51 | |
52 | info!; |
53 | |
54 | // We try deserializing the finalize response first as it is smaller and just as common |
55 | if let Ok = |
56 | if finalize.success |
57 | info!; |
58 | |
59 | return Ok; |
60 | else |
61 | socket.close .await?; |
62 | return Err; |
63 | |
64 | else |
65 | match |
66 | Ok => |
67 | // let message = if !validate_version(&response.version) { |
68 | // error!( |
69 | // "Version compatibility failure! Our Version: {}, Their Version: {}", |
70 | // version(), |
71 | // response.version |
72 | // ); |
73 | |
74 | // HandshakeFinalize { success: false } |
75 | // } else { |
76 | // info!("Connected with a compatible version"); |
77 | |
78 | // HandshakeFinalize { success: true } |
79 | // }; |
80 | |
81 | warn!; |
82 | |
83 | let message = HandshakeFinalize ; |
84 | // Send [`HandshakeFinalize`] to indicate if we're compatible or not |
85 | Self send_raw_message .await?; |
86 | |
87 | Err => |
88 | error!; |
89 | continue; |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | Ok |
96 | |
97 | |
98 | async |
99 | _socket: &Socket, |
100 | _message: &T, |
101 | |
102 | todo! |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | ; |
109 |