瀏覽代碼

network: Remove unnecessary "response" field.

Whether a packet is a request or a response is completely defined by
whether the packet is sent by the server or the client.
Mathias Gottschlag 5 年之前
父節點
當前提交
35c1ad464b
共有 3 個檔案被更改,包括 21 行新增30 行删除
  1. 10
    13
      src/network/client.rs
  2. 3
    4
      src/network/mod.rs
  3. 8
    13
      src/protocol.rs

+ 10
- 13
src/network/client.rs 查看文件

@@ -129,7 +129,6 @@ async fn client_connection_task<StreamType, ErrorType, PacketType>(
129 129
                         let id = free_ids.alloc();
130 130
                         let packet = Packet {
131 131
                             id: id,
132
-                            response: false,
133 132
                             payload: call.data,
134 133
                         };
135 134
                         let mut serialized = Vec::new();
@@ -314,13 +313,12 @@ mod tests {
314 313
 
315 314
     type TestPayload = u32;
316 315
 
317
-    fn serialize_packet<T>(id: u32, response: bool, payload: T) -> Vec<u8>
316
+    fn serialize_packet<T>(id: u32, payload: T) -> Vec<u8>
318 317
     where
319 318
         T: Serialize,
320 319
     {
321 320
         let packet = Packet {
322 321
             id,
323
-            response,
324 322
             payload,
325 323
         };
326 324
         let mut serialized = Vec::new();
@@ -352,20 +350,20 @@ mod tests {
352 350
                 }),
353 351
                 tokio::spawn(async move {
354 352
                     // Invalid ID, should be ignored.
355
-                    pipe2.send(serialize_packet(42, true, 42)).await.unwrap();
353
+                    pipe2.send(serialize_packet(42, 42)).await.unwrap();
356 354
 
357
-                    assert_eq!(pipe2.next().await, Some(Ok(serialize_packet(0, false, 42))));
358
-                    pipe2.send(serialize_packet(0, true, 1337)).await.unwrap();
355
+                    assert_eq!(pipe2.next().await, Some(Ok(serialize_packet(0, 42))));
356
+                    pipe2.send(serialize_packet(0, 1337)).await.unwrap();
359 357
 
360 358
                     // Network errors shall be ignored if the stream is not closed.
361 359
                     pipe2.inject_error();
362 360
 
363 361
                     // The ID has to be reused, and a second concurrent call has to have a
364 362
                     // different ID.
365
-                    assert_eq!(pipe2.next().await, Some(Ok(serialize_packet(0, false, 43))));
366
-                    assert_eq!(pipe2.next().await, Some(Ok(serialize_packet(1, false, 44))));
367
-                    pipe2.send(serialize_packet(1, true, 1339)).await.unwrap();
368
-                    pipe2.send(serialize_packet(0, true, 1338)).await.unwrap();
363
+                    assert_eq!(pipe2.next().await, Some(Ok(serialize_packet(0, 43))));
364
+                    assert_eq!(pipe2.next().await, Some(Ok(serialize_packet(1, 44))));
365
+                    pipe2.send(serialize_packet(1, 1339)).await.unwrap();
366
+                    pipe2.send(serialize_packet(0, 1338)).await.unwrap();
369 367
                 }),
370 368
             );
371 369
 
@@ -412,7 +410,7 @@ mod tests {
412 410
                     assert_eq!(events.next().await, None);
413 411
                 }),
414 412
                 tokio::spawn(async move {
415
-                    pipe2.send(serialize_packet(SERVER_EVENT_ID, false, 42)).await.unwrap();
413
+                    pipe2.send(serialize_packet(SERVER_EVENT_ID, 42)).await.unwrap();
416 414
                     drop(pipe2);
417 415
                 }),
418 416
             );
@@ -424,8 +422,7 @@ mod tests {
424 422
 
425 423
     // TODO:
426 424
     // - Test for unparseable response.
427
-    // - Test for server events.
428
-    // - Test wether the client correctly closes the connection and whether futures return an error
425
+    // - Test whether the client correctly closes the connection and whether futures return an error
429 426
     // in this case.
430 427
 }
431 428
 

+ 3
- 4
src/network/mod.rs 查看文件

@@ -8,10 +8,10 @@
8 8
 //! Remote procedure call:
