Create `NetworkedSubstack`.
# giterated-protocol - Create `NetworkedSubstack` which will handle all networked operations giterated needs - Add support for `NetworkedSubstack` for both the daemon and client - Pipe everything through but leave APIs temp # `giterated-daemon` - Remove a bunch of random old code, dead code, and files that aren't needed. - Moved all connection handling to `client.rs`, simplified connection logic with new types
parent: tbd commit: 202bb12
1 | use Arc; |
2 | |
3 | use ; |
4 | use |
5 | , | AuthenticatedPayload
6 | , |
7 | , | Instance
8 | , | ObjectBackend
9 | ; |
10 | use ; |
11 | use ; |
12 | use TcpStream; |
13 | use ; |
14 | |
15 | pub async |
16 | our_instance: Instance, |
17 | mut socket: , |
18 | runtime: , |
19 | |
20 | loop |
21 | let message = socket.next .await; |
22 | |
23 | if message.is_none |
24 | // Keep an eye out for this, I dont see why we shouldn't end the connection |
25 | unreachable! |
26 | |
27 | |
28 | let message = message.unwrap; |
29 | |
30 | let payload = match message |
31 | Ok => |
32 | let payload = match message |
33 | => payload, | Binary
34 | => | Ping
35 | let _ = socket.send .await; |
36 | continue; |
37 | |
38 | => return, | Close
39 | _ => continue, |
40 | ; |
41 | |
42 | payload |
43 | |
44 | Err => |
45 | // Connection error |
46 | warn!; |
47 | |
48 | return; |
49 | |
50 | ; |
51 | |
52 | let payload = match |
53 | Ok => payload, |
54 | Err => |
55 | warn! |
56 | "A network payload deserialization failure has occurred: {:?}", |
57 | e |
58 | ; |
59 | |
60 | continue; |
61 | |
62 | ; |
63 | |
64 | let operation_state = StackOperationState |
65 | our_instance: our_instance.clone, |
66 | runtime: runtime.clone, |
67 | instance: None, |
68 | user: None, |
69 | ; |
70 | |
71 | let result = handle_client_message .await; |
72 | |
73 | // Grab operation errors so we can log them, they don't make it across the network |
74 | if let Err = &result |
75 | error!; |
76 | |
77 | |
78 | // Map error to the network variant |
79 | let result = result.map_err; |
80 | |
81 | socket |
82 | .send |
83 | .await |
84 | .expect; |
85 | |
86 | |
87 | |
88 | pub async |
89 | payload: AuthenticatedPayload, |
90 | operation_state: StackOperationState, |
91 | runtime: , |
92 | |
93 | let mut networked_object = runtime |
94 | . |
95 | .await |
96 | .as_internal_error_with_context?; |
97 | |
98 | let networked_operation = new; |
99 | |
100 | networked_object |
101 | .request |
102 | .await |
103 | |
104 |