@push.rocks/smartproxy 18.0.2 → 18.2.0

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.
Files changed (53) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/certificate/certificate-manager.d.ts +150 -0
  3. package/dist_ts/certificate/certificate-manager.js +505 -0
  4. package/dist_ts/certificate/events/simplified-events.d.ts +56 -0
  5. package/dist_ts/certificate/events/simplified-events.js +13 -0
  6. package/dist_ts/certificate/models/certificate-errors.d.ts +69 -0
  7. package/dist_ts/certificate/models/certificate-errors.js +141 -0
  8. package/dist_ts/certificate/models/certificate-strategy.d.ts +60 -0
  9. package/dist_ts/certificate/models/certificate-strategy.js +73 -0
  10. package/dist_ts/certificate/simplified-certificate-manager.d.ts +150 -0
  11. package/dist_ts/certificate/simplified-certificate-manager.js +501 -0
  12. package/dist_ts/http/index.d.ts +1 -9
  13. package/dist_ts/http/index.js +5 -11
  14. package/dist_ts/plugins.d.ts +3 -1
  15. package/dist_ts/plugins.js +4 -2
  16. package/dist_ts/proxies/network-proxy/network-proxy.js +3 -1
  17. package/dist_ts/proxies/network-proxy/simplified-certificate-bridge.d.ts +48 -0
  18. package/dist_ts/proxies/network-proxy/simplified-certificate-bridge.js +76 -0
  19. package/dist_ts/proxies/network-proxy/websocket-handler.js +41 -4
  20. package/dist_ts/proxies/smart-proxy/cert-store.d.ts +10 -0
  21. package/dist_ts/proxies/smart-proxy/cert-store.js +70 -0
  22. package/dist_ts/proxies/smart-proxy/certificate-manager.d.ts +116 -0
  23. package/dist_ts/proxies/smart-proxy/certificate-manager.js +401 -0
  24. package/dist_ts/proxies/smart-proxy/legacy-smart-proxy.d.ts +168 -0
  25. package/dist_ts/proxies/smart-proxy/legacy-smart-proxy.js +642 -0
  26. package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +26 -0
  27. package/dist_ts/proxies/smart-proxy/models/route-types.js +1 -1
  28. package/dist_ts/proxies/smart-proxy/models/simplified-smartproxy-config.d.ts +65 -0
  29. package/dist_ts/proxies/smart-proxy/models/simplified-smartproxy-config.js +31 -0
  30. package/dist_ts/proxies/smart-proxy/models/smartproxy-options.d.ts +102 -0
  31. package/dist_ts/proxies/smart-proxy/models/smartproxy-options.js +73 -0
  32. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +10 -44
  33. package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +66 -202
  34. package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +4 -0
  35. package/dist_ts/proxies/smart-proxy/route-connection-handler.js +62 -2
  36. package/dist_ts/proxies/smart-proxy/simplified-smart-proxy.d.ts +41 -0
  37. package/dist_ts/proxies/smart-proxy/simplified-smart-proxy.js +132 -0
  38. package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +18 -13
  39. package/dist_ts/proxies/smart-proxy/smart-proxy.js +79 -196
  40. package/package.json +7 -5
  41. package/readme.md +224 -10
  42. package/readme.plan.md +1405 -617
  43. package/ts/00_commitinfo_data.ts +1 -1
  44. package/ts/http/index.ts +5 -12
  45. package/ts/plugins.ts +4 -1
  46. package/ts/proxies/network-proxy/network-proxy.ts +3 -0
  47. package/ts/proxies/network-proxy/websocket-handler.ts +38 -3
  48. package/ts/proxies/smart-proxy/cert-store.ts +86 -0
  49. package/ts/proxies/smart-proxy/certificate-manager.ts +506 -0
  50. package/ts/proxies/smart-proxy/models/route-types.ts +33 -3
  51. package/ts/proxies/smart-proxy/network-proxy-bridge.ts +86 -239
  52. package/ts/proxies/smart-proxy/route-connection-handler.ts +74 -1
  53. package/ts/proxies/smart-proxy/smart-proxy.ts +105 -222
package/readme.md CHANGED
@@ -9,6 +9,7 @@ A unified high-performance proxy toolkit for Node.js, with **SmartProxy** as the
9
9
  - **Multiple Action Types**: Forward (with TLS modes), redirect, or block traffic
10
10
  - **Dynamic Port Management**: Add or remove listening ports at runtime without restart
11
11
  - **Security Features**: IP allowlists, connection limits, timeouts, and more
12
+ - **NFTables Integration**: High-performance kernel-level packet forwarding with Linux NFTables
12
13
 
13
14
  ## Project Architecture Overview
14
15
 
