fix(plugins): Simplified plugin import structure across codebase

This commit is contained in:
Philipp Kunz 2025-02-21 23:11:13 +00:00
parent 233b26c308
commit 438d65107d
7 changed files with 27 additions and 6 deletions

View File

@ -1,5 +1,12 @@
# Changelog
## 2025-02-21 - 3.8.1 - fix(plugins)
Simplified plugin import structure across codebase
- Consolidated plugin imports under a single 'plugins.ts' file.
- Replaced individual plugin imports in smartproxy files with the consolidated plugin imports.
- Fixed error handling for early socket errors in PortProxy setup.
## 2025-02-21 - 3.8.0 - feat(PortProxy)
Add active connection tracking and logging in PortProxy

View File

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

View File

@ -1,4 +1,4 @@
import * as plugins from './smartproxy.plugins.js';
import * as plugins from './plugins.js';
import { ProxyRouter } from './smartproxy.classes.router.js';
import * as fs from 'fs';
import * as path from 'path';

View File

@ -1,4 +1,4 @@
import * as plugins from './smartproxy.plugins.js';
import * as plugins from './plugins.js';
export class ProxyRouter {
public reverseProxyConfigs: plugins.tsclass.network.IReverseProxyConfig[] = [];

View File

@ -1,4 +1,4 @@
import * as plugins from './smartproxy.plugins.js';
import * as plugins from './plugins.js';
export class SslRedirect {
httpServer: plugins.http.Server;

View File

@ -1,4 +1,4 @@
import * as plugins from './smartproxy.plugins.js';
import * as plugins from './plugins.js';
export interface IDomainConfig {
domain: string; // glob pattern for domain
@ -167,7 +167,19 @@ export class PortProxy {
// Create a plain net server for TLS passthrough.
this.netServer = plugins.net.createServer((socket: plugins.net.Socket) => {
const remoteIP = socket.remoteAddress || '';
// Flag to detect if we've received the first data chunk.
let initialDataReceived = false;
// Immediately attach an error handler to catch early errors.
socket.on('error', (err: Error) => {
if (!initialDataReceived) {
console.log(`(Premature) Incoming socket error from ${remoteIP} before data received: ${err.message}`);
} else {
console.log(`(Immediate) Incoming socket error from ${remoteIP}: ${err.message}`);
}
});
// Track the new incoming connection.
this.activeConnections.add(socket);
console.log(`New connection from ${remoteIP}. Active connections: ${this.activeConnections.size}`);
@ -265,6 +277,7 @@ export class PortProxy {
// For SNI-enabled connections, peek at the first chunk.
if (this.settings.sniEnabled) {
socket.once('data', (chunk: Buffer) => {
initialDataReceived = true;
// Try to extract the server name from the ClientHello.
const serverName = extractSNI(chunk) || '';
console.log(`Received connection from ${remoteIP} with SNI: ${serverName}`);
@ -272,6 +285,7 @@ export class PortProxy {
});
} else {
// For non-SNI connections, simply check defaultAllowedIPs.
initialDataReceived = true;
if (!this.settings.defaultAllowedIPs || !isAllowed(remoteIP, this.settings.defaultAllowedIPs)) {
console.log(`Connection rejected: IP ${remoteIP} not allowed for non-SNI connection`);
socket.end();