feat(socket-handler): implement direct socket passing for DNS and email services
- Add socket-handler mode eliminating internal port binding for improved performance - Add `dnsDomain` config option for automatic DNS-over-HTTPS (DoH) setup - Add `useSocketHandler` flag to email config for direct socket processing - Update SmartProxy route generation to support socket-handler actions - Integrate smartdns with manual HTTPS mode for DoH without port binding - Add automatic route creation for DNS paths when dnsDomain is configured - Update documentation with socket-handler configuration and benefits - Improve resource efficiency by eliminating internal port forwarding
This commit is contained in:
69
readme.md
69
readme.md
@ -212,6 +212,7 @@ interface IDcRouterOptions {
|
||||
tls?: ITlsConfig;
|
||||
maxMessageSize?: number;
|
||||
rateLimits?: IRateLimitConfig;
|
||||
useSocketHandler?: boolean; // Enable socket-handler mode (no port binding)
|
||||
};
|
||||
|
||||
// DNS server configuration
|
||||
@ -221,6 +222,9 @@ interface IDcRouterOptions {
|
||||
records?: IDnsRecord[];
|
||||
};
|
||||
|
||||
// DNS domain for automatic DNS-over-HTTPS setup
|
||||
dnsDomain?: string; // e.g., 'dns.example.com'
|
||||
|
||||
// TLS and certificate configuration
|
||||
tls?: {
|
||||
contactEmail: string;
|
||||
@ -262,6 +266,71 @@ interface IRouteConfig {
|
||||
}
|
||||
```
|
||||
|
||||
## Socket-Handler Mode
|
||||
|
||||
DcRouter supports an advanced socket-handler mode that eliminates internal port binding for both DNS and email services. Instead of services listening on internal ports, SmartProxy passes sockets directly to the services.
|
||||
|
||||
### DNS Socket-Handler
|
||||
|
||||
When `dnsDomain` is configured, DcRouter automatically:
|
||||
- Sets up DNS server for UDP on port 53
|
||||
- Creates SmartProxy routes for DNS-over-HTTPS (DoH) on the specified domain
|
||||
- Uses socket-handler for HTTPS/DoH traffic (no HTTPS port binding)
|
||||
|
||||
```typescript
|
||||
const router = new DcRouter({
|
||||
dnsDomain: 'dns.example.com', // Enables DNS with DoH
|
||||
smartProxyConfig: {
|
||||
// DNS routes are automatically created
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
This creates:
|
||||
- UDP DNS service on port 53 (standard DNS queries)
|
||||
- HTTPS routes for `dns.example.com/dns-query` and `dns.example.com/resolve`
|
||||
- Automatic TLS certificates via Let's Encrypt
|
||||
|
||||
### Email Socket-Handler
|
||||
|
||||
When `useSocketHandler` is enabled in email config:
|
||||
- Email server doesn't bind to any ports
|
||||
- SmartProxy passes sockets directly to email handlers
|
||||
- Reduces latency and resource usage
|
||||
|
||||
```typescript
|
||||
const router = new DcRouter({
|
||||
emailConfig: {
|
||||
ports: [25, 587, 465],
|
||||
hostname: 'mail.example.com',
|
||||
useSocketHandler: true, // Enable socket-handler mode
|
||||
routes: [/* email routes */]
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Benefits of Socket-Handler Mode
|
||||
|
||||
1. **Performance**: Eliminates internal port forwarding overhead
|
||||
2. **Security**: No exposed internal ports
|
||||
3. **Resource Efficiency**: Fewer open ports and listeners
|
||||
4. **Simplified Networking**: Direct socket passing
|
||||
5. **Automatic Configuration**: Routes created automatically
|
||||
|
||||
### Traditional vs Socket-Handler Mode
|
||||
|
||||
**Traditional Mode (default):**
|
||||
```
|
||||
External Port → SmartProxy → Internal Port → Service
|
||||
25 → 10025 → Email
|
||||
```
|
||||
|
||||
**Socket-Handler Mode:**
|
||||
```
|
||||
External Port → SmartProxy → Socket Handler → Service
|
||||
25 → (direct socket) → Email
|
||||
```
|
||||
|
||||
## Email System
|
||||
|
||||
### Email Route Actions
|
||||
|
Reference in New Issue
Block a user