@push.rocks/smartproxy 21.1.7 → 22.6.0

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 (155) hide show
  1. package/changelog.md +109 -0
  2. package/dist_rust/rustproxy +0 -0
  3. package/dist_ts/00_commitinfo_data.js +1 -1
  4. package/dist_ts/core/utils/shared-security-manager.d.ts +17 -0
  5. package/dist_ts/core/utils/shared-security-manager.js +66 -1
  6. package/dist_ts/index.d.ts +1 -5
  7. package/dist_ts/index.js +3 -9
  8. package/dist_ts/protocols/common/fragment-handler.js +5 -1
  9. package/dist_ts/proxies/http-proxy/default-certificates.d.ts +54 -0
  10. package/dist_ts/proxies/http-proxy/default-certificates.js +127 -0
  11. package/dist_ts/proxies/http-proxy/http-proxy.d.ts +1 -1
  12. package/dist_ts/proxies/http-proxy/http-proxy.js +9 -14
  13. package/dist_ts/proxies/http-proxy/index.d.ts +5 -1
  14. package/dist_ts/proxies/http-proxy/index.js +6 -2
  15. package/dist_ts/proxies/http-proxy/security-manager.d.ts +4 -12
  16. package/dist_ts/proxies/http-proxy/security-manager.js +66 -99
  17. package/dist_ts/proxies/index.d.ts +1 -5
  18. package/dist_ts/proxies/index.js +2 -6
  19. package/dist_ts/proxies/nftables-proxy/index.d.ts +1 -0
  20. package/dist_ts/proxies/nftables-proxy/index.js +2 -1
  21. package/dist_ts/proxies/nftables-proxy/nftables-proxy.d.ts +4 -26
  22. package/dist_ts/proxies/nftables-proxy/nftables-proxy.js +84 -236
  23. package/dist_ts/proxies/nftables-proxy/utils/index.d.ts +9 -0
  24. package/dist_ts/proxies/nftables-proxy/utils/index.js +12 -0
  25. package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.d.ts +66 -0
  26. package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.js +131 -0
  27. package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.d.ts +39 -0
  28. package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.js +112 -0
  29. package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.d.ts +59 -0
  30. package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.js +130 -0
  31. package/dist_ts/proxies/smart-proxy/certificate-manager.js +4 -3
  32. package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +13 -2
  33. package/dist_ts/proxies/smart-proxy/connection-manager.js +16 -6
  34. package/dist_ts/proxies/smart-proxy/http-proxy-bridge.js +35 -10
  35. package/dist_ts/proxies/smart-proxy/index.d.ts +5 -10
  36. package/dist_ts/proxies/smart-proxy/index.js +7 -13
  37. package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -3
  38. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +17 -0
  39. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +72 -9
  40. package/dist_ts/proxies/smart-proxy/route-preprocessor.d.ts +37 -0
  41. package/dist_ts/proxies/smart-proxy/route-preprocessor.js +103 -0
  42. package/dist_ts/proxies/smart-proxy/rust-binary-locator.d.ts +23 -0
  43. package/dist_ts/proxies/smart-proxy/rust-binary-locator.js +104 -0
  44. package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.d.ts +74 -0
  45. package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.js +146 -0
  46. package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.d.ts +49 -0
  47. package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.js +259 -0
  48. package/dist_ts/proxies/smart-proxy/security-manager.d.ts +14 -12
  49. package/dist_ts/proxies/smart-proxy/security-manager.js +80 -74
  50. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +39 -157
  51. package/dist_ts/proxies/smart-proxy/smart-proxy.js +224 -622
  52. package/dist_ts/proxies/smart-proxy/socket-handler-server.d.ts +45 -0
  53. package/dist_ts/proxies/smart-proxy/socket-handler-server.js +253 -0
  54. package/dist_ts/proxies/smart-proxy/tls-manager.d.ts +2 -9
  55. package/dist_ts/proxies/smart-proxy/tls-manager.js +3 -26
  56. package/dist_ts/proxies/smart-proxy/utils/index.d.ts +1 -1
  57. package/dist_ts/proxies/smart-proxy/utils/index.js +3 -4
  58. package/dist_ts/proxies/smart-proxy/utils/route-helpers/api-helpers.d.ts +49 -0
  59. package/dist_ts/proxies/smart-proxy/utils/route-helpers/api-helpers.js +108 -0
  60. package/dist_ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.d.ts +57 -0
  61. package/dist_ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.js +89 -0
  62. package/dist_ts/proxies/smart-proxy/utils/route-helpers/http-helpers.d.ts +17 -0
  63. package/dist_ts/proxies/smart-proxy/utils/route-helpers/http-helpers.js +32 -0
  64. package/dist_ts/proxies/smart-proxy/utils/route-helpers/https-helpers.d.ts +68 -0
  65. package/dist_ts/proxies/smart-proxy/utils/route-helpers/https-helpers.js +117 -0
  66. package/dist_ts/proxies/smart-proxy/utils/route-helpers/index.d.ts +17 -0
  67. package/dist_ts/proxies/smart-proxy/utils/route-helpers/index.js +27 -0
  68. package/dist_ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.d.ts +63 -0
  69. package/dist_ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.js +105 -0
  70. package/dist_ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.d.ts +83 -0
  71. package/dist_ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.js +126 -0
  72. package/dist_ts/proxies/smart-proxy/utils/route-helpers/security-helpers.d.ts +47 -0
  73. package/dist_ts/proxies/smart-proxy/utils/route-helpers/security-helpers.js +66 -0
  74. package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.d.ts +70 -0
  75. package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.js +287 -0
  76. package/dist_ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.d.ts +46 -0
  77. package/dist_ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.js +67 -0
  78. package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +4 -457
  79. package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +6 -950
  80. package/dist_ts/proxies/smart-proxy/utils/route-utils.js +2 -2
  81. package/dist_ts/proxies/smart-proxy/utils/route-validator.d.ts +67 -1
  82. package/dist_ts/proxies/smart-proxy/utils/route-validator.js +251 -3
  83. package/dist_ts/routing/index.d.ts +1 -1
  84. package/dist_ts/routing/index.js +3 -3
  85. package/dist_ts/routing/models/http-types.d.ts +119 -4
  86. package/dist_ts/routing/models/http-types.js +93 -5
  87. package/npmextra.json +12 -6
  88. package/package.json +34 -24
  89. package/readme.hints.md +184 -1
  90. package/readme.md +580 -266
  91. package/ts/00_commitinfo_data.ts +1 -1
  92. package/ts/core/utils/shared-security-manager.ts +98 -13
  93. package/ts/index.ts +4 -12
  94. package/ts/protocols/common/fragment-handler.ts +4 -0
  95. package/ts/proxies/index.ts +1 -9
  96. package/ts/proxies/nftables-proxy/index.ts +1 -0
  97. package/ts/proxies/nftables-proxy/nftables-proxy.ts +116 -290
  98. package/ts/proxies/nftables-proxy/utils/index.ts +38 -0
  99. package/ts/proxies/nftables-proxy/utils/nft-command-executor.ts +162 -0
  100. package/ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.ts +125 -0
  101. package/ts/proxies/nftables-proxy/utils/nft-rule-validator.ts +156 -0
  102. package/ts/proxies/smart-proxy/index.ts +6 -13
  103. package/ts/proxies/smart-proxy/models/interfaces.ts +6 -5
  104. package/ts/proxies/smart-proxy/route-preprocessor.ts +122 -0
  105. package/ts/proxies/smart-proxy/rust-binary-locator.ts +112 -0
  106. package/ts/proxies/smart-proxy/rust-metrics-adapter.ts +161 -0
  107. package/ts/proxies/smart-proxy/rust-proxy-bridge.ts +310 -0
  108. package/ts/proxies/smart-proxy/smart-proxy.ts +282 -800
  109. package/ts/proxies/smart-proxy/socket-handler-server.ts +279 -0
  110. package/ts/proxies/smart-proxy/utils/index.ts +3 -5
  111. package/ts/proxies/smart-proxy/utils/route-helpers/api-helpers.ts +144 -0
  112. package/ts/proxies/smart-proxy/utils/route-helpers/dynamic-helpers.ts +124 -0
  113. package/ts/proxies/smart-proxy/utils/route-helpers/http-helpers.ts +40 -0
  114. package/ts/proxies/smart-proxy/utils/route-helpers/https-helpers.ts +163 -0
  115. package/ts/proxies/smart-proxy/utils/route-helpers/index.ts +62 -0
  116. package/ts/proxies/smart-proxy/utils/route-helpers/load-balancer-helpers.ts +154 -0
  117. package/ts/proxies/smart-proxy/utils/route-helpers/nftables-helpers.ts +202 -0
  118. package/ts/proxies/smart-proxy/utils/route-helpers/security-helpers.ts +96 -0
  119. package/ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.ts +337 -0
  120. package/ts/proxies/smart-proxy/utils/route-helpers/websocket-helpers.ts +98 -0
  121. package/ts/proxies/smart-proxy/utils/route-helpers.ts +5 -1302
  122. package/ts/proxies/smart-proxy/utils/route-utils.ts +1 -1
  123. package/ts/proxies/smart-proxy/utils/route-validator.ts +274 -4
  124. package/ts/routing/index.ts +2 -2
  125. package/ts/routing/models/http-types.ts +147 -4
  126. package/ts/proxies/http-proxy/certificate-manager.ts +0 -244
  127. package/ts/proxies/http-proxy/connection-pool.ts +0 -228
  128. package/ts/proxies/http-proxy/context-creator.ts +0 -145
  129. package/ts/proxies/http-proxy/function-cache.ts +0 -279
  130. package/ts/proxies/http-proxy/handlers/index.ts +0 -5
  131. package/ts/proxies/http-proxy/http-proxy.ts +0 -675
  132. package/ts/proxies/http-proxy/http-request-handler.ts +0 -331
  133. package/ts/proxies/http-proxy/http2-request-handler.ts +0 -255
  134. package/ts/proxies/http-proxy/index.ts +0 -13
  135. package/ts/proxies/http-proxy/models/http-types.ts +0 -148
  136. package/ts/proxies/http-proxy/models/index.ts +0 -5
  137. package/ts/proxies/http-proxy/models/types.ts +0 -125
  138. package/ts/proxies/http-proxy/request-handler.ts +0 -878
  139. package/ts/proxies/http-proxy/security-manager.ts +0 -433
  140. package/ts/proxies/http-proxy/websocket-handler.ts +0 -581
  141. package/ts/proxies/smart-proxy/acme-state-manager.ts +0 -112
  142. package/ts/proxies/smart-proxy/cert-store.ts +0 -92
  143. package/ts/proxies/smart-proxy/certificate-manager.ts +0 -894
  144. package/ts/proxies/smart-proxy/connection-manager.ts +0 -796
  145. package/ts/proxies/smart-proxy/http-proxy-bridge.ts +0 -187
  146. package/ts/proxies/smart-proxy/metrics-collector.ts +0 -453
  147. package/ts/proxies/smart-proxy/nftables-manager.ts +0 -271
  148. package/ts/proxies/smart-proxy/port-manager.ts +0 -358
  149. package/ts/proxies/smart-proxy/route-connection-handler.ts +0 -1640
  150. package/ts/proxies/smart-proxy/route-orchestrator.ts +0 -297
  151. package/ts/proxies/smart-proxy/security-manager.ts +0 -257
  152. package/ts/proxies/smart-proxy/throughput-tracker.ts +0 -138
  153. package/ts/proxies/smart-proxy/timeout-manager.ts +0 -196
  154. package/ts/proxies/smart-proxy/tls-manager.ts +0 -207
  155. package/ts/proxies/smart-proxy/utils/route-validators.ts +0 -283
