feat(smart-proxy): add socket-handler relay, fast-path port-only forwarding, metrics and bridge improvements, and various TS/Rust integration fixes

This commit is contained in:
2026-02-09 16:25:33 +00:00
parent 41efdb47f8
commit f7605e042e
17 changed files with 724 additions and 300 deletions

View File

@@ -214,8 +214,8 @@ const echoRoute = createSocketHandlerRoute(
const customRoute = createSocketHandlerRoute(
'custom.example.com',
9999,
async (socket, context) => {
console.log(`Connection from ${context.clientIp}`);
async (socket) => {
console.log(`New connection on custom protocol`);
socket.write('Welcome to my custom protocol!\n');
socket.on('data', (data) => {
@@ -261,8 +261,7 @@ const proxy = new SmartProxy({
{
ports: 443,
certificate: 'auto',
preserveSourceIP: true, // Backend sees real client IP
maxRate: '1gbps' // QoS rate limiting
preserveSourceIP: true // Backend sees real client IP
}
)
]
@@ -529,7 +528,7 @@ interface IRouteTarget {
```typescript
interface IRouteTls {
mode: 'passthrough' | 'terminate' | 'terminate-and-reencrypt';
certificate: 'auto' | {
certificate?: 'auto' | {
key: string;
cert: string;
ca?: string;
@@ -543,7 +542,7 @@ interface IRouteTls {
renewBeforeDays?: number;
};
versions?: string[];
ciphers?: string[];
ciphers?: string;
honorCipherOrder?: boolean;
sessionTimeout?: number;
}
@@ -569,10 +568,10 @@ interface IRouteLoadBalancing {
algorithm: 'round-robin' | 'least-connections' | 'ip-hash';
healthCheck?: {
path: string;
interval: number; // ms
timeout: number; // ms
unhealthyThreshold?: number;
healthyThreshold?: number;
interval: number; // ms
timeout: number; // ms
unhealthyThreshold: number;
healthyThreshold: number;
};
}
```
@@ -700,7 +699,7 @@ interface ISmartProxyOptions {
// Timeouts
connectionTimeout?: number; // Backend connection timeout (default: 30s)
initialDataTimeout?: number; // Initial data/SNI timeout (default: 120s)
initialDataTimeout?: number; // Initial data/SNI timeout (default: 60s)
socketTimeout?: number; // Socket inactivity timeout (default: 1h)
maxConnectionLifetime?: number; // Max connection lifetime (default: 24h)
inactivityTimeout?: number; // Inactivity timeout (default: 4h)
@@ -739,18 +738,21 @@ A standalone class for managing nftables NAT rules directly (Linux only, require
import { NfTablesProxy } from '@push.rocks/smartproxy';
const nftProxy = new NfTablesProxy({
fromPorts: [80, 443],
fromPort: [80, 443],
toPort: [8080, 8443],
toHost: 'backend-server',
toPorts: [8080, 8443],
protocol: 'tcp',
preserveSourceIP: true,
enableIPv6: true,
maxRate: '1gbps',
useIPSets: true
ipv6Support: true,
useIPSets: true,
qos: {
enabled: true,
maxRate: '1gbps'
}
});
await nftProxy.start(); // Apply nftables rules
const status = nftProxy.getStatus();
const status = await nftProxy.getStatus();
await nftProxy.stop(); // Remove rules
```