add: more debugging

add: more options for testing
This commit is contained in:
Tobias Reisinger 2020-08-14 23:18:22 +02:00
parent 0efbd2a22f
commit e84d54f562
23 changed files with 130 additions and 63 deletions

View file

@ -127,6 +127,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
int16_t payload[1];
payload[0] = discover_server_port;
LOGGER_DEBUG("sending udp broadcast\n");
if(send_udp_broadcast("255.255.255.255", global_config.discovery_port, payload, sizeof(payload)) < 0)
{
LOGGER_ERR("failed to send UDP broadcast\n");
@ -149,7 +150,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
controller_t **known_controllers = controller_get_all();
while(true)
for(;;)
{
addr_size = sizeof(their_addr);
@ -198,6 +199,8 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
continue;
}
LOGGER_DEBUG("received info for discovered controller\n");
uuid_t discovered_id;
mpack_tree_t tree;
@ -225,6 +228,8 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
{
if(uuid_compare(known_controllers[i]->uid, discovered_id) == 0)
{
LOGGER_DEBUG("rediscovered a known controller\n");
known_controllers[i]->active = 1;
strncpy(known_controllers[i]->name, discovered_name, discovered_name_len);
known_controllers[i]->name[discovered_name_len] = '\0';
@ -246,6 +251,8 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
if(!found_discovered_in_list)
{
LOGGER_DEBUG("discovered a new controller\n");
controller_t *discovered_controller = malloc(sizeof(controller_t));
discovered_controller->id = 0;
strcpy(discovered_controller->ip, inet_ntoa(addr.sin_addr));
@ -299,9 +306,9 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
}
for(int i = 0; known_controllers[i] != NULL; i++)
{
LOGGER_DEBUG("lost controller %s at %s\n", known_controllers[i]->name, known_controllers[i]->ip);
known_controllers[i]->active = false;
controller_save(known_controllers[i]);
LOGGER_DEBUG("lost: %s\n", known_controllers[i]->name);
}
controller_free_list(known_controllers);