@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,54 +1,106 @@
1
1
  /**
2
- * Interface for proxy statistics and metrics
2
+ * Interface for throughput sample data
3
3
  */
4
- export interface IProxyStats {
5
- /**
6
- * Get the current number of active connections
7
- */
8
- getActiveConnections(): number;
9
-
10
- /**
11
- * Get connection counts grouped by route name
12
- */
13
- getConnectionsByRoute(): Map<string, number>;
4
+ export interface IThroughputSample {
5
+ timestamp: number;
6
+ bytesIn: number;
7
+ bytesOut: number;
8
+ }
9
+
10
+ /**
11
+ * Interface for throughput data
12
+ */
13
+ export interface IThroughputData {
14
+ in: number;
15
+ out: number;
16
+ }
17
+
18
+ /**
19
+ * Interface for time-series throughput data
20
+ */
21
+ export interface IThroughputHistoryPoint {
22
+ timestamp: number;
23
+ in: number;
24
+ out: number;
25
+ }
26
+
27
+ /**
28
+ * Main metrics interface with clean, grouped API
29
+ */
30
+ export interface IMetrics {
31
+ // Connection metrics
32
+ connections: {
33
+ active(): number;
34
+ total(): number;
35
+ byRoute(): Map<string, number>;
36
+ byIP(): Map<string, number>;
37
+ topIPs(limit?: number): Array<{ ip: string; count: number }>;
38
+ };
14
39
 
15
- /**
16
- * Get connection counts grouped by IP address
17
- */
18
- getConnectionsByIP(): Map<string, number>;
40
+ // Throughput metrics (bytes per second)
41
+ throughput: {
42
+ instant(): IThroughputData; // Last 1 second
43
+ recent(): IThroughputData; // Last 10 seconds
44
+ average(): IThroughputData; // Last 60 seconds
45
+ custom(seconds: number): IThroughputData;
46
+ history(seconds: number): Array<IThroughputHistoryPoint>;
47
+ byRoute(windowSeconds?: number): Map<string, IThroughputData>;
48
+ byIP(windowSeconds?: number): Map<string, IThroughputData>;
49
+ };
19
50
 
20
- /**
21
- * Get the total number of connections since proxy start
22
- */
23
- getTotalConnections(): number;
51
+ // Request metrics
52
+ requests: {
53
+ perSecond(): number;
54
+ perMinute(): number;
55
+ total(): number;
56
+ };
24
57
 
25
- /**
26
- * Get the current requests per second rate
27
- */
28
- getRequestsPerSecond(): number;
58
+ // Cumulative totals
59
+ totals: {
60
+ bytesIn(): number;
61
+ bytesOut(): number;
62
+ connections(): number;
63
+ };
29
64
 
30
- /**
31
- * Get total throughput (bytes transferred)
32
- */
33
- getThroughput(): { bytesIn: number; bytesOut: number };
65
+ // Performance metrics
66
+ percentiles: {
67
+ connectionDuration(): { p50: number; p95: number; p99: number };
68
+ bytesTransferred(): {
69
+ in: { p50: number; p95: number; p99: number };
70
+ out: { p50: number; p95: number; p99: number };
71
+ };
72
+ };
34
73
  }
35
74
 
36
75
  /**
37
- * Extended interface for additional metrics helpers
76
+ * Configuration for metrics collection
38
77
  */
39
- export interface IProxyStatsExtended extends IProxyStats {
40
- /**
41
- * Get throughput rate (bytes per second) for last minute
42
- */
43
- getThroughputRate(): { bytesInPerSec: number; bytesOutPerSec: number };
78
+ export interface IMetricsConfig {
79
+ enabled: boolean;
80
+
81
+ // Sampling configuration
82
+ sampleIntervalMs: number; // Default: 1000 (1 second)
83
+ retentionSeconds: number; // Default: 3600 (1 hour)
44
84
 
45
- /**
46
- * Get top IPs by connection count
47
- */
48
- getTopIPs(limit?: number): Array<{ ip: string; connections: number }>;
85
+ // Performance tuning
86
+ enableDetailedTracking: boolean; // Per-connection byte history
87
+ enablePercentiles: boolean; // Calculate percentiles
88
+ cacheResultsMs: number; // Cache expensive calculations
49
89
 
50
- /**
51
- * Check if an IP has reached the connection limit
52
- */
53
- isIPBlocked(ip: string, maxConnectionsPerIP: number): boolean;
90
+ // Export configuration
91
+ prometheusEnabled: boolean;
92
+ prometheusPath: string; // Default: /metrics
93
+ prometheusPrefix: string; // Default: smartproxy_
94
+ }
95
+
96
+ /**
97
+ * Internal interface for connection byte tracking
98
+ */
99
+ export interface IByteTracker {
100
+ connectionId: string;
101
+ routeName: string;
102
+ remoteIP: string;
103
+ bytesIn: number;
104
+ bytesOut: number;
105
+ lastUpdate: number;
54
106
  }
@@ -10,7 +10,7 @@ import type {
10
10
  TPortRange,
11
11
  INfTablesOptions
12
12
  } from './models/route-types.js';
13
- import type { ISmartProxyOptions } from './models/interfaces.js';
13
+ import type { SmartProxy } from './smart-proxy.js';
14
14
 
15
15
  /**
16
16
  * Manages NFTables rules based on SmartProxy route configurations
@@ -25,9 +25,9 @@ export class NFTablesManager {
25
25
  /**
26
26
  * Creates a new NFTablesManager
27
27
  *
28
- * @param options The SmartProxy options
28
+ * @param smartProxy The SmartProxy instance
29
29
  */
30
- constructor(private options: ISmartProxyOptions) {}
30
+ constructor(private smartProxy: SmartProxy) {}
31
31
 
32
32
  /**
33
33
  * Provision NFTables rules for a route
@@ -166,10 +166,10 @@ export class NFTablesManager {
166
166
  protocol: action.nftables?.protocol || 'tcp',
167
167
  preserveSourceIP: action.nftables?.preserveSourceIP !== undefined ?
168
168
  action.nftables.preserveSourceIP :
169
- this.options.preserveSourceIP,
169
+ this.smartProxy.settings.preserveSourceIP,
170
170
  useIPSets: action.nftables?.useIPSets !== false,
171
171
  useAdvancedNAT: action.nftables?.useAdvancedNAT,
172
- enableLogging: this.options.enableDetailedLogging,
172
+ enableLogging: this.smartProxy.settings.enableDetailedLogging,
173
173
  deleteOnExit: true,
174
174
  tableName: action.nftables?.tableName || 'smartproxy'
175
175
  };
@@ -1,8 +1,7 @@
1
1
  import * as plugins from '../../plugins.js';
2
- import type { ISmartProxyOptions } from './models/interfaces.js';
3
- import { RouteConnectionHandler } from './route-connection-handler.js';
4
2
  import { logger } from '../../core/utils/logger.js';
5
3
  import { cleanupSocket } from '../../core/utils/socket-utils.js';
4
+ import type { SmartProxy } from './smart-proxy.js';
6
5
 
7
6
  /**
8
7
  * PortManager handles the dynamic creation and removal of port listeners
@@ -16,8 +15,6 @@ import { cleanupSocket } from '../../core/utils/socket-utils.js';
16
15
  */
17
16
  export class PortManager {
18
17
  private servers: Map<number, plugins.net.Server> = new Map();
19
- private settings: ISmartProxyOptions;
20
- private routeConnectionHandler: RouteConnectionHandler;
21
18
  private isShuttingDown: boolean = false;
22
19
  // Track how many routes are using each port
23
20
  private portRefCounts: Map<number, number> = new Map();
@@ -25,16 +22,11 @@ export class PortManager {
25
22
  /**
26
23
  * Create a new PortManager
27
24
  *
28
- * @param settings The SmartProxy settings
29
- * @param routeConnectionHandler The handler for new connections
25
+ * @param smartProxy The SmartProxy instance
30
26
  */
31
27
  constructor(
32
- settings: ISmartProxyOptions,
33
- routeConnectionHandler: RouteConnectionHandler
34
- ) {
35
- this.settings = settings;
36
- this.routeConnectionHandler = routeConnectionHandler;
37
- }
28
+ private smartProxy: SmartProxy
29
+ ) {}
38
30
 
39
31
  /**
40
32
  * Start listening on a specific port
@@ -70,7 +62,7 @@ export class PortManager {
70
62
  }
71
63
 
72
64
  // Delegate to route connection handler
73
- this.routeConnectionHandler.handleConnection(socket);
65
+ this.smartProxy.routeConnectionHandler.handleConnection(socket);
74
66
  }).on('error', (err: Error) => {
75
67
  try {
76
68
  logger.log('error', `Server Error on port ${port}: ${err.message}`, {
@@ -86,7 +78,7 @@ export class PortManager {
86
78
  // Start listening on the port
87
79
  return new Promise<void>((resolve, reject) => {
88
80
  server.listen(port, () => {
89
- const isHttpProxyPort = this.settings.useHttpProxy?.includes(port);
81
+ const isHttpProxyPort = this.smartProxy.settings.useHttpProxy?.includes(port);
90
82
  try {
91
83
  logger.log('info', `SmartProxy -> OK: Now listening on port ${port}${
92
84
  isHttpProxyPort ? ' (HttpProxy forwarding enabled)' : ''