Git repository hosting, collaboration, and discovery for the Fediverse.
Initial Commit
commit: 780cc59
1 | use ; |
2 | |
3 | use ; |
4 | use |
5 | |
6 | |
7 | CreateRepositoryCommand, RepositoryInfoRequest, RepositoryMessage, |
8 | RepositoryMessageKind, RepositoryRequest, RepositoryResponse, |
9 | , |
10 | MessageKind, |
11 | , |
12 | , |
13 | |
14 | , | Instance
15 | , |
16 | , |
17 | ; |
18 | use Serialize; |
19 | use |
20 | , |
21 | , |
22 | ; |
23 | use ; |
24 | |
25 | type Socket = ; |
26 | |
27 | |
28 | extern crate tracing; |
29 | |
30 | ; |
31 | |
32 | |
33 | pub async |
34 | target: Instance, |
35 | request: CreateRepositoryCommand, |
36 | |
37 | let mut socket = Self connect_to .await?; |
38 | let target = Repository |
39 | name: request.name.clone, |
40 | instance: target, |
41 | ; |
42 | |
43 | Self send_message |
44 | & Repository |
45 | target, |
46 | command: Request |
47 | request, |
48 | , |
49 | , |
50 | &mut socket, |
51 | |
52 | .await?; |
53 | |
54 | while let Ok = Self next_payload .await |
55 | if let Ok |
56 | command: |
57 | , | Response
58 | .. |
59 | = from_slice |
60 | |
61 | return Ok; |
62 | |
63 | |
64 | |
65 | unreachable! |
66 | |
67 | |
68 | pub async |
69 | let mut socket = Self connect_to .await?; |
70 | |
71 | Self send_message |
72 | & Repository |
73 | target: repository.clone, |
74 | command: Request |
75 | RepositoryInfoRequest, |
76 | , |
77 | , |
78 | &mut socket, |
79 | |
80 | .await?; |
81 | |
82 | while let Ok = Self next_payload .await |
83 | if let Ok |
84 | command: |
85 | , | Response
86 | .. |
87 | = from_slice |
88 | |
89 | return Ok; |
90 | |
91 | |
92 | |
93 | unreachable! |
94 | |
95 | |
96 | async |
97 | let url = url.to_string; |
98 | let = connect_async .await?; |
99 | Self handle_handshake .await?; |
100 | |
101 | Ok |
102 | |
103 | |
104 | async |
105 | // Send handshake initiation |
106 | |
107 | Self send_message |
108 | & Handshake |
109 | identity: Instance |
110 | url: String from, |
111 | , |
112 | version: String from, |
113 | , |
114 | socket, |
115 | |
116 | .await?; |
117 | |
118 | while let Some = socket.next .await |
119 | let message = match message |
120 | Ok => message, |
121 | Err => |
122 | error!; |
123 | continue; |
124 | |
125 | ; |
126 | |
127 | let payload = match message |
128 | => text.into_bytes, | Text
129 | => bytes, | Binary
130 | => continue, | Ping
131 | => continue, | Pong
132 | => | Close
133 | panic! |
134 | |
135 | _ => unreachable!, |
136 | ; |
137 | |
138 | let message = match |
139 | Ok => message, |
140 | Err => |
141 | error!; |
142 | continue; |
143 | |
144 | ; |
145 | |
146 | if let Handshake = message |
147 | match handshake |
148 | => unimplemented!, | Initiate
149 | => | Response
150 | // Send HandshakeMessage::Finalize |
151 | Self send_message |
152 | & Handshake |
153 | HandshakeFinalize , |
154 | , |
155 | socket, |
156 | |
157 | .await?; |
158 | |
159 | => | Finalize
160 | if finalize.success |
161 | return Ok; |
162 | else |
163 | panic! |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | Ok |
171 | |
172 | |
173 | async |
174 | message: &T, |
175 | socket: &mut Socket, |
176 | |
177 | socket |
178 | .send |
179 | .await?; |
180 | Ok |
181 | |
182 | |
183 | async |
184 | while let Some = socket.next .await |
185 | let message = message?; |
186 | |
187 | match message |
188 | => return Ok, | Text
189 | => return Ok, | Binary
190 | => continue, | Ping
191 | => continue, | Pong
192 | => | Close
193 | panic! |
194 | |
195 | _ => unreachable!, |
196 | |
197 | |
198 | |
199 | unreachable! |
200 | |
201 | |
202 |