From f592e378d3738b59d9bef88a57cfbd5db83ebab5 Mon Sep 17 00:00:00 2001 From: JLChnToZ Date: Wed, 2 Jan 2019 17:23:42 +0800 Subject: [PATCH] Use MessagePack for IPC --- lib/terminals/pty.js | 2 +- lib/terminals/pty.js.map | 2 +- lib/terminals/uachost.js | 140 ++++++++++++------------------- lib/terminals/uachost.js.map | 2 +- lib/terminals/uacwrapper.js | 131 +++++++++++------------------ lib/terminals/uacwrapper.js.map | 2 +- lib/terminals/wslpty.js | 2 +- lib/terminals/wslpty.js.map | 2 +- package.json | 2 + src/terminals/pty.ts | 4 +- src/terminals/uachost.ts | 142 ++++++++++++++------------------ src/terminals/uacwrapper.ts | 136 ++++++++++++------------------ src/terminals/wslpty.ts | 4 +- yarn.lock | 39 ++++++++- 14 files changed, 266 insertions(+), 344 deletions(-) diff --git a/lib/terminals/pty.js b/lib/terminals/pty.js index bb85465..215c045 100644 --- a/lib/terminals/pty.js +++ b/lib/terminals/pty.js @@ -61,7 +61,7 @@ class PtyShell extends base_1.TerminalBase { _destroy(err, callback) { if (this.pty) this.pty.kill(); - callback(); + callback(null); } dropFiles(files) { if (files.length) diff --git a/lib/terminals/pty.js.map b/lib/terminals/pty.js.map index 7845113..ca3ccbe 100644 --- a/lib/terminals/pty.js.map +++ b/lib/terminals/pty.js.map @@ -1 +1 @@ -{"version":3,"file":"pty.js","sourceRoot":"","sources":["../../src/terminals/pty.ts"],"names":[],"mappings":";;AAAA,8CAA8C;AAC9C,uCAAuC;AACvC,+BAA0C;AAC1C,uCAAuC;AACvC,4CAA0C;AAC1C,sDAA6C;AAC7C,iCAAuD;AAEvD,MAAM,OAAO,GAAG,yBAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAE5C,MAAa,QAAS,SAAQ,mBAAkB;IAC9C,IAAI,GAAG,KAAK,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SA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,QAAQ,CAAC,CAAC;gBAC/D,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aACvB;iBAAM,IAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAC9B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,CAAC;;gBACrD,OAAO,QAAQ,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;YACrD,OAAO,QAAQ,EAAE,CAAC;SACnB;QAAC,OAAM,GAAG,EAAE;YACX,QAAQ,CAAC,GAAG,CAAC,CAAC;SACf;IACH,CAAC;IAEM,QAAQ,CAAC,GAAiB,EAAE,QAAqC;QACtE,IAAG,IAAI,CAAC,GAAG;YACT,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAClB,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;IAEM,SAAS,CAAC,KAAe;QAC9B,IAAG,KAAK,CAAC,MAAM;YACb,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAClC,CAAC;CACF;AA3DD,4BA2DC"} \ No newline at end of file diff --git a/lib/terminals/uachost.js b/lib/terminals/uachost.js index f2e1226..805c34e 100644 --- a/lib/terminals/uachost.js +++ b/lib/terminals/uachost.js @@ -1,110 +1,67 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +const msgpack_lite_1 = require("msgpack-lite"); const net_1 = require("net"); const path_1 = require("path"); const selector_1 = require("./selector"); function connectToClient(path) { - let buffer; let host; + let flushRequested = false; const client = net_1.connect(path_1.join('\\\\.\\pipe', path)); client - .on('data', handleRequest) + .on('error', handleRemoteClose) .on('close', handleRemoteClose) - .on('error', handleRemoteClose); + .pipe(msgpack_lite_1.createDecodeStream()) + .on('data', handleRequest); + const writer = msgpack_lite_1.createEncodeStream(); + writer.pipe(client); function handleRequest(data) { - if (!buffer) - buffer = data; - else - buffer = Buffer.concat([buffer, data]); - let dataSize = 1; - while (buffer && buffer.length >= dataSize) { - const cmd = buffer.readUInt8(0); - try { - switch (cmd) { - case 128 /* Spawn */: - dataSize += buffer.readUInt32BE(1) + 4; - if (buffer.length < dataSize) - return; - if (host) - throw new Error('Host is already spawned.'); - host = selector_1.createBackend(JSON.parse(buffer.slice(5, dataSize).toString('utf8'))); - host - .on('data', handleResponse) - .on('end', handleClose) - .on('error', handleError) - .spawn(); - break; - case 1 /* Data */: - dataSize += buffer.readUInt32BE(1) + 4; - if (buffer.length < dataSize) - return; - if (!host) - throw new Error('Host is not spawned.'); - host.write(buffer.slice(5, dataSize)); - break; - case 2 /* Resize */: - dataSize += 4; - if (buffer.length < dataSize) - return; - if (!host) - throw new Error('Host is not spawned.'); - host.resize(buffer.readUInt16BE(1), buffer.readUInt16BE(3)); - break; - case 255 /* Exit */: - if (!host) - throw new Error('Host is not spawned.'); - host.end(); - host = undefined; - throw new Error('Host closed.'); - default: throw new Error('Invalid code'); - } + try { + switch (data[0]) { + case 3 /* Spawn */: + if (host) + throw new Error('Host is already spawned.'); + host = selector_1.createBackend(data[1]); + host + .on('data', handleResponse) + .on('end', handleClose) + .on('error', handleError) + .spawn(); + break; + case 1 /* Data */: + if (!host) + throw new Error('Host is not spawned.'); + host.write(data[1]); + break; + case 2 /* Resize */: + if (!host) + throw new Error('Host is not spawned.'); + host.resize(data[1], data[2]); + break; + case 127 /* Exit */: + if (!host) + throw new Error('Host is not spawned.'); + host.end(); + host = undefined; + throw new Error('Host closed.'); + default: throw new Error('Invalid code'); } - catch (_a) { - client.end(); - process.exit(); - } - if (buffer.length > dataSize) - buffer = buffer.slice(dataSize); - else - buffer = undefined; - dataSize = 1; + } + catch (_a) { + client.end(); + process.exit(); } } function handleResponse(data) { - const encoding = host && host.encoding || 'utf8'; - if (Buffer.isBuffer(data)) { - const buf = Buffer.allocUnsafe(5); - buf.writeUInt8(1 /* Data */, 0); - buf.writeUInt32BE(data.length, 1); - client.write(Buffer.concat([buf, data])); - } - else { - const dataLength = Buffer.byteLength(data, encoding); - const buf = Buffer.allocUnsafe(5 + dataLength); - buf.writeUInt8(1 /* Data */, 0); - buf.writeUInt32BE(dataLength, 1); - buf.write(data, 5, dataLength, encoding); - client.write(buf); - } + writeAndFlush(1 /* Data */, data); } function handleClose(code, signal) { - const buf = Buffer.allocUnsafe(5); - buf.writeUInt8(255 /* Exit */, 0); - buf.writeUInt16BE(code || 0, 1); - buf.writeUInt16BE(signal || 0, 3); - client.write(buf); + writeAndFlush(127 /* Exit */, code || 0, signal || 0); client.end(); process.exit(); } function handleError(error) { - const encoding = host && host.encoding || 'utf8'; - const message = error.message || JSON.stringify(error); - const dataLength = Buffer.byteLength(message, encoding); - const buf = Buffer.allocUnsafe(5 + dataLength); - buf.writeUInt8(254 /* Error */, 0); - buf.writeUInt32BE(dataLength, 1); - buf.write(message, 5, dataLength, encoding); - client.write(buf); + writeAndFlush(126 /* Error */, error.message); } function handleRemoteClose() { if (host) @@ -112,6 +69,17 @@ function connectToClient(path) { host = undefined; process.exit(); } + function writeAndFlush(...data) { + writer.write(data); + if (flushRequested) + return; + flushRequested = true; + process.nextTick(flush); + } + function flush() { + writer.encoder.flush(); + flushRequested = false; + } } exports.connectToClient = connectToClient; //# sourceMappingURL=uachost.js.map \ No newline at end of file diff --git a/lib/terminals/uachost.js.map b/lib/terminals/uachost.js.map index e8221bc..0971bd9 100644 --- a/lib/terminals/uachost.js.map +++ b/lib/terminals/uachost.js.map @@ -1 +1 @@ -{"version":3,"file":"uachost.js","sourceRoot":"","sources":["../../src/terminals/uachost.ts"],"names":[],"mappings":";;AAAA,6BAA+C;AAC/C,+BAAwC;AAExC,yCAA2C;AAU3C,SAAgB,eAAe,CAAC,IAAY;IAC1C,IAAI,MAA0B,CAAC;IAC/B,IAAI,IAAuC,CAAC;IAC5C,MAAM,MAAM,GAAG,aAAa,CAAC,WAAQ,CAAC,aAAa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AAqB;QAC3C,aAAa,eAAe,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,SAAS,WAAW,CAAC,IAAa,EAAE,MAAe;QACjD,aAAa,iBAAe,IAAI,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;QACpD,MAAM,CAAC,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;IAED,SAAS,WAAW,CAAC,KAAY;QAC/B,aAAa,kBAAgB,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,SAAS,iBAAiB;QACxB,IAAG,IAAI;YAAE,IAAI,CAAC,GAAG,EAAE,CAAC;QACpB,IAAI,GAAG,SAAS,CAAC;QACjB,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;IAED,SAAS,aAAa,CAAC,GAAG,IAAa;QACrC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACnB,IAAG,cAAc;YAAE,OAAO;QAC1B,cAAc,GAAG,IAAI,CAAC;QACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,SAAS,KAAK;QACZ,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvB,cAAc,GAAG,KAAK,CAAC;IACzB,CAAC;AACH,CAAC;AA5ED,0CA4EC"} \ No newline at end of file diff --git a/lib/terminals/uacwrapper.js b/lib/terminals/uacwrapper.js index a7bce92..5044fd8 100644 --- a/lib/terminals/uacwrapper.js +++ b/lib/terminals/uacwrapper.js @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const crypto_1 = require("crypto"); const defaultShell = require("default-shell"); +const msgpack_lite_1 = require("msgpack-lite"); const net_1 = require("net"); const path_1 = require("path"); const util_1 = require("util"); @@ -23,6 +24,7 @@ class UACClient extends base_1.TerminalBase { this.handleError = this.handleError.bind(this); this.handleExit = this.handleExit.bind(this); this.handleSpawnerClose = this.handleSpawnerClose.bind(this); + this.flushEncoder = this.flushEncoder.bind(this); } async spawn() { const path = this.path || defaultShell; @@ -52,35 +54,14 @@ class UACClient extends base_1.TerminalBase { } resize(cols, rows) { super.resize(cols, rows); - if (this.pty) { - const buf = Buffer.allocUnsafe(5); - buf.writeUInt8(2 /* Resize */, 0); - buf.writeUInt16BE(cols || 0, 1); - buf.writeUInt16BE(rows || 0, 3); - this.pty.write(buf); - } + if (this.pty) + this.writeToRemote(2 /* Resize */, cols || 0, rows || 0); } _write(chunk, encoding, callback) { if (!this.pty) return callback(new Error('Process is not yet attached.')); try { - if (Buffer.isBuffer(chunk)) { - const buf = Buffer.allocUnsafe(5); - buf.writeUInt8(1 /* Data */, 0); - buf.writeUInt32BE(chunk.length, 1); - this.pty.write(buf); - this.pty.write(chunk); - } - else if (typeof chunk === 'string') { - const dataLength = Buffer.byteLength(chunk, encoding); - const buf = Buffer.allocUnsafe(5 + dataLength); - buf.writeUInt8(1 /* Data */, 0); - buf.writeUInt32BE(dataLength, 1); - buf.write(chunk, 5, dataLength, encoding); - this.pty.write(buf); - } - else - return callback(new Error('Unknown data type')); + this.writeToRemote(1 /* Data */, chunk); return callback(); } catch (err) { @@ -89,23 +70,23 @@ class UACClient extends base_1.TerminalBase { } _destroy(err, callback) { if (this.pty) { - const buf = Buffer.allocUnsafe(1); - buf.writeUInt8(255 /* Exit */, 0); - this.pty.write(buf); + this.writeToRemote(127 /* Exit */); this.pty.end(); delete this.pty; } - callback(); + callback(null); } handleConnection(client) { if (this.pty) return; - this.pty = client; client - .on('data', this.handleResponse) .on('error', this.handleError) - .on('end', this.handleExit); - const optionsStr = JSON.stringify({ + .on('close', this.handleExit) + .pipe(msgpack_lite_1.createDecodeStream()) + .on('data', this.handleResponse); + this.pty = msgpack_lite_1.createEncodeStream(); + this.pty.pipe(client); + this.writeToRemote(3 /* Spawn */, { path: this.path, argv: this.argv, cwd: this.cwd, @@ -114,62 +95,29 @@ class UACClient extends base_1.TerminalBase { rows: this.rows, encoding: this.encoding, }); - const dataLength = Buffer.byteLength(optionsStr, 'utf8'); - const buf = Buffer.allocUnsafe(dataLength + 5); - buf.writeUInt8(128 /* Spawn */, 0); - buf.writeUInt32BE(dataLength, 1); - buf.write(optionsStr, 5, dataLength, 'utf8'); - client.write(buf); + this._pushData('\x1b[2J\x1b[1;1H\x1b[?25h\x1b[0m'); } handleResponse(data) { - if (!this.rawBuffer) - this.rawBuffer = data; - else - this.rawBuffer = Buffer.concat([this.rawBuffer, data]); - if (!this.connected) { - this.connected = true; - this._pushData('\x1b[2J\x1b[1;1H\x1b[?25h\x1b[0m'); - } - let dataSize = 1; - while (this.rawBuffer && this.rawBuffer.length >= dataSize) { - const { rawBuffer: buffer } = this; - const cmd = buffer.readUInt8(0); - try { - switch (cmd) { - case 1 /* Data */: - dataSize += buffer.readUInt32BE(1) + 4; - if (buffer.length < dataSize) - return; - this._pushData(buffer.slice(5, dataSize)); - break; - case 254 /* Error */: - dataSize += buffer.readUInt32BE(1) + 4; - if (buffer.length < dataSize) - return; - this.emit('error', new Error(`Remote error: ${buffer.toString('utf8', 5, dataSize)}`)); - break; - case 255 /* Exit */: - dataSize += 4; - if (buffer.length < dataSize) - return; - this.emit('end', buffer.readUInt16BE(1), buffer.readUInt16BE(3)); - throw new Error('Remote dismissed'); - default: throw new Error(`Invalid Code: ${cmd}`); - } + try { + switch (data[0]) { + case 1 /* Data */: + this._pushData(data[1]); + break; + case 126 /* Error */: + this.emit('error', new Error(`Remote error: ${data[1]}`)); + break; + case 127 /* Exit */: + this.emit('end', data[1], data[2]); + throw new Error('Remote dismissed'); + default: throw new Error(`Invalid Code: ${data[0]}`); } - catch (error) { - console.error(process.platform === 'win32' ? error : (error.message || error)); - if (this.pty) { - this.pty.end(); - delete this.pty; - } - return; + } + catch (error) { + console.error(process.type === 'renderer' ? error : (error.message || error)); + if (this.pty) { + this.pty.end(); + delete this.pty; } - if (buffer.length > dataSize) - this.rawBuffer = buffer.slice(dataSize); - else - this.rawBuffer = undefined; - dataSize = 1; } } handleError(error) { @@ -187,6 +135,21 @@ class UACClient extends base_1.TerminalBase { handleExit() { delete this.pty; } + writeToRemote(...data) { + if (!this.pty) + return; + this.pty.write(data); + if (this.flushRequested) + return; + this.flushRequested = true; + process.nextTick(this.flushEncoder); + } + flushEncoder() { + if (!this.pty) + return; + this.pty.encoder.flush(); + this.flushRequested = false; + } } exports.UACClient = UACClient; //# sourceMappingURL=uacwrapper.js.map \ No newline at end of file diff --git a/lib/terminals/uacwrapper.js.map b/lib/terminals/uacwrapper.js.map index f91dae9..b86a354 100644 --- a/lib/terminals/uacwrapper.js.map +++ b/lib/terminals/uacwrapper.js.map @@ -1 +1 @@ -{"version":3,"file":"uacwrapper.js","sourceRoot":"","sources":["../../src/terminals/uacwrapper.ts"],"names":[],"mappings":";;AAAA,iDAAyC;AACzC,mCAAqC;AACrC,8CAA8C;AAC9C,6BAAmD;AACnD,+BAAkD;AAClD,+BAAiC;AACjC,4CAA0C;AAC1C,sDAA6C;AAC7C,iCAAuD;AAGvD,MAAM,eAAe,GAAG,yBAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,yBAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC;AAC5F,MAAM,OAAO,GAAG,yBAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC5C,MAAM,gBAAgB,GAAG,gBAAS,CAAC,oBAAW,CAAC,CAAC;AAEhD,SAAS,WAAW;IAClB,IAAI,CAAC,KAAK,EAAE,CAAC;AACf,CAAC;AAED,MAAa,SAAU,SAAQ,mBAAoB;IAIjD,YAAmB,OAAyB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc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/E,IAAG,IAAI,CAAC,GAAG,EAAE;oBACX,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;oBACf,OAAO,IAAI,CAAC,GAAG,CAAC;iBACjB;gBACD,OAAO;aACR;YACD,IAAG,MAAM,CAAC,MAAM,GAAG,QAAQ;gBACzB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;;gBAExC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC7B,QAAQ,GAAG,CAAC,CAAC;SACd;IACH,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEO,kBAAkB,CAAC,IAAa;QACtC,IAAG,IAAI,EAAE;YACP,IAAG,IAAI,CAAC,GAAG,EAAE;gBACX,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;gBACf,OAAO,IAAI,CAAC,GAAG,CAAC;aACjB;YACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC,CAAC;SACzE;IACH,CAAC;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF;AA7KD,8BA6KC"} \ No newline at end of file +{"version":3,"file":"uacwrapper.js","sourceRoot":"","sources":["../../src/terminals/uacwrapper.ts"],"names":[],"mappings":";;AAAA,iDAAyC;AACzC,mCAAqC;AACrC,8CAA8C;AAC9C,+CAAoF;AACpF,6BAAmD;AACnD,+BAAkD;AAClD,+BAAiC;AACjC,4CAA0C;AAC1C,sDAA6C;AAC7C,iCAAuD;AAGvD,MAAM,eAAe,GAAG,yBAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,yBAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC;AAC5F,MAAM,OAAO,GAAG,yBAA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I,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC;IAEO,YAAY;QAClB,IAAG,CAAC,IAAI,CAAC,GAAG;YAAE,OAAO;QACrB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;IAC9B,CAAC;CACF;AA5ID,8BA4IC"} \ No newline at end of file diff --git a/lib/terminals/wslpty.js b/lib/terminals/wslpty.js index d57973e..81dc8e0 100644 --- a/lib/terminals/wslpty.js +++ b/lib/terminals/wslpty.js @@ -94,7 +94,7 @@ class WslPtyShell extends base_1.TerminalBase { _destroy(err, callback) { if (this.pty) this.pty.kill(); - callback(); + callback(null); } async dropFiles(files) { if (!files.length) diff --git a/lib/terminals/wslpty.js.map b/lib/terminals/wslpty.js.map index 8fbcd16..08a0ea8 100644 --- a/lib/terminals/wslpty.js.map +++ b/lib/terminals/wslpty.js.map @@ -1 +1 @@ -{"version":3,"file":"wslpty.js","sourceRoot":"","sources":["../../src/terminals/wslpty.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AACvC,mCAAqC;AACrC,4CAA8C;AAC9C,iCAAuD;AAEvD,MAAa,WAAY,SAAQ,mBAAkB;IACjD,IAAI,OAAO,KAAK,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAElF,YAAY,OAAyB;QACnC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,kBAAkB;QAClB,IAAG,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE;YACzB,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;YACxB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;YAEvC,4BAA4B;YAC5B,KAAI,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,CAAC,SAAS,CAAC,KAAe;QACpC,IAAG,CAAC,KAAK,CAAC,MAAM;YAAE,OAAO;QACzB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;CACF;AAjGD,kCAiGC"} \ No newline at end of file diff --git a/package.json b/package.json index d17ef05..f5eba00 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@types/gist-package-json": "git+https://gist.github.com/5c1cc527fe6b5b7dba41fec7fe54bf6e.git", "@types/hyperscript": "0.0.3", "@types/js-yaml": "^3.11.2", + "@types/msgpack-lite": "^0.1.6", "@types/shell-escape": "^0.2.0", "@types/which": "^1.3.1", "@types/yargs": "^12.0.4", @@ -48,6 +49,7 @@ "hyperscript": "^2.0.2", "isexe": "^2.0.0", "js-yaml": "^3.12.0", + "msgpack-lite": "^0.1.26", "node-pty": "^0.8.0", "shell-escape": "^0.2.0", "tocas-ui": "^2.3.2", diff --git a/src/terminals/pty.ts b/src/terminals/pty.ts index b3b728c..036b9a7 100644 --- a/src/terminals/pty.ts +++ b/src/terminals/pty.ts @@ -57,10 +57,10 @@ export class PtyShell extends TerminalBase { } } - public _destroy(err: Error, callback: () => void) { + public _destroy(err: Error | null, callback: (err: Error | null) => void) { if(this.pty) this.pty.kill(); - callback(); + callback(null); } public dropFiles(files: string[]) { diff --git a/src/terminals/uachost.ts b/src/terminals/uachost.ts index d78c0ab..780a9be 100644 --- a/src/terminals/uachost.ts +++ b/src/terminals/uachost.ts @@ -1,111 +1,83 @@ +import { createDecodeStream, createEncodeStream } from 'msgpack-lite'; import { connect as connectServer } from 'net'; import { join as joinPath } from 'path'; +import { TerminalLaunchOptions } from '../interfaces'; import { TerminalBase } from './base'; import { createBackend } from './selector'; export const enum CMDType { Data = 0x01, Resize = 0x02, - Spawn = 0x80, - Error = 0xFE, - Exit = 0xFF, + Spawn = 0x03, + Error = 0x7E, + Exit = 0x7F, } +export type CMDData = + [CMDType.Data, any] | + [CMDType.Resize, number, number] | + [CMDType.Spawn, TerminalLaunchOptions] | + [CMDType.Error, string] | + [CMDType.Exit, number, number] | + [CMDType, ...any[]]; + export function connectToClient(path: string) { - let buffer: Buffer | undefined; let host: TerminalBase | undefined; + let flushRequested = false; const client = connectServer(joinPath('\\\\.\\pipe', path)); client - .on('data', handleRequest) + .on('error', handleRemoteClose) .on('close', handleRemoteClose) - .on('error', handleRemoteClose); + .pipe(createDecodeStream()) + .on('data', handleRequest); + const writer = createEncodeStream(); + writer.pipe(client); - function handleRequest(data: Buffer) { - if(!buffer) buffer = data; - else buffer = Buffer.concat([buffer, data]); - let dataSize = 1; - while(buffer && buffer.length >= dataSize) { - const cmd: CMDType = buffer.readUInt8(0); - try { - switch(cmd) { - case CMDType.Spawn: - dataSize += buffer.readUInt32BE(1) + 4; - if(buffer.length < dataSize) return; - if(host) throw new Error('Host is already spawned.'); - host = createBackend(JSON.parse(buffer.slice(5, dataSize).toString('utf8'))); - host - .on('data', handleResponse) - .on('end', handleClose) - .on('error', handleError) - .spawn(); - break; - case CMDType.Data: - dataSize += buffer.readUInt32BE(1) + 4; - if(buffer.length < dataSize) return; - if(!host) throw new Error('Host is not spawned.'); - host.write(buffer.slice(5, dataSize)); - break; - case CMDType.Resize: - dataSize += 4; - if(buffer.length < dataSize) return; - if(!host) throw new Error('Host is not spawned.'); - host.resize(buffer.readUInt16BE(1), buffer.readUInt16BE(3)); - break; - case CMDType.Exit: - if(!host) throw new Error('Host is not spawned.'); - host.end(); - host = undefined; - throw new Error('Host closed.'); - default: throw new Error('Invalid code'); - } - } catch { - client.end(); - process.exit(); + function handleRequest(data: CMDData) { + try { + switch(data[0]) { + case CMDType.Spawn: + if(host) throw new Error('Host is already spawned.'); + host = createBackend(data[1]); + host + .on('data', handleResponse) + .on('end', handleClose) + .on('error', handleError) + .spawn(); + break; + case CMDType.Data: + if(!host) throw new Error('Host is not spawned.'); + host.write(data[1]); + break; + case CMDType.Resize: + if(!host) throw new Error('Host is not spawned.'); + host.resize(data[1], data[2]); + break; + case CMDType.Exit: + if(!host) throw new Error('Host is not spawned.'); + host.end(); + host = undefined; + throw new Error('Host closed.'); + default: throw new Error('Invalid code'); } - if(buffer.length > dataSize) - buffer = buffer.slice(dataSize); - else - buffer = undefined; - dataSize = 1; + } catch { + client.end(); + process.exit(); } } function handleResponse(data: string | Buffer) { - const encoding = host && host.encoding || 'utf8'; - if(Buffer.isBuffer(data)) { - const buf = Buffer.allocUnsafe(5); - buf.writeUInt8(CMDType.Data, 0); - buf.writeUInt32BE(data.length, 1); - client.write(Buffer.concat([buf, data])); - } else { - const dataLength = Buffer.byteLength(data, encoding); - const buf = Buffer.allocUnsafe(5 + dataLength); - buf.writeUInt8(CMDType.Data, 0); - buf.writeUInt32BE(dataLength, 1); - buf.write(data, 5, dataLength, encoding); - client.write(buf); - } + writeAndFlush(CMDType.Data, data); } function handleClose(code?: number, signal?: number) { - const buf = Buffer.allocUnsafe(5); - buf.writeUInt8(CMDType.Exit, 0); - buf.writeUInt16BE(code || 0, 1); - buf.writeUInt16BE(signal || 0, 3); - client.write(buf); + writeAndFlush(CMDType.Exit, code || 0, signal || 0); client.end(); process.exit(); } function handleError(error: Error) { - const encoding = host && host.encoding || 'utf8'; - const message = error.message || JSON.stringify(error); - const dataLength = Buffer.byteLength(message, encoding); - const buf = Buffer.allocUnsafe(5 + dataLength); - buf.writeUInt8(CMDType.Error, 0); - buf.writeUInt32BE(dataLength, 1); - buf.write(message, 5, dataLength, encoding); - client.write(buf); + writeAndFlush(CMDType.Error, error.message); } function handleRemoteClose() { @@ -113,4 +85,16 @@ export function connectToClient(path: string) { host = undefined; process.exit(); } + + function writeAndFlush(...data: CMDData) { + writer.write(data); + if(flushRequested) return; + flushRequested = true; + process.nextTick(flush); + } + + function flush() { + writer.encoder.flush(); + flushRequested = false; + } } diff --git a/src/terminals/uacwrapper.ts b/src/terminals/uacwrapper.ts index 0d0c886..bbf98a4 100644 --- a/src/terminals/uacwrapper.ts +++ b/src/terminals/uacwrapper.ts @@ -1,13 +1,14 @@ import { execFile } from 'child_process'; import { randomBytes } from 'crypto'; import * as defaultShell from 'default-shell'; +import { createDecodeStream, createEncodeStream, EncodeStream } from 'msgpack-lite'; import { createServer, Server, Socket } from 'net'; import { basename, join as joinPath } from 'path'; import { promisify } from 'util'; import { whichAsync } from '../pathutils'; import { electron } from '../remote-wrapper'; import { TerminalBase, TerminalOptions } from './base'; -import { CMDType } from './uachost'; +import { CMDData, CMDType } from './uachost'; const appPathResolver = electron.app.isPackaged ? '' : `\`"${electron.app.getAppPath()}\`"`; const exePath = electron.app.getPath('exe'); @@ -17,9 +18,8 @@ function closeServer(this: Server) { this.close(); } -export class UACClient extends TerminalBase { - private rawBuffer?: Buffer; - private connected?: boolean; +export class UACClient extends TerminalBase { + private flushRequested?: boolean; public constructor(options?: TerminalOptions) { super(options); @@ -28,6 +28,7 @@ export class UACClient extends TerminalBase { this.handleError = this.handleError.bind(this); this.handleExit = this.handleExit.bind(this); this.handleSpawnerClose = this.handleSpawnerClose.bind(this); + this.flushEncoder = this.flushEncoder.bind(this); } public async spawn() { @@ -59,58 +60,39 @@ export class UACClient extends TerminalBase { public resize(cols: number, rows: number) { super.resize(cols, rows); - if(this.pty) { - const buf = Buffer.allocUnsafe(5); - buf.writeUInt8(CMDType.Resize, 0); - buf.writeUInt16BE(cols || 0, 1); - buf.writeUInt16BE(rows || 0, 3); - this.pty.write(buf); - } + if(this.pty) + this.writeToRemote(CMDType.Resize, cols || 0, rows || 0); } public _write(chunk: any, encoding: string, callback: (err?: Error) => void) { if(!this.pty) return callback(new Error('Process is not yet attached.')); try { - if(Buffer.isBuffer(chunk)) { - const buf = Buffer.allocUnsafe(5); - buf.writeUInt8(CMDType.Data, 0); - buf.writeUInt32BE(chunk.length, 1); - this.pty.write(buf); - this.pty.write(chunk); - } else if(typeof chunk === 'string') { - const dataLength = Buffer.byteLength(chunk, encoding); - const buf = Buffer.allocUnsafe(5 + dataLength); - buf.writeUInt8(CMDType.Data, 0); - buf.writeUInt32BE(dataLength, 1); - buf.write(chunk, 5, dataLength, encoding); - this.pty.write(buf); - } else - return callback(new Error('Unknown data type')); + this.writeToRemote(CMDType.Data, chunk); return callback(); } catch(err) { callback(err); } } - public _destroy(err: Error, callback: () => void) { + public _destroy(err: Error | null, callback: (err: Error | null) => void) { if(this.pty) { - const buf = Buffer.allocUnsafe(1); - buf.writeUInt8(CMDType.Exit, 0); - this.pty.write(buf); + this.writeToRemote(CMDType.Exit); this.pty.end(); delete this.pty; } - callback(); + callback(null); } private handleConnection(client: Socket) { if(this.pty) return; - this.pty = client; client - .on('data', this.handleResponse) .on('error', this.handleError) - .on('end', this.handleExit); - const optionsStr = JSON.stringify({ + .on('close', this.handleExit) + .pipe(createDecodeStream()) + .on('data', this.handleResponse); + this.pty = createEncodeStream(); + this.pty.pipe(client); + this.writeToRemote(CMDType.Spawn, { path: this.path, argv: this.argv, cwd: this.cwd, @@ -118,58 +100,30 @@ export class UACClient extends TerminalBase { cols: this.cols, rows: this.rows, encoding: this.encoding, - } as TerminalOptions); - const dataLength = Buffer.byteLength(optionsStr, 'utf8'); - const buf = Buffer.allocUnsafe(dataLength + 5); - buf.writeUInt8(CMDType.Spawn, 0); - buf.writeUInt32BE(dataLength, 1); - buf.write(optionsStr, 5, dataLength, 'utf8'); - client.write(buf); + }); + this._pushData('\x1b[2J\x1b[1;1H\x1b[?25h\x1b[0m'); } - private handleResponse(data: Buffer) { - if(!this.rawBuffer) this.rawBuffer = data; - else this.rawBuffer = Buffer.concat([this.rawBuffer, data]); - if(!this.connected) { - this.connected = true; - this._pushData('\x1b[2J\x1b[1;1H\x1b[?25h\x1b[0m'); - } - let dataSize = 1; - while(this.rawBuffer && this.rawBuffer.length >= dataSize) { - const { rawBuffer: buffer } = this; - const cmd = buffer.readUInt8(0) as CMDType; - try { - switch(cmd) { - case CMDType.Data: - dataSize += buffer.readUInt32BE(1) + 4; - if(buffer.length < dataSize) return; - this._pushData(buffer.slice(5, dataSize)); - break; - case CMDType.Error: - dataSize += buffer.readUInt32BE(1) + 4; - if(buffer.length < dataSize) return; - this.emit('error', new Error(`Remote error: ${buffer.toString('utf8', 5, dataSize)}`)); - break; - case CMDType.Exit: - dataSize += 4; - if(buffer.length < dataSize) return; - this.emit('end', buffer.readUInt16BE(1), buffer.readUInt16BE(3)); - throw new Error('Remote dismissed'); - default: throw new Error(`Invalid Code: ${cmd}`); - } - } catch(error) { - console.error(process.platform === 'win32' ? error : (error.message || error)); - if(this.pty) { - this.pty.end(); - delete this.pty; - } - return; + private handleResponse(data: CMDData) { + try { + switch(data[0]) { + case CMDType.Data: + this._pushData(data[1]); + break; + case CMDType.Error: + this.emit('error', new Error(`Remote error: ${data[1]}`)); + break; + case CMDType.Exit: + this.emit('end', data[1], data[2]); + throw new Error('Remote dismissed'); + default: throw new Error(`Invalid Code: ${data[0]}`); + } + } catch(error) { + console.error(process.type === 'renderer' ? error : (error.message || error)); + if(this.pty) { + this.pty.end(); + delete this.pty; } - if(buffer.length > dataSize) - this.rawBuffer = buffer.slice(dataSize); - else - this.rawBuffer = undefined; - dataSize = 1; } } @@ -190,4 +144,18 @@ export class UACClient extends TerminalBase { private handleExit() { delete this.pty; } + + private writeToRemote(...data: CMDData) { + if(!this.pty) return; + this.pty.write(data); + if(this.flushRequested) return; + this.flushRequested = true; + process.nextTick(this.flushEncoder); + } + + private flushEncoder() { + if(!this.pty) return; + this.pty.encoder.flush(); + this.flushRequested = false; + } } diff --git a/src/terminals/wslpty.ts b/src/terminals/wslpty.ts index 7e5137c..a6692d3 100644 --- a/src/terminals/wslpty.ts +++ b/src/terminals/wslpty.ts @@ -90,10 +90,10 @@ export class WslPtyShell extends TerminalBase { } } - public _destroy(err: Error, callback: () => void) { + public _destroy(err: Error | null, callback: (err: Error | null) => void) { if(this.pty) this.pty.kill(); - callback(); + callback(null); } public async dropFiles(files: string[]) { diff --git a/yarn.lock b/yarn.lock index 5322cc7..1b5b528 100644 --- a/yarn.lock +++ b/yarn.lock @@ -44,6 +44,18 @@ version "3.11.2" resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.11.2.tgz#699ad86054cc20043c30d66a6fcde30bbf5d3d5e" +"@types/msgpack-lite@^0.1.6": + version "0.1.6" + resolved "https://registry.yarnpkg.com/@types/msgpack-lite/-/msgpack-lite-0.1.6.tgz#27e2a7eea4514f084ed4f9b53f8f63e6db4d6d50" + integrity sha512-Y9GFyM8qt5p7p+HtM9rsSAnle4ZmcpNAhbaFQyj1XzaHgEVCYgRNJiCeGxf5Jf81/a/G1o+LuGDE3mvLosU2MA== + dependencies: + "@types/node" "*" + +"@types/node@*": + version "10.12.18" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67" + integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ== + "@types/node@^7.0.12": version "7.10.2" resolved "https://registry.yarnpkg.com/@types/node/-/node-7.10.2.tgz#a98845168012d7a63a84d50e738829da43bdb0de" @@ -1715,6 +1727,11 @@ esutils@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" +event-lite@^0.1.1: + version "0.1.2" + resolved "https://registry.yarnpkg.com/event-lite/-/event-lite-0.1.2.tgz#838a3e0fdddef8cc90f128006c8e55a4e4e4c11b" + integrity sha512-HnSYx1BsJ87/p6swwzv+2v6B4X+uxUteoDfRxsAb1S1BePzQqOLevVmkdA15GHJVd9A9Ok6wygUR18Hu0YeV9g== + execa@^0.10.0: version "0.10.0" resolved "https://registry.yarnpkg.com/execa/-/execa-0.10.0.tgz#ff456a8f53f90f8eccc71a96d11bdfc7f082cb50" @@ -2136,6 +2153,11 @@ hyperscript@^2.0.2: class-list "~0.1.0" html-element "^2.0.0" +ieee754@^1.1.8: + version "1.1.12" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.12.tgz#50bf24e5b9c8bb98af4964c941cdb0918da7b60b" + integrity sha512-GguP+DRY+pJ3soyIiGPTvdiVXjZ+DbXOxGpXn3eMvNW4x4irjqXm4wHKscC+TfxSJ0yw/S1F24tqdMNsMZTiLA== + image-size@~0.5.0: version "0.5.5" resolved "https://registry.yarnpkg.com/image-size/-/image-size-0.5.5.tgz#09dfd4ab9d20e29eb1c3e80b8990378df9e3cb9c" @@ -2169,6 +2191,11 @@ ini@~1.3.0: version "1.3.5" resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927" +int64-buffer@^0.1.9: + version "0.1.10" + resolved "https://registry.yarnpkg.com/int64-buffer/-/int64-buffer-0.1.10.tgz#277b228a87d95ad777d07c13832022406a473423" + integrity sha1-J3siiofZWtd30HwTgyAiQGpHNCM= + invariant@^2.2.2: version "2.2.4" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" @@ -2255,7 +2282,7 @@ isarray@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" -isarray@~1.0.0: +isarray@^1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" @@ -2668,6 +2695,16 @@ ms@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" +msgpack-lite@^0.1.26: + version "0.1.26" + resolved "https://registry.yarnpkg.com/msgpack-lite/-/msgpack-lite-0.1.26.tgz#dd3c50b26f059f25e7edee3644418358e2a9ad89" + integrity sha1-3TxQsm8FnyXn7e42REGDWOKprYk= + dependencies: + event-lite "^0.1.1" + ieee754 "^1.1.8" + int64-buffer "^0.1.9" + isarray "^1.0.0" + nan@2.10.0: version "2.10.0" resolved "http://registry.npmjs.org/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"