chore: rebuild InboundListener

This commit is contained in:
wwqgtxx
2022-12-04 21:53:13 +08:00
parent 8144373725
commit 62226e8b3d
14 changed files with 138 additions and 96 deletions

View File

@ -43,6 +43,7 @@ var (
mixedUDPLister *socks.UDPListener
tunnelTCPListeners = map[string]*tunnel.Listener{}
tunnelUDPListeners = map[string]*tunnel.PacketConn{}
inboundListeners = map[string]C.InboundListener{}
tunLister *sing_tun.Listener
shadowSocksListener C.AdvanceListener
vmessListener *sing_vmess.Listener
@ -58,6 +59,7 @@ var (
tproxyMux sync.Mutex
mixedMux sync.Mutex
tunnelMux sync.Mutex
inboundMux sync.Mutex
tunMux sync.Mutex
ssMux sync.Mutex
vmessMux sync.Mutex
@ -682,6 +684,35 @@ func PatchTunnel(tunnels []tunnel.Tunnel, tcpIn chan<- C.ConnContext, udpIn chan
}
}
func PatchInboundListeners(newListenerMap map[string]C.InboundListener, tcpIn chan<- C.ConnContext, udpIn chan<- C.PacketAdapter, dropOld bool) {
inboundMux.Lock()
defer inboundMux.Unlock()
for name, newListener := range newListenerMap {
if oldListener, ok := inboundListeners[name]; ok {
if !oldListener.Config().Equal(newListener.Config()) {
_ = oldListener.Close()
} else {
continue
}
}
if err := newListener.Listen(tcpIn, udpIn); err != nil {
log.Errorln("Listener %s listen err: %s", name, err.Error())
continue
}
inboundListeners[name] = newListener
}
if dropOld {
for name, oldListener := range inboundListeners {
if _, ok := newListenerMap[name]; !ok {
_ = oldListener.Close()
delete(inboundListeners, name)
}
}
}
}
// GetPorts return the ports of proxy servers
func GetPorts() *Ports {
ports := &Ports{}