mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
use loop to update connections
This commit is contained in:
parent
b34f9e3018
commit
7508faae91
9 changed files with 74 additions and 29 deletions
|
@ -1,7 +1,8 @@
|
|||
config network
|
||||
option broadcast_ip '10.0.0.255'
|
||||
option broadcast_port '1025'
|
||||
option multicast '0'
|
||||
option tcp_port '1026'
|
||||
option network_option '2' # 0 udp broadcast, 1 mutlicast, 2 tcp
|
||||
option shared_key 'Niiiiiiiiiiiiiik'
|
||||
option iv 'Niiiiiiiiiiiiiik'
|
||||
|
||||
|
@ -17,22 +18,23 @@ config times
|
|||
option remove_probe '120'
|
||||
option remove_ap '460'
|
||||
option update_hostapd '10'
|
||||
option update_tcp_con '10'
|
||||
|
||||
config metric
|
||||
option ht_support '0'
|
||||
option vht_support '0'
|
||||
option ht_support '10'
|
||||
option vht_support '100'
|
||||
option no_ht_support '0'
|
||||
option no_vht_support '0'
|
||||
option rssi '0'
|
||||
option low_rssi '0'
|
||||
option freq '0'
|
||||
option low_rssi '-500'
|
||||
option freq '100'
|
||||
option chan_util '0'
|
||||
option max_chan_util '0'
|
||||
option rssi_val '0'
|
||||
option low_rssi_val '0'
|
||||
option chan_util_val '0'
|
||||
option max_chan_util_val '0'
|
||||
option min_probe_count '0'
|
||||
option bandwith_threshold '0'
|
||||
option use_station_count '0'
|
||||
option eval_probe_req '0'
|
||||
option rssi_val '-60'
|
||||
option low_rssi_val '-80'
|
||||
option chan_util_val '140'
|
||||
option max_chan_util_val '170'
|
||||
option min_probe_count '4'
|
||||
option bandwith_threshold '6'
|
||||
option use_station_count '1'
|
||||
option eval_probe_req '1'
|
|
@ -10,12 +10,20 @@ NAME=dawn
|
|||
|
||||
start_service()
|
||||
{
|
||||
local _tcp_buffer
|
||||
config_load dawn
|
||||
load_tcp_port() {
|
||||
config_get _tcp_buffer "$1" tcp_port
|
||||
}
|
||||
config_foreach load_tcp_port network
|
||||
|
||||
echo "Starting Service..."
|
||||
procd_open_instance
|
||||
procd_set_param command $PROG
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_add_mdns "dawn" "tcp" "1026"
|
||||
procd_add_mdns "dawn" "tcp" "${_tcp_buffer}"
|
||||
procd_close_instance
|
||||
echo "Dawn instance started!"
|
||||
echo "UMDNS with port ${_tcp_buffer}"
|
||||
}
|
|
@ -61,11 +61,13 @@ struct time_config_s {
|
|||
time_t remove_probe;
|
||||
time_t remove_ap;
|
||||
time_t update_hostapd;
|
||||
time_t update_tcp_con;
|
||||
};
|
||||
|
||||
struct network_config_s {
|
||||
const char* broadcast_ip;
|
||||
int broadcast_port;
|
||||
int network_option;
|
||||
const char* multicast;
|
||||
const char* shared_key;
|
||||
const char* iv;
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "datastorage.h"
|
||||
|
||||
void start_umdns_update();
|
||||
|
||||
int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir);
|
||||
|
||||
int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req);
|
||||
|
|
32
src/main.c
32
src/main.c
|
@ -20,6 +20,8 @@ void daemon_shutdown();
|
|||
|
||||
void signal_handler(int sig);
|
||||
|
||||
int run_tcp_server();
|
||||
|
||||
int init_mutex();
|
||||
|
||||
struct sigaction signal_action;
|
||||
|
@ -79,6 +81,18 @@ int init_mutex()
|
|||
printf("\n mutex init failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&tcp_array_mutex, NULL) != 0) {
|
||||
printf("\n mutex init failed\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int run_tcp_server()
|
||||
{
|
||||
pthread_create(&tid_tcp_server, NULL, &run_tcp_socket, NULL);
|
||||
start_umdns_update();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -107,15 +121,25 @@ int main(int argc, char **argv) {
|
|||
struct time_config_s time_config = uci_get_time_config();
|
||||
timeout_config = time_config; // TODO: Refactor...
|
||||
|
||||
pthread_create(&tid_tcp_server, NULL, &run_tcp_socket, NULL);
|
||||
pthread_create(&tid_connections, NULL, &update_connections_thread, NULL);
|
||||
|
||||
hostapd_dir_glob = uci_get_dawn_hostapd_dir();
|
||||
sort_string = (char*) uci_get_dawn_sort_order();
|
||||
|
||||
init_mutex();
|
||||
|
||||
init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast);
|
||||
switch(net_config.network_option)
|
||||
{
|
||||
case 0:
|
||||
init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, 0);
|
||||
break;
|
||||
case 1:
|
||||
init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, 1);
|
||||
break;
|
||||
case 2:
|
||||
run_tcp_server();
|
||||
break;
|
||||
default:
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
insert_macs_from_file();
|
||||
dawn_init_ubus(ubus_socket, hostapd_dir_glob);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
// http://www.geeksforgeeks.org/socket-programming-in-cc-handling-multiple-clients-on-server-without-multi-threading/
|
||||
|
||||
#include "tcpsocket.h"
|
||||
|
|
|
@ -845,6 +845,7 @@ void remove_probe_array_cb(struct uloop_timeout *t) {
|
|||
pthread_mutex_lock(&probe_array_mutex);
|
||||
printf("[Thread] : Removing old entries!\n");
|
||||
remove_old_probe_entries(time(0), timeout_config.remove_probe);
|
||||
printf("[Thread] : Removing old FINISHED!\n");
|
||||
pthread_mutex_unlock(&probe_array_mutex);
|
||||
uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ struct time_config_s uci_get_time_config() {
|
|||
ret.remove_probe = uci_lookup_option_int(uci_ctx, s, "remove_probe");
|
||||
ret.update_hostapd = uci_lookup_option_int(uci_ctx, s, "update_hostapd");
|
||||
ret.remove_ap = uci_lookup_option_int(uci_ctx, s, "remove_ap");
|
||||
ret.update_tcp_con = uci_lookup_option_int(uci_ctx, s, "update_tcp_con");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +91,7 @@ struct network_config_s uci_get_dawn_network() {
|
|||
printf("multicast: %s\n", ret.broadcast_ip);
|
||||
ret.shared_key = uci_lookup_option_string(uci_ctx, s, "shared_key");
|
||||
ret.iv = uci_lookup_option_string(uci_ctx, s, "iv");
|
||||
ret.network_option = uci_lookup_option_int(uci_ctx, s, "network_option");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,17 +29,19 @@ static struct blob_buf network_buf;
|
|||
static struct blob_buf data_buf;
|
||||
static struct blob_buf b_probe;
|
||||
|
||||
|
||||
|
||||
|
||||
void update_clients(struct uloop_timeout *t);
|
||||
|
||||
void update_tcp_connections(struct uloop_timeout *t);
|
||||
|
||||
struct uloop_timeout client_timer = {
|
||||
.cb = update_clients
|
||||
};
|
||||
struct uloop_timeout hostapd_timer = {
|
||||
.cb = update_hostapd_sockets
|
||||
};
|
||||
struct uloop_timeout umdns_timer = {
|
||||
.cb = update_tcp_connections
|
||||
};
|
||||
|
||||
#define MAX_HOSTAPD_SOCKETS 10
|
||||
uint32_t hostapd_sock_arr[MAX_HOSTAPD_SOCKETS];
|
||||
|
@ -702,7 +704,6 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
|
|||
ctx_clients = ubus_connect(ubus_socket_clients);
|
||||
uloop_timeout_add(&client_timer);
|
||||
|
||||
|
||||
ubus_call_umdns();
|
||||
|
||||
ubus_add_oject();
|
||||
|
@ -863,13 +864,15 @@ void update_clients(struct uloop_timeout *t) {
|
|||
uloop_timeout_set(&client_timer, timeout_config.update_client * 1000);
|
||||
}
|
||||
|
||||
void *update_connections_thread(void *arg) {
|
||||
while (1) {
|
||||
sleep(TIME_THRESHOLD_CLIENT_KICK);
|
||||
printf("[Thread] : Updating Connections!\n");
|
||||
ubus_call_umdns();
|
||||
}
|
||||
return 0;
|
||||
void update_tcp_connections(struct uloop_timeout *t) {
|
||||
ubus_call_umdns();
|
||||
uloop_timeout_set(&umdns_timer, timeout_config.update_tcp_con * 1000);
|
||||
}
|
||||
|
||||
void start_umdns_update()
|
||||
{
|
||||
// update connections
|
||||
uloop_timeout_add(&umdns_timer);
|
||||
}
|
||||
|
||||
void update_hostapd_sockets(struct uloop_timeout *t) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue