fix(PortProxy): fixed import usage of net and tls libraries for PortProxy

This commit is contained in:
Philipp Kunz 2025-02-21 15:17:19 +00:00
parent 23f61eb60b
commit 6c0c65bb1a
4 changed files with 16 additions and 11 deletions

View File

@ -1,5 +1,11 @@
# Changelog # 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) ## 2025-02-21 - 3.3.0 - feat(PortProxy)
Enhanced PortProxy with domain and IP filtering, SNI support, and minimatch integration Enhanced PortProxy with domain and IP filtering, SNI support, and minimatch integration

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartproxy', name: '@push.rocks/smartproxy',
version: '3.3.0', version: '3.3.1',
description: 'a proxy for handling high workloads of proxying' description: 'a proxy for handling high workloads of proxying'
} }

View File

@ -2,9 +2,10 @@
import * as http from 'http'; import * as http from 'http';
import * as https from 'https'; import * as https from 'https';
import * as net from 'net'; import * as net from 'net';
import * as tls from 'tls';
import * as url from 'url'; import * as url from 'url';
export { http, https, net, url }; export { http, https, net, tls, url };
// tsclass scope // tsclass scope
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';

View File

@ -1,6 +1,4 @@
import * as plugins from './smartproxy.plugins.js'; import * as plugins from './smartproxy.plugins.js';
import * as net from 'net';
import * as tls from 'tls';
export interface DomainConfig { export interface DomainConfig {
@ -11,17 +9,17 @@ export interface DomainConfig {
export interface ProxySettings { export interface ProxySettings {
domains: DomainConfig[]; domains: DomainConfig[];
sniEnabled?: boolean; sniEnabled?: boolean;
tlsOptions?: tls.TlsOptions; tlsOptions?: plugins.tls.TlsOptions;
defaultAllowedIPs?: string[]; // Optional default IP patterns if no matching domain found defaultAllowedIPs?: string[]; // Optional default IP patterns if no matching domain found
} }
export class PortProxy { export class PortProxy {
netServer: plugins.net.Server; netServer: plugins.net.Server | plugins.tls.Server;
fromPort: number; fromPort: number;
toPort: number; toPort: number;
settings: ProxySettings; settings: ProxySettings;
constructor(fromPortArg: number, toPortArg: number, settings: ProxySettings) { constructor(fromPortArg: number, toPortArg: number, settings: plugins.tls.TlsOptions & ProxySettings) {
this.fromPort = fromPortArg; this.fromPort = fromPortArg;
this.toPort = toPortArg; this.toPort = toPortArg;
this.settings = settings; this.settings = settings;
@ -46,11 +44,11 @@ export class PortProxy {
return this.settings.domains.find(config => plugins.minimatch(serverName, config.domain)); 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 || ''; 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 serverName = (from as any).servername || '';
const domainConfig = findMatchingDomain(serverName); const domainConfig = findMatchingDomain(serverName);
@ -75,7 +73,7 @@ export class PortProxy {
return; return;
} }
const to = net.createConnection({ const to = plugins.net.createConnection({
host: 'localhost', host: 'localhost',
port: this.toPort, port: this.toPort,
}); });