@@ -71,6 +72,8 @@ SmartProxy has been restructured using a modern, modular architecture with a uni
71
72
  Helper functions for common redirect and security configurations
72
73
  - **createLoadBalancerRoute**, **createHttpsServer**
73
74
  Helper functions for complex configurations
75
+ - **createNfTablesRoute**, **createNfTablesTerminateRoute**
76
+ Helper functions for NFTables-based high-performance kernel-level routing
74
77
 
75
78
  ### Specialized Components
76
79
 
@@ -108,7 +111,7 @@ npm install @push.rocks/smartproxy
108
111
 
109
112
  ## Quick Start with SmartProxy
110
113
 
111
- SmartProxy v16.0.0 continues the evolution of the unified route-based configuration system making your proxy setup more flexible and intuitive with improved helper functions.
114
+ SmartProxy v18.0.0 continues the evolution of the unified route-based configuration system making your proxy setup more flexible and intuitive with improved helper functions and NFTables integration for high-performance kernel-level routing.
112
115
 
113
116
  ```typescript
114
117
  import {
@@ -122,7 +125,9 @@ import {
122
125
  createStaticFileRoute,
123
126
  createApiRoute,
124
127
  createWebSocketRoute,
125
- createSecurityConfig
128
+ createSecurityConfig,
129
+ createNfTablesRoute,
130
+ createNfTablesTerminateRoute
126
131
  } from '@push.rocks/smartproxy';
127
132
 
128
133
  // Create a new SmartProxy instance with route-based configuration
@@ -185,7 +190,22 @@ const proxy = new SmartProxy({
185
190
  maxConnections: 1000
186
191
  })
187
192
  }
188
- )
193
+ ),
194
+
195
+ // High-performance NFTables route (requires root/sudo)
196
+ createNfTablesRoute('fast.example.com', { host: 'backend-server', port: 8080 }, {
197
+ ports: 80,
198
+ protocol: 'tcp',
199
+ preserveSourceIP: true,
200
+ ipAllowList: ['10.0.0.*']
201
+ }),
202
+
203
+ // NFTables HTTPS termination for ultra-fast TLS handling
204
+ createNfTablesTerminateRoute('secure-fast.example.com', { host: 'backend-ssl', port: 443 }, {
205
+ ports: 443,
206
+ certificate: 'auto',
207
+ maxRate: '100mbps'
208
+ })
189
209
  ],
190
210
 
191
211
  // Global settings that apply to all routes
@@ -319,6 +339,12 @@ interface IRouteAction {
319
339
 
320
340
  // Advanced options
321
341
  advanced?: IRouteAdvanced;
342
+
343
+ // Forwarding engine selection
344
+ forwardingEngine?: 'node' | 'nftables';
345
+
346
+ // NFTables-specific options
347
+ nftables?: INfTablesOptions;
322
348
  }
323
349
  ```
324
350
 
