edgehog-device-manager / edgehog-device-runtime

Edgehog Device Runtime is a portable middleware written in Rust, that enables remote device management on Linux-based systems.
Apache License 2.0
11 stars 10 forks source link

feat(http): implement http over websocket #287

Closed rgallor closed 4 months ago

rgallor commented 9 months ago

To enhance code comprehension, it is advisable to follow this order when inspecting the code files:

  1. edgehog-device-runtime/src/forwarder.rs: This module is responsible for initiating a new forwarder instance upon receiving an Astarte event. A forwarder task is created, which, in turn, generates a ConnectionsManager (see point 3) responsible for handling all connection-related tasks.
  2. edgehog-device-runtime/src/lib.rs: In this file, the DeviceManager now includes a new field called forwarder_handler, which utilizes the forwarder.rs module when an Astarte event pertaining to the RemoteTerminalRequest interface is received and converted into a ConnectionInfo struct (defined in edgehog-device-runtime-forwarder/src/astarte.rs).
  3. edgehog-device-runtime-forwarder/src/connections_manager.rs: This file defines the ConnectionsManager struct, which is accountable for establishing a WebSocket connection between the device and Edgehog. Additionally, it functions as a multiplexer to forward messages between Edgehog and internal device connections (e.g., with TTYD). When it receives a WebSocket frame from Edgehog, it first extracts the frame and, if it is binary, decodes the protobuf data into an internal Rust representation defined in edgehog-device-runtime-forwarder/src/messages.rs. It also handles HTTP requests (WebSocket's requests are still pending). In case a device connection (e.g., with TTYD) (see point 4) sends data to the manager, it encodes the message into a WebSocket frame and forwards it to Edgehog. The manager is also responsible for reconnection operations in case a WebSocket error occurs during communication. The Connections structure serves as a collection of connections and maintains a channel writing handle necessary for each device connection to forward messages to the manager.
  4. edgehog-device-runtime-forwarder/src/connection.rs: This file defines the Connection and ConnectionHandle structs, which are responsible for creating a new connection and spawning the Tokio task responsible for managing it. Currently, a connection task sends an HTTP request (e.g., to TTYD), waits for a response, encodes it into a protobuf message, and forwards it to the ConnectionsManager.

Close #275

codecov[bot] commented 9 months ago

Codecov Report

Attention: Patch coverage is 68.54220% with 123 lines in your changes are missing coverage. Please review.

Project coverage is 63.4%. Comparing base (575a679) to head (01335ac).

Additional details and impacted files | [Files](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager) | Coverage Δ | | |---|---|---| | [edgehog-device-runtime-forwarder/src/astarte.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-ZWRnZWhvZy1kZXZpY2UtcnVudGltZS1mb3J3YXJkZXIvc3JjL2FzdGFydGUucnM=) | `100.0% <100.0%> (ø)` | | | [...dgehog-device-runtime-forwarder/tests/http\_test.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-ZWRnZWhvZy1kZXZpY2UtcnVudGltZS1mb3J3YXJkZXIvdGVzdHMvaHR0cF90ZXN0LnJz) | `100.0% <100.0%> (ø)` | | | [src/lib.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-c3JjL2xpYi5ycw==) | `39.7% <33.3%> (-0.2%)` | :arrow_down: | | [edgehog-device-runtime-forwarder/src/messages.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-ZWRnZWhvZy1kZXZpY2UtcnVudGltZS1mb3J3YXJkZXIvc3JjL21lc3NhZ2VzLnJz) | `97.8% <97.8%> (ø)` | | | [src/data/astarte\_device\_sdk\_lib.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-c3JjL2RhdGEvYXN0YXJ0ZV9kZXZpY2Vfc2RrX2xpYi5ycw==) | `34.2% <0.0%> (-3.1%)` | :arrow_down: | | [src/data/astarte\_message\_hub\_node.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-c3JjL2RhdGEvYXN0YXJ0ZV9tZXNzYWdlX2h1Yl9ub2RlLnJz) | `64.7% <0.0%> (-8.7%)` | :arrow_down: | | [edgehog-device-runtime-forwarder/src/connection.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-ZWRnZWhvZy1kZXZpY2UtcnVudGltZS1mb3J3YXJkZXIvc3JjL2Nvbm5lY3Rpb24ucnM=) | `44.4% <44.4%> (ø)` | | | [edgehog-device-runtime-forwarder/src/collection.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-ZWRnZWhvZy1kZXZpY2UtcnVudGltZS1mb3J3YXJkZXIvc3JjL2NvbGxlY3Rpb24ucnM=) | `30.7% <30.7%> (ø)` | | | [...evice-runtime-forwarder/src/connections\_manager.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-ZWRnZWhvZy1kZXZpY2UtcnVudGltZS1mb3J3YXJkZXIvc3JjL2Nvbm5lY3Rpb25zX21hbmFnZXIucnM=) | `25.4% <25.4%> (ø)` | | | [src/forwarder.rs](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager#diff-c3JjL2ZvcndhcmRlci5ycw==) | `48.8% <48.8%> (ø)` | | ... and [8 files with indirect coverage changes](https://app.codecov.io/gh/edgehog-device-manager/edgehog-device-runtime/pull/287/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=edgehog-device-manager)
rgallor commented 5 months ago

332 should be merged to fix clippy warnings