1
0
mirror of https://github.com/lxsang/antd-tunnel-plugin synced 2024-11-16 09:48:21 +01:00

use standard websoket ping message to verify client

This commit is contained in:
lxsang 2021-01-03 02:40:43 +01:00
parent 602d121403
commit fc33873d19
2 changed files with 21 additions and 1 deletions

Binary file not shown.

View File

@ -1050,6 +1050,16 @@ void *handle(void *rq_data)
free(buffer); free(buffer);
} }
} }
else if(h->opcode == WS_PONG)
{
buffer = (uint8_t *)malloc(h->plen + 1);
if (buffer)
{
ws_read_data(rq->client, h, h->plen, buffer);
LOG("Receive pong message from client: %s. Client Alive", buffer);
free(buffer);
}
}
else else
{ {
LOG("Websocket: Text data is not supported"); LOG("Websocket: Text data is not supported");
@ -1072,7 +1082,7 @@ void *handle(void *rq_data)
// check whether we need to send ping message to client // check whether we need to send ping message to client
if (difftime(time(NULL), client->last_io) > (double)PING_INTERVAL) if (difftime(time(NULL), client->last_io) > (double)PING_INTERVAL)
{ {
// send message to client /*
msg.header.type = TUNNEL_PING; msg.header.type = TUNNEL_PING;
msg.header.client_id = 0; msg.header.client_id = 0;
msg.header.channel_id = 0; msg.header.channel_id = 0;
@ -1080,6 +1090,16 @@ void *handle(void *rq_data)
msg.data = NULL; msg.data = NULL;
if (write_msg_to_client(&msg, client) != 0) if (write_msg_to_client(&msg, client) != 0)
{
// close the connection
pthread_mutex_lock(&g_tunnel.lock);
//ws_close(rq->client, 1011);
bst_for_each(g_tunnel.channels, unsubscribe_notify, argv, 1);
pthread_mutex_unlock(&g_tunnel.lock);
ERROR("Unable to ping client, close the connection: %d", client->sock);
return task;
}*/
if(ws_ping(client,"ANTD-TUNNEL",0) != 0)
{ {
// close the connection // close the connection
pthread_mutex_lock(&g_tunnel.lock); pthread_mutex_lock(&g_tunnel.lock);