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) addr := genAddr(bindAddress, port, allowLan)
if socksListener != nil { if socksListener != nil {
if socksListener.Address() == addr { if socksListener.Address() != addr {
return nil socksListener.Close()
socksListener = nil
}
}
if socksUDPListener != nil {
if socksUDPListener.Address() != addr {
socksUDPListener.Close()
socksUDPListener = nil
} }
socksListener.Close()
socksListener = nil
} }
if portIsZero(addr) { if portIsZero(addr) {
return nil return nil
} }
var err error tcpListener, err := socks.NewSocksProxy(addr)
socksListener, err = socks.NewSocksProxy(addr)
if err != nil { if err != nil {
return err return err
} }
return reCreateSocksUDP(addr) udpListener, err := socks.NewSocksUDPProxy(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)
if err != nil { if err != nil {
tcpListener.Close()
return err return err
} }
socksListener = tcpListener
socksUDPListener = udpListener
return nil return nil
} }