mirror of
https://github.com/fatedier/frp.git
synced 2025-01-22 17:42:09 +00:00
fix the issue of duplicate xtcp proxies will cause the previous proxy to become ineffective (#3489)
This commit is contained in:
parent
e1cef053be
commit
15a245766e
@ -121,7 +121,7 @@ func (c *Controller) CleanWorker(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) ListenClient(name string, sk string, allowUsers []string) chan string {
|
func (c *Controller) ListenClient(name string, sk string, allowUsers []string) (chan string, error) {
|
||||||
cfg := &ClientCfg{
|
cfg := &ClientCfg{
|
||||||
name: name,
|
name: name,
|
||||||
sk: sk,
|
sk: sk,
|
||||||
@ -130,9 +130,11 @@ func (c *Controller) ListenClient(name string, sk string, allowUsers []string) c
|
|||||||
}
|
}
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
// TODO(fatedier): return error if name already exists
|
if _, ok := c.clientCfgs[name]; ok {
|
||||||
|
return nil, fmt.Errorf("proxy [%s] is repeated", name)
|
||||||
|
}
|
||||||
c.clientCfgs[name] = cfg
|
c.clientCfgs[name] = cfg
|
||||||
return cfg.sidCh
|
return cfg.sidCh, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) CloseClient(name string) {
|
func (c *Controller) CloseClient(name string) {
|
||||||
|
@ -577,6 +577,11 @@ func (ctl *Control) RegisterProxy(pxyMsg *msg.NewProxy) (remoteAddr string, err
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctl.pxyManager.Exist(pxyMsg.ProxyName) {
|
||||||
|
err = fmt.Errorf("proxy [%s] already exists", pxyMsg.ProxyName)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
remoteAddr, err = pxy.Run()
|
remoteAddr, err = pxy.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -324,6 +324,13 @@ func (pm *Manager) Add(name string, pxy Proxy) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pm *Manager) Exist(name string) bool {
|
||||||
|
pm.mu.RLock()
|
||||||
|
defer pm.mu.RUnlock()
|
||||||
|
_, ok := pm.pxys[name]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func (pm *Manager) Del(name string) {
|
func (pm *Manager) Del(name string) {
|
||||||
pm.mu.Lock()
|
pm.mu.Lock()
|
||||||
defer pm.mu.Unlock()
|
defer pm.mu.Unlock()
|
||||||
|
@ -58,7 +58,10 @@ func (pxy *XTCPProxy) Run() (remoteAddr string, err error) {
|
|||||||
if len(allowUsers) == 0 {
|
if len(allowUsers) == 0 {
|
||||||
allowUsers = []string{pxy.GetUserInfo().User}
|
allowUsers = []string{pxy.GetUserInfo().User}
|
||||||
}
|
}
|
||||||
sidCh := pxy.rc.NatHoleController.ListenClient(pxy.GetName(), pxy.cfg.Sk, allowUsers)
|
sidCh, err := pxy.rc.NatHoleController.ListenClient(pxy.GetName(), pxy.cfg.Sk, allowUsers)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -37,7 +37,7 @@ var _ = ginkgo.Describe("[Feature: Server Manager]", func() {
|
|||||||
[tcp-port-not-allowed]
|
[tcp-port-not-allowed]
|
||||||
type = tcp
|
type = tcp
|
||||||
local_port = {{ .%s }}
|
local_port = {{ .%s }}
|
||||||
remote_port = 20001
|
remote_port = 25001
|
||||||
`, framework.TCPEchoServerPort)
|
`, framework.TCPEchoServerPort)
|
||||||
clientConf += fmt.Sprintf(`
|
clientConf += fmt.Sprintf(`
|
||||||
[tcp-port-unavailable]
|
[tcp-port-unavailable]
|
||||||
@ -55,7 +55,7 @@ var _ = ginkgo.Describe("[Feature: Server Manager]", func() {
|
|||||||
[udp-port-not-allowed]
|
[udp-port-not-allowed]
|
||||||
type = udp
|
type = udp
|
||||||
local_port = {{ .%s }}
|
local_port = {{ .%s }}
|
||||||
remote_port = 20003
|
remote_port = 25003
|
||||||
`, framework.UDPEchoServerPort)
|
`, framework.UDPEchoServerPort)
|
||||||
|
|
||||||
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
||||||
@ -65,7 +65,7 @@ var _ = ginkgo.Describe("[Feature: Server Manager]", func() {
|
|||||||
framework.NewRequestExpect(f).PortName(tcpPortName).Ensure()
|
framework.NewRequestExpect(f).PortName(tcpPortName).Ensure()
|
||||||
|
|
||||||
// Not Allowed
|
// Not Allowed
|
||||||
framework.NewRequestExpect(f).Port(25003).ExpectError(true).Ensure()
|
framework.NewRequestExpect(f).Port(25001).ExpectError(true).Ensure()
|
||||||
|
|
||||||
// Unavailable, already bind by frps
|
// Unavailable, already bind by frps
|
||||||
framework.NewRequestExpect(f).PortName(consts.PortServerName).ExpectError(true).Ensure()
|
framework.NewRequestExpect(f).PortName(consts.PortServerName).ExpectError(true).Ensure()
|
||||||
|
Loading…
Reference in New Issue
Block a user