[PR #3382] [MERGED] feat(nathole): use serverUDPPort in nathole discovery when available #4738

Closed
opened 2026-05-05 14:47:47 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fatedier/frp/pull/3382
Author: @fatedier
Created: 3/30/2023
Status: Merged
Merged: 3/30/2023
Merged by: @fatedier

Base: devHead: nathole


📝 Commits (1)

  • 80e4db8 feat(nathole): use serverUDPPort in nathole discovery when available

📊 Changes

3 files changed (+151 additions, -97 deletions)

View changed files

📝 cmd/frpc/sub/nathole.go (+9 -4)
📝 pkg/nathole/discovery.go (+125 -93)
📝 pkg/nathole/utils.go (+17 -0)

📄 Description

Summary

🤖 Generated by Copilot at 80e4db8

This pull request adds a feature to enable NAT hole punching without a server UDP port, using the server TCP port and multiple stun servers instead. It modifies cmd/frpc/sub/nathole.go to handle the new feature, and refactors and enhances pkg/nathole/discovery.go and pkg/nathole/utils.go to use strings, a new discoverConn type, and a new ChangedAddress type for nathole discovery.

WHY

Walkthrough

🤖 Generated by Copilot at 80e4db8

  • Add support for NAT hole punching without a server UDP port
  • Validate the server UDP port only if it is not zero (link)
  • Ensure that at least two addresses are returned from the nathole discovery function (link)
  • Remove the validation of the server UDP port from the nathole client (link)
  • Modify the nathole discovery function to use the server TCP port instead of the UDP port (link)
  • Add new methods to the discoverConn type to send stun requests and discover external addresses from primary and secondary stun servers (link)
  • Add a new type ChangedAddress to get the changed address attribute from a stun response (link)
  • Add new imports to the nathole package for net, strconv, and github.com/pion/stun (link)
  • Remove the unused type Address from the nathole package (link)
  • Remove the code that parses the stun servers and the server address into net.Addr objects (link)
  • Encapsulate the UDP connection and the message channel in the discoverConn type (link)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fatedier/frp/pull/3382 **Author:** [@fatedier](https://github.com/fatedier) **Created:** 3/30/2023 **Status:** ✅ Merged **Merged:** 3/30/2023 **Merged by:** [@fatedier](https://github.com/fatedier) **Base:** `dev` ← **Head:** `nathole` --- ### 📝 Commits (1) - [`80e4db8`](https://github.com/fatedier/frp/commit/80e4db8c7e4ce7819242c156f1f083a6c3f09f22) feat(nathole): use serverUDPPort in nathole discovery when available ### 📊 Changes **3 files changed** (+151 additions, -97 deletions) <details> <summary>View changed files</summary> 📝 `cmd/frpc/sub/nathole.go` (+9 -4) 📝 `pkg/nathole/discovery.go` (+125 -93) 📝 `pkg/nathole/utils.go` (+17 -0) </details> ### 📄 Description ### Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 80e4db8</samp> This pull request adds a feature to enable NAT hole punching without a server UDP port, using the server TCP port and multiple stun servers instead. It modifies `cmd/frpc/sub/nathole.go` to handle the new feature, and refactors and enhances `pkg/nathole/discovery.go` and `pkg/nathole/utils.go` to use strings, a new `discoverConn` type, and a new `ChangedAddress` type for nathole discovery. ### WHY <!-- author to complete --> ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 80e4db8</samp> * Add support for NAT hole punching without a server UDP port * Validate the server UDP port only if it is not zero ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-5ac4ee81516dfc6b3f0a0abd3e447ee4a2d03d59a7a62be497d7dbf208c3da0dL56-R61)) * Ensure that at least two addresses are returned from the nathole discovery function ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-5ac4ee81516dfc6b3f0a0abd3e447ee4a2d03d59a7a62be497d7dbf208c3da0dR69-R72)) * Remove the validation of the server UDP port from the nathole client ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-5ac4ee81516dfc6b3f0a0abd3e447ee4a2d03d59a7a62be497d7dbf208c3da0dL82-L84)) * Modify the nathole discovery function to use the server TCP port instead of the UDP port ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-44722a17206af87db167e83e9a7dd3b726ca21e5a6b47e6e9f5103e498163013L64-R69)) * Add new methods to the `discoverConn` type to send stun requests and discover external addresses from primary and secondary stun servers ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-44722a17206af87db167e83e9a7dd3b726ca21e5a6b47e6e9f5103e498163013R113-R224)) * Add a new type `ChangedAddress` to get the changed address attribute from a stun response ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-181aa632a4a44ec627ca2c893ab904ffbd3b63a6615f888cb6d11c8a6ec4781eR52-R65)) * Add new imports to the nathole package for `net`, `strconv`, and `github.com/pion/stun` ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-181aa632a4a44ec627ca2c893ab904ffbd3b63a6615f888cb6d11c8a6ec4781eL19-R23)) * Remove the unused type `Address` from the nathole package ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-44722a17206af87db167e83e9a7dd3b726ca21e5a6b47e6e9f5103e498163013L29-L33)) * Remove the code that parses the stun servers and the server address into `net.Addr` objects ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-44722a17206af87db167e83e9a7dd3b726ca21e5a6b47e6e9f5103e498163013L40-L53)) * Encapsulate the UDP connection and the message channel in the `discoverConn` type ([link](https://github.com/fatedier/frp/pull/3382/files?diff=unified&w=0#diff-44722a17206af87db167e83e9a7dd3b726ca21e5a6b47e6e9f5103e498163013L64-R69)) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 14:47:47 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#4738
No description provided.