9 9
 //! - The client allocates an ID from the range between 0..2^31-1 that is not currently in use
10 10
 //!   for another RPC in progress.
11
-//! - The client prepares a packet with this ID, "response = false", and the appropriate
12
-//!   payload and sends the packet to the server.
11
+//! - The client prepares a packet with this ID and the appropriate payload and sends the packet to
12
+//!   the server.
13 13
 //! - The server receives the packet, processes the request and sends a packet back with the
14
-//!   identical ID and "response = true".
14
+//!   identical ID.
15 15
 //! - In case of an error, the payload has the type "Error" which in turn contains the error
16 16
 //!   type.
17 17
 //! - Unpon reception of the response, the client is free to reuse the ID for further RPCs.
@@ -39,7 +39,6 @@ pub const SERVER_EVENT_ID: u32 = u32::max_value();
39 39
 #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
40 40
 pub struct Packet<Payload> {
41 41
     pub id: u32,
42
-    pub response: bool, // TODO: Not really required.
43 42
     pub payload: Payload,
44 43
 }
45 44
 

+ 8
- 13
src/protocol.rs 查看文件

@@ -152,40 +152,35 @@ mod tests {
152 152
             (
153 153
                 Packet {
154 154
                     id: 42,
155
-                    response: false,
156 155
                     payload: PacketPayload::ServerInfo,
157 156
                 },
158 157
                 vec![
159
-                    131, 162, 105, 100, 42, 168, 114, 101, 115, 112, 111, 110, 115, 101, 194, 167,
160
-                    112, 97, 121, 108, 111, 97, 100, 129, 170, 83, 101, 114, 118, 101, 114, 73,
161
-                    110, 102, 111, 192,
158
+                    130, 162, 105, 100, 42, 167, 112, 97, 121, 108, 111, 97, 100, 129, 170, 83,
159
+                    101, 114, 118, 101, 114, 73, 110, 102, 111, 192,
162 160
                 ],
163 161
             ),
164 162
             (
165 163
                 Packet {
166 164
                     id: 42,
167
-                    response: true,
168 165
                     payload: PacketPayload::ServerInfoResponse(ServerInfoResponse {
169 166
                         version: "0.1".to_owned(),
170 167
                     }),
171 168
                 },
172 169
                 vec![
173
-                    131, 162, 105, 100, 42, 168, 114, 101, 115, 112, 111, 110, 115, 101, 195, 167,
174
-                    112, 97, 121, 108, 111, 97, 100, 129, 178, 83, 101, 114, 118, 101, 114, 73,
175
-                    110, 102, 111, 82, 101, 115, 112, 111, 110, 115, 101, 129, 167, 118, 101, 114,
176
-                    115, 105, 111, 110, 163, 48, 46, 49,
170
+                    130, 162, 105, 100, 42, 167, 112, 97, 121, 108, 111, 97, 100, 129, 178, 83,
171
+                    101, 114, 118, 101, 114, 73, 110, 102, 111, 82, 101, 115, 112, 111, 110, 115,
172
+                    101, 129, 167, 118, 101, 114, 115, 105, 111, 110, 163, 48, 46, 49,
177 173
                 ],
178 174
             ),
179 175
             (
180 176
                 Packet {
181 177
                     id: 42,
182
-                    response: true,
183 178
                     payload: PacketPayload::Error(crate::protocol::Error::InvalidParameter),
184 179
                 },
185 180
                 vec![
186
-                    131, 162, 105, 100, 42, 168, 114, 101, 115, 112, 111, 110, 115, 101, 195, 167,
187
-                    112, 97, 121, 108, 111, 97, 100, 129, 165, 69, 114, 114, 111, 114, 129, 176,
188
-                    73, 110, 118, 97, 108, 105, 100, 80, 97, 114, 97, 109, 101, 116, 101, 114, 192,
181
+                    130, 162, 105, 100, 42, 167, 112, 97, 121, 108, 111, 97, 100, 129, 165, 69,
182
+                    114, 114, 111, 114, 129, 176, 73, 110, 118, 97, 108, 105, 100, 80, 97, 114, 97,
183
+                    109, 101, 116, 101, 114, 192,
189 184
                 ],
190 185
             ),
191 186
         ];

Loading…
取消
儲存