To enhance code comprehension, it is advisable to follow this order when inspecting the code files:
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.
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).
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.
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.
To enhance code comprehension, it is advisable to follow this order when inspecting the code files:
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 aConnectionsManager
(see point 3) responsible for handling all connection-related tasks.edgehog-device-runtime/src/lib.rs
: In this file, theDeviceManager
now includes a new field calledforwarder_handler
, which utilizes theforwarder.rs
module when an Astarte event pertaining to theRemoteTerminalRequest
interface is received and converted into aConnectionInfo
struct (defined inedgehog-device-runtime-forwarder/src/astarte.rs
).edgehog-device-runtime-forwarder/src/connections_manager.rs
: This file defines theConnectionsManager
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 theprotobuf
data into an internal Rust representation defined inedgehog-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. TheConnections
structure serves as a collection of connections and maintains a channel writing handle necessary for each device connection to forward messages to the manager.edgehog-device-runtime-forwarder/src/connection.rs
: This file defines theConnection
andConnectionHandle
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 theConnectionsManager
.Close #275