Fix: UDP socks recreate behavior (#355)

This commit is contained in:
gVisor bot 2019-10-13 05:19:46 +02:00
parent 421705caa1
commit 845acc2c92

View file

@ -75,41 +75,37 @@ func ReCreateSocks(port int) error {
addr := genAddr(bindAddress, port, allowLan)
if socksListener != nil {
if socksListener.Address() == addr {
return nil
if socksListener.Address() != addr {
socksListener.Close()
socksListener = nil
}
}
if socksUDPListener != nil {
if socksUDPListener.Address() != addr {
socksUDPListener.Close()
socksUDPListener = nil
}
socksListener.Close()
socksListener = nil
}
if portIsZero(addr) {
return nil
}
var err error
socksListener, err = socks.NewSocksProxy(addr)
tcpListener, err := socks.NewSocksProxy(addr)
if err != nil {
return err
}
return reCreateSocksUDP(addr)
}
func reCreateSocksUDP(addr string) error {
if socksUDPListener != nil {
if socksUDPListener.Address() == addr {
return nil
}
socksUDPListener.Close()
socksUDPListener = nil
}
var err error
socksUDPListener, err = socks.NewSocksUDPProxy(addr)
udpListener, err := socks.NewSocksUDPProxy(addr)
if err != nil {
tcpListener.Close()
return err
}
socksListener = tcpListener
socksUDPListener = udpListener
return nil
}