diff --git a/src/connections/stream_api.rs b/src/connections/stream_api.rs index e960c4b..a329b12 100644 --- a/src/connections/stream_api.rs +++ b/src/connections/stream_api.rs @@ -118,7 +118,7 @@ impl ConnectedStreamApi { /// /// # Arguments /// - /// * `packet_router` - A generic packet router field that implements the `PacketRouter` trait. + /// * `packet_router` - A struct that implements the `PacketRouter` trait. /// * `byte_data` - A `Vec` containing the byte data to send. /// * `port_num` - A `PortNum` enum that specifies the port number to send the packet on. /// * `destination` - A `PacketDestination` enum that specifies the destination of the packet. @@ -210,18 +210,22 @@ impl ConnectedStreamApi { ..Default::default() }; + mesh_packet.rx_time = current_epoch_secs_u32(); + + let payload_variant = Some(protobufs::to_radio::PayloadVariant::Packet( + mesh_packet.clone(), + )); + self.send_to_radio_packet(payload_variant).await?; + + // If the sending was successful, echo it back to the client via the `PacketRouter` if echo_response { - mesh_packet.rx_time = current_epoch_secs_u32(); - packet_router - .handle_mesh_packet(mesh_packet.clone()) - .map_err(|e| Error::PacketHandlerFailure { + packet_router.handle_mesh_packet(mesh_packet).map_err(|e| { + Error::PacketHandlerFailure { source: Box::new(e), - })?; + } + })?; } - let payload_variant = Some(protobufs::to_radio::PayloadVariant::Packet(mesh_packet)); - self.send_to_radio_packet(payload_variant).await?; - Ok(()) }