diff --git a/files/dawn.config b/files/dawn.config index a6486c3..95ae816 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -10,6 +10,11 @@ config settings ordering config settings hostapd option hostapd_dir '/var/run/hostapd' +config settings times + option update_client '50' + option remove_client '120' + option remove_probe '120' + config settings metric option ht_support '10' option vht_support '50' diff --git a/src/include/datastorage.h b/src/include/datastorage.h index d688b52..6d5659d 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -28,8 +28,14 @@ struct probe_metric_s { int min_probe_count; }; +struct time_config_s { + time_t update_client; + time_t remove_client; + time_t remove_probe; +}; + #define SORT_NUM 5 -#define TIME_THRESHOLD 30 // every minute +#define TIME_THRESHOLD 120 // every minute // Probe entrys typedef struct probe_entry_s { diff --git a/src/include/dawn_uci.h b/src/include/dawn_uci.h index 8241e9f..b2ee0cf 100644 --- a/src/include/dawn_uci.h +++ b/src/include/dawn_uci.h @@ -3,4 +3,6 @@ struct probe_metric_s uci_get_dawn_metric(); +struct time_config_s uci_get_time_config(); + #endif //DAWN_UCI_H_H diff --git a/src/main.c b/src/main.c index b9b11f4..4036535 100644 --- a/src/main.c +++ b/src/main.c @@ -187,6 +187,8 @@ int main(int argc, char **argv) { gcrypt_init(); gcrypt_set_key_and_iv(shared_key, iv); + struct time_config_s time_config = uci_get_time_config(); + if (pthread_mutex_init(&list_mutex, NULL) != 0) { printf("\n mutex init failed\n"); return 1; @@ -209,9 +211,9 @@ int main(int argc, char **argv) { init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); - pthread_create(&tid_probe, NULL, &remove_array_thread, NULL); - //pthread_create(&tid_client, NULL, &remove_client_array_thread, NULL); - pthread_create(&tid_get_client, NULL, &update_clients_thread, NULL); + pthread_create(&tid_probe, NULL, &remove_array_thread, (void*)&time_config.remove_probe); + pthread_create(&tid_client, NULL, &remove_client_array_thread, (void*)&time_config.remove_client); + pthread_create(&tid_get_client, NULL, &update_clients_thread, (void*)&time_config.update_client); //pthread_create(&tid_kick_clients, NULL, &kick_clients_thread, NULL); //pthread_create(&tid_ap, NULL, &remove_ap_array_thread, NULL); diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index cd358d3..52f897b 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -470,33 +470,39 @@ void remove_old_ap_entries(time_t current_time, long long int threshold) { } void *remove_array_thread(void *arg) { + printf("Removing thread with time: %lu\n", *(long int*)arg); + time_t time_treshold = *(time_t*)arg; while (1) { - sleep(TIME_THRESHOLD); + sleep(time_treshold); pthread_mutex_lock(&probe_array_mutex); printf("[Thread] : Removing old entries!\n"); - remove_old_probe_entries(time(0), TIME_THRESHOLD); + remove_old_probe_entries(time(0), time_treshold); pthread_mutex_unlock(&probe_array_mutex); } return 0; } void *remove_client_array_thread(void *arg) { + time_t time_treshold_client = *(time_t*)arg; + printf("Removing client thread with time: %lu\n", time_treshold_client); while (1) { - sleep(TIME_THRESHOLD_CLIENT); + sleep(time_treshold_client); pthread_mutex_lock(&client_array_mutex); printf("[Thread] : Removing old client entries!\n"); - remove_old_client_entries(time(0), TIME_THRESHOLD_CLIENT); + remove_old_client_entries(time(0), time_treshold_client); pthread_mutex_unlock(&client_array_mutex); } return 0; } void *remove_ap_array_thread(void *arg) { + time_t time_treshold_ap = *(time_t*)arg; + printf("Removing ap thread with time: %lu\n", time_treshold_ap); while (1) { - sleep(TIME_THRESHOLD_AP); + sleep(time_treshold_ap); pthread_mutex_lock(&ap_array_mutex); printf("[Thread] : Removing old ap entries!\n"); - remove_old_ap_entries(time(0), TIME_THRESHOLD_AP); + remove_old_ap_entries(time(0), time_treshold_ap); pthread_mutex_unlock(&ap_array_mutex); } return 0; diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index acba381..3d3a06c 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -13,6 +13,56 @@ dawn.metric.freq */ +/* + config settings times + option update_client '50' + option remove_client '120' + option remove_probe '120' + */ + +struct time_config_s uci_get_time_config() +{ + struct time_config_s ret; + + struct uci_context *c; + struct uci_ptr ptr; + + c = uci_alloc_context (); + + printf("Loading TImes!"); + + + char tmp_update_client[] = "dawn.times.update_client"; + if (uci_lookup_ptr (c, &ptr, tmp_update_client, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if(ptr.o->type == UCI_TYPE_STRING) + ret.update_client = atoi(ptr.o->v.string); + + char tmp_remove_client[] = "dawn.times.remove_client"; + if (uci_lookup_ptr (c, &ptr, tmp_remove_client, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if(ptr.o->type == UCI_TYPE_STRING) + ret.remove_client = atoi(ptr.o->v.string); + + char tmp_remove_probe[] = "dawn.times.remove_probe"; + if (uci_lookup_ptr (c, &ptr, tmp_remove_probe, 1) != UCI_OK) { + uci_perror(c, "uci_get_daw_metric Error"); + return ret; + } + if(ptr.o->type == UCI_TYPE_STRING) + ret.remove_probe = atoi(ptr.o->v.string); + + printf("Times: %lu, %lu, %lu\n", ret.update_client, ret.remove_client, ret.remove_probe); + + uci_free_context(c); + + return ret; +} + struct probe_metric_s uci_get_dawn_metric() { struct probe_metric_s ret; diff --git a/src/utils/ubus.c b/src/utils/ubus.c index 150a2db..c4e792d 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -515,11 +515,14 @@ static int ubus_get_clients() { } void *update_clients_thread(void *arg) { + time_t time_update_client = *(time_t*)arg; + printf("Update client thread with time: %lu\n", time_update_client); + const char *ubus_socket = NULL; ctx_clients = ubus_connect(ubus_socket); while (1) { - sleep(TIME_THRESHOLD_CLIENT_UPDATE); + sleep(time_update_client); printf("[Thread] : Kicking clients!\n"); ubus_get_clients(); }