@push.rocks/smartproxy 22.4.2 → 23.0.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.
- package/changelog.md +36 -0
- package/dist_rust/rustproxy +0 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/index.d.ts +1 -6
- package/dist_ts/index.js +3 -11
- package/dist_ts/protocols/common/fragment-handler.js +5 -1
- package/dist_ts/proxies/index.d.ts +1 -6
- package/dist_ts/proxies/index.js +2 -8
- package/dist_ts/proxies/smart-proxy/index.d.ts +5 -10
- package/dist_ts/proxies/smart-proxy/index.js +7 -13
- package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -2
- package/dist_ts/proxies/smart-proxy/models/route-types.js +1 -1
- package/dist_ts/proxies/smart-proxy/route-preprocessor.d.ts +37 -0
- package/dist_ts/proxies/smart-proxy/route-preprocessor.js +103 -0
- package/dist_ts/proxies/smart-proxy/rust-binary-locator.d.ts +23 -0
- package/dist_ts/proxies/smart-proxy/rust-binary-locator.js +104 -0
- package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.d.ts +74 -0
- package/dist_ts/proxies/smart-proxy/rust-metrics-adapter.js +146 -0
- package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.d.ts +49 -0
- package/dist_ts/proxies/smart-proxy/rust-proxy-bridge.js +259 -0
- package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +39 -157
- package/dist_ts/proxies/smart-proxy/smart-proxy.js +224 -621
- package/dist_ts/proxies/smart-proxy/socket-handler-server.d.ts +45 -0
- package/dist_ts/proxies/smart-proxy/socket-handler-server.js +253 -0
- package/dist_ts/routing/index.d.ts +1 -1
- package/dist_ts/routing/index.js +3 -3
- package/dist_ts/routing/models/http-types.d.ts +119 -4
- package/dist_ts/routing/models/http-types.js +93 -5
- package/package.json +1 -1
- package/readme.md +444 -219
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/index.ts +4 -15
- package/ts/protocols/common/fragment-handler.ts +4 -0
- package/ts/proxies/index.ts +1 -12
- package/ts/proxies/smart-proxy/index.ts +6 -13
- package/ts/proxies/smart-proxy/models/interfaces.ts +6 -4
- package/ts/proxies/smart-proxy/models/route-types.ts +0 -2
- package/ts/proxies/smart-proxy/route-preprocessor.ts +122 -0
- package/ts/proxies/smart-proxy/rust-binary-locator.ts +112 -0
- package/ts/proxies/smart-proxy/rust-metrics-adapter.ts +161 -0
- package/ts/proxies/smart-proxy/rust-proxy-bridge.ts +310 -0
- package/ts/proxies/smart-proxy/smart-proxy.ts +282 -798
- package/ts/proxies/smart-proxy/socket-handler-server.ts +279 -0
- package/ts/routing/index.ts +2 -2
- package/ts/routing/models/http-types.ts +147 -4
- package/dist_ts/proxies/nftables-proxy/index.d.ts +0 -6
- package/dist_ts/proxies/nftables-proxy/index.js +0 -7
- package/dist_ts/proxies/nftables-proxy/models/errors.d.ts +0 -15
- package/dist_ts/proxies/nftables-proxy/models/errors.js +0 -28
- package/dist_ts/proxies/nftables-proxy/models/index.d.ts +0 -5
- package/dist_ts/proxies/nftables-proxy/models/index.js +0 -6
- package/dist_ts/proxies/nftables-proxy/models/interfaces.d.ts +0 -75
- package/dist_ts/proxies/nftables-proxy/models/interfaces.js +0 -5
- package/dist_ts/proxies/nftables-proxy/nftables-proxy.d.ts +0 -124
- package/dist_ts/proxies/nftables-proxy/nftables-proxy.js +0 -1374
- package/dist_ts/proxies/nftables-proxy/utils/index.d.ts +0 -9
- package/dist_ts/proxies/nftables-proxy/utils/index.js +0 -12
- package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.d.ts +0 -66
- package/dist_ts/proxies/nftables-proxy/utils/nft-command-executor.js +0 -131
- package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.d.ts +0 -39
- package/dist_ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.js +0 -112
- package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.d.ts +0 -59
- package/dist_ts/proxies/nftables-proxy/utils/nft-rule-validator.js +0 -130
- package/ts/proxies/http-proxy/connection-pool.ts +0 -228
- package/ts/proxies/http-proxy/context-creator.ts +0 -145
- package/ts/proxies/http-proxy/default-certificates.ts +0 -150
- package/ts/proxies/http-proxy/function-cache.ts +0 -279
- package/ts/proxies/http-proxy/handlers/index.ts +0 -5
- package/ts/proxies/http-proxy/http-proxy.ts +0 -669
- package/ts/proxies/http-proxy/http-request-handler.ts +0 -331
- package/ts/proxies/http-proxy/http2-request-handler.ts +0 -255
- package/ts/proxies/http-proxy/index.ts +0 -18
- package/ts/proxies/http-proxy/models/http-types.ts +0 -148
- package/ts/proxies/http-proxy/models/index.ts +0 -5
- package/ts/proxies/http-proxy/models/types.ts +0 -125
- package/ts/proxies/http-proxy/request-handler.ts +0 -878
- package/ts/proxies/http-proxy/security-manager.ts +0 -413
- package/ts/proxies/http-proxy/websocket-handler.ts +0 -581
- package/ts/proxies/nftables-proxy/index.ts +0 -6
- package/ts/proxies/nftables-proxy/models/errors.ts +0 -30
- package/ts/proxies/nftables-proxy/models/index.ts +0 -5
- package/ts/proxies/nftables-proxy/models/interfaces.ts +0 -94
- package/ts/proxies/nftables-proxy/nftables-proxy.ts +0 -1754
- package/ts/proxies/nftables-proxy/utils/index.ts +0 -38
- package/ts/proxies/nftables-proxy/utils/nft-command-executor.ts +0 -162
- package/ts/proxies/nftables-proxy/utils/nft-port-spec-normalizer.ts +0 -125
- package/ts/proxies/nftables-proxy/utils/nft-rule-validator.ts +0 -156
- package/ts/proxies/smart-proxy/acme-state-manager.ts +0 -112
- package/ts/proxies/smart-proxy/cert-store.ts +0 -92
- package/ts/proxies/smart-proxy/certificate-manager.ts +0 -895
- package/ts/proxies/smart-proxy/connection-manager.ts +0 -809
- package/ts/proxies/smart-proxy/http-proxy-bridge.ts +0 -213
- package/ts/proxies/smart-proxy/metrics-collector.ts +0 -453
- package/ts/proxies/smart-proxy/nftables-manager.ts +0 -271
- package/ts/proxies/smart-proxy/port-manager.ts +0 -358
- package/ts/proxies/smart-proxy/route-connection-handler.ts +0 -1712
- package/ts/proxies/smart-proxy/route-orchestrator.ts +0 -297
- package/ts/proxies/smart-proxy/security-manager.ts +0 -269
- package/ts/proxies/smart-proxy/throughput-tracker.ts +0 -138
- package/ts/proxies/smart-proxy/timeout-manager.ts +0 -196
- package/ts/proxies/smart-proxy/tls-manager.ts +0 -171
|
@@ -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
|
-
}
|