From 847d33f0373b106bf12cc968ab34edb627dc807f Mon Sep 17 00:00:00 2001 From: Micooz Date: Sat, 3 Feb 2018 23:46:56 +0800 Subject: [PATCH] lib: regen --- lib/core/relay.js | 2 +- lib/transports/ws.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/relay.js b/lib/core/relay.js index 54eb02f..d43c1ea 100644 --- a/lib/core/relay.js +++ b/lib/core/relay.js @@ -1 +1 @@ -'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.Relay=undefined;var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i['return'])_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){return sliceIterator(arr,i)}else{throw new TypeError('Invalid attempt to destructure non-iterable instance')}}}();var _extends=Object.assign||function(target){for(var i=1;ithis.onBoundClose(outbound,inbound));this._outbound.on('updatePresets',this.updatePresets);this._inbound.setOutbound(this._outbound);this._inbound.on('close',()=>this.onBoundClose(inbound,outbound));this._inbound.on('updatePresets',this.updatePresets)}init({proxyRequest}){this._proxyRequest=proxyRequest;this._pipe.broadcast('pipe',{type:_defs.CONNECTION_CREATED,payload:_extends({transport:this._transport},this._remoteInfo)});if(proxyRequest){this._pipe.broadcast(null,{type:_defs.CONNECT_TO_REMOTE,payload:proxyRequest})}}getBounds(transport){const mapping={'tcp':[_transports.TcpInbound,_transports.TcpOutbound],'udp':[_transports.UdpInbound,_transports.UdpOutbound],'tls':[_transports.TlsInbound,_transports.TlsOutbound],'ws':[_transports.WsInbound,_transports.WsOutbound],'mux':[_transports.MuxInbound,_transports.MuxOutbound]};let Inbound=null,Outbound=null;if(transport==='udp'){Inbound=_transports.UdpInbound;Outbound=_transports.UdpOutbound}else{var _ref=__IS_CLIENT__?[_transports.TcpInbound,mapping[transport][1]]:[mapping[transport][0],_transports.TcpOutbound];var _ref2=_slicedToArray(_ref,2);Inbound=_ref2[0];Outbound=_ref2[1]}return{Inbound,Outbound}}onBoundClose(thisBound,anotherBound){if(anotherBound.__closed){if(!this._pipe.destroyed){this._pipe.broadcast('pipe',{type:_defs.CONNECTION_CLOSED,payload:this._remoteInfo})}this.destroy();this.emit('close')}else{if(!this._pipe.destroyed){this._pipe.broadcast('pipe',{type:_defs.CONNECTION_WILL_CLOSE,payload:this._remoteInfo})}thisBound.__closed=true}}getOutbound(){return this._outbound}getInbound(){return this._inbound}getContext(){return this._ctx}onBroadcast(action){const type=action.type;if(__MUX__&&this._transport!=='udp'){if(__IS_CLIENT__&&type===_defs.CONNECT_TO_REMOTE){const remote=`${this._remoteInfo.host}:${this._remoteInfo.port}`;const target=`${action.payload.host}:${action.payload.port}`;_utils.logger.info(`[relay] [${remote}] request over mux(id=${this._ctx.muxRelay.id}): ${target}`);return}}if(type===_defs.CHANGE_PRESET_SUITE){this.onChangePresetSuite(action);return}this._inbound&&this._inbound.onBroadcast(action);this._outbound&&this._outbound.onBroadcast(action)}onChangePresetSuite(action){var _action$payload=action.payload;const type=_action$payload.type,suite=_action$payload.suite,data=_action$payload.data;_utils.logger.verbose(`[relay] changing presets suite to: ${JSON.stringify(suite)}`);this.updatePresets(this.preparePresets([...suite.presets,{'name':'auto-conf'}]));const transport=this._transport;const proxyRequest=this._proxyRequest;this._pipe.broadcast('pipe',{type:_defs.CONNECTION_CREATED,payload:_extends({transport},this._remoteInfo)});if(__IS_CLIENT__){this._pipe.broadcast(null,{type:_defs.CONNECT_TO_REMOTE,payload:_extends({},proxyRequest,{keepAlive:true})})}this._pipe.feed(type,data)}onEncoded(buffer){if(__IS_CLIENT__){this._outbound.write(buffer)}else{this._inbound.write(buffer)}}onDecoded(buffer){if(__IS_CLIENT__){this._inbound.write(buffer)}else{this._outbound.write(buffer)}}encode(buffer,extraArgs){if(this._pipe){this._pipe.feed(_constants.PIPE_ENCODE,buffer,extraArgs)}}decode(buffer,extraArgs){if(this._pipe){this._pipe.feed(_constants.PIPE_DECODE,buffer,extraArgs)}}hasListener(name){return this.listenerCount(name)>0}isOutboundReady(){return this._outbound&&this._outbound.writable}preparePresets(presets){const last=presets[presets.length-1];if(!last||last.name!=='tracker'){presets=presets.concat([{'name':'tracker'}])}return presets}updatePresets(value){this._presets=typeof value==='function'?value(this._presets):value;this._pipe.updateMiddlewares(this._presets)}createPipe(presets){const pipe=new _pipe.Pipe({presets,isUdp:this._transport==='udp'});pipe.on('broadcast',this.onBroadcast.bind(this));pipe.on(`post_${_constants.PIPE_ENCODE}`,this.onEncoded);pipe.on(`post_${_constants.PIPE_DECODE}`,this.onDecoded);return pipe}destroy(){if(!this._destroyed){this._pipe&&this._pipe.destroy();this._inbound&&this._inbound.close();this._outbound&&this._outbound.close();this._ctx=null;this._pipe=null;this._inbound=null;this._outbound=null;this._presets=null;this._remoteInfo=null;this._proxyRequest=null;this._destroyed=true}}}exports.Relay=Relay; \ No newline at end of file +'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.Relay=undefined;var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i['return'])_i['return']()}finally{if(_d)throw _e}}return _arr}return function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){return sliceIterator(arr,i)}else{throw new TypeError('Invalid attempt to destructure non-iterable instance')}}}();var _extends=Object.assign||function(target){for(var i=1;ithis.onBoundClose(outbound,inbound));this._outbound.on('updatePresets',this.updatePresets);this._inbound.setOutbound(this._outbound);this._inbound.on('close',()=>this.onBoundClose(inbound,outbound));this._inbound.on('updatePresets',this.updatePresets)}init({proxyRequest}){this._proxyRequest=proxyRequest;this._pipe.broadcast('pipe',{type:_defs.CONNECTION_CREATED,payload:_extends({transport:this._transport},this._remoteInfo)});if(proxyRequest){this._pipe.broadcast(null,{type:_defs.CONNECT_TO_REMOTE,payload:proxyRequest})}}getBounds(transport){const mapping={'tcp':[_transports.TcpInbound,_transports.TcpOutbound],'udp':[_transports.UdpInbound,_transports.UdpOutbound],'tls':[_transports.TlsInbound,_transports.TlsOutbound],'ws':[_transports.WsInbound,_transports.WsOutbound],'mux':[_transports.MuxInbound,_transports.MuxOutbound]};let Inbound=null,Outbound=null;if(transport==='udp'){Inbound=_transports.UdpInbound;Outbound=_transports.UdpOutbound}else{var _ref=__IS_CLIENT__?[_transports.TcpInbound,mapping[transport][1]]:[mapping[transport][0],_transports.TcpOutbound];var _ref2=_slicedToArray(_ref,2);Inbound=_ref2[0];Outbound=_ref2[1]}return{Inbound,Outbound}}onBoundClose(thisBound,anotherBound){if(anotherBound.__closed){if(this._pipe&&!this._pipe.destroyed){this._pipe.broadcast('pipe',{type:_defs.CONNECTION_CLOSED,payload:this._remoteInfo})}this.destroy();this.emit('close')}else{if(!this._pipe.destroyed){this._pipe.broadcast('pipe',{type:_defs.CONNECTION_WILL_CLOSE,payload:this._remoteInfo})}thisBound.__closed=true}}getOutbound(){return this._outbound}getInbound(){return this._inbound}getContext(){return this._ctx}onBroadcast(action){const type=action.type;if(__MUX__&&this._transport!=='udp'){if(__IS_CLIENT__&&type===_defs.CONNECT_TO_REMOTE){const remote=`${this._remoteInfo.host}:${this._remoteInfo.port}`;const target=`${action.payload.host}:${action.payload.port}`;_utils.logger.info(`[relay] [${remote}] request over mux(id=${this._ctx.muxRelay.id}): ${target}`);return}}if(type===_defs.CHANGE_PRESET_SUITE){this.onChangePresetSuite(action);return}this._inbound&&this._inbound.onBroadcast(action);this._outbound&&this._outbound.onBroadcast(action)}onChangePresetSuite(action){var _action$payload=action.payload;const type=_action$payload.type,suite=_action$payload.suite,data=_action$payload.data;_utils.logger.verbose(`[relay] changing presets suite to: ${JSON.stringify(suite)}`);this.updatePresets(this.preparePresets([...suite.presets,{'name':'auto-conf'}]));const transport=this._transport;const proxyRequest=this._proxyRequest;this._pipe.broadcast('pipe',{type:_defs.CONNECTION_CREATED,payload:_extends({transport},this._remoteInfo)});if(__IS_CLIENT__){this._pipe.broadcast(null,{type:_defs.CONNECT_TO_REMOTE,payload:_extends({},proxyRequest,{keepAlive:true})})}this._pipe.feed(type,data)}onEncoded(buffer){if(__IS_CLIENT__){this._outbound.write(buffer)}else{this._inbound.write(buffer)}}onDecoded(buffer){if(__IS_CLIENT__){this._inbound.write(buffer)}else{this._outbound.write(buffer)}}encode(buffer,extraArgs){if(this._pipe){this._pipe.feed(_constants.PIPE_ENCODE,buffer,extraArgs)}}decode(buffer,extraArgs){if(this._pipe){this._pipe.feed(_constants.PIPE_DECODE,buffer,extraArgs)}}hasListener(name){return this.listenerCount(name)>0}isOutboundReady(){return this._outbound&&this._outbound.writable}preparePresets(presets){const last=presets[presets.length-1];if(!last||last.name!=='tracker'){presets=presets.concat([{'name':'tracker'}])}return presets}updatePresets(value){this._presets=typeof value==='function'?value(this._presets):value;this._pipe.updateMiddlewares(this._presets)}createPipe(presets){const pipe=new _pipe.Pipe({presets,isUdp:this._transport==='udp'});pipe.on('broadcast',this.onBroadcast.bind(this));pipe.on(`post_${_constants.PIPE_ENCODE}`,this.onEncoded);pipe.on(`post_${_constants.PIPE_DECODE}`,this.onDecoded);return pipe}destroy(){if(!this._destroyed){this._pipe&&this._pipe.destroy();this._inbound&&this._inbound.close();this._outbound&&this._outbound.close();this._ctx=null;this._pipe=null;this._inbound=null;this._outbound=null;this._presets=null;this._remoteInfo=null;this._proxyRequest=null;this._destroyed=true}}}exports.Relay=Relay; \ No newline at end of file diff --git a/lib/transports/ws.js b/lib/transports/ws.js index 4624fa4..b29635a 100644 --- a/lib/transports/ws.js +++ b/lib/transports/ws.js @@ -1 +1 @@ -'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.WsOutbound=exports.WsInbound=undefined;var _ws=require('ws');var _ws2=_interopRequireDefault(_ws);var _tcp=require('./tcp');var _utils=require('../utils');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _asyncToGenerator(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{return Promise.resolve(value).then(function(value){step('next',value)},function(err){step('throw',err)})}}return step('next')})}}function patchWebsocket(ws){ws.write=buffer=>ws.send(buffer,{compress:false,mask:false,fin:true},()=>this.emit('drain'));ws.destroy=()=>ws.close();ws.setTimeout=()=>{};ws.on('open',(...args)=>ws.emit('connect',...args));return ws}class WsInbound extends _tcp.TcpInbound{constructor(props){super(props);if(this._socket){const socket=this._socket;socket.on('message',this.onReceive);socket.on('close',()=>socket.destroyed=true);patchWebsocket.call(this,socket)}}get name(){return'ws:inbound'}get bufferSize(){return this._socket?this._socket.bufferedAmount:0}get writable(){return this._socket&&this._socket.readyState===_ws2.default.OPEN}}exports.WsInbound=WsInbound;class WsOutbound extends _tcp.TcpOutbound{get name(){return'ws:outbound'}get bufferSize(){return this._socket?this._socket.bufferedAmount:0}get writable(){return this._socket&&this._socket.readyState===_ws2.default.OPEN}_connect({host,port}){var _this=this;return _asyncToGenerator(function*(){_utils.logger.info(`[${_this.name}] [${_this.remote}] connecting to ws://${host}:${port}`);const socket=new _ws2.default(`ws://${host}:${port}`,{perMessageDeflate:false});socket.on('message',_this.onReceive);socket.on('close',function(){return socket.destroyed=true});return patchWebsocket.call(_this,socket)})()}}exports.WsOutbound=WsOutbound; \ No newline at end of file +'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.WsOutbound=exports.WsInbound=undefined;var _ws=require('ws');var _ws2=_interopRequireDefault(_ws);var _tcp=require('./tcp');var _utils=require('../utils');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _asyncToGenerator(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{return Promise.resolve(value).then(function(value){step('next',value)},function(err){step('throw',err)})}}return step('next')})}}function patchWebsocket(ws){ws.write=buffer=>ws.send(buffer,{compress:false,mask:false,fin:true},()=>this.emit('drain'));ws.end=()=>ws.close();ws.destroy=()=>ws.close();ws.setTimeout=()=>{};ws.on('open',(...args)=>ws.emit('connect',...args));return ws}class WsInbound extends _tcp.TcpInbound{constructor(props){super(props);if(this._socket){const socket=this._socket;socket.on('message',this.onReceive);socket.on('close',()=>socket.destroyed=true);patchWebsocket.call(this,socket)}}get name(){return'ws:inbound'}get bufferSize(){return this._socket?this._socket.bufferedAmount:0}get writable(){return this._socket&&this._socket.readyState===_ws2.default.OPEN}}exports.WsInbound=WsInbound;class WsOutbound extends _tcp.TcpOutbound{get name(){return'ws:outbound'}get bufferSize(){return this._socket?this._socket.bufferedAmount:0}get writable(){return this._socket&&this._socket.readyState===_ws2.default.OPEN}_connect({host,port}){var _this=this;return _asyncToGenerator(function*(){_utils.logger.info(`[${_this.name}] [${_this.remote}] connecting to ws://${host}:${port}`);const socket=new _ws2.default(`ws://${host}:${port}`,{perMessageDeflate:false});socket.on('message',_this.onReceive);socket.on('close',function(){return socket.destroyed=true});return patchWebsocket.call(_this,socket)})()}}exports.WsOutbound=WsOutbound; \ No newline at end of file