Introducing MPUDP: A Multi-Path UDP Relay Service

Author Avatar
Axell Dec 28, 2024
  • Read this article on other devices

GitHub: Axellwppr/mpudp_tunnel

Introduction

SSH connections to overseas servers are always a frustrating issue, especially in some restricted network environments. Currently, there are many implementations of Multi-Path TCP protocols, but very few corresponding UDP protocol implementations—the existing ones often come at the cost of sending multiple packets, which greatly wastes network bandwidth.

In today’s networked world, ensuring reliable and efficient data transmission is more critical than ever. Whether you’re dealing with NAT traversal issues or simply striving for optimal performance across multiple UDP channels, MPUDP Relay offers a robust solution tailored to your needs.

The Challenge

Imagine a scenario where you need to connect to a terminal device that offers multiple UDP endpoints. This is common in situations where frp mapping is used for devices behind NAT. To avoid single points of failure, multiple frp servers might be deployed—each server having a distinct address but pointing to the same terminal port. However, these diverse network paths come with varying performance characteristics, such as differences in latency (RTT), packet loss, and throughput. Managing these variables manually can be a daunting task.

Our Solution

MPUDP Relay is designed to simplify and optimize this process. It operates on a client-server architecture, bridging the gap between your local applications and remote servers while actively monitoring multiple network links. Here’s how it works:

  • Client-Server Architecture: The service consists of a client component and a server component. Your local applications connect to the MPUDP client, which then relays data to the MPUDP server. The server, in turn, communicates with the upstream server, ensuring that data travels the best possible route.
  • Multi-Link Configuration: The client supports configuring multiple links. This is particularly useful when different servers (e.g., multiple frp servers) are available, each with its unique address.
  • Heartbeat Monitoring: To maintain a real-time view of link performance, the client regularly sends heartbeat packets. These packets are used to measure key performance metrics, including RTT, packet loss, and throughput.
  • Automatic Link Switching: The client doesn’t just passively monitor; it actively manages the network routes. Based on performance metrics, it automatically switches to the best available link. For example, if one link experiences increased packet loss or latency, the client can seamlessly transition to a more stable connection.
  • DNS Refreshing: For scenarios where IP addresses might change (or for dynamic environments), the service periodically refreshes DNS, ensuring that the client always has up-to-date connection information.
  • Debug Mode: For developers and network administrators, a debug mode is available to help diagnose issues and fine-tune performance.

Configuration Made Simple

MPUDP Relay uses a JSON configuration file (config.json) to manage its settings. Here’s an example configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
"mode": "client",
"server": {
"listen_addr": ":5000",
"upstream_addr": "127.0.0.1:6000",
"heartbeat_timeout_sec": 10
},
"client": {
"listen_addr": "0.0.0.0:8999",
"links": [
{
"remote_addr": "1.2.3.4:5000"
},
{
"remote_addr": "[240c::1]:5000"
}
],
"heartbeat_interval_sec": 1,
"loss_weight": 5.0,
"rtt_weight": 1.0,
"switch_threshold": 25.0,
"throughput_threshold_kbps": 500,
"max_consecutive_fail": 5,
"dns_refresh_interval_sec": 600,
"debug": false
}
}

Key Configuration Parameters

  • Mode: Set the service to either "client" or "server" depending on your role.
  • Server Settings:
    • listen_addr: The address and port for incoming client connections.
    • upstream_addr: The upstream server’s address.
    • heartbeat_timeout_sec: The time after which an inactive client is considered disconnected.
  • Client Settings:
    • listen_addr: The address for local application traffic.
    • links: An array of remote server addresses for your UDP links.
    • heartbeat_interval_sec: The frequency of heartbeat packets to monitor link quality.
    • loss_weight & rtt_weight: These weights help determine the scoring of each link based on performance.
    • switch_threshold: The minimum score improvement needed to justify a switch.
    • throughput_threshold_kbps: A throughput safeguard to prevent unnecessary switching.
    • max_consecutive_fail: The maximum number of failed heartbeats before a link is deemed unavailable.
    • dns_refresh_interval_sec: How often to refresh DNS entries.
    • debug: Toggle for enabling debug logs.

Getting Started

To deploy MPUDP Relay, follow these simple steps:

  1. Build and Run the Service:
    Navigate to the project directory, build the executable, and start the service:

    1
    2
    3
    cd mpudp
    go build -o mpudp
    ./mpudp -config=config.json
  2. Configure the Environment:
    Ensure your JSON configuration file is properly set up, reflecting your network’s needs and your performance goals.

  3. Monitor and Enjoy Seamless Connectivity:
    Once running, the client monitors your multiple links in real-time and dynamically chooses the best route for your UDP traffic.

Last Things

MPUDP Relay is not just a tool but a learning experience in tackling real-world network challenges with a focus on UDP traffic.

For performance reasons, it only signs critical control packets, so it’s best paired with protocols like WireGuard to ensure that application data packets are also properly encrypted.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Link to this article: https://blog.axell.top/archives/introducing-mpudp-a-multi-path-udp-relay-service/