Cleanup interfaces

This commit is contained in:
2025-10-08 17:35:32 -04:00
parent 9627b76183
commit e1435b53b5
9 changed files with 27 additions and 93 deletions

View File

@@ -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) {

View File

@@ -124,6 +124,8 @@ TCPServer::~TCPServer() {
const auto that = static_cast<TCPServer *>(args);
while (true) {
vTaskDelay(0); // Avoid starving other threads
fd_set readfds;
FD_ZERO(&readfds);
int max_fd = -1;
@@ -135,13 +137,18 @@ TCPServer::~TCPServer() {
}
xSemaphoreGive(that->m_mutex);
timeval timeout = {1, 0}; // 1 second 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<int> 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<std::vector<uint8_t>>();
@@ -159,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 {
@@ -210,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;
}

View File

@@ -6,7 +6,10 @@
#define IDISCOVERYSERVICE_H
class IDiscoveryService {
public:
virtual ~IDiscoveryService() = default;
virtual static void setup() = 0;
virtual static void set_connected_boards(const std::vector<int>& boards) = 0;
}
#endif //IDISCOVERYSERVICE_H

View File

@@ -1,8 +0,0 @@
//
// Created by Johnathon Slightham on 2025-05-25.
//
#ifndef IMESSAGINGINTERFACE_H
#define IMESSAGINGINTERFACE_H
#endif //IMESSAGINGINTERFACE_H

View File

@@ -6,7 +6,9 @@
#define IRPCSERVER_H
class IRPCServer {
public:
virtual ~IRPCServer() = default;
virtual int send_msg(char* buffer, uint32_t length) const = 0;
};
#endif //IRPCSERVER_H