From 34d905c5490e207b55aee4b653adffd9fe991454 Mon Sep 17 00:00:00 2001 From: prlanzarin Date: Thu, 10 Oct 2019 13:01:20 -0300 Subject: [PATCH] [tcp] Handle double CRLF keep alive ping with pong and avoid botching the parser with it --- src/TransportTCP.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/TransportTCP.js b/src/TransportTCP.js index 5b6932808..43a24a10e 100644 --- a/src/TransportTCP.js +++ b/src/TransportTCP.js @@ -283,8 +283,26 @@ Transport.prototype = { let pendingSegments; var messages = [], transaction; + // CRLFCRLF keep-alive request, send CRLF response + if (dataString == '\r\n\r\n' || dataString == '\n\r\n\r') { + this.logger.log('received TCP message with CRLFCRLF Keep Alive ping'); + if (socket) { + return socket.write('\r\n', (e) => { + if (e) { + this.logger.warn(`unable to send keep-alive pong due to ${e}`); + } + if (this.ua.configuration.traceSip === true) { + this.logger.log('sent TCP Keep Alive pong'); + } + }); + } else { + this.logger.warn(`unable to send keep-alive pong because there is no socket`); + return; + } + } + // CRLF Keep Alive response from server. Ignore it. - if(dataString === '\r\n') { + if(dataString === '\r\n' || dataString == '\n\r') { SIP.Timers.clearTimeout(this.keepAliveTimeout); this.keepAliveTimeout = null;