mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
Remove old entries
This commit is contained in:
parent
454e44cf5d
commit
a1d488b633
3 changed files with 27 additions and 5 deletions
|
@ -14,7 +14,7 @@
|
|||
#endif
|
||||
|
||||
#define SORT_NUM 5
|
||||
#define TIME_THRESHOLD 60 // every minute
|
||||
#define TIME_THRESHOLD 5 // every minute
|
||||
|
||||
// Probe entrys
|
||||
typedef struct probe_entry_s {
|
||||
|
@ -38,6 +38,7 @@ void insert_to_array(probe_entry entry, int inc_counter);
|
|||
void probe_array_insert(probe_entry entry);
|
||||
probe_entry* probe_array_delete(probe_entry entry);
|
||||
void print_array();
|
||||
void *remove_array_thread(void *arg);
|
||||
|
||||
pthread_mutex_t probe_array_mutex;
|
||||
|
||||
|
|
|
@ -55,7 +55,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 0);
|
||||
|
||||
//pthread_t tid;
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, &remove_array_thread, NULL);
|
||||
//pthread_create(&tid, NULL, &remove_thread, NULL);
|
||||
|
||||
dawn_init_ubus(ubus_socket, opt_hostapd_dir);
|
||||
|
|
|
@ -9,6 +9,7 @@ int go_next(char sort_order[], int i, probe_entry entry,
|
|||
int mac_is_equal(uint8_t addr1[], uint8_t addr2[]);
|
||||
int mac_is_greater(uint8_t addr1[], uint8_t addr2[]);
|
||||
void print_probe_entry(probe_entry entry);
|
||||
void remove_old_probe_entries(time_t current_time, long long int threshold);
|
||||
|
||||
int probe_entry_last = -1;
|
||||
|
||||
|
@ -93,7 +94,7 @@ void print_array()
|
|||
void insert_to_array(probe_entry entry, int inc_counter)
|
||||
{
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
|
||||
|
||||
entry.time = time(0);
|
||||
entry.counter = 0;
|
||||
probe_entry* tmp = probe_array_delete(entry);
|
||||
|
@ -112,9 +113,28 @@ void insert_to_array(probe_entry entry, int inc_counter)
|
|||
|
||||
pthread_mutex_unlock(&probe_array_mutex);
|
||||
}
|
||||
|
||||
void remove_old_probe_entries(time_t current_time, long long int threshold)
|
||||
{
|
||||
for(int i = 0; i < probe_entry_last; i++)
|
||||
{
|
||||
if (probe_array[i].time < current_time - threshold)
|
||||
{
|
||||
probe_array_delete(probe_array[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *remove_array_thread(void *arg) {
|
||||
while (1) {
|
||||
sleep(TIME_THRESHOLD);
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
printf("[Thread] : Removing old entries!\n");
|
||||
remove_old_probe_entries(time(0), TIME_THRESHOLD);
|
||||
pthread_mutex_unlock(&probe_array_mutex);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue