|
|
@ -179,9 +179,9 @@ export function validatePortForwarding(forwarding: PortForwarding): PortForwardi
|
|
|
|
|
|
|
|
|
|
|
|
async function createLocalForwarding(connection: Connection, forwarding: PortForwardingLocalRemote): Promise<ActivePortForwarding> {
|
|
|
|
async function createLocalForwarding(connection: Connection, forwarding: PortForwardingLocalRemote): Promise<ActivePortForwarding> {
|
|
|
|
validateLocalRemoteForwarding(forwarding);
|
|
|
|
validateLocalRemoteForwarding(forwarding);
|
|
|
|
const { localAddress, localPort, remoteAddress, remotePort } = forwarding;
|
|
|
|
if (forwarding.localAddress === '') forwarding = { ...forwarding, localAddress: undefined };
|
|
|
|
if (forwarding.localAddress === '*') forwarding = { ...forwarding, localAddress: undefined };
|
|
|
|
|
|
|
|
if (forwarding.localAddress === '*') forwarding = { ...forwarding, localAddress: undefined };
|
|
|
|
if (forwarding.localAddress === '*') forwarding = { ...forwarding, localAddress: undefined };
|
|
|
|
|
|
|
|
const { localAddress, localPort, remoteAddress, remotePort } = forwarding;
|
|
|
|
const logging = Logging.scope(formatPortForwarding(forwarding));
|
|
|
|
const logging = Logging.scope(formatPortForwarding(forwarding));
|
|
|
|
logging.info(`Setting up local forwarding`);
|
|
|
|
logging.info(`Setting up local forwarding`);
|
|
|
|
const { client } = connection;
|
|
|
|
const { client } = connection;
|
|
|
@ -260,11 +260,12 @@ async function createRemoteForwarding(connection: Connection, forwarding: PortFo
|
|
|
|
unlisten = () => connection.client.off('unix connection', listener);
|
|
|
|
unlisten = () => connection.client.off('unix connection', listener);
|
|
|
|
logging.info(`Listening on remote socket path: ${remoteAddress}`);
|
|
|
|
logging.info(`Listening on remote socket path: ${remoteAddress}`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const actualPort = await toPromise<number>(cb => connection.client.forwardIn(remoteAddress || '', remotePort!, cb));
|
|
|
|
const rAddr = remoteAddress === '*' ? '' : remoteAddress || '';
|
|
|
|
|
|
|
|
const actualPort = await toPromise<number>(cb => connection.client.forwardIn(rAddr, remotePort!, cb));
|
|
|
|
forwarding = { ...forwarding, remotePort: actualPort };
|
|
|
|
forwarding = { ...forwarding, remotePort: actualPort };
|
|
|
|
const listener = (details: TcpConnectionDetails, accept: () => ClientChannel) => {
|
|
|
|
const listener = (details: TcpConnectionDetails, accept: () => ClientChannel) => {
|
|
|
|
if (details.destPort !== actualPort) return;
|
|
|
|
if (details.destPort !== actualPort) return;
|
|
|
|
if (details.destIP !== (remoteAddress || '')) return;
|
|
|
|
if (details.destIP !== rAddr) return;
|
|
|
|
onSocket(accept());
|
|
|
|
onSocket(accept());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
connection.client.on('tcp connection', listener);
|
|
|
|
connection.client.on('tcp connection', listener);
|
|
|
|