[PR #3488] [MERGED] server/proxy: simplify the code #4759

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

📋 Pull Request Information

Original PR: https://github.com/fatedier/frp/pull/3488
Author: @fatedier
Created: 6/15/2023
Status: Merged
Merged: 6/15/2023
Merged by: @fatedier

Base: devHead: code


📝 Commits (1)

  • 12a1233 server/proxy: simplify the code

📊 Changes

10 files changed (+209 additions, -147 deletions)

View changed files

📝 pkg/nathole/controller.go (+1 -0)
📝 server/proxy/http.go (+16 -5)
📝 server/proxy/https.go (+17 -7)
📝 server/proxy/proxy.go (+57 -83)
📝 server/proxy/stcp.go (+17 -6)
📝 server/proxy/sudp.go (+17 -6)
📝 server/proxy/tcp.go (+27 -16)
📝 server/proxy/tcpmux.go (+17 -7)
📝 server/proxy/udp.go (+24 -12)
📝 server/proxy/xtcp.go (+16 -5)

📄 Description

Summary

🤖 Generated by Copilot at 12a1233

This pull request refactors the proxy package to use a proxy factory registry, simplify the creation and handling of different proxy types, and add support for new proxy types such as HTTPProxy, TCPMuxProxy, and XTCPProxy. It also adds a TODO comment to pkg/nathole/controller.go to handle name conflicts in the NAT hole punching service.

WHY

Walkthrough

🤖 Generated by Copilot at 12a1233

  • Implement a proxy factory registry using reflect package to create proxies based on their configuration types (link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link)
  • Use the common function startCommonTCPListenersHandler defined in the BaseProxy type to start goroutine handlers for TCP-based proxies, instead of using the startListenHandler function (link,link,link,link,link,link)
  • Use the proxy configuration stored in the BaseProxy type, instead of calling the GetConf function of the proxy, in the function HandleUserTCPConnection and the proxy handlers (link,link,link)
  • Rename the field realPort to realBindPort in the TCPProxy, UDPProxy, and XTCPProxy types, which reflects the fact that this field stores the port that the proxy binds to on the server side (link,link,link,link,link)
  • Remove the unused or duplicated GetLimiter function from the HTTPProxy, HTTPSProxy, STCPProxy, SUDPProxy, TCPMuxProxy, and XTCPProxy types, and use the GetLimiter function defined in the BaseProxy type instead (link,link,link,link,link,link,link)
  • Add a TODO comment to the function ListenClient in pkg/nathole/controller.go to handle the case where a client tries to register a name that already exists in the NAT hole punching service (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/3488 **Author:** [@fatedier](https://github.com/fatedier) **Created:** 6/15/2023 **Status:** ✅ Merged **Merged:** 6/15/2023 **Merged by:** [@fatedier](https://github.com/fatedier) **Base:** `dev` ← **Head:** `code` --- ### 📝 Commits (1) - [`12a1233`](https://github.com/fatedier/frp/commit/12a1233f68195184638d4a5e2dcef592b9c98f61) server/proxy: simplify the code ### 📊 Changes **10 files changed** (+209 additions, -147 deletions) <details> <summary>View changed files</summary> 📝 `pkg/nathole/controller.go` (+1 -0) 📝 `server/proxy/http.go` (+16 -5) 📝 `server/proxy/https.go` (+17 -7) 📝 `server/proxy/proxy.go` (+57 -83) 📝 `server/proxy/stcp.go` (+17 -6) 📝 `server/proxy/sudp.go` (+17 -6) 📝 `server/proxy/tcp.go` (+27 -16) 📝 `server/proxy/tcpmux.go` (+17 -7) 📝 `server/proxy/udp.go` (+24 -12) 📝 `server/proxy/xtcp.go` (+16 -5) </details> ### 📄 Description ### Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 12a1233</samp> This pull request refactors the `proxy` package to use a proxy factory registry, simplify the creation and handling of different proxy types, and add support for new proxy types such as `HTTPProxy`, `TCPMuxProxy`, and `XTCPProxy`. It also adds a TODO comment to `pkg/nathole/controller.go` to handle name conflicts in the NAT hole punching service. ### WHY <!-- author to complete --> ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 12a1233</samp> * Implement a proxy factory registry using `reflect` package to create proxies based on their configuration types ([link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-caa797e117b55f9ac97a0334c16735f3f3775ca8e0d4800a4ff7b66be7ab1e07L20-R23),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-caa797e117b55f9ac97a0334c16735f3f3775ca8e0d4800a4ff7b66be7ab1e07R33-R36),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-ffeee43b930a44c7d8ea834888693156097988a8da5d4dde5cdbc16c04782d46L18-R20),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-ffeee43b930a44c7d8ea834888693156097988a8da5d4dde5cdbc16c04782d46R26-R29),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6R22),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6R40-R45),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6R73),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6L196-R212),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6R266-R302),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-a8a3608f703647da704896989ae588d6b548f5cb25859adb54a2f1fe8f33b4d1L18-R26),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-a8a3608f703647da704896989ae588d6b548f5cb25859adb54a2f1fe8f33b4d1R32-R42),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-27e265b12a950d00fe661898c5422ce6a3c99d7b928c44443c293737439122bbL18-R26),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-27e265b12a950d00fe661898c5422ce6a3c99d7b928c44443c293737439122bbR32-R42),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-633b82351162c59f88cada389d9cbf9d310d3810f6c092bac10430f0c330b1e5L20-R52),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-726a3183adcaf6e00708e701699b38c362eaa7011b9b9bc222689eea3ba2cca8L20-R22),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-726a3183adcaf6e00708e701699b38c362eaa7011b9b9bc222689eea3ba2cca8R29-R32),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-7daa863210605d2a527d8323dc1270152f3729178fa2ca658a6001a3481c7613R22),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-7daa863210605d2a527d8323dc1270152f3729178fa2ca658a6001a3481c7613L37-R45),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-52f5ffea2008402b178846549fb887fd3961403113f5a846202923dc48936b1cL19-R21),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-52f5ffea2008402b178846549fb887fd3961403113f5a846202923dc48936b1cR27-R30)) * Use the common function `startCommonTCPListenersHandler` defined in the `BaseProxy` type to start goroutine handlers for TCP-based proxies, instead of using the `startListenHandler` function ([link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-caa797e117b55f9ac97a0334c16735f3f3775ca8e0d4800a4ff7b66be7ab1e07R44-R54),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-ffeee43b930a44c7d8ea834888693156097988a8da5d4dde5cdbc16c04782d46L70-R84),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6L158-R171),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6L190-R200),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-a8a3608f703647da704896989ae588d6b548f5cb25859adb54a2f1fe8f33b4d1L43-R58),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-726a3183adcaf6e00708e701699b38c362eaa7011b9b9bc222689eea3ba2cca8L81-R95)) * Use the proxy configuration stored in the `BaseProxy` type, instead of calling the `GetConf` function of the proxy, in the function `HandleUserTCPConnection` and the proxy handlers ([link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6L280-R218),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6L297),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-1934fd5992845347455fe5e26d6ed40e53ba26f246a0fc9c3d4a70efdbbad6e6L320-R257)) * Rename the field `realPort` to `realBindPort` in the `TCPProxy`, `UDPProxy`, and `XTCPProxy` types, which reflects the fact that this field stores the port that the proxy binds to on the server side ([link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-633b82351162c59f88cada389d9cbf9d310d3810f6c092bac10430f0c330b1e5L47-R66),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-633b82351162c59f88cada389d9cbf9d310d3810f6c092bac10430f0c330b1e5L57-R75),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-633b82351162c59f88cada389d9cbf9d310d3810f6c092bac10430f0c330b1e5L79-R97),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-7daa863210605d2a527d8323dc1270152f3729178fa2ca658a6001a3481c7613L70-R92),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-7daa863210605d2a527d8323dc1270152f3729178fa2ca658a6001a3481c7613L257-R269)) * Remove the unused or duplicated `GetLimiter` function from the `HTTPProxy`, `HTTPSProxy`, `STCPProxy`, `SUDPProxy`, `TCPMuxProxy`, and `XTCPProxy` types, and use the `GetLimiter` function defined in the `BaseProxy` type instead ([link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-caa797e117b55f9ac97a0334c16735f3f3775ca8e0d4800a4ff7b66be7ab1e07L140-L143),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-ffeee43b930a44c7d8ea834888693156097988a8da5d4dde5cdbc16c04782d46L79-L82),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-a8a3608f703647da704896989ae588d6b548f5cb25859adb54a2f1fe8f33b4d1L51-L54),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-27e265b12a950d00fe661898c5422ce6a3c99d7b928c44443c293737439122bbL51-L54),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-726a3183adcaf6e00708e701699b38c362eaa7011b9b9bc222689eea3ba2cca8L104-L107),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-7daa863210605d2a527d8323dc1270152f3729178fa2ca658a6001a3481c7613L236-L239),[link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-52f5ffea2008402b178846549fb887fd3961403113f5a846202923dc48936b1cL75-L78)) * Add a TODO comment to the function `ListenClient` in `pkg/nathole/controller.go` to handle the case where a client tries to register a name that already exists in the NAT hole punching service ([link](https://github.com/fatedier/frp/pull/3488/files?diff=unified&w=0#diff-2f15ef36bc925196e99eb8971b235db30a64a9c44c6ac37215abdaaac812777fR133)) --- <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:48:13 -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#4759
No description provided.