@push.rocks/smartproxy 19.5.18 → 19.5.20
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/00_commitinfo_data.js +2 -2
- package/dist_ts/core/models/index.d.ts +2 -0
- package/dist_ts/core/models/index.js +3 -1
- package/dist_ts/core/models/socket-types.d.ts +14 -0
- package/dist_ts/core/models/socket-types.js +15 -0
- package/dist_ts/core/models/wrapped-socket.d.ts +34 -0
- package/dist_ts/core/models/wrapped-socket.js +82 -0
- package/dist_ts/core/routing/index.d.ts +11 -0
- package/dist_ts/core/routing/index.js +17 -0
- package/dist_ts/core/routing/matchers/domain.d.ts +34 -0
- package/dist_ts/core/routing/matchers/domain.js +91 -0
- package/dist_ts/core/routing/matchers/header.d.ts +32 -0
- package/dist_ts/core/routing/matchers/header.js +94 -0
- package/dist_ts/core/routing/matchers/index.d.ts +18 -0
- package/dist_ts/core/routing/matchers/index.js +20 -0
- package/dist_ts/core/routing/matchers/ip.d.ts +53 -0
- package/dist_ts/core/routing/matchers/ip.js +169 -0
- package/dist_ts/core/routing/matchers/path.d.ts +44 -0
- package/dist_ts/core/routing/matchers/path.js +148 -0
- package/dist_ts/core/routing/route-manager.d.ts +88 -0
- package/dist_ts/core/routing/route-manager.js +342 -0
- package/dist_ts/core/routing/route-utils.d.ts +28 -0
- package/dist_ts/core/routing/route-utils.js +67 -0
- package/dist_ts/core/routing/specificity.d.ts +30 -0
- package/dist_ts/core/routing/specificity.js +115 -0
- package/dist_ts/core/routing/types.d.ts +41 -0
- package/dist_ts/core/routing/types.js +5 -0
- package/dist_ts/core/utils/index.d.ts +0 -2
- package/dist_ts/core/utils/index.js +1 -3
- package/dist_ts/core/utils/route-manager.d.ts +0 -30
- package/dist_ts/core/utils/route-manager.js +6 -47
- package/dist_ts/core/utils/route-utils.d.ts +2 -68
- package/dist_ts/core/utils/route-utils.js +21 -218
- package/dist_ts/core/utils/security-utils.js +4 -4
- package/dist_ts/core/utils/socket-utils.d.ts +0 -15
- package/dist_ts/core/utils/socket-utils.js +1 -35
- package/dist_ts/forwarding/handlers/https-terminate-to-http-handler.js +47 -32
- package/dist_ts/forwarding/handlers/https-terminate-to-https-handler.js +51 -32
- package/dist_ts/index.d.ts +2 -5
- package/dist_ts/index.js +5 -11
- package/dist_ts/proxies/http-proxy/http-proxy.d.ts +0 -1
- package/dist_ts/proxies/http-proxy/http-proxy.js +15 -60
- package/dist_ts/proxies/http-proxy/models/types.d.ts +0 -90
- package/dist_ts/proxies/http-proxy/models/types.js +1 -242
- package/dist_ts/proxies/http-proxy/request-handler.d.ts +3 -5
- package/dist_ts/proxies/http-proxy/request-handler.js +20 -171
- package/dist_ts/proxies/http-proxy/websocket-handler.d.ts +2 -5
- package/dist_ts/proxies/http-proxy/websocket-handler.js +15 -23
- package/dist_ts/proxies/index.d.ts +2 -2
- package/dist_ts/proxies/index.js +4 -3
- package/dist_ts/proxies/smart-proxy/connection-manager.d.ts +3 -1
- package/dist_ts/proxies/smart-proxy/connection-manager.js +15 -7
- package/dist_ts/proxies/smart-proxy/http-proxy-bridge.d.ts +2 -1
- package/dist_ts/proxies/smart-proxy/http-proxy-bridge.js +5 -2
- package/dist_ts/proxies/smart-proxy/index.d.ts +1 -1
- package/dist_ts/proxies/smart-proxy/index.js +2 -2
- package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +6 -2
- package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +1 -1
- package/dist_ts/proxies/smart-proxy/route-connection-handler.js +48 -25
- package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +1 -1
- package/dist_ts/proxies/smart-proxy/smart-proxy.js +15 -4
- package/dist_ts/proxies/smart-proxy/utils/route-utils.js +10 -43
- package/dist_ts/routing/router/http-router.d.ts +89 -0
- package/dist_ts/routing/router/http-router.js +205 -0
- package/dist_ts/routing/router/index.d.ts +2 -5
- package/dist_ts/routing/router/index.js +3 -4
- package/package.json +1 -1
- package/readme.delete.md +187 -0
- package/readme.hints.md +210 -1
- package/readme.plan.md +621 -0
- package/readme.routing.md +341 -0
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/core/models/index.ts +2 -0
- package/ts/core/models/socket-types.ts +21 -0
- package/ts/core/models/wrapped-socket.ts +99 -0
- package/ts/core/routing/index.ts +21 -0
- package/ts/core/routing/matchers/domain.ts +119 -0
- package/ts/core/routing/matchers/header.ts +120 -0
- package/ts/core/routing/matchers/index.ts +22 -0
- package/ts/core/routing/matchers/ip.ts +207 -0
- package/ts/core/routing/matchers/path.ts +184 -0
- package/ts/core/{utils → routing}/route-manager.ts +7 -57
- package/ts/core/routing/route-utils.ts +88 -0
- package/ts/core/routing/specificity.ts +141 -0
- package/ts/core/routing/types.ts +49 -0
- package/ts/core/utils/index.ts +0 -2
- package/ts/core/utils/security-utils.ts +3 -7
- package/ts/core/utils/socket-utils.ts +0 -44
- package/ts/forwarding/handlers/https-terminate-to-http-handler.ts +47 -33
- package/ts/forwarding/handlers/https-terminate-to-https-handler.ts +55 -35
- package/ts/index.ts +4 -14
- package/ts/proxies/http-proxy/http-proxy.ts +13 -68
- package/ts/proxies/http-proxy/models/types.ts +0 -324
- package/ts/proxies/http-proxy/request-handler.ts +15 -186
- package/ts/proxies/http-proxy/websocket-handler.ts +15 -26
- package/ts/proxies/index.ts +3 -2
- package/ts/proxies/smart-proxy/connection-manager.ts +15 -7
- package/ts/proxies/smart-proxy/http-proxy-bridge.ts +6 -2
- package/ts/proxies/smart-proxy/index.ts +1 -1
- package/ts/proxies/smart-proxy/models/interfaces.ts +8 -2
- package/ts/proxies/smart-proxy/route-connection-handler.ts +58 -30
- package/ts/proxies/smart-proxy/smart-proxy.ts +15 -3
- package/ts/proxies/smart-proxy/utils/route-utils.ts +11 -49
- package/ts/routing/router/http-router.ts +266 -0
- package/ts/routing/router/index.ts +3 -8
- package/readme.problems.md +0 -170
- package/ts/core/utils/route-utils.ts +0 -312
- package/ts/proxies/smart-proxy/route-manager.ts +0 -554
- package/ts/routing/router/proxy-router.ts +0 -437
- package/ts/routing/router/route-router.ts +0 -482
package/readme.hints.md
CHANGED
|
@@ -640,4 +640,213 @@ export function setupBidirectionalForwarding(
|
|
|
640
640
|
- **Neutral**: Half-open connections still available when needed (opt-in)
|
|
641
641
|
|
|
642
642
|
### Migration Notes
|
|
643
|
-
No configuration changes needed. The fix applies to all proxy chains automatically.
|
|
643
|
+
No configuration changes needed. The fix applies to all proxy chains automatically.
|
|
644
|
+
|
|
645
|
+
## Socket Cleanup Handler Deprecation (v19.5.15+)
|
|
646
|
+
|
|
647
|
+
### Issue
|
|
648
|
+
The deprecated `createSocketCleanupHandler()` function was still being used in forwarding handlers, despite being marked as deprecated.
|
|
649
|
+
|
|
650
|
+
### Solution
|
|
651
|
+
Updated all forwarding handlers to use the new centralized socket utilities:
|
|
652
|
+
1. **Replaced `createSocketCleanupHandler()`** with `setupBidirectionalForwarding()` in:
|
|
653
|
+
- `https-terminate-to-https-handler.ts`
|
|
654
|
+
- `https-terminate-to-http-handler.ts`
|
|
655
|
+
2. **Removed deprecated function** from `socket-utils.ts`
|
|
656
|
+
|
|
657
|
+
### Benefits
|
|
658
|
+
- Consistent socket handling across all handlers
|
|
659
|
+
- Proper cleanup in proxy chains (no half-open connections by default)
|
|
660
|
+
- Better backpressure handling with the centralized implementation
|
|
661
|
+
- Reduced code duplication
|
|
662
|
+
|
|
663
|
+
### Migration Notes
|
|
664
|
+
No user-facing changes. All forwarding handlers now use the same robust socket handling as the main SmartProxy connection handler.
|
|
665
|
+
|
|
666
|
+
## WrappedSocket Class Evaluation for PROXY Protocol (v19.5.19+)
|
|
667
|
+
|
|
668
|
+
### Current Socket Handling Architecture
|
|
669
|
+
- Sockets are handled directly as `net.Socket` instances throughout the codebase
|
|
670
|
+
- Socket augmentation via TypeScript module augmentation for TLS properties
|
|
671
|
+
- Metadata tracked separately in `IConnectionRecord` objects
|
|
672
|
+
- Socket utilities provide helper functions but don't encapsulate the socket
|
|
673
|
+
- Connection records track extensive metadata (IDs, timestamps, byte counters, TLS state, etc.)
|
|
674
|
+
|
|
675
|
+
### Evaluation: Should We Introduce a WrappedSocket Class?
|
|
676
|
+
|
|
677
|
+
**Yes, a WrappedSocket class would make sense**, particularly for PROXY protocol implementation and future extensibility.
|
|
678
|
+
|
|
679
|
+
### Design Considerations for WrappedSocket
|
|
680
|
+
|
|
681
|
+
```typescript
|
|
682
|
+
class WrappedSocket {
|
|
683
|
+
private socket: net.Socket;
|
|
684
|
+
private connectionId: string;
|
|
685
|
+
private metadata: {
|
|
686
|
+
realClientIP?: string; // From PROXY protocol
|
|
687
|
+
realClientPort?: number; // From PROXY protocol
|
|
688
|
+
proxyIP?: string; // Immediate connection IP
|
|
689
|
+
proxyPort?: number; // Immediate connection port
|
|
690
|
+
bytesReceived: number;
|
|
691
|
+
bytesSent: number;
|
|
692
|
+
lastActivity: number;
|
|
693
|
+
isTLS: boolean;
|
|
694
|
+
// ... other metadata
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
// PROXY protocol handling
|
|
698
|
+
private proxyProtocolParsed: boolean = false;
|
|
699
|
+
private pendingData: Buffer[] = [];
|
|
700
|
+
|
|
701
|
+
constructor(socket: net.Socket) {
|
|
702
|
+
this.socket = socket;
|
|
703
|
+
this.setupHandlers();
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// Getters for clean access
|
|
707
|
+
get remoteAddress(): string {
|
|
708
|
+
return this.metadata.realClientIP || this.socket.remoteAddress || '';
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
get remotePort(): number {
|
|
712
|
+
return this.metadata.realClientPort || this.socket.remotePort || 0;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
get isFromTrustedProxy(): boolean {
|
|
716
|
+
return !!this.metadata.realClientIP;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// PROXY protocol parsing
|
|
720
|
+
async parseProxyProtocol(trustedProxies: string[]): Promise<boolean> {
|
|
721
|
+
// Implementation here
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// Delegate socket methods
|
|
725
|
+
write(data: any): boolean {
|
|
726
|
+
this.metadata.bytesSent += Buffer.byteLength(data);
|
|
727
|
+
return this.socket.write(data);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
destroy(error?: Error): void {
|
|
731
|
+
this.socket.destroy(error);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// Event forwarding
|
|
735
|
+
on(event: string, listener: Function): this {
|
|
736
|
+
this.socket.on(event, listener);
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
### Implementation Benefits
|
|
743
|
+
|
|
744
|
+
1. **Encapsulation**: Bundle socket + metadata + behavior in one place
|
|
745
|
+
2. **PROXY Protocol Integration**: Cleaner handling without modifying existing socket code
|
|
746
|
+
3. **State Management**: Centralized socket state tracking and validation
|
|
747
|
+
4. **API Consistency**: Uniform interface for all socket operations
|
|
748
|
+
5. **Future Extensibility**: Easy to add new socket-level features (compression, encryption, etc.)
|
|
749
|
+
6. **Type Safety**: Better TypeScript support without module augmentation
|
|
750
|
+
7. **Testing**: Easier to mock and test socket behavior
|
|
751
|
+
|
|
752
|
+
### Implementation Drawbacks
|
|
753
|
+
|
|
754
|
+
1. **Major Refactoring**: Would require changes throughout the codebase
|
|
755
|
+
2. **Performance Overhead**: Additional abstraction layer (minimal but present)
|
|
756
|
+
3. **Compatibility**: Need to maintain event emitter compatibility
|
|
757
|
+
4. **Learning Curve**: Developers need to understand the wrapper
|
|
758
|
+
|
|
759
|
+
### Recommended Approach: Phased Implementation
|
|
760
|
+
|
|
761
|
+
**Phase 1: PROXY Protocol Only** (Immediate)
|
|
762
|
+
- Create minimal `ProxyProtocolSocket` wrapper for new connections from trusted proxies
|
|
763
|
+
- Use in connection handler when receiving from trusted proxy IPs
|
|
764
|
+
- Minimal disruption to existing code
|
|
765
|
+
|
|
766
|
+
```typescript
|
|
767
|
+
class ProxyProtocolSocket {
|
|
768
|
+
constructor(
|
|
769
|
+
public socket: net.Socket,
|
|
770
|
+
public realClientIP?: string,
|
|
771
|
+
public realClientPort?: number
|
|
772
|
+
) {}
|
|
773
|
+
|
|
774
|
+
get remoteAddress(): string {
|
|
775
|
+
return this.realClientIP || this.socket.remoteAddress || '';
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
get remotePort(): number {
|
|
779
|
+
return this.realClientPort || this.socket.remotePort || 0;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
**Phase 2: Gradual Migration** (Future)
|
|
785
|
+
- Extend wrapper with more functionality
|
|
786
|
+
- Migrate critical paths to use wrapper
|
|
787
|
+
- Add performance monitoring
|
|
788
|
+
|
|
789
|
+
**Phase 3: Full Adoption** (Long-term)
|
|
790
|
+
- Complete migration to WrappedSocket
|
|
791
|
+
- Remove socket augmentation
|
|
792
|
+
- Standardize all socket handling
|
|
793
|
+
|
|
794
|
+
### Decision Summary
|
|
795
|
+
|
|
796
|
+
✅ **Implement minimal ProxyProtocolSocket for immediate PROXY protocol support**
|
|
797
|
+
- Low risk, high value
|
|
798
|
+
- Solves the immediate proxy chain connection limit issue
|
|
799
|
+
- Sets foundation for future improvements
|
|
800
|
+
- Can be implemented alongside existing code
|
|
801
|
+
|
|
802
|
+
📋 **Consider full WrappedSocket for future major version**
|
|
803
|
+
- Cleaner architecture
|
|
804
|
+
- Better maintainability
|
|
805
|
+
- But requires significant refactoring
|
|
806
|
+
|
|
807
|
+
## WrappedSocket Implementation (PROXY Protocol Phase 1) - v19.5.19+
|
|
808
|
+
|
|
809
|
+
The WrappedSocket class has been implemented as the foundation for PROXY protocol support:
|
|
810
|
+
|
|
811
|
+
### Implementation Details
|
|
812
|
+
|
|
813
|
+
1. **Design Approach**: Uses JavaScript Proxy to delegate all Socket methods/properties to the underlying socket while allowing override of specific properties (remoteAddress, remotePort).
|
|
814
|
+
|
|
815
|
+
2. **Key Design Decisions**:
|
|
816
|
+
- NOT a Duplex stream - Initially tried this approach but it created infinite loops
|
|
817
|
+
- Simple wrapper using Proxy pattern for transparent delegation
|
|
818
|
+
- All sockets are wrapped, not just those from trusted proxies
|
|
819
|
+
- Trusted proxy detection happens after wrapping
|
|
820
|
+
|
|
821
|
+
3. **Usage Pattern**:
|
|
822
|
+
```typescript
|
|
823
|
+
// In RouteConnectionHandler.handleConnection()
|
|
824
|
+
const wrappedSocket = new WrappedSocket(socket);
|
|
825
|
+
// Pass wrappedSocket throughout the flow
|
|
826
|
+
|
|
827
|
+
// When calling socket-utils functions, extract underlying socket:
|
|
828
|
+
const underlyingSocket = getUnderlyingSocket(socket);
|
|
829
|
+
setupBidirectionalForwarding(underlyingSocket, targetSocket, {...});
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
4. **Important Implementation Notes**:
|
|
833
|
+
- Socket utility functions (setupBidirectionalForwarding, cleanupSocket) expect raw net.Socket
|
|
834
|
+
- Always extract underlying socket before passing to these utilities using `getUnderlyingSocket()`
|
|
835
|
+
- WrappedSocket preserves all Socket functionality through Proxy delegation
|
|
836
|
+
- TypeScript typing handled via index signature: `[key: string]: any`
|
|
837
|
+
|
|
838
|
+
5. **Files Modified**:
|
|
839
|
+
- `ts/core/models/wrapped-socket.ts` - The WrappedSocket implementation
|
|
840
|
+
- `ts/core/models/socket-types.ts` - Helper functions and type guards
|
|
841
|
+
- `ts/proxies/smart-proxy/route-connection-handler.ts` - Updated to wrap all incoming sockets
|
|
842
|
+
- `ts/proxies/smart-proxy/connection-manager.ts` - Updated to accept WrappedSocket
|
|
843
|
+
- `ts/proxies/smart-proxy/http-proxy-bridge.ts` - Updated to handle WrappedSocket
|
|
844
|
+
|
|
845
|
+
6. **Test Coverage**:
|
|
846
|
+
- `test/test.wrapped-socket-forwarding.ts` - Verifies data forwarding through wrapped sockets
|
|
847
|
+
|
|
848
|
+
### Next Steps for PROXY Protocol
|
|
849
|
+
- Phase 2: Parse PROXY protocol header from trusted proxies
|
|
850
|
+
- Phase 3: Update real client IP/port after parsing
|
|
851
|
+
- Phase 4: Test with HAProxy and AWS ELB
|
|
852
|
+
- Phase 5: Documentation and configuration
|