client/proxy: simplify the code (#3465)

This commit is contained in:
fatedier
2023-05-30 22:18:56 +08:00
committed by GitHub
parent 9aef3b9944
commit cceab7e1b1
5 changed files with 147 additions and 224 deletions

View File

@@ -17,6 +17,7 @@ package proxy
import (
"io"
"net"
"reflect"
"strconv"
"sync"
"time"
@@ -31,6 +32,10 @@ import (
utilnet "github.com/fatedier/frp/pkg/util/net"
)
func init() {
RegisterProxyFactory(reflect.TypeOf(&config.SUDPProxyConf{}), NewSUDPProxy)
}
type SUDPProxy struct {
*BaseProxy
@@ -41,6 +46,18 @@ type SUDPProxy struct {
closeCh chan struct{}
}
func NewSUDPProxy(baseProxy *BaseProxy, cfg config.ProxyConf) Proxy {
unwrapped, ok := cfg.(*config.SUDPProxyConf)
if !ok {
return nil
}
return &SUDPProxy{
BaseProxy: baseProxy,
cfg: unwrapped,
closeCh: make(chan struct{}),
}
}
func (pxy *SUDPProxy) Run() (err error) {
pxy.localAddr, err = net.ResolveUDPAddr("udp", net.JoinHostPort(pxy.cfg.LocalIP, strconv.Itoa(pxy.cfg.LocalPort)))
if err != nil {