server/proxy: simplify the code (#3488)

This commit is contained in:
fatedier
2023-06-16 00:14:19 +08:00
committed by GitHub
parent 9ba6a06470
commit e1cef053be
10 changed files with 235 additions and 173 deletions

View File

@@ -17,21 +17,35 @@ package proxy
import (
"fmt"
"net"
"reflect"
"strings"
"golang.org/x/time/rate"
"github.com/fatedier/frp/pkg/config"
"github.com/fatedier/frp/pkg/consts"
"github.com/fatedier/frp/pkg/util/util"
"github.com/fatedier/frp/pkg/util/vhost"
)
func init() {
RegisterProxyFactory(reflect.TypeOf(&config.TCPMuxProxyConf{}), NewTCPMuxProxy)
}
type TCPMuxProxy struct {
*BaseProxy
cfg *config.TCPMuxProxyConf
}
func NewTCPMuxProxy(baseProxy *BaseProxy, cfg config.ProxyConf) Proxy {
unwrapped, ok := cfg.(*config.TCPMuxProxyConf)
if !ok {
return nil
}
return &TCPMuxProxy{
BaseProxy: baseProxy,
cfg: unwrapped,
}
}
func (pxy *TCPMuxProxy) httpConnectListen(
domain, routeByHTTPUser, httpUser, httpPwd string, addrs []string) ([]string, error,
) {
@@ -78,7 +92,7 @@ func (pxy *TCPMuxProxy) httpConnectRun() (remoteAddr string, err error) {
}
}
pxy.startListenHandler(pxy, HandleUserTCPConnection)
pxy.startCommonTCPListenersHandler()
remoteAddr = strings.Join(addrs, ",")
return remoteAddr, err
}
@@ -101,10 +115,6 @@ func (pxy *TCPMuxProxy) GetConf() config.ProxyConf {
return pxy.cfg
}
func (pxy *TCPMuxProxy) GetLimiter() *rate.Limiter {
return pxy.limiter
}
func (pxy *TCPMuxProxy) Close() {
pxy.BaseProxy.Close()
}