@push.rocks/smartproxy 19.6.2 → 19.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +4 -7
  2. package/dist_ts/proxies/smart-proxy/connection-manager.js +22 -22
  3. package/dist_ts/proxies/smart-proxy/http-proxy-bridge.d.ts +4 -3
  4. package/dist_ts/proxies/smart-proxy/http-proxy-bridge.js +9 -9
  5. package/dist_ts/proxies/smart-proxy/metrics-collector.d.ts +68 -56
  6. package/dist_ts/proxies/smart-proxy/metrics-collector.js +226 -176
  7. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -0
  8. package/dist_ts/proxies/smart-proxy/models/metrics-types.d.ts +94 -48
  9. package/dist_ts/proxies/smart-proxy/nftables-manager.d.ts +4 -4
  10. package/dist_ts/proxies/smart-proxy/nftables-manager.js +6 -6
  11. package/dist_ts/proxies/smart-proxy/port-manager.d.ts +4 -7
  12. package/dist_ts/proxies/smart-proxy/port-manager.js +6 -9
  13. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +4 -15
  14. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +128 -128
  15. package/dist_ts/proxies/smart-proxy/security-manager.d.ts +3 -3
  16. package/dist_ts/proxies/smart-proxy/security-manager.js +9 -9
  17. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +20 -13
  18. package/dist_ts/proxies/smart-proxy/smart-proxy.js +16 -13
  19. package/dist_ts/proxies/smart-proxy/throughput-tracker.d.ts +36 -0
  20. package/dist_ts/proxies/smart-proxy/throughput-tracker.js +117 -0
  21. package/dist_ts/proxies/smart-proxy/timeout-manager.d.ts +4 -3
  22. package/dist_ts/proxies/smart-proxy/timeout-manager.js +16 -16
  23. package/dist_ts/proxies/smart-proxy/tls-manager.d.ts +3 -3
  24. package/dist_ts/proxies/smart-proxy/tls-manager.js +12 -12
  25. package/package.json +8 -17
  26. package/readme.hints.md +0 -897
  27. package/readme.md +960 -54
  28. package/readme.plan.md +301 -562
  29. package/ts/proxies/smart-proxy/connection-manager.ts +23 -21
  30. package/ts/proxies/smart-proxy/http-proxy-bridge.ts +9 -8
  31. package/ts/proxies/smart-proxy/metrics-collector.ts +277 -189
  32. package/ts/proxies/smart-proxy/models/interfaces.ts +7 -0
  33. package/ts/proxies/smart-proxy/models/metrics-types.ts +93 -41
  34. package/ts/proxies/smart-proxy/nftables-manager.ts +5 -5
  35. package/ts/proxies/smart-proxy/port-manager.ts +6 -14
  36. package/ts/proxies/smart-proxy/route-connection-handler.ts +136 -136
  37. package/ts/proxies/smart-proxy/security-manager.ts +8 -8
  38. package/ts/proxies/smart-proxy/smart-proxy.ts +26 -35
  39. package/ts/proxies/smart-proxy/throughput-tracker.ts +144 -0
  40. package/ts/proxies/smart-proxy/timeout-manager.ts +16 -15
  41. package/ts/proxies/smart-proxy/tls-manager.ts +11 -11
  42. package/readme.connections.md +0 -724
  43. package/readme.delete.md +0 -187
  44. package/readme.memory-leaks-fixed.md +0 -45
  45. package/readme.metrics.md +0 -591
  46. package/readme.monitoring.md +0 -202
  47. package/readme.proxy-chain-summary.md +0 -112
  48. package/readme.proxy-protocol-example.md +0 -462
  49. package/readme.proxy-protocol.md +0 -415
  50. package/readme.routing.md +0 -341
  51. package/readme.websocket-keepalive-config.md +0 -140
  52. package/readme.websocket-keepalive-fix.md +0 -63
@@ -1,11 +1,10 @@
1
1
  import * as plugins from '../../plugins.js';
2
- import type { IConnectionRecord, ISmartProxyOptions } from './models/interfaces.js';
3
- import { SecurityManager } from './security-manager.js';
4
- import { TimeoutManager } from './timeout-manager.js';
2
+ import type { IConnectionRecord } from './models/interfaces.js';
5
3
  import { logger } from '../../core/utils/logger.js';
6
4
  import { LifecycleComponent } from '../../core/utils/lifecycle-component.js';
7
5
  import { cleanupSocket } from '../../core/utils/socket-utils.js';
8
6
  import { WrappedSocket } from '../../core/models/wrapped-socket.js';
