diff --git a/gui/src/discoverymanager.cpp b/gui/src/discoverymanager.cpp index 836d4a5..9911a91 100644 --- a/gui/src/discoverymanager.cpp +++ b/gui/src/discoverymanager.cpp @@ -21,7 +21,7 @@ DiscoveryManager::DiscoveryManager(QObject *parent) : QObject(parent) { ChiakiDiscoveryServiceOptions options; options.ping_ms = 500; - options.servers_max = 16; + options.hosts_max = 16; options.send_addr = nullptr; // TODO options.send_addr_size = 0; // TODO diff --git a/lib/include/chiaki/discoveryservice.h b/lib/include/chiaki/discoveryservice.h index 8a67c9b..f6cea77 100644 --- a/lib/include/chiaki/discoveryservice.h +++ b/lib/include/chiaki/discoveryservice.h @@ -27,25 +27,29 @@ extern "C" { typedef struct chiaki_discovery_service_options_t { - size_t servers_max; + size_t hosts_max; uint64_t ping_ms; struct sockaddr *send_addr; size_t send_addr_size; } ChiakiDiscoveryServiceOptions; -typedef struct chiaki_discovery_service_server_t +typedef struct chiaki_discovery_service_host_discovery_info_t { uint64_t last_ping_index; -} ChiakiDiscoveryServiceServer; +} ChiakiDiscoveryServiceHostDiscoveryInfo; typedef struct chiaki_discovery_service_t { ChiakiLog *log; ChiakiDiscoveryServiceOptions options; ChiakiDiscovery discovery; + uint64_t ping_index; - ChiakiDiscoveryServiceServer *servers; - size_t servers_count; + ChiakiDiscoveryHost *hosts; + ChiakiDiscoveryServiceHostDiscoveryInfo *host_discovery_infos; + size_t hosts_count; + ChiakiMutex state_mutex; + ChiakiThread thread; ChiakiBoolPredCond stop_cond; } ChiakiDiscoveryService; diff --git a/lib/src/discoveryservice.c b/lib/src/discoveryservice.c index cefe347..e21aa9c 100644 --- a/lib/src/discoveryservice.c +++ b/lib/src/discoveryservice.c @@ -20,18 +20,19 @@ #include static void *discovery_service_thread_func(void *user); +static void discovery_service_ping(ChiakiDiscoveryService *service); CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_service_init(ChiakiDiscoveryService *service, ChiakiDiscoveryServiceOptions *options, ChiakiLog *log) { service->options = *options; - service->servers = calloc(service->options.servers_max, sizeof(ChiakiDiscoveryServiceServer)); - if(!service->servers) + service->host_discovery_infos = calloc(service->options.hosts_max, sizeof(ChiakiDiscoveryServiceHostDiscoveryInfo)); + if(!service->host_discovery_infos) return CHIAKI_ERR_MEMORY; service->options.send_addr = malloc(service->options.send_addr_size); if(!service->options.send_addr) goto error_servers; memcpy(service->options.send_addr, options->send_addr, service->options.send_addr_size); - service->servers_count = 0; + service->hosts_count = 0; ChiakiErrorCode err = chiaki_discovery_init(&service->discovery, log, service->options.send_addr->sa_family); if(err != CHIAKI_ERR_SUCCESS) @@ -55,7 +56,7 @@ error_discovery: error_send_addr: free(service->options.send_addr); error_servers: - free(service->servers); + free(service->host_discovery_infos); return err; } @@ -65,12 +66,10 @@ CHIAKI_EXPORT void chiaki_discovery_service_fini(ChiakiDiscoveryService *service chiaki_thread_join(&service->thread, NULL); chiaki_bool_pred_cond_fini(&service->stop_cond); chiaki_discovery_fini(&service->discovery); - free(service->servers); + free(service->host_discovery_infos); free(service->options.send_addr); } -static void discovery_service_ping(ChiakiDiscoveryService *service); - static void *discovery_service_thread_func(void *user) { ChiakiDiscoveryService *service = user; @@ -93,6 +92,7 @@ static void *discovery_service_thread_func(void *user) static void discovery_service_ping(ChiakiDiscoveryService *service) { + CHIAKI_LOGV(service->log, "Discovery Service sending ping"); ChiakiDiscoveryPacket packet = { 0 }; packet.cmd = CHIAKI_DISCOVERY_CMD_SRCH; chiaki_discovery_send(&service->discovery, &packet, service->options.send_addr, service->options.send_addr_size);