fix the issue of duplicate xtcp proxies will cause the previous proxy to become ineffective (#3489)

This commit is contained in:
fatedier
2023-06-16 00:41:06 +08:00
committed by GitHub
parent e1cef053be
commit 15a245766e
5 changed files with 24 additions and 7 deletions

View File

@@ -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()
if err != nil {
return

View File

@@ -324,6 +324,13 @@ func (pm *Manager) Add(name string, pxy Proxy) error {
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) {
pm.mu.Lock()
defer pm.mu.Unlock()

View File

@@ -58,7 +58,10 @@ func (pxy *XTCPProxy) Run() (remoteAddr string, err error) {
if len(allowUsers) == 0 {
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() {
for {
select {