NodePass TCP/UDP Network Tunneling
repository·main·Indexed 42 days ago
https://github.com/nodepassproject/nodepassAn open-source, lightweight, enterprise-grade TCP/UDP network tunneling solution featuring an all-in-one architecture with separated control and data channels. It supports NAT traversal, protocol conversion, and connection pooling via TCP, QUIC, WebSocket, and HTTP/2. NodePass operates in three modes: server, client, and master (REST/OpenAPI control interface), and offers three TLS security modes including plaintext, self-signed, and strict validation.
What's inside NodePass
- NodePass provides a RESTful API when running in Master Mode. This API is designed to support frontend integration and automation tasks. The API surface includes various endpoints for interacting with the NodePass instance, real-time event streaming via Server-Sent Events (SSE), and structured data exchange using the Instance Data Structure.
Overview of NodePass System Architecture
mainNodePass is built on a layered, decoupled architecture designed for cloud-native environments.
Core Architectural Layers
- Transport Layer: Separates control and data channels. This prevents control signaling from interfering with data throughput and allows independent optimization of TCP and UDP.
- Security Layer: A pluggable TLS implementation that supports modular security levels, automated certificate management, and key rotation.
- Management Layer: An API-first, stateless design that is container-friendly and supports horizontal scaling.
Key Performance Innovations
- Connection Pool Warm-up: Instead of "connect-on-demand," NodePass uses a "pre-warm-and-ready" approach to eliminate cold start latency.
- Fault Isolation: Provides connection-level isolation so that a single point of failure does not impact the entire service. It also features automatic reconnection and graceful degradation strategies.
Operational behaviors and limitations of NodePass MCP
mainWhen automating NodePass via MCP, be aware of the following behaviors:
- Asynchronous Execution: Tools like
create_instance,control_instance,delete_instance, andimport_instancesreturn a response once the request is accepted. You must pollget_instanceorlist_instancesto confirm completion. - Configuration Updates: When using setter tools, if an instance is currently running, NodePass will stop it, update the configuration, regenerate the config URL, and restart it.
- Tag Replacement: The
tagsargument inupdate_instancereplaces the entire existing tag map. It does not perform a merge. - Protected Data: The internal ID
********is used to store the API key and master ID. This ID is hidden fromlist_instancesand cannot be modified by instance mutation tools. - Structured Data: MCP returns structured data fields in addition to text. Automation clients should prioritize consuming these structured fields for better reliability.
- Asynchronous Execution: Tools like
Configure WebSocket Pool Settings and Security
mainWhen using the WebSocket-based pool (
type=2), NodePass establishes connections via standard HTTP upgrade requests, making it highly compatible with proxies and load balancers.Security Configuration: TLS is required for all WebSocket pools (WSS). You can select from two TLS modes:
- Mode 1: WSS with self-signed certificates.
- Mode 2: WSS with full certificate verification (required for production).
Key Characteristics:
- Traversal: Uses standard ports 80 (ws) or 443 (wss) and can be deployed through CDNs.
- Lifecycle: The server assigns a unique connection ID during the handshake, which is sent to the client via the control channel to allow the client to retrieve the connection as a
net.Conn. - Validation: Supports Origin validation to prevent cross-site WebSocket hijacking and allows custom authentication headers.
Core Concepts of NodePass Architecture
mainNodePass uses an integrated S/C/M (Server/Client/Master) architecture designed with the full decoupling of control and data channels.
- Server: Handles incoming tunnel connections and manages traffic relay to target destinations.
- Client: Establishes the tunnel connection to a server to bridge local traffic to a remote target.
- Master: Provides multi-instance management and coordination.
- Connection Pooling: Supports TCP, QUIC, WebSocket, and HTTP/2 transport methods to eliminate handshake delays and support 0-RTT.
- Security Modes: Offers three TLS modes: plaintext, self-signed, and strict validation.
Compare TCP and UDP data exchange
mainNodePass supports both TCP and UDP protocols with different handling characteristics:
- TCP: Provides full bidirectional streaming using persistent connections. It uses
conn.DataExchange()for continuous data transfer and supports automatic error handling with reconnection capabilities. - UDP: Uses datagram forwarding. It is optimized for low-latency, stateless communication. It uses one-shot datagram forwarding with configurable buffer sizes (
UDP_DATA_BUF_SIZE) and supports read timeout control for waiting for responses.
- TCP: Provides full bidirectional streaming using persistent connections. It uses
How bidirectional data flow modes work
mainNodePass automatically selects an operating mode based on the tunnel and target addresses provided in the connection URL. Understanding these modes helps in configuring different networking scenarios:
Client Single-End Forwarding Mode:
- Behavior: The client listens on a local tunnel address and uses connection pooling to forward directly to the target address.
- Key Feature: No server is required for the handshake; it operates independently.
- Use Case: Local proxies, simple port forwarding, or high-performance forwarding in testing environments.
- Trigger: Enabled if the client's tunnel address is a local address.
Server Receives Mode:
- Behavior: The server listens on the
target_addrand forwards incoming connections through the tunnel to the client. - Use Case: Exposing internal services to external access.
- Trigger: Enabled if the target address is a local address.
- Behavior: The server listens on the
Server Sends Mode:
- Behavior: The server connects to a remote
target_addrto fetch data and sends it through the tunnel to the client. - Use Case: Accessing remote services through a tunnel proxy.
- Trigger: Enabled if the target address is a remote address.
- Behavior: The server connects to a remote
Configure Instance URLs (Server and Client modes)
mainNodePass uses two primary URL formats for instance configuration. These URLs define how traffic is routed and which protocols are used.
Server Mode
Format:
server://<bind_address>:<bind_port>/<target_host>:<target_port>?<parameters>Used to listen on a specific address/port and forward traffic to a target. Example:server://0.0.0.0:8080/localhost:3000(Listen on 8080, forward to local 3000).Client Mode
Format:
client://<server_host>:<server_port>/<local_host>:<local_port>?<parameters>Used to connect to a remote server and listen on a local port. Example:client://example.com:8080/localhost:3000(Connect to example.com:8080, listen locally on 3000).Understand NodePass Operating Modes
mainNodePass operates using three core modes, specified by the
<core>component in the command URI:server: Acts as the tunnel endpoint. It manages connection pools and can configure TLS and pool types which are then communicated to the client.client: Connects to a server to establish a tunnel for data exchange.master: Used for API-driven control, where the<target_addr>acts as an API prefix.
Use the NodePass MCP JSON-RPC 2.0 interface
mainNodePass accepts MCP requests via HTTP
POSTwith a JSON-RPC 2.0 body.Required Headers:
Content-Type: application/jsonX-API-Key: <api-key>
Response Formats:
- Success: Returns HTTP
200with aresultobject. - JSON-RPC Error: Returns HTTP
200with anerrorobject containingcode,message, anddata. - HTTP Errors: Errors like
401(Unauthorized) or405(Method Not Allowed) are returned before JSON-RPC processing.
{ "jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {} }Implement High Availability with Target Address Groups
mainNodePass supports high availability and load balancing by providing a comma-separated list of target addresses.
- Load Balancing: When using
mode=2on the server side, NodePass uses a round-robin algorithm to distribute traffic across the provided addresses. - Automatic Failover: If one backend fails, NodePass automatically switches to another available server in the group and resumes traffic to recovered servers.
- Best Practices:
- Use 2-5 addresses per group; too many can increase failure detection time.
- Ensure backend services have their own health checks.
- Maintain port consistency across addresses or specify the port for each.
# Server side: Round-robin load balancing across 3 backends nodepass "server://0.0.0.0:10101/web1.internal:8080,web2.internal:8080,web3.internal:8080?mode=2&tls=1" # Client side: High-performance local proxy with primary/replica failover nodepass "client://127.0.0.1:3306/db-primary.local:3306,db-secondary.local:3306?mode=1"- Load Balancing: When using
Configure and use Tunnel Keys for authentication
mainTunnel keys are used to authenticate the connection between a client and a server. You can specify a key using two different methods in your connection URL:
1. Explicit Key (Username Method)
Specify the key as the username part of the URL. This is the most reliable way to set a custom key.
# Use 'mypassword' as the tunnel key nodepass server://mypassword@10.1.0.1:10101/10.1.0.1:8080 nodepass client://mypassword@10.1.0.1:10101/127.0.0.1:80802. Port-Derived Key (Automatic Method)
If no username is provided in the URL, NodePass derives the key from the hexadecimal value of the port number.
# Port 10101's hexadecimal value '2775' will be used as the tunnel key nodepass server://10.1.0.1:10101/10.1.0.1:8080Handshake Lifecycle
- Connection: Client connects to the server's tunnel address.
- Authentication: Client sends the encrypted tunnel key.
- Verification: Server decrypts and verifies the key.
- Sync: Upon success, the server sends configuration (data flow direction, max connection pool capacity, TLS mode).
- Establishment: Data transmission begins.
# Explicit Key Example nodepass server://mypassword@10.1.0.1:10101/10.1.0.1:8080 # Port-Derived Key Example nodepass server://10.1.0.1:10101/10.1.0.1:8080