proxy.js
/*
tcp request relay
directly connect the target and source
*/
tcp request relay
directly connect the target and source
tcp request relay directly connect the target and source
function relayTCP(socket, address, port, CMD_REPLY){
	let relay=new TCPRelay(socket, address, port, CMD_REPLY, opts.localAddress, opts.localPort);
	relay.on('connection',(socket,relaySocket)=>{
		console.log('[TCP]',`${socket.remoteAddress}:${socket.remotePort} ==> ${net.isIP(address)?'':'('+address+')'} ${relaySocket.remoteAddress}:${relaySocket.remotePort}`);
	}).on('proxy_error',(err,socket,relaySocket)=>{
		console.error('	[TCP proxy error]',`${relay.remoteAddress}:${relay.remotePort}`,err.message);
	}).once('close',e=>{
		let msg='';
		if(socket.remoteAddress)
			msg+=`${socket.remoteAddress}:${socket.remotePort} ==> `;
		if(relay.remoteAddress){
			msg+=`${net.isIP(address)?'':'('+address+')'} ${relay.remoteAddress}:${relay.remotePort}`;
		}else{
			msg+=`${address}:${port}`;
		}
		console.log('  [TCP closed]',msg);
	});
	relay.outModifier=null;
	relay.inModifier=null;
}
function relayTCP ( socket , address , port , CMD_REPLY ) { let relay = new TCPRelay ( socket , address , port , CMD_REPLY , opts . localAddress , opts . localPort ) ; relay . on ( 'connection' , ( socket , relaySocket ) => { console . log ( '[TCP]' , ` ${ socket . remoteAddress } ${ socket . remotePort } ${ net . isIP ( address ) ? '' : '(' + address + ')' } ${ relaySocket . remoteAddress } ${ relaySocket . remotePort } ` ) ; } ) . on ( 'proxy_error' , ( err , socket , relaySocket ) => { console . error ( '	[TCP proxy error]' , ` ${ relay . remoteAddress } ${ relay . remotePort } ` , err . message ) ; } ) . once ( 'close' , e => { let msg = '' ; if ( socket . remoteAddress ) msg += ` ${ socket . remoteAddress } ${ socket . remotePort } ` ; if ( relay . remoteAddress ) { msg += ` ${ net . isIP ( address ) ? '' : '(' + address + ')' } ${ relay . remoteAddress } ${ relay . remotePort } ` ; } else { msg += ` ${ address } ${ port } ` ; } console . log ( '  [TCP closed]' , msg ) ; } ) ; relay . outModifier = null ; relay . inModifier = null ; }
tcp request relay
directly connect the target and source
tcp request relay directly connect the target and source
//example for modify data
 //give a readable stream here to modify outgoing data
 //give a readable stream here to modify incoming data
