diff --git a/components/flatbuffers/TopologyMessageBuilder.cpp b/components/flatbuffers/TopologyMessageBuilder.cpp index dc7cbb3..9a933da 100644 --- a/components/flatbuffers/TopologyMessageBuilder.cpp +++ b/components/flatbuffers/TopologyMessageBuilder.cpp @@ -30,8 +30,4 @@ namespace Flatbuffers { return {builder_.GetBufferPointer(), builder_.GetSize()}; } - - const Messaging::TopologyMessage* TopologyMessageBuilder::parse_topology_message(const uint8_t* buffer) { - return flatbuffers::GetRoot(buffer); - } } diff --git a/components/flatbuffers/include/TopologyMessageBuilder.h b/components/flatbuffers/include/TopologyMessageBuilder.h index e0aeae6..07fb34c 100644 --- a/components/flatbuffers/include/TopologyMessageBuilder.h +++ b/components/flatbuffers/include/TopologyMessageBuilder.h @@ -23,8 +23,6 @@ namespace Flatbuffers { const std::vector& channel_to_module, const std::vector& orientation_to_module); - static const Messaging::TopologyMessage* parse_topology_message(const uint8_t* buffer); - private: flatbuffers::FlatBufferBuilder builder_; }; diff --git a/components/rpc/CommunicationRouter.cpp b/components/rpc/CommunicationRouter.cpp index 7729747..67fdca6 100644 --- a/components/rpc/CommunicationRouter.cpp +++ b/components/rpc/CommunicationRouter.cpp @@ -100,6 +100,13 @@ void CommunicationRouter::update_leader() { } void CommunicationRouter::route(uint8_t* buffer, const size_t length) const { + flatbuffers::Verifier verifier(buffer, length); + bool ok = Messaging::VerifyMPIMessageBuffer(verifier); + if (!ok) { // This could be moved to just be called on wireline data to save cpu cycles. + ESP_LOGW(TAG, "route: got an invalid MPI message, disregarding"); + return; + } + const auto& mpi_message = Flatbuffers::MPIMessageBuilder::parse_mpi_message(buffer); if (mpi_message->destination() == m_module_id) { diff --git a/components/rpc/TCPServer.cpp b/components/rpc/TCPServer.cpp index 9660926..d6cfe7e 100644 --- a/components/rpc/TCPServer.cpp +++ b/components/rpc/TCPServer.cpp @@ -124,7 +124,8 @@ TCPServer::~TCPServer() { const auto that = static_cast(args); while (true) { - vTaskDelay(1 / portTICK_PERIOD_MS); // Avoid starving other threads + vTaskDelay(0); // Avoid starving other threads + fd_set readfds; FD_ZERO(&readfds); int max_fd = -1; @@ -136,13 +137,18 @@ TCPServer::~TCPServer() { } xSemaphoreGive(that->m_mutex); - timeval timeout = {0, 100000}; // 100 ms timeout + // todo: Select seems to be timing out the watchdog, even though we have a 50ms timeout. + // Potentially select is not respecting our timeout? + timeval timeout = {0, 50000}; // 50 ms timeout int ret = select(max_fd + 1, &readfds, nullptr, nullptr, &timeout); + vTaskDelay(0); // Avoid starving other threads + if (ret > 0) { xSemaphoreTake(that->m_mutex, portMAX_DELAY); std::vector to_remove; for (int sock : that->m_clients) { + vTaskDelay(0); // Avoid starving other threads if (FD_ISSET(sock, &readfds)) { // Handle socket auto buffer = std::make_unique>(); @@ -160,7 +166,7 @@ TCPServer::~TCPServer() { ESP_LOGE(TAG, "Error occurred during receiving: errno %d\n", errno); to_remove.emplace_back(sock); } else if (0 == len) { - ESP_LOGW(TAG, "Connection closed\n"); + ESP_LOGI(TAG, "TCP Connection closed\n"); close(sock); to_remove.emplace_back(sock); } else { @@ -211,8 +217,6 @@ bool TCPServer::authenticate_client(int sock) { } int TCPServer::send_msg(char *buffer, uint32_t length) const { - // todo: should we assign a unique rank to each pc? - if (!is_network_connected()) { return -1; }