From 6c0c65bb1a31e2e12fec66c016d571a28bf17300 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Fri, 21 Feb 2025 15:17:19 +0000 Subject: [PATCH] fix(PortProxy): fixed import usage of net and tls libraries for PortProxy --- changelog.md | 6 ++++++ ts/00_commitinfo_data.ts | 2 +- ts/smartproxy.plugins.ts | 3 ++- ts/smartproxy.portproxy.ts | 16 +++++++--------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/changelog.md b/changelog.md index 8adce93..acc2aa3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-02-21 - 3.3.1 - fix(PortProxy) +fixed import usage of net and tls libraries for PortProxy + +- Corrected the use of plugins for importing 'tls' and 'net' libraries in the PortProxy module. +- Updated the constructor of PortProxy to accept combined tls options with ProxySettings. + ## 2025-02-21 - 3.3.0 - feat(PortProxy) Enhanced PortProxy with domain and IP filtering, SNI support, and minimatch integration diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 1cf7e3c..c1359ce 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartproxy', - version: '3.3.0', + version: '3.3.1', description: 'a proxy for handling high workloads of proxying' } diff --git a/ts/smartproxy.plugins.ts b/ts/smartproxy.plugins.ts index 47a8e6a..da14888 100644 --- a/ts/smartproxy.plugins.ts +++ b/ts/smartproxy.plugins.ts @@ -2,9 +2,10 @@ import * as http from 'http'; import * as https from 'https'; import * as net from 'net'; +import * as tls from 'tls'; import * as url from 'url'; -export { http, https, net, url }; +export { http, https, net, tls, url }; // tsclass scope import * as tsclass from '@tsclass/tsclass'; diff --git a/ts/smartproxy.portproxy.ts b/ts/smartproxy.portproxy.ts index 8cc4c46..8f70ff2 100644 --- a/ts/smartproxy.portproxy.ts +++ b/ts/smartproxy.portproxy.ts @@ -1,6 +1,4 @@ import * as plugins from './smartproxy.plugins.js'; -import * as net from 'net'; -import * as tls from 'tls'; export interface DomainConfig { @@ -11,17 +9,17 @@ export interface DomainConfig { export interface ProxySettings { domains: DomainConfig[]; sniEnabled?: boolean; - tlsOptions?: tls.TlsOptions; + tlsOptions?: plugins.tls.TlsOptions; defaultAllowedIPs?: string[]; // Optional default IP patterns if no matching domain found } export class PortProxy { - netServer: plugins.net.Server; + netServer: plugins.net.Server | plugins.tls.Server; fromPort: number; toPort: number; settings: ProxySettings; - constructor(fromPortArg: number, toPortArg: number, settings: ProxySettings) { + constructor(fromPortArg: number, toPortArg: number, settings: plugins.tls.TlsOptions & ProxySettings) { this.fromPort = fromPortArg; this.toPort = toPortArg; this.settings = settings; @@ -46,11 +44,11 @@ export class PortProxy { return this.settings.domains.find(config => plugins.minimatch(serverName, config.domain)); }; - const server = this.settings.sniEnabled ? tls.createServer(this.settings.tlsOptions || {}) : net.createServer(); + const server = this.settings.sniEnabled ? plugins.tls.createServer(this.settings.tlsOptions || {}) : plugins.net.createServer(); - this.netServer = server.on('connection', (from: net.Socket) => { + this.netServer = server.on('connection', (from: plugins.net.Socket) => { const remoteIP = from.remoteAddress || ''; - if (this.settings.sniEnabled && from instanceof tls.TLSSocket) { + if (this.settings.sniEnabled && from instanceof plugins.tls.TLSSocket) { const serverName = (from as any).servername || ''; const domainConfig = findMatchingDomain(serverName); @@ -75,7 +73,7 @@ export class PortProxy { return; } - const to = net.createConnection({ + const to = plugins.net.createConnection({ host: 'localhost', port: this.toPort, });