network: ping pong keepalive for tcp connections

To make the tcp connections keepalive and better handle the timeout
of connections

con_timeout indicate the connection timeout and it is configurable

Signed-off-by: Chen Minqiang <ptpt52@gmail.com>
This commit is contained in:
Chen Minqiang 2022-07-21 06:03:58 +08:00
parent 4fa5bc2e37
commit ba56bac909
8 changed files with 136 additions and 30 deletions

View file

@ -79,7 +79,7 @@ struct time_config_s uci_get_time_config() {
.update_tcp_con = 10,
.update_chan_util = 5,
.update_beacon_reports = 20,
.client_timeout = 60,
.con_timeout = 60,
};
dawnlog_debug_func("Entering...");
@ -106,8 +106,8 @@ struct time_config_s uci_get_time_config() {
DAWN_SET_CONFIG_TIME(ret, s, update_chan_util);
//CONFIG-T: update_beacon_reports|Timer to ask all connected clients for a new BEACON REPORT|[20]
DAWN_SET_CONFIG_TIME(ret, s, update_beacon_reports);
//CONFIG-T: client_timeout|Timespan to check if a client timed out|[60]
DAWN_SET_CONFIG_TIME(ret, s, client_timeout);
//CONFIG-T: con_timeout|Timespan to check if a connection timed out|[60]
DAWN_SET_CONFIG_TIME(ret, s, con_timeout);
return ret;
}
}

View file

@ -656,7 +656,7 @@ enum {
UCI_UPDATE_TCP_CON,
UCI_UPDATE_CHAN_UTIL,
UCI_UPDATE_BEACON_REPORTS,
UCI_CLIENT_TIMEOUT,
UCI_CON_TIMEOUT,
__UCI_TIMES_MAX,
};
@ -714,7 +714,7 @@ static const struct blobmsg_policy uci_times_policy[__UCI_TIMES_MAX] = {
[UCI_UPDATE_TCP_CON] = {.name = "update_tcp_con", .type = BLOBMSG_TYPE_INT32},
[UCI_UPDATE_CHAN_UTIL] = {.name = "update_chan_util", .type = BLOBMSG_TYPE_INT32},
[UCI_UPDATE_BEACON_REPORTS] = {.name = "update_beacon_reports", .type = BLOBMSG_TYPE_INT32},
[UCI_CLIENT_TIMEOUT] = {.name = "client_timeout", .type = BLOBMSG_TYPE_INT32},
[UCI_CON_TIMEOUT] = {.name = "con_timeout", .type = BLOBMSG_TYPE_INT32},
};
static void set_uci_item(char* m, struct blob_attr* a)
@ -897,7 +897,7 @@ static int handle_uci_config(struct blob_attr* msg) {
set_uci_item("dawn.@times[0].update_beacon_reports=%d", tb_times[UCI_UPDATE_BEACON_REPORTS]);
set_uci_item("dawn.@times[0].client_timeout=%d", tb_times[UCI_CLIENT_TIMEOUT]);
set_uci_item("dawn.@times[0].con_timeout=%d", tb_times[UCI_CON_TIMEOUT]);
uci_reset();
dawn_metric = uci_get_dawn_metric();

View file

@ -23,7 +23,9 @@ void update_clients(struct uloop_timeout *t);
void update_tcp_connections(struct uloop_timeout *t);
void check_client_timeouts(struct uloop_timeout *t);
void server_ping_clients(struct uloop_timeout *t);
void check_timeouts(struct uloop_timeout *t);
void update_channel_utilization(struct uloop_timeout *t);
@ -40,8 +42,11 @@ struct uloop_timeout hostapd_timer = {
struct uloop_timeout tcp_con_timer = {
.cb = update_tcp_connections
};
struct uloop_timeout client_timeout_timer = {
.cb = check_client_timeouts
struct uloop_timeout server_ping_timer = {
.cb = server_ping_clients
};
struct uloop_timeout check_timeout_timer = {
.cb = check_timeouts
};
struct uloop_timeout channel_utilization_timer = {
.cb = update_channel_utilization
@ -1153,20 +1158,29 @@ void update_tcp_connections(struct uloop_timeout *t) {
uloop_timeout_set(&tcp_con_timer, timeout_config.update_tcp_con * 1000);
}
void check_client_timeouts(struct uloop_timeout *t) {
void server_ping_clients(struct uloop_timeout *t) {
dawnlog_debug_func("Entering...");
check_client_timeout(timeout_config.client_timeout);
server_to_clients_ping();
uloop_timeout_set(&client_timeout_timer, CHECK_CLIENT_TIMEOUT * 1000);
uloop_timeout_set(&server_ping_timer, 20 * 1000);
}
void check_timeouts(struct uloop_timeout *t) {
dawnlog_debug_func("Entering...");
check_timeout(timeout_config.con_timeout);
uloop_timeout_set(&check_timeout_timer, CHECK_TIMEOUT * 1000);
}
void start_tcp_con_update() {
dawnlog_debug_func("Entering...");
uloop_timeout_add(&server_ping_timer);
// update connections
uloop_timeout_add(&tcp_con_timer); // callback = update_tcp_connections
uloop_timeout_add(&client_timeout_timer); // callback = client_timeout
uloop_timeout_add(&check_timeout_timer); // callback = con_timeout
}
void update_hostapd_sockets(struct uloop_timeout *t) {
@ -1902,7 +1916,7 @@ int uci_send_via_network()
blobmsg_add_u32(&b, "update_tcp_con", timeout_config.update_tcp_con);
blobmsg_add_u32(&b, "update_chan_util", timeout_config.update_chan_util);
blobmsg_add_u32(&b, "update_beacon_reports", timeout_config.update_beacon_reports);
blobmsg_add_u32(&b, "client_timeout", timeout_config.client_timeout);
blobmsg_add_u32(&b, "con_timeout", timeout_config.con_timeout);
blobmsg_close_table(&b, times);
send_blob_attr_via_network(b.head, "uci");