fix(readme): update

This commit is contained in:
Juergen Kunz
2025-06-13 17:22:31 +00:00
parent 7e1b7b190c
commit 424407d879
14 changed files with 85 additions and 4804 deletions

View File

@ -1625,6 +1625,34 @@ The `IProxyStats` interface provides the following methods:
- `getConnectionsByRoute()`: Connection count per route
- `getConnectionsByIP()`: Connection count per client IP
Additional extended methods available:
- `getThroughputRate()`: Bytes per second rate for the last minute
- `getTopIPs(limit?: number)`: Get top IPs by connection count
- `isIPBlocked(ip: string, maxConnectionsPerIP: number)`: Check if an IP has reached the connection limit
### Extended Metrics Example
```typescript
const stats = proxy.getStats() as any; // Extended methods are available
// Get throughput rate
const rate = stats.getThroughputRate();
console.log(`Incoming: ${rate.bytesInPerSec} bytes/sec`);
console.log(`Outgoing: ${rate.bytesOutPerSec} bytes/sec`);
// Get top 10 IPs by connection count
const topIPs = stats.getTopIPs(10);
topIPs.forEach(({ ip, connections }) => {
console.log(`${ip}: ${connections} connections`);
});
// Check if an IP should be rate limited
if (stats.isIPBlocked('192.168.1.100', 100)) {
console.log('IP has too many connections');
}
```
### Monitoring Example
```typescript
@ -2391,6 +2419,62 @@ createHttpToHttpsRedirect('old.example.com', 443)
}
```
## WebSocket Keep-Alive Configuration
If your WebSocket connections are disconnecting every 30 seconds in SNI passthrough mode, here's how to configure keep-alive settings:
### Extended Keep-Alive Treatment (Recommended)
```typescript
const proxy = new SmartProxy({
// Extend timeout for keep-alive connections
keepAliveTreatment: 'extended',
keepAliveInactivityMultiplier: 10, // 10x the base timeout
inactivityTimeout: 14400000, // 4 hours base (40 hours with multiplier)
routes: [
{
name: 'websocket-passthrough',
match: {
ports: 443,
domains: ['ws.example.com', 'wss.example.com']
},
action: {
type: 'forward',
target: { host: 'backend', port: 443 },
tls: { mode: 'passthrough' }
}
}
]
});
```
### Immortal Connections (Never Timeout)
```typescript
const proxy = new SmartProxy({
// Never timeout keep-alive connections
keepAliveTreatment: 'immortal',
routes: [
// ... same as above
]
});
```
### Understanding the Issue
In SNI passthrough mode:
1. **WebSocket Heartbeat**: The HTTP proxy's WebSocket handler sends ping frames every 30 seconds
2. **SNI Passthrough**: In passthrough mode, traffic is encrypted end-to-end
3. **Can't Inject Pings**: The proxy can't inject ping frames into encrypted traffic
4. **Connection Terminated**: After 30 seconds, connection is marked inactive and closed
The solution involves:
- Longer grace periods for encrypted connections (5 minutes vs 30 seconds)
- Relying on OS-level TCP keep-alive instead of application-level heartbeat
- Different timeout strategies per route type
## Configuration Options
### SmartProxy (IRoutedSmartProxyOptions)
@ -2401,6 +2485,7 @@ createHttpToHttpsRedirect('old.example.com', 443)
- `httpProxyPort` (number, default 8443) - Port where HttpProxy listens for forwarded connections
- Connection timeouts: `initialDataTimeout`, `socketTimeout`, `inactivityTimeout`, etc.
- Socket opts: `noDelay`, `keepAlive`, `enableKeepAliveProbes`
- Keep-alive configuration: `keepAliveTreatment` ('standard'|'extended'|'immortal'), `keepAliveInactivityMultiplier`
- `certProvisionFunction` (callback) - Custom certificate provisioning
#### SmartProxy Dynamic Port Management Methods