Skip to content

Connection Mechanism

This chapter covers the connection mechanism in MSST-Net.

Virtual Network Addresses

MSST-Net assigns each connected device a set of fixed virtual IP addresses for inter-device communication.

Virtual address ranges:

  • IPv4: 172.22.0.0/16
  • IPv6: fd22:2222:2222:2222::/64

Each device's virtual IP is deterministically derived from its device ID, so it remains consistent across sessions.


Data Encryption

MSST-Net uses the WireGuard protocol to encrypt all data transmitted between devices.

Each device generates a unique Curve25519 key pair on first startup. The public key is submitted to the coordinator during device registration, enabling encrypted communication with peers.


Connection Paths

MSST-Net automatically selects the optimal connection path, routing traffic between devices through the lowest-latency channel.

There are three connection path modes:

ModeDescription
RelayData is forwarded through a relay server
ProbingProbing for a direct path; data still goes through relay
DirectPeer-to-peer direct connection established; no relay

Relay Mode

Relay mode is the initial state for all connections.

In this mode, packets are forwarded through MSST-Net relay servers, unaffected by NAT or firewall restrictions.

Relay mode is the most stable connection method, but has higher latency than direct connections.


Probing Mode

When the system obtains endpoint information for a remote peer, it enters probing mode and attempts to establish a peer-to-peer direct connection.

During probing, data still goes through the relay and normal communication is unaffected.

The probing process sends probe packets to each candidate address of the peer (including IPv6 and IPv4, with IPv6 tested first) and tracks responses.

Upgrade to Direct Connection

Both of the following conditions must be met to upgrade from probing to direct mode:

  1. Consecutive successful responses: 10 or more consecutive probe responses received from a candidate address
  2. Latency advantage: The P2P path round-trip time (RTT) is no more than 80% of the relay path RTT

For devices on the same local network, condition 2 is automatically satisfied (LAN endpoints are unconditionally preferred).


Direct Mode

In direct mode, packets travel directly between two devices without going through a relay server, resulting in lower latency and better performance.

After a direct connection is established, the system continuously monitors connection quality and automatically falls back to relay mode if:

Downgrade ReasonBehavior
3 consecutive missed keepalive responsesImmediate downgrade
RTT spikes to more than 3× the baselineImmediate downgrade
Packet loss exceeds 20% after the hold periodDowngrade

After downgrading, the system continues probing and upgrades back to direct once conditions are met.


Hold Period

After each path switch (upgrade or downgrade), the system enters a 20-second hold period.

During the hold period, no new path upgrades are initiated (though downgrades due to path failure are still allowed).

The hold period prevents frequent path switching during network instability.


Connection Negotiation

When two devices need to establish a connection, the coordinator notifies each side of the other's endpoint information and encryption public key via WebSocket, triggering P2P probing.

Device endpoint information is automatically detected and reported by the client when joining a room or network, including:

  • Local LAN address
  • NAT-mapped public address (detected via STUN)

IPv6 Support

MSST-Net prefers IPv6 for direct connection probing.

If the local network does not support IPv6 routing, the system automatically falls back to IPv4.

In dual-stack (IPv4+IPv6) environments, IPv6 candidate addresses are tested first.

Designed by MSST-Net Dev Team, built with Claude Code