@@ -1,279 +0,0 @@
1
- import type { IRouteContext } from '../../core/models/route-context.js';
2
- import type { ILogger } from './models/types.js';
3
-
4
- /**
5
- * Interface for cached function result
6
- */
7
- interface ICachedResult<T> {
8
- value: T;
9
- expiry: number;
10
- hash: string;
11
- }
12
-
13
- /**
14
- * Function cache for NetworkProxy function-based targets
15
- *
16
- * This cache improves performance for function-based targets by storing
17
- * the results of function evaluations and reusing them for similar contexts.
18
- */
19
- export class FunctionCache {
20
- // Cache storage
21
- private hostCache: Map<string, ICachedResult<string | string[]>> = new Map();
22
- private portCache: Map<string, ICachedResult<number>> = new Map();
23
-
24
- // Maximum number of entries to store in each cache
25
- private maxCacheSize: number;
26
-
27
- // Default TTL for cache entries in milliseconds (default: 5 seconds)
28
- private defaultTtl: number;
29
-
30
- // Logger
31
- private logger: ILogger;
32
-
33
- // Cleanup interval timer
34
- private cleanupInterval: NodeJS.Timeout | null = null;
35
-
36
- /**
37
- * Creates a new function cache
38
- *
39
- * @param logger Logger for debug output
40
- * @param options Cache options
41
- */
42
- constructor(
43
- logger: ILogger,
44
- options: {
45
- maxCacheSize?: number;
46
- defaultTtl?: number;
47
- } = {}
48
- ) {
49
- this.logger = logger;
50
- this.maxCacheSize = options.maxCacheSize || 1000;
51
- this.defaultTtl = options.defaultTtl || 5000; // 5 seconds default
52
-
53
- // Start the cache cleanup timer
54
- this.cleanupInterval = setInterval(() => this.cleanupCache(), 30000); // Cleanup every 30 seconds
55
-
56
- // Make sure the interval doesn't keep the process alive
57
- if (this.cleanupInterval.unref) {
58
- this.cleanupInterval.unref();
59
- }
60
- }
61
-
62
- /**
63
- * Compute a hash for a context object
64
- * This is used to identify similar contexts for caching
65
- *
66
- * @param context The route context to hash
67
- * @param functionId Identifier for the function (usually route name or ID)
68
- * @returns A string hash
69
- */
70
- private computeContextHash(context: IRouteContext, functionId: string): string {
71
- // Extract relevant properties for the hash
72
- const hashBase = {
73
- functionId,
74
- port: context.port,
75
- domain: context.domain,
76
- clientIp: context.clientIp,
77
- path: context.path,
78
- query: context.query,
79
- isTls: context.isTls,
80
- tlsVersion: context.tlsVersion
81
- };
82
-
83
- // Generate a hash string
84
- return JSON.stringify(hashBase);
85
- }
86
-
87
- /**
88
- * Get cached host result for a function and context
89
- *
90
- * @param context Route context
91
- * @param functionId Identifier for the function
92
- * @returns Cached host value or undefined if not found
93
- */
94
- public getCachedHost(context: IRouteContext, functionId: string): string | string[] | undefined {
95
- const hash = this.computeContextHash(context, functionId);
96
- const cached = this.hostCache.get(hash);
97
-
98
- // Return if no cached value or expired
99
- if (!cached || cached.expiry < Date.now()) {
100
- if (cached) {
101
- // If expired, remove from cache
102
- this.hostCache.delete(hash);
103
- this.logger.debug(`Cache miss (expired) for host function: ${functionId}`);
104
- } else {
105
- this.logger.debug(`Cache miss for host function: ${functionId}`);
106
- }
107
- return undefined;
108
- }
109
-
110
- this.logger.debug(`Cache hit for host function: ${functionId}`);
111
- return cached.value;
112
- }
113
-
114
- /**
115
- * Get cached port result for a function and context
116
- *
117
- * @param context Route context
118
- * @param functionId Identifier for the function
119
- * @returns Cached port value or undefined if not found
120
- */
121
- public getCachedPort(context: IRouteContext, functionId: string): number | undefined {
122
- const hash = this.computeContextHash(context, functionId);
123
- const cached = this.portCache.get(hash);
124
-
125
- // Return if no cached value or expired
126
- if (!cached || cached.expiry < Date.now()) {
127
- if (cached) {
128
- // If expired, remove from cache
129
- this.portCache.delete(hash);
130
- this.logger.debug(`Cache miss (expired) for port function: ${functionId}`);
131
- } else {
132
- this.logger.debug(`Cache miss for port function: ${functionId}`);
133
- }
134
- return undefined;
135
- }
136
-
137
- this.logger.debug(`Cache hit for port function: ${functionId}`);
138
- return cached.value;
139
- }
140
-
141
- /**
142
- * Store a host function result in the cache
143
- *
144
- * @param context Route context
145
- * @param functionId Identifier for the function
146
- * @param value Host value to cache
147
- * @param ttl Optional TTL in milliseconds
148
- */
149
- public cacheHost(
150
- context: IRouteContext,
151
- functionId: string,
152
- value: string | string[],
153
- ttl?: number
154
- ): void {
155
- const hash = this.computeContextHash(context, functionId);
156
- const expiry = Date.now() + (ttl || this.defaultTtl);
157
-
158
- // Check if we need to prune the cache before adding
159
- if (this.hostCache.size >= this.maxCacheSize) {
160
- this.pruneOldestEntries(this.hostCache);
161
- }
162
-
163
- // Store the result
164
- this.hostCache.set(hash, { value, expiry, hash });
165
- this.logger.debug(`Cached host function result for: ${functionId}`);
166
- }
167
-
168
- /**
169
- * Store a port function result in the cache
170
- *
171
- * @param context Route context
172
- * @param functionId Identifier for the function
173
- * @param value Port value to cache
174
- * @param ttl Optional TTL in milliseconds
175
- */
176
- public cachePort(
177
- context: IRouteContext,
178
- functionId: string,
179
- value: number,
180
- ttl?: number
181
- ): void {
182
- const hash = this.computeContextHash(context, functionId);
183
- const expiry = Date.now() + (ttl || this.defaultTtl);
184
-
185
- // Check if we need to prune the cache before adding
186
- if (this.portCache.size >= this.maxCacheSize) {
187
- this.pruneOldestEntries(this.portCache);
188
- }
189
-
190
- // Store the result
191
- this.portCache.set(hash, { value, expiry, hash });
192
- this.logger.debug(`Cached port function result for: ${functionId}`);
193
- }
194
-
195
- /**
196
- * Remove expired entries from the cache
197
- */
198
- private cleanupCache(): void {
199
- const now = Date.now();
200
- let expiredCount = 0;
201
-
202
- // Clean up host cache
203
- for (const [hash, cached] of this.hostCache.entries()) {
204
- if (cached.expiry < now) {
205
- this.hostCache.delete(hash);
206
- expiredCount++;
207
- }
208
- }
209
-
210
- // Clean up port cache
211
- for (const [hash, cached] of this.portCache.entries()) {
212
- if (cached.expiry < now) {
213
- this.portCache.delete(hash);
214
- expiredCount++;
215
- }
216
- }
217
-
218
- if (expiredCount > 0) {
219
- this.logger.debug(`Cleaned up ${expiredCount} expired cache entries`);
220
- }
221
- }
222
-
223
- /**
224
- * Prune oldest entries from a cache map
225
- * Used when the cache exceeds the maximum size
226
- *
227
- * @param cache The cache map to prune
228
- */
229
- private pruneOldestEntries<T>(cache: Map<string, ICachedResult<T>>): void {
230
- // Find the oldest entries
231
- const now = Date.now();
232
- const itemsToRemove = Math.floor(this.maxCacheSize * 0.2); // Remove 20% of the cache
233
-
234
- // Convert to array for sorting
235
- const entries = Array.from(cache.entries());
236
-
237
- // Sort by expiry (oldest first)
238
- entries.sort((a, b) => a[1].expiry - b[1].expiry);
239
-
240
- // Remove oldest entries
241
- const toRemove = entries.slice(0, itemsToRemove);
242
- for (const [hash] of toRemove) {
243
- cache.delete(hash);
244
- }
245
-
246
- this.logger.debug(`Pruned ${toRemove.length} oldest cache entries`);
247
- }
248
-
249
- /**
250
- * Get current cache stats
251
- */
252
- public getStats(): { hostCacheSize: number; portCacheSize: number } {
253
- return {
254
- hostCacheSize: this.hostCache.size,
255
- portCacheSize: this.portCache.size
256
- };
257
- }
258
-
259
- /**
260
- * Clear all cached entries
261
- */
262
- public clearCache(): void {
263
- this.hostCache.clear();
264
- this.portCache.clear();
265
- this.logger.info('Function cache cleared');
266
- }
267
-
268
- /**
269
- * Destroy the cache and cleanup resources
270
- */
271
- public destroy(): void {
272
- if (this.cleanupInterval) {
273
- clearInterval(this.cleanupInterval);
274
- this.cleanupInterval = null;
275
- }
276
- this.clearCache();
277
- this.logger.debug('Function cache destroyed');
278
- }
279
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * HTTP handlers for various route types
3
- */
4
-
5
- // Empty - all handlers have been removed