7
+ import type { SmartProxy } from './smart-proxy.js';
9
8
 
10
9
  /**
11
10
  * Manages connection lifecycle, tracking, and cleanup with performance optimizations
@@ -29,17 +28,15 @@ export class ConnectionManager extends LifecycleComponent {
29
28
  private cleanupTimer: NodeJS.Timeout | null = null;
30
29
 
31
30
  constructor(
32
- private settings: ISmartProxyOptions,
33
- private securityManager: SecurityManager,
34
- private timeoutManager: TimeoutManager
31
+ private smartProxy: SmartProxy
35
32
  ) {
36
33
  super();
37
34
 
38
35
  // Set reasonable defaults for connection limits
39
- this.maxConnections = settings.defaults?.security?.maxConnections || 10000;
36
+ this.maxConnections = smartProxy.settings.defaults?.security?.maxConnections || 10000;
40
37
 
41
38
  // Start inactivity check timer if not disabled
42
- if (!settings.disableInactivityCheck) {
39
+ if (!smartProxy.settings.disableInactivityCheck) {
43
40
  this.startInactivityCheckTimer();
44
41
  }
45
42
  }
@@ -108,10 +105,10 @@ export class ConnectionManager extends LifecycleComponent {
108
105
  */
109
106
  public trackConnection(connectionId: string, record: IConnectionRecord): void {
110
107
  this.connectionRecords.set(connectionId, record);
111
- this.securityManager.trackConnectionByIP(record.remoteIP, connectionId);
108
+ this.smartProxy.securityManager.trackConnectionByIP(record.remoteIP, connectionId);
112
109
 
113
110
  // Schedule inactivity check
114
- if (!this.settings.disableInactivityCheck) {
111
+ if (!this.smartProxy.settings.disableInactivityCheck) {
115
112
  this.scheduleInactivityCheck(connectionId, record);
116
113
  }
117
114
  }
@@ -120,14 +117,14 @@ export class ConnectionManager extends LifecycleComponent {
120
117
  * Schedule next inactivity check for a connection
121
118
  */
122
119
  private scheduleInactivityCheck(connectionId: string, record: IConnectionRecord): void {
123
- let timeout = this.settings.inactivityTimeout!;
120
+ let timeout = this.smartProxy.settings.inactivityTimeout!;
124
121
 
125
122
  if (record.hasKeepAlive) {
126
- if (this.settings.keepAliveTreatment === 'immortal') {
123
+ if (this.smartProxy.settings.keepAliveTreatment === 'immortal') {
127
124
  // Don't schedule check for immortal connections
128
125
  return;
129
- } else if (this.settings.keepAliveTreatment === 'extended') {
130
- const multiplier = this.settings.keepAliveInactivityMultiplier || 6;
126
+ } else if (this.smartProxy.settings.keepAliveTreatment === 'extended') {
127
+ const multiplier = this.smartProxy.settings.keepAliveInactivityMultiplier || 6;
131
128
  timeout = timeout * multiplier;
132
129
  }
133
130
  }
@@ -172,7 +169,7 @@ export class ConnectionManager extends LifecycleComponent {
172
169
  * Initiates cleanup once for a connection
173
170
  */
174
171
  public initiateCleanupOnce(record: IConnectionRecord, reason: string = 'normal'): void {
175
- if (this.settings.enableDetailedLogging) {
172
+ if (this.smartProxy.settings.enableDetailedLogging) {
176
173
  logger.log('info', `Connection cleanup initiated`, {
177
174
  connectionId: record.id,
178
175
  remoteIP: record.remoteIP,
@@ -253,7 +250,12 @@ export class ConnectionManager extends LifecycleComponent {
253
250
  this.nextInactivityCheck.delete(record.id);
254
251
 
255
252
  // Track connection termination
256
- this.securityManager.removeConnectionByIP(record.remoteIP, record.id);
253
+ this.smartProxy.securityManager.removeConnectionByIP(record.remoteIP, record.id);
254
+
255
+ // Remove from metrics tracking
256
+ if (this.smartProxy.metricsCollector) {
257
+ this.smartProxy.metricsCollector.removeConnection(record.id);
258
+ }
257
259
 
258
260
  if (record.cleanupTimer) {
259
261
  clearTimeout(record.cleanupTimer);
@@ -334,7 +336,7 @@ export class ConnectionManager extends LifecycleComponent {
334
336
  this.connectionRecords.delete(record.id);
335
337
 
336
338
  // Log connection details
337
- if (this.settings.enableDetailedLogging) {
339
+ if (this.smartProxy.settings.enableDetailedLogging) {
338
340
  logger.log('info',
339
341
  `Connection terminated: ${record.remoteIP}:${record.localPort} (${reason}) - ` +
340
342
  `${plugins.prettyMs(duration)}, IN: ${record.bytesReceived}B, OUT: ${record.bytesSent}B`,
@@ -414,7 +416,7 @@ export class ConnectionManager extends LifecycleComponent {
414
416
  */
415
417
  public handleClose(side: 'incoming' | 'outgoing', record: IConnectionRecord) {
416
418
  return () => {
417
- if (this.settings.enableDetailedLogging) {
419
+ if (this.smartProxy.settings.enableDetailedLogging) {
418
420
  logger.log('info', `Connection closed on ${side} side`, {
419
421
  connectionId: record.id,
420
422
  side,
@@ -553,9 +555,9 @@ export class ConnectionManager extends LifecycleComponent {
553
555
  const inactivityTime = now - record.lastActivity;
554
556
 
555
557
  // Use extended timeout for extended-treatment keep-alive connections
556
- let effectiveTimeout = this.settings.inactivityTimeout!;
557
- if (record.hasKeepAlive && this.settings.keepAliveTreatment === 'extended') {
558
- const multiplier = this.settings.keepAliveInactivityMultiplier || 6;
558
+ let effectiveTimeout = this.smartProxy.settings.inactivityTimeout!;
559
+ if (record.hasKeepAlive && this.smartProxy.settings.keepAliveTreatment === 'extended') {
560
+ const multiplier = this.smartProxy.settings.keepAliveInactivityMultiplier || 6;
559
561
  effectiveTimeout = effectiveTimeout * multiplier;
560
562
  }
561
563
 
@@ -1,14 +1,15 @@
1
1
  import * as plugins from '../../plugins.js';
2
2
  import { HttpProxy } from '../http-proxy/index.js';
3
3
  import { setupBidirectionalForwarding } from '../../core/utils/socket-utils.js';
4
- import type { IConnectionRecord, ISmartProxyOptions } from './models/interfaces.js';
4
+ import type { IConnectionRecord } from './models/interfaces.js';
5
5
  import type { IRouteConfig } from './models/route-types.js';
6
6
  import { WrappedSocket } from '../../core/models/wrapped-socket.js';
7
+ import type { SmartProxy } from './smart-proxy.js';
7
8
 
8
9
  export class HttpProxyBridge {
9
10
  private httpProxy: HttpProxy | null = null;
10
11
 
11
- constructor(private settings: ISmartProxyOptions) {}
12
+ constructor(private smartProxy: SmartProxy) {}
12
13
 
13
14
  /**
14
15
  * Get the HttpProxy instance
@@ -21,18 +22,18 @@ export class HttpProxyBridge {
21
22
  * Initialize HttpProxy instance
22
23
  */
23
24
  public async initialize(): Promise<void> {
24
- if (!this.httpProxy && this.settings.useHttpProxy && this.settings.useHttpProxy.length > 0) {
25
+ if (!this.httpProxy && this.smartProxy.settings.useHttpProxy && this.smartProxy.settings.useHttpProxy.length > 0) {
25
26
  const httpProxyOptions: any = {
26
- port: this.settings.httpProxyPort!,
27
+ port: this.smartProxy.settings.httpProxyPort!,
27
28
  portProxyIntegration: true,
28
- logLevel: this.settings.enableDetailedLogging ? 'debug' : 'info'
29
+ logLevel: this.smartProxy.settings.enableDetailedLogging ? 'debug' : 'info'
29
30
  };
30
31
 
31
32
  this.httpProxy = new HttpProxy(httpProxyOptions);
32
- console.log(`Initialized HttpProxy on port ${this.settings.httpProxyPort}`);
33
+ console.log(`Initialized HttpProxy on port ${this.smartProxy.settings.httpProxyPort}`);
33
34
 
34
35
  // Apply route configurations to HttpProxy
35
- await this.syncRoutesToHttpProxy(this.settings.routes || []);
36
+ await this.syncRoutesToHttpProxy(this.smartProxy.settings.routes || []);
36
37
  }
37
38
  }
38
39
 
@@ -51,7 +52,7 @@ export class HttpProxyBridge {
51
52
  : [route.match.ports];
52
53
 
53
54
  return routePorts.some(port =>
54
- this.settings.useHttpProxy?.includes(port)
55
+ this.smartProxy.settings.useHttpProxy?.includes(port)
55
56
  );
56
57
  })
57
58
  .map(route => this.routeToHttpProxyConfig(route));