/
githubmirror
/
tabby
Обзор
Документация
Войти
/
githubmirror
/
tabby
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tabby-ssh/src/session/forwards.ts
65 строк
2 KB
Eugene Pankov
fixed #5000 - native socksv5 connection support in ssh and connection mode UI overhaul
28 ноя 2021, 20:21
Не верифицирован
28 ноя 2021, 20:21
9856249
Код
Авторство
О чём код?
import socksv5 from '@luminati-io/socksv5' import { Server, Socket, createServer } from 'net' import { ForwardedPortConfig, PortForwardType } from '../api' export class ForwardedPort implements ForwardedPortConfig { type: PortForwardType host = '127.0.0.1' port: number targetAddress: string targetPort: number description: string private listener: Server|null = null async startLocalListener (callback: (accept: () => Socket, reject: () => void, sourceAddress: string|null, sourcePort: number|null, targetAddress: string, targetPort: number) => void): Promise<void> { if (this.type === PortForwardType.Local) { const listener = this.listener = createServer(s => callback( () => s, () => s.destroy(), s.remoteAddress ?? null, s.remotePort ?? null, this.targetAddress, this.targetPort, )) return new Promise((resolve, reject) => { listener.listen(this.port, this.host) listener.on('error', reject) listener.on('listening', resolve) }) } else if (this.type === PortForwardType.Dynamic) { return new Promise((resolve, reject) => { this.listener = socksv5.createServer((info, acceptConnection, rejectConnection) => { callback( () => acceptConnection(true), () => rejectConnection(), null, null, info.dstAddr, info.dstPort, ) }) as Server this.listener.on('error', reject) this.listener.listen(this.port, this.host, resolve) this.listener['useAuth'](socksv5.auth.None()) }) } else { throw new Error('Invalid forward type for a local listener') } } stopLocalListener (): void { this.listener?.close() } toString (): string { if (this.type === PortForwardType.Local) { return `(local) ${this.host}:${this.port} → (remote) ${this.targetAddress}:${this.targetPort}` } if (this.type === PortForwardType.Remote) { return `(remote) ${this.host}:${this.port} → (local) ${this.targetAddress}:${this.targetPort}` } else { return `(dynamic) ${this.host}:${this.port}` } } }