Skip to content

Commit

Permalink
[tcp] Handle double CRLF keep alive ping with pong and avoid botching…
Browse files Browse the repository at this point in the history
… the parser with it
  • Loading branch information
prlanzarin committed Oct 10, 2019
1 parent 8071576 commit 34d905c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/TransportTCP.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 34d905c

Please sign in to comment.