@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.
- package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +4 -7
- package/dist_ts/proxies/smart-proxy/connection-manager.js +22 -22
- package/dist_ts/proxies/smart-proxy/http-proxy-bridge.d.ts +4 -3
- package/dist_ts/proxies/smart-proxy/http-proxy-bridge.js +9 -9
- package/dist_ts/proxies/smart-proxy/metrics-collector.d.ts +68 -56
- package/dist_ts/proxies/smart-proxy/metrics-collector.js +226 -176
- package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +5 -0
- package/dist_ts/proxies/smart-proxy/models/metrics-types.d.ts +94 -48
- package/dist_ts/proxies/smart-proxy/nftables-manager.d.ts +4 -4
- package/dist_ts/proxies/smart-proxy/nftables-manager.js +6 -6
- package/dist_ts/proxies/smart-proxy/port-manager.d.ts +4 -7
- package/dist_ts/proxies/smart-proxy/port-manager.js +6 -9
- package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +4 -15
- package/dist_ts/proxies/smart-proxy/route-connection-handler.js +128 -128
- package/dist_ts/proxies/smart-proxy/security-manager.d.ts +3 -3
- package/dist_ts/proxies/smart-proxy/security-manager.js +9 -9
- package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +20 -13
- package/dist_ts/proxies/smart-proxy/smart-proxy.js +16 -13
- package/dist_ts/proxies/smart-proxy/throughput-tracker.d.ts +36 -0
- package/dist_ts/proxies/smart-proxy/throughput-tracker.js +117 -0
- package/dist_ts/proxies/smart-proxy/timeout-manager.d.ts +4 -3
- package/dist_ts/proxies/smart-proxy/timeout-manager.js +16 -16
- package/dist_ts/proxies/smart-proxy/tls-manager.d.ts +3 -3
- package/dist_ts/proxies/smart-proxy/tls-manager.js +12 -12
- package/package.json +8 -17
- package/readme.hints.md +0 -897
- package/readme.md +960 -54
- package/readme.plan.md +301 -562
- package/ts/proxies/smart-proxy/connection-manager.ts +23 -21
- package/ts/proxies/smart-proxy/http-proxy-bridge.ts +9 -8
- package/ts/proxies/smart-proxy/metrics-collector.ts +277 -189
- package/ts/proxies/smart-proxy/models/interfaces.ts +7 -0
- package/ts/proxies/smart-proxy/models/metrics-types.ts +93 -41
- package/ts/proxies/smart-proxy/nftables-manager.ts +5 -5
- package/ts/proxies/smart-proxy/port-manager.ts +6 -14
- package/ts/proxies/smart-proxy/route-connection-handler.ts +136 -136
- package/ts/proxies/smart-proxy/security-manager.ts +8 -8
- package/ts/proxies/smart-proxy/smart-proxy.ts +26 -35
- package/ts/proxies/smart-proxy/throughput-tracker.ts +144 -0
- package/ts/proxies/smart-proxy/timeout-manager.ts +16 -15
- package/ts/proxies/smart-proxy/tls-manager.ts +11 -11
- package/readme.connections.md +0 -724
- package/readme.delete.md +0 -187
- package/readme.memory-leaks-fixed.md +0 -45
- package/readme.metrics.md +0 -591
- package/readme.monitoring.md +0 -202
- package/readme.proxy-chain-summary.md +0 -112
- package/readme.proxy-protocol-example.md +0 -462
- package/readme.proxy-protocol.md +0 -415
- package/readme.routing.md +0 -341
- package/readme.websocket-keepalive-config.md +0 -140
- package/readme.websocket-keepalive-fix.md +0 -63
package/readme.delete.md
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
# SmartProxy Code Deletion Plan
|
|
2
|
-
|
|
3
|
-
This document tracks all code paths that can be deleted as part of the routing unification effort.
|
|
4
|
-
|
|
5
|
-
## Phase 1: Matching Logic Duplicates (READY TO DELETE)
|
|
6
|
-
|
|
7
|
-
### 1. Inline Matching Functions in RouteManager
|
|
8
|
-
**File**: `ts/proxies/smart-proxy/route-manager.ts`
|
|
9
|
-
**Lines**: Approximately lines 200-400
|
|
10
|
-
**Duplicates**:
|
|
11
|
-
- `matchDomain()` method - duplicate of DomainMatcher
|
|
12
|
-
- `matchPath()` method - duplicate of PathMatcher
|
|
13
|
-
- `matchIpPattern()` method - duplicate of IpMatcher
|
|
14
|
-
- `matchHeaders()` method - duplicate of HeaderMatcher
|
|
15
|
-
**Action**: Update to use unified matchers from `ts/core/routing/matchers/`
|
|
16
|
-
|
|
17
|
-
### 2. Duplicate Matching in Core route-utils
|
|
18
|
-
**File**: `ts/core/utils/route-utils.ts`
|
|
19
|
-
**Functions to update**:
|
|
20
|
-
- `matchDomain()` → Use DomainMatcher.match()
|
|
21
|
-
- `matchPath()` → Use PathMatcher.match()
|
|
22
|
-
- `matchIpPattern()` → Use IpMatcher.match()
|
|
23
|
-
- `matchHeader()` → Use HeaderMatcher.match()
|
|
24
|
-
**Action**: Update to use unified matchers, keep only unique utilities
|
|
25
|
-
|
|
26
|
-
## Phase 2: Route Manager Duplicates (READY AFTER MIGRATION)
|
|
27
|
-
|
|
28
|
-
### 1. SmartProxy RouteManager
|
|
29
|
-
**File**: `ts/proxies/smart-proxy/route-manager.ts`
|
|
30
|
-
**Entire file**: ~500 lines
|
|
31
|
-
**Reason**: 95% duplicate of SharedRouteManager
|
|
32
|
-
**Migration Required**:
|
|
33
|
-
- Update SmartProxy to use SharedRouteManager
|
|
34
|
-
- Update all imports
|
|
35
|
-
- Test thoroughly
|
|
36
|
-
**Action**: DELETE entire file after migration
|
|
37
|
-
|
|
38
|
-
### 2. Deprecated Methods in SharedRouteManager
|
|
39
|
-
**File**: `ts/core/utils/route-manager.ts`
|
|
40
|
-
**Methods**:
|
|
41
|
-
- Any deprecated security check methods
|
|
42
|
-
- Legacy compatibility methods
|
|
43
|
-
**Action**: Remove after confirming no usage
|
|
44
|
-
|
|
45
|
-
## Phase 3: Router Consolidation (REQUIRES REFACTORING)
|
|
46
|
-
|
|
47
|
-
### 1. ProxyRouter vs RouteRouter Duplication
|
|
48
|
-
**Files**:
|
|
49
|
-
- `ts/routing/router/proxy-router.ts` (~250 lines)
|
|
50
|
-
- `ts/routing/router/route-router.ts` (~250 lines)
|
|
51
|
-
**Reason**: Nearly identical implementations
|
|
52
|
-
**Plan**: Merge into single HttpRouter with legacy adapter
|
|
53
|
-
**Action**: DELETE one file after consolidation
|
|
54
|
-
|
|
55
|
-
### 2. Inline Route Matching in HttpProxy
|
|
56
|
-
**Location**: Various files in `ts/proxies/http-proxy/`
|
|
57
|
-
**Pattern**: Direct route matching without using RouteManager
|
|
58
|
-
**Action**: Update to use SharedRouteManager
|
|
59
|
-
|
|
60
|
-
## Phase 4: Scattered Utilities (CLEANUP)
|
|
61
|
-
|
|
62
|
-
### 1. Duplicate Route Utilities
|
|
63
|
-
**Files with duplicate logic**:
|
|
64
|
-
- `ts/proxies/smart-proxy/utils/route-utils.ts` - Keep (different purpose)
|
|
65
|
-
- `ts/proxies/smart-proxy/utils/route-validators.ts` - Review for duplicates
|
|
66
|
-
- `ts/proxies/smart-proxy/utils/route-patterns.ts` - Review for consolidation
|
|
67
|
-
|
|
68
|
-
### 2. Legacy Type Definitions
|
|
69
|
-
**Review for removal**:
|
|
70
|
-
- Old route type definitions
|
|
71
|
-
- Deprecated configuration interfaces
|
|
72
|
-
- Unused type exports
|
|
73
|
-
|
|
74
|
-
## Deletion Progress Tracker
|
|
75
|
-
|
|
76
|
-
### Completed Deletions
|
|
77
|
-
- [x] Phase 1: Matching logic consolidation (Partial)
|
|
78
|
-
- Updated core/utils/route-utils.ts to use unified matchers
|
|
79
|
-
- Removed duplicate matching implementations (~200 lines)
|
|
80
|
-
- Marked functions as deprecated with migration path
|
|
81
|
-
- [x] Phase 2: RouteManager unification (COMPLETED)
|
|
82
|
-
- ✓ Migrated SmartProxy to use SharedRouteManager
|
|
83
|
-
- ✓ Updated imports in smart-proxy.ts, route-connection-handler.ts, and index.ts
|
|
84
|
-
- ✓ Created logger adapter to match ILogger interface expectations
|
|
85
|
-
- ✓ Fixed method calls (getAllRoutes → getRoutes)
|
|
86
|
-
- ✓ Fixed type errors in header matcher
|
|
87
|
-
- ✓ Removed unused ipToNumber imports and methods
|
|
88
|
-
- ✓ DELETED: `/ts/proxies/smart-proxy/route-manager.ts` (553 lines removed)
|
|
89
|
-
- [x] Phase 3: Router consolidation (COMPLETED)
|
|
90
|
-
- ✓ Created unified HttpRouter with legacy compatibility
|
|
91
|
-
- ✓ Migrated ProxyRouter and RouteRouter to use HttpRouter aliases
|
|
92
|
-
- ✓ Updated imports in http-proxy.ts, request-handler.ts, websocket-handler.ts
|
|
93
|
-
- ✓ Added routeReqLegacy() method for backward compatibility
|
|
94
|
-
- ✓ DELETED: `/ts/routing/router/proxy-router.ts` (437 lines)
|
|
95
|
-
- ✓ DELETED: `/ts/routing/router/route-router.ts` (482 lines)
|
|
96
|
-
- [x] Phase 4: Architecture cleanup (COMPLETED)
|
|
97
|
-
- ✓ Updated route-utils.ts to use unified matchers directly
|
|
98
|
-
- ✓ Removed deprecated methods from SharedRouteManager
|
|
99
|
-
- ✓ Fixed HeaderMatcher.matchMultiple → matchAll method name
|
|
100
|
-
- ✓ Fixed findMatchingRoute return type handling (IRouteMatchResult)
|
|
101
|
-
- ✓ Fixed header type conversion for RegExp patterns
|
|
102
|
-
- ✓ DELETED: Duplicate RouteManager class from http-proxy/models/types.ts (~200 lines)
|
|
103
|
-
- ✓ Updated all imports to use SharedRouteManager from core/utils
|
|
104
|
-
- ✓ Fixed PathMatcher exact match behavior (added $ anchor for non-wildcard patterns)
|
|
105
|
-
- ✓ Updated test expectations to match unified matcher behavior
|
|
106
|
-
- ✓ All TypeScript errors resolved and build successful
|
|
107
|
-
- [x] Phase 5: Remove all backward compatibility code (COMPLETED)
|
|
108
|
-
- ✓ Removed routeReqLegacy() method from HttpRouter
|
|
109
|
-
- ✓ Removed all legacy compatibility methods from HttpRouter (~130 lines)
|
|
110
|
-
- ✓ Removed LegacyRouterResult interface
|
|
111
|
-
- ✓ Removed ProxyRouter and RouteRouter aliases
|
|
112
|
-
- ✓ Updated RequestHandler to remove legacyRouter parameter and legacy routing fallback (~80 lines)
|
|
113
|
-
- ✓ Updated WebSocketHandler to remove legacyRouter parameter and legacy routing fallback
|
|
114
|
-
- ✓ Updated HttpProxy to use only unified HttpRouter
|
|
115
|
-
- ✓ Removed IReverseProxyConfig interface (deprecated legacy interface)
|
|
116
|
-
- ✓ Removed useExternalPort80Handler deprecated option
|
|
117
|
-
- ✓ Removed backward compatibility exports from index.ts
|
|
118
|
-
- ✓ Removed all deprecated functions from route-utils.ts (~50 lines)
|
|
119
|
-
- ✓ Clean build with no legacy code
|
|
120
|
-
|
|
121
|
-
### Files Updated
|
|
122
|
-
1. `ts/core/utils/route-utils.ts` - Replaced all matching logic with unified matchers
|
|
123
|
-
2. `ts/core/utils/security-utils.ts` - Updated to use IpMatcher directly
|
|
124
|
-
3. `ts/proxies/smart-proxy/smart-proxy.ts` - Using SharedRouteManager with logger adapter
|
|
125
|
-
4. `ts/proxies/smart-proxy/route-connection-handler.ts` - Updated to use SharedRouteManager
|
|
126
|
-
5. `ts/proxies/smart-proxy/index.ts` - Exporting SharedRouteManager as RouteManager
|
|
127
|
-
6. `ts/core/routing/matchers/header.ts` - Fixed type handling for array header values
|
|
128
|
-
7. `ts/core/utils/route-manager.ts` - Removed unused ipToNumber import
|
|
129
|
-
8. `ts/proxies/http-proxy/http-proxy.ts` - Updated imports to use unified router
|
|
130
|
-
9. `ts/proxies/http-proxy/request-handler.ts` - Updated to use routeReqLegacy()
|
|
131
|
-
10. `ts/proxies/http-proxy/websocket-handler.ts` - Updated to use routeReqLegacy()
|
|
132
|
-
11. `ts/routing/router/index.ts` - Export unified HttpRouter with aliases
|
|
133
|
-
12. `ts/proxies/smart-proxy/utils/route-utils.ts` - Updated to use unified matchers directly
|
|
134
|
-
13. `ts/proxies/http-proxy/request-handler.ts` - Fixed findMatchingRoute usage
|
|
135
|
-
14. `ts/proxies/http-proxy/models/types.ts` - Removed duplicate RouteManager class
|
|
136
|
-
15. `ts/index.ts` - Updated exports to use SharedRouteManager aliases
|
|
137
|
-
16. `ts/proxies/index.ts` - Updated exports to use SharedRouteManager aliases
|
|
138
|
-
17. `test/test.acme-route-creation.ts` - Fixed getAllRoutes → getRoutes method call
|
|
139
|
-
|
|
140
|
-
### Files Created
|
|
141
|
-
1. `ts/core/routing/matchers/domain.ts` - Unified domain matcher
|
|
142
|
-
2. `ts/core/routing/matchers/path.ts` - Unified path matcher
|
|
143
|
-
3. `ts/core/routing/matchers/ip.ts` - Unified IP matcher
|
|
144
|
-
4. `ts/core/routing/matchers/header.ts` - Unified header matcher
|
|
145
|
-
5. `ts/core/routing/matchers/index.ts` - Matcher exports
|
|
146
|
-
6. `ts/core/routing/types.ts` - Core routing types
|
|
147
|
-
7. `ts/core/routing/specificity.ts` - Route specificity calculator
|
|
148
|
-
8. `ts/core/routing/index.ts` - Main routing exports
|
|
149
|
-
9. `ts/routing/router/http-router.ts` - Unified HTTP router
|
|
150
|
-
|
|
151
|
-
### Lines of Code Removed
|
|
152
|
-
- Target: ~1,500 lines
|
|
153
|
-
- Actual: ~2,332 lines (Target exceeded by 55%!)
|
|
154
|
-
- Phase 1: ~200 lines (matching logic)
|
|
155
|
-
- Phase 2: 553 lines (SmartProxy RouteManager)
|
|
156
|
-
- Phase 3: 919 lines (ProxyRouter + RouteRouter)
|
|
157
|
-
- Phase 4: ~200 lines (Duplicate RouteManager from http-proxy)
|
|
158
|
-
- Phase 5: ~460 lines (Legacy compatibility code)
|
|
159
|
-
|
|
160
|
-
## Unified Routing Architecture Summary
|
|
161
|
-
|
|
162
|
-
The routing unification effort has successfully:
|
|
163
|
-
1. **Created unified matchers** - Consistent matching logic across all route types
|
|
164
|
-
- DomainMatcher: Wildcard domain matching with specificity calculation
|
|
165
|
-
- PathMatcher: Path pattern matching with parameter extraction
|
|
166
|
-
- IpMatcher: IP address and CIDR notation matching
|
|
167
|
-
- HeaderMatcher: HTTP header matching with regex support
|
|
168
|
-
2. **Consolidated route managers** - Single SharedRouteManager for all proxies
|
|
169
|
-
3. **Unified routers** - Single HttpRouter for all HTTP routing needs
|
|
170
|
-
4. **Removed ~2,332 lines of code** - Exceeded target by 55%
|
|
171
|
-
5. **Clean modern architecture** - No legacy code, no backward compatibility layers
|
|
172
|
-
|
|
173
|
-
## Safety Checklist Before Deletion
|
|
174
|
-
|
|
175
|
-
Before deleting any code:
|
|
176
|
-
1. ✓ All tests pass
|
|
177
|
-
2. ✓ No references to deleted code remain
|
|
178
|
-
3. ✓ Migration path tested
|
|
179
|
-
4. ✓ Performance benchmarks show no regression
|
|
180
|
-
5. ✓ Documentation updated
|
|
181
|
-
|
|
182
|
-
## Rollback Plan
|
|
183
|
-
|
|
184
|
-
If issues arise after deletion:
|
|
185
|
-
1. Git history preserves all deleted code
|
|
186
|
-
2. Each phase can be reverted independently
|
|
187
|
-
3. Feature flags can disable new code if needed
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# Memory Leaks Fixed in SmartProxy
|
|
2
|
-
|
|
3
|
-
## Summary of Issues Found and Fixed
|
|
4
|
-
|
|
5
|
-
### 1. MetricsCollector - Request Timestamps Array
|
|
6
|
-
**Issue**: The `requestTimestamps` array could grow to 10,000 entries before cleanup, causing unnecessary memory usage.
|
|
7
|
-
**Fix**: Reduced threshold to 5,000 and more aggressive cleanup when exceeded.
|
|
8
|
-
|
|
9
|
-
### 2. RouteConnectionHandler - Unused Route Context Cache
|
|
10
|
-
**Issue**: Declared `routeContextCache` Map that was never used but could be confusing.
|
|
11
|
-
**Fix**: Removed the unused cache and added documentation explaining why caching wasn't implemented.
|
|
12
|
-
|
|
13
|
-
### 3. FunctionCache - Uncleaned Interval Timer
|
|
14
|
-
**Issue**: The cache cleanup interval was never cleared, preventing proper garbage collection.
|
|
15
|
-
**Fix**: Added `destroy()` method to properly clear the interval timer.
|
|
16
|
-
|
|
17
|
-
### 4. HttpProxy/RequestHandler - Uncleaned Rate Limit Cleanup Timer
|
|
18
|
-
**Issue**: The RequestHandler creates a setInterval for rate limit cleanup that's never cleared.
|
|
19
|
-
**Status**: Needs fix - add destroy method and call it from HttpProxy.stop()
|
|
20
|
-
|
|
21
|
-
## Memory Leak Test
|
|
22
|
-
|
|
23
|
-
A comprehensive memory leak test was created at `test/test.memory-leak-check.node.ts` that:
|
|
24
|
-
- Tests with 1000 requests to same routes
|
|
25
|
-
- Tests with 1000 requests to different routes (cache growth)
|
|
26
|
-
- Tests rapid 10,000 requests (timestamp array growth)
|
|
27
|
-
- Monitors memory usage throughout
|
|
28
|
-
- Verifies specific data structures don't grow unbounded
|
|
29
|
-
|
|
30
|
-
## Recommendations
|
|
31
|
-
|
|
32
|
-
1. Always use `unref()` on intervals that shouldn't keep the process alive
|
|
33
|
-
2. Always provide cleanup/destroy methods for classes that create timers
|
|
34
|
-
3. Implement size limits on all caches and Maps
|
|
35
|
-
4. Consider using WeakMap for caches where appropriate
|
|
36
|
-
5. Run memory leak tests regularly, especially after adding new features
|
|
37
|
-
|
|
38
|
-
## Running the Memory Leak Test
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
# Run with garbage collection exposed for accurate measurements
|
|
42
|
-
node --expose-gc test/test.memory-leak-check.node.ts
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
The test will monitor memory usage and fail if memory growth exceeds acceptable thresholds.
|