@push.rocks/smartvpn 1.9.0 → 1.10.1

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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartvpn',
6
- version: '1.9.0',
6
+ version: '1.10.1',
7
7
  description: 'A VPN solution with TypeScript control plane and Rust data plane daemon'
8
8
  };
9
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxzQkFBc0I7SUFDNUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHlFQUF5RTtDQUN2RixDQUFBIn0=
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxzQkFBc0I7SUFDNUIsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLHlFQUF5RTtDQUN2RixDQUFBIn0=
@@ -29,6 +29,9 @@ export interface IVpnClientConfig {
29
29
  transport?: 'auto' | 'websocket' | 'quic' | 'wireguard';
30
30
  /** For QUIC: SHA-256 hash of server certificate (base64) for cert pinning */
31
31
  serverCertHash?: string;
32
+ /** Forwarding mode: 'tun' (TUN device, requires root) or 'testing' (no TUN).
33
+ * Default: 'testing'. */
34
+ forwardingMode?: 'tun' | 'testing';
32
35
  /** WireGuard: client private key (base64, X25519) */
33
36
  wgPrivateKey?: string;
34
37
  /** WireGuard: client TUN address (e.g. 10.8.0.2) */
@@ -69,6 +72,9 @@ export interface IVpnServerConfig {
69
72
  keepaliveIntervalSecs?: number;
70
73
  /** Enable NAT/masquerade for client traffic */
71
74
  enableNat?: boolean;
75
+ /** Forwarding mode: 'tun' (kernel TUN, requires root), 'socket' (userspace NAT),
76
+ * or 'testing' (monitoring only). Default: 'testing'. */
77
+ forwardingMode?: 'tun' | 'socket' | 'testing';
72
78
  /** Default rate limit for new clients (bytes/sec). Omit for unlimited. */
73
79
  defaultRateLimitBytesPerSec?: number;
74
80
  /** Default burst size for new clients (bytes). Omit for unlimited. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartvpn",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "private": false,
5
5
  "description": "A VPN solution with TypeScript control plane and Rust data plane daemon",
6
6
  "type": "module",
@@ -12,7 +12,7 @@
12
12
  "scripts": {
13
13
  "build": "(tsbuild tsfolders) && (tsrust)",
14
14
  "test:before": "(tsrust)",
15
- "test": "tstest test/ --verbose",
15
+ "test": "tstest test/ --verbose --logfile --timeout 90",
16
16
  "buildDocs": "tsdoc"
17
17
  },
18
18
  "repository": {
package/readme.md CHANGED
@@ -9,6 +9,7 @@ A high-performance VPN solution with a **TypeScript control plane** and a **Rust
9
9
  📊 **Adaptive QoS**: per-client rate limiting, priority queues, connection quality tracking
10
10
  🔄 **Hub API**: one `createClient()` call generates keys, assigns IP, returns both SmartVPN + WireGuard configs
11
11
  📡 **Real-time telemetry**: RTT, jitter, loss ratio, link health — all via typed APIs
12
+ 🌐 **Flexible forwarding**: TUN device (kernel), userspace NAT (no root), or testing mode
12
13
 
13
14
  ## Issue Reporting and Security
14
15
 
@@ -54,6 +55,7 @@ await server.start({
54
55
  publicKey: '<server-noise-public-key-base64>',
55
56
  subnet: '10.8.0.0/24',
56
57
  transportMode: 'both', // WebSocket + QUIC simultaneously
58
+ forwardingMode: 'tun', // 'tun' (kernel), 'socket' (userspace NAT), or 'testing'
57
59
  enableNat: true,
58
60
  dns: ['1.1.1.1', '8.8.8.8'],
59
61
  });
@@ -152,6 +154,33 @@ await server.start({
152
154
  - `remoteAddr` field on `IVpnClientInfo` exposes the real client IP for monitoring
153
155
  - **Security**: must be `false` (default) when accepting direct connections — only enable behind a trusted proxy
154
156
 
157
+ ### 📦 Packet Forwarding Modes
158
+
159
+ SmartVPN supports three forwarding modes, configurable per-server and per-client:
160
+
161
+ | Mode | Flag | Description | Root Required |
162
+ |------|------|-------------|---------------|
163
+ | **TUN** | `'tun'` | Kernel TUN device — real packet forwarding with system routing | ✅ Yes |
164
+ | **Userspace NAT** | `'socket'` | Userspace TCP/UDP proxy via `connect(2)` — no TUN, no root needed | ❌ No |
165
+ | **Testing** | `'testing'` | Monitoring only — packets are counted but not forwarded | ❌ No |
166
+
167
+ ```typescript
168
+ // Server with userspace NAT (no root required)
169
+ await server.start({
170
+ // ...
171
+ forwardingMode: 'socket',
172
+ enableNat: true,
173
+ });
174
+
175
+ // Client with TUN device
176
+ const { assignedIp } = await client.connect({
177
+ // ...
178
+ forwardingMode: 'tun',
179
+ });
180
+ ```
181
+
182
+ The userspace NAT mode extracts destination IP/port from IP packets, opens a real socket to the destination, and relays data — supporting both TCP streams and UDP datagrams without requiring `CAP_NET_ADMIN` or root privileges.
183
+
155
184
  ### 📊 Telemetry & QoS
156
185
 
157
186
  - **Connection quality**: Smoothed RTT, jitter, min/max RTT, loss ratio, link health (`healthy` / `degraded` / `critical`)
@@ -244,8 +273,8 @@ const unit = VpnInstaller.generateServiceUnit({
244
273
 
245
274
  | Interface | Purpose |
246
275
  |-----------|---------|
247
- | `IVpnServerConfig` | Server configuration (listen addr, keys, subnet, transport mode, clients, proxy protocol) |
248
- | `IVpnClientConfig` | Client configuration (server URL, keys, transport, WG options) |
276
+ | `IVpnServerConfig` | Server configuration (listen addr, keys, subnet, transport mode, forwarding mode, clients, proxy protocol) |
277
+ | `IVpnClientConfig` | Client configuration (server URL, keys, transport, forwarding mode, WG options) |
249
278
  | `IClientEntry` | Server-side client definition (ID, keys, security, priority, tags, expiry) |
250
279
  | `IClientSecurity` | Per-client ACLs and rate limits (SmartProxy-aligned naming) |
251
280
  | `IClientRateLimit` | Rate limiting config (bytesPerSec, burstBytes) |
@@ -341,7 +370,7 @@ pnpm install
341
370
  # Build (TypeScript + Rust cross-compile)
342
371
  pnpm build
343
372
 
344
- # Run all tests (79 TS + 129 Rust = 208 tests)
373
+ # Run all tests (79 TS + 132 Rust = 211 tests)
345
374
  pnpm test
346
375
 
347
376
  # Run Rust tests directly
@@ -380,6 +409,7 @@ smartvpn/
380
409
  │ ├── codec.rs # Binary frame protocol
381
410
  │ ├── keepalive.rs # Adaptive keepalives
382
411
  │ ├── ratelimit.rs # Token bucket
412
+ │ ├── userspace_nat.rs # Userspace TCP/UDP NAT proxy
383
413
  │ └── ... # tunnel, network, telemetry, qos, mtu, reconnect
384
414
  ├── test/ # 9 test files (79 tests)
385
415
  ├── dist_ts/ # Compiled TypeScript
@@ -388,7 +418,7 @@ smartvpn/
388
418
 
389
419
  ## License and Legal Information
390
420
 
391
- This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license.md) file.
421
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
392
422
 
393
423
  **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
394
424
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartvpn',
6
- version: '1.9.0',
6
+ version: '1.10.1',
7
7
  description: 'A VPN solution with TypeScript control plane and Rust data plane daemon'
8
8
  }
@@ -40,6 +40,9 @@ export interface IVpnClientConfig {
40
40
  transport?: 'auto' | 'websocket' | 'quic' | 'wireguard';
41
41
  /** For QUIC: SHA-256 hash of server certificate (base64) for cert pinning */
42
42
  serverCertHash?: string;
43
+ /** Forwarding mode: 'tun' (TUN device, requires root) or 'testing' (no TUN).
44
+ * Default: 'testing'. */
45
+ forwardingMode?: 'tun' | 'testing';
43
46
  /** WireGuard: client private key (base64, X25519) */
44
47
  wgPrivateKey?: string;
45
48
  /** WireGuard: client TUN address (e.g. 10.8.0.2) */
@@ -86,6 +89,9 @@ export interface IVpnServerConfig {
86
89
  keepaliveIntervalSecs?: number;
87
90
  /** Enable NAT/masquerade for client traffic */
88
91
  enableNat?: boolean;
92
+ /** Forwarding mode: 'tun' (kernel TUN, requires root), 'socket' (userspace NAT),
93
+ * or 'testing' (monitoring only). Default: 'testing'. */
94
+ forwardingMode?: 'tun' | 'socket' | 'testing';
89
95
  /** Default rate limit for new clients (bytes/sec). Omit for unlimited. */
90
96
  defaultRateLimitBytesPerSec?: number;
91
97
  /** Default burst size for new clients (bytes). Omit for unlimited. */