Fixed tunnel ping/pong that would corrupt traffic.

This commit is contained in:
Ylian Saint-Hilaire 2020-07-19 14:45:29 -07:00
parent 154c503e97
commit eacc7c91b2
5 changed files with 13 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2227,7 +2227,8 @@ function OnWebSocket(msg, s, head) {
if (this.parent.tunneling == false) {
msg = msg.toString();
if ((msg == 'c') || (msg == 'cr')) {
this.parent.tunneling = true; this.pipe(this.parent.tcp); this.parent.tcp.pipe(this); debug(1, "Tunnel active");
// Pipe the connection, but don't pipe text websocket frames into the TCP socket.
this.parent.tunneling = true; this.pipe(this.parent.tcp, { dataTypeSkip: 1 }); this.parent.tcp.pipe(this); debug(1, "Tunnel active");
} else if ((msg.length > 6) && (msg.substring(0, 6) == 'error:')) {
console.log(msg.substring(6));
disconnectTunnel(this.tcp, this, msg.substring(6));

View File

@ -1179,7 +1179,10 @@ function createMeshCore(agent) {
// Called when we get data from the server for a TCP relay (We have to skip the first received 'c' and pipe the rest)
function onTcpRelayServerTunnelData(data) {
if (this.first == true) { this.first = false; this.pipe(this.tcprelay); } // Pipe Server --> Target
if (this.first == true) {
this.first = false;
this.pipe(this.tcprelay, { dataTypeSkip: 1 }); // Pipe Server --> Target (don't pipe text type websocket frames)
}
}
function onTunnelClosed() {
@ -2279,6 +2282,13 @@ function createMeshCore(agent) {
if (sdp != null) { ws.write({ type: 'answer', ctrlChannel: '102938', sdp: sdp }); }
break;
}
case 'ping': {
ws.write("{\"ctrlChannel\":\"102938\",\"type\":\"pong\"}"); // Send pong response
break;
}
case 'pong': { // NOP
break;
}
case 'rtt': {
ws.write({ type: 'rtt', ctrlChannel: '102938', time: obj.time });
break;