@@ -349,6 +375,25 @@ interface IRouteTls {
349
375
  - **terminate:** Terminate TLS and forward as HTTP
350
376
  - **terminate-and-reencrypt:** Terminate TLS and create a new TLS connection to the backend
351
377
 
378
+ **Forwarding Engine:**
379
+ When `forwardingEngine` is specified, it determines how packets are forwarded:
380
+ - **node:** (default) Application-level forwarding using Node.js
381
+ - **nftables:** Kernel-level forwarding using Linux NFTables (requires root privileges)
382
+
383
+ **NFTables Options:**
384
+ When using `forwardingEngine: 'nftables'`, you can configure:
385
+ ```typescript
386
+ interface INfTablesOptions {
387
+ protocol?: 'tcp' | 'udp' | 'all';
388
+ preserveSourceIP?: boolean;
389
+ maxRate?: string; // Rate limiting (e.g., '100mbps')
390
+ priority?: number; // QoS priority
391
+ tableName?: string; // Custom NFTables table name
392
+ useIPSets?: boolean; // Use IP sets for performance
393
+ useAdvancedNAT?: boolean; // Use connection tracking
394
+ }
395
+ ```
396
+
352
397
  **Redirect Action:**
353
398
  When `type: 'redirect'`, the client is redirected:
354
399
  ```typescript
@@ -459,6 +504,35 @@ Routes with higher priority values are matched first, allowing you to create spe
459
504
  priority: 100,
460
505
  tags: ['api', 'secure', 'internal']
461
506
  }
507
+
508
+ // Example with NFTables forwarding engine
509
+ {
510
+ match: {
511
+ ports: [80, 443],
512
+ domains: 'high-traffic.example.com'
513
+ },
514
+ action: {
515
+ type: 'forward',
516
+ target: {
517
+ host: 'backend-server',
518
+ port: 8080
519
+ },
520
+ forwardingEngine: 'nftables', // Use kernel-level forwarding
521
+ nftables: {
522
+ protocol: 'tcp',
523
+ preserveSourceIP: true,
524
+ maxRate: '1gbps',
525
+ useIPSets: true
526
+ },
527
+ security: {
528
+ ipAllowList: ['10.0.0.*'],
529
+ blockedIps: ['malicious.ip.range.*']
530
+ }
531
+ },
532
+ name: 'High Performance NFTables Route',
533
+ description: 'Kernel-level forwarding for maximum performance',
534
+ priority: 150
535
+ }
462
536
  ```
463
537
 
464
538
  ### Using Helper Functions
@@ -489,6 +563,8 @@ Available helper functions:
489
563
  - `createStaticFileRoute()` - Create a route for serving static files
490
564
  - `createApiRoute()` - Create an API route with path matching and CORS support
491
565
  - `createWebSocketRoute()` - Create a route for WebSocket connections
566
+ - `createNfTablesRoute()` - Create a high-performance NFTables route
567
+ - `createNfTablesTerminateRoute()` - Create an NFTables route with TLS termination
492
568
  - `createPortRange()` - Helper to create port range configurations
493
569
  - `createSecurityConfig()` - Helper to create security configuration objects
494
570
  - `createBlockRoute()` - Create a route to block specific traffic
@@ -589,6 +665,16 @@ Available helper functions:
589
665
  await proxy.removeListeningPort(8081);
590
666
  ```
591
667
 
668
+ 9. **High-Performance NFTables Routing**
669
+ ```typescript
670
+ // Use kernel-level packet forwarding for maximum performance
671
+ createNfTablesRoute('high-traffic.example.com', { host: 'backend', port: 8080 }, {
672
+ ports: 80,
673
+ preserveSourceIP: true,
674
+ maxRate: '1gbps'
675
+ })
676
+ ```
677
+
592
678
  ## Other Components
593
679
 
594
680
  While SmartProxy provides a unified API for most needs, you can also use individual components:
@@ -694,16 +780,137 @@ const redirect = new SslRedirect(80);
694
780
  await redirect.start();
695
781
  ```
696
782
 
697
- ## Migration to v16.0.0
783
+ ## NFTables Integration
784
+
785
+ SmartProxy v18.0.0 includes full integration with Linux NFTables for high-performance kernel-level packet forwarding. NFTables operates directly in the Linux kernel, providing much better performance than user-space proxying for high-traffic scenarios.
786
+
787
+ ### When to Use NFTables
788
+
789
+ NFTables routing is ideal for:
790
+ - High-traffic TCP/UDP forwarding where performance is critical
791
+ - Port forwarding scenarios where you need minimal latency
792
+ - Load balancing across multiple backend servers
793
+ - Security filtering with IP allowlists/blocklists at kernel level
794
+
795
+ ### Requirements
796
+
797
+ NFTables support requires:
798
+ - Linux operating system with NFTables installed
799
+ - Root or sudo permissions to configure NFTables rules
800
+ - NFTables kernel modules loaded
801
+
802
+ ### NFTables Route Configuration
803
+
804
+ Use the NFTables helper functions to create high-performance routes:
805
+
806
+ ```typescript
807
+ import { SmartProxy, createNfTablesRoute, createNfTablesTerminateRoute } from '@push.rocks/smartproxy';
808
+
809
+ const proxy = new SmartProxy({
810
+ routes: [
811
+ // Basic TCP forwarding with NFTables
812
+ createNfTablesRoute('tcp-forward', {
813
+ host: 'backend-server',
814
+ port: 8080
815
+ }, {
816
+ ports: 80,
817
+ protocol: 'tcp'
818
+ }),
819
+
820
+ // NFTables with IP filtering
821
+ createNfTablesRoute('secure-tcp', {
822
+ host: 'secure-backend',
823
+ port: 8443
824
+ }, {
825
+ ports: 443,
826
+ ipAllowList: ['10.0.0.*', '192.168.1.*'],
827
+ preserveSourceIP: true
828
+ }),
829
+
830
+ // NFTables with QoS (rate limiting)
831
+ createNfTablesRoute('limited-service', {
832
+ host: 'api-server',
833
+ port: 3000
834
+ }, {
835
+ ports: 8080,
836
+ maxRate: '50mbps',
837
+ priority: 1
838
+ }),
839
+
840
+ // NFTables TLS termination
841
+ createNfTablesTerminateRoute('https-nftables', {
842
+ host: 'backend',
843
+ port: 8080
844
+ }, {
845
+ ports: 443,
846
+ certificate: 'auto',
847
+ useAdvancedNAT: true
848
+ })
849
+ ]
850
+ });
851
+
852
+ await proxy.start();
853
+ ```
854
+
855
+ ### NFTables Route Options
856
+
857
+ The NFTables integration supports these options:
858
+
859
+ - `protocol`: 'tcp' | 'udp' | 'all' - Protocol to forward
860
+ - `preserveSourceIP`: boolean - Preserve client IP for backend
861
+ - `ipAllowList`: string[] - Allow only these IPs (glob patterns)
862
+ - `ipBlockList`: string[] - Block these IPs (glob patterns)
863
+ - `maxRate`: string - Rate limit (e.g., '100mbps', '1gbps')
864
+ - `priority`: number - QoS priority level
865
+ - `tableName`: string - Custom NFTables table name
866
+ - `useIPSets`: boolean - Use IP sets for better performance
867
+ - `useAdvancedNAT`: boolean - Enable connection tracking
868
+
869
+ ### NFTables Status Monitoring
870
+
871
+ You can monitor the status of NFTables rules:
872
+
873
+ ```typescript
874
+ // Get status of all NFTables rules
875
+ const nftStatus = await proxy.getNfTablesStatus();
876
+
877
+ // Status includes:
878
+ // - active: boolean
879
+ // - ruleCount: { total, added, removed }
880
+ // - packetStats: { forwarded, dropped }
881
+ // - lastUpdate: Date
882
+ ```
883
+
884
+ ### Performance Considerations
885
+
886
+ NFTables provides significantly better performance than application-level proxying:
887
+ - Operates at kernel level with minimal overhead
888
+ - Can handle millions of packets per second
889
+ - Direct packet forwarding without copying to userspace
890
+ - Hardware offload support on compatible network cards
891
+
892
+ ### Limitations
698
893
 
699
- Version 16.0.0 completes the migration to a fully unified route-based configuration system with improved helper functions:
894
+ NFTables routing has some limitations:
895
+ - Cannot modify HTTP headers or content
896
+ - Limited to basic NAT and forwarding operations
897
+ - Requires root permissions
898
+ - Linux-only (not available on Windows/macOS)
899
+ - No WebSocket message inspection
900
+
901
+ For scenarios requiring application-level features (header manipulation, WebSocket handling, etc.), use the standard SmartProxy routes without NFTables.
902
+
903
+ ## Migration to v18.0.0
904
+
905
+ Version 18.0.0 continues the evolution with NFTables integration while maintaining the unified route-based configuration system:
700
906
 
701
907
  ### Key Changes
702
908
 
703
- 1. **Pure Route-Based API**: The configuration now exclusively uses the match/action pattern with no legacy interfaces
704
- 2. **Improved Helper Functions**: Enhanced helper functions with cleaner parameter signatures
705
- 3. **Removed Legacy Support**: Legacy domain-based APIs have been completely removed
706
- 4. **More Route Pattern Helpers**: Additional helper functions for common routing patterns
909
+ 1. **NFTables Integration**: High-performance kernel-level packet forwarding for Linux systems
910
+ 2. **Pure Route-Based API**: The configuration now exclusively uses the match/action pattern with no legacy interfaces
911
+ 3. **Improved Helper Functions**: Enhanced helper functions with cleaner parameter signatures
912
+ 4. **Removed Legacy Support**: Legacy domain-based APIs have been completely removed
913
+ 5. **More Route Pattern Helpers**: Additional helper functions for common routing patterns including NFTables routes
707
914
 
708
915
  ### Migration Example
709
916
 
@@ -723,7 +930,7 @@ const proxy = new SmartProxy({
723
930
  });
724
931
  ```
725
932
 
726
- **Current Configuration (v16.0.0)**:
933
+ **Current Configuration (v18.0.0)**:
727
934
  ```typescript
728
935
  import { SmartProxy, createHttpsTerminateRoute } from '@push.rocks/smartproxy';
729
936
 
@@ -1212,6 +1419,13 @@ NetworkProxy now supports full route-based configuration including:
1212
1419
  - Use higher priority for block routes to ensure they take precedence
1213
1420
  - Enable `enableDetailedLogging` or `enableTlsDebugLogging` for debugging
1214
1421
 
1422
+ ### NFTables Integration
1423
+ - Ensure NFTables is installed: `apt install nftables` or `yum install nftables`
1424
+ - Verify root/sudo permissions for NFTables operations
1425
+ - Check NFTables service is running: `systemctl status nftables`
1426
+ - For debugging, check the NFTables rules: `nft list ruleset`
1427
+ - Monitor NFTables rule status: `await proxy.getNfTablesStatus()`
1428
+
1215
1429
  ### TLS/Certificates
1216
1430
  - For certificate issues, check the ACME settings and domain validation
1217
1431
  - Ensure domains are publicly accessible for Let's Encrypt validation