From 4375415b9228c0537d1d18b1f1ba263d286f7f3a Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Thu, 10 Feb 2022 21:21:07 +0000 Subject: Relay server PINGs to all clients in case they rely on PINGs to stay alive. --- message.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'message.c') diff --git a/message.c b/message.c index 5f0c2fe..9c07a83 100644 --- a/message.c +++ b/message.c @@ -39,6 +39,14 @@ int processservermessage(SSL *server_ssl, char *str, struct client *clients, int // sourcefd = 0 as this is a trusted response sendtoserver(server_ssl, outgoingmsg, strlen(outgoingmsg), 0, clients, settings); + // Also relay the request to all clients in case they were expecting PINGs to keep themselves alive + if (!snprintf(outgoingmsg, MAXDATASIZE, "PING %s", tokens[1])) { // TODO - Make sure tokens[1] actually has a token + fprintf(stderr, "Error while preparing PING relay!\n"); + debugprint(DEBUG_CRIT, "Error while preparing PING relay!\n"); + outgoingmsg[0] = '\0'; + } + sendtoallclients(clients, outgoingmsg, EXCEPT_NONE, settings); + // We processed something so return true return 1; } @@ -1091,6 +1099,13 @@ int processclientmessage(SSL *server_ssl, char *str, struct client *clients, int return 1; } + // Client PONG received? This is almost certainly in response to a relayed server PING from us. + // We can ignore it since we don't actively PING clients, instead relying on the server's PING frequency. + if (strncasecmp(tokens[0], "PONG", strlen(tokens[0])) == 0) { + debugprint(DEBUG_FULL, "Client PONG found and it is: %s with length %zd! Ignoring since we don't track client PONGs.\n", tokens[0], strlen(tokens[0])); + return 1; + } + // TODO - Ignoring CAP for now so as not to confuse other clients, but we should probably query the server then relay the response to the client if (strncasecmp(tokens[0], "CAP", strlen(tokens[0])) == 0) { debugprint(DEBUG_FULL, "Client CAP found and it is: %s with length %zd! Ignoring completely for now - TODO - do something useful!\n", tokens[0], strlen(tokens[0])); -- cgit v1.2.3