Skip to content

Add SRV DNS resolution for multiplayer server addresses#639

Open
Copilot wants to merge 6 commits intomainfrom
copilot/support-srv-dns-resolution
Open

Add SRV DNS resolution for multiplayer server addresses#639
Copilot wants to merge 6 commits intomainfrom
copilot/support-srv-dns-resolution

Conversation

Copy link

Copilot AI commented Feb 3, 2026

Enables users to connect to multiplayer servers using domain names only (e.g., example.com) instead of requiring explicit host:port format. Client queries _phira._tcp.<domain> SRV records to resolve target host and port.

Implementation

  • SRV resolver module (srv_resolver.rs)

    • Queries DNS SRV records with _phira._tcp. prefix
    • Singleton Lazy<TokioAsyncResolver> for efficiency
    • Port detection logic distinguishes IPv4/IPv6 with ports from bare addresses
    • Returns addresses with explicit ports unchanged (backwards compatible)
  • Port detection logic

    • example.com:12345 → pass-through
    • [::1]:8080 → pass-through (IPv6 with port)
    • example.com → SRV lookup
    • ::1 → SRV lookup (bare IPv6 detected by multiple colons before last colon)
  • Connection updates

    • phira/src/mp/panel.rs: Added resolve_server_address() before TcpStream::connect()
    • phira-monitor/src/scene.rs: Same pattern for monitor application

Dependencies

  • trust-dns-resolver 0.23.2 - SRV record queries
  • once_cell 1.21.3 - Singleton resolver instance

Example Usage

Server administrator configures DNS:

_phira._tcp.example.com. 86400 IN SRV 0 5 12345 game-server.example.com.

User connects with just example.com → client resolves to game-server.example.com:12345

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 8.8.4.4
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 8.8.8.8
    • Triggering command: REDACTED, pid is -1 (packet block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https --emit=dep-info,metadata -C opt-level=2 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on --check-cfg cfg(docsrs,test) stup�� in.so /lto-wrapper bin/rustc 6detect_compiler/home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/bin/rustc stup/toolchains/--crate-name stup/toolchains/rustc_hash bin/rustc (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>标题:支持 SRV DNS 解析以允许在联机服务器地址中省略端口号</issue_title>
<issue_description>描述:
当前在设置联机服务器地址时必须明确指定主机和端口(例如 example.com:12345)。建议在解析地址时加入 SRV(DNS Service)解析支持,允许用户只填写域名(例如 example.com),客户端通过 SRV 记录获取实际的目标主机和端口,从而简化配置并兼容使用 SRV 的托管/代理方案。

动机:

  • 提升用户体验:用户只需填写域名,无需记住或填写端口号。
  • 便于服务迁移与负载均衡:服务端可通过 SRV 指向不同主机和端口,而无需强制用户更改客户端设置。
  • 降低配置错误:对使用自定义端口或反向代理的部署更友好。

建议实现(行为规范):

  1. 当用户输入的服务器地址未包含端口(无 ":" 及端口号)时,尝试进行 SRV 查询。
  2. 默认 SRV 前缀建议为 _phira._tcp.,并将该前缀作为可配置项以支持其它部署约定。
  3. 若 SRV 查询成功且返回记录,按 SRV 的 target:port 使用解析到的主机和端口进行连接;应遵循 SRV 的优先级与权重规则(至少实现优先级排序,针对相同优先级可按权重或随机选择)。
  4. 若 SRV 查询失败(无记录或查询超时/错误),回退到现有行为(使用默认端口或用户显式指定的端口)。显式指定端口应始终优先于 SRV 解析结果。
  5. 为避免阻塞与感知延迟,应设定合理的 SRV 查询超时时间与缓存策略(例如短期缓存、异步解析或在 UI 上提示“正在解析地址”)。

示例:

  • 用户输入:example.com
    • 客户端查询 _phira._tcp.example.com 的 SRV 记录,若返回 target=myserver.example.net port=26666,则连接 myserver.example.net:26666。
  • 用户输入:example.com:25566
    • 直接使用指定的端口,不进行 SRV 查询(显式端口优先)。

验收条件:

  • 在无端口的地址输入场景下,可成功解析并连接到通过 SRV 指定的主机与端口(含优先级/权重处理或明确说明实现策略)。
  • 当 SRV 不存在或解析失败时,行为回退并与当前版本一致(不影响已有配置)。
  • 明确显式端口优先于 SRV。
  • 提供单元/集成测试覆盖:成功 SRV 解析、无 SRV 回退、SRV 多记录的优先级/权重处理、超时与错误处理。
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 3, 2026 02:41
Co-authored-by: ChickenPige0n <95085281+ChickenPige0n@users.noreply.github.com>
…nce tests

Co-authored-by: ChickenPige0n <95085281+ChickenPige0n@users.noreply.github.com>
…improve documentation

Co-authored-by: ChickenPige0n <95085281+ChickenPige0n@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for SRV DNS resolution in server address configuration Add SRV DNS resolution for multiplayer server addresses Feb 3, 2026
Copilot AI requested a review from ChickenPige0n February 3, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

标题:支持 SRV DNS 解析以允许在联机服务器地址中省略端口号

2 participants