c8386f9deefde40a7275d2157c7eda1808e01cfa
The Marionette protocol is designed to facilitate concurrent, asynchronous messages. Each request message includes a message ID, and the corresponding response includes the same message ID. This allows several requests to be in flight at once. In order for this to be useful, the client needs to maintain a record of each request it has sent so that it knows how to handle responses, even if they arrive out of order. To implement this functionality in *mqttmarionette*, the `MarionetteConnection` structure spawns a Tokio task to handle all incoming messages from the server. When a message arrives, its ID is looked up in a registry that maps message IDs to Tokio "oneshot" channels. If a channel is found in the map, the response is sent back to the caller through the channel. In order to handle incoming messages in a separate task, the TCP stream has to be split into its read and write parts. The receiver task cannot be spawned, though, until after the first unsolicited message is read from the socket, since a) there is no caller to send the message back to and b) it does not follow the same encoding scheme as the rest of the Marionette messages. As such, I've refactored the `MarionetteConnection` structure to handle the initial message in the `connect` function and dropped the `handshake` method. A new `start_session` method is responsible for initiating the Marionette session.
Description
No description provided
Languages
Rust
99.9%
Shell
0.1%