uottun: serve in goroutine

This commit is contained in:
nadoo 2018-01-20 15:23:56 +08:00
parent 38de018d91
commit 47820cccba
2 changed files with 11 additions and 9 deletions

2
ss.go
View File

@ -178,7 +178,7 @@ func (s *SS) ListenAndServeUDP() {
nm.Store(raddr.String(), pc)
go func() {
timedCopy(c, raddr, pc, 1*time.Minute)
timedCopy(c, raddr, pc, 2*time.Minute)
pc.Close()
nm.Delete(raddr.String())
}()

View File

@ -53,21 +53,23 @@ func (s *UoTTun) ListenAndServe() {
rc.Write(buf[:n])
// no remote forwarder, just a local udp forwarder
if urc, ok := rc.(*net.UDPConn); ok {
go func() {
timedCopy(c, clientAddr, urc, 5*time.Minute)
go func() {
// no remote forwarder, just a local udp forwarder
if urc, ok := rc.(*net.UDPConn); ok {
timedCopy(c, clientAddr, urc, 2*time.Minute)
urc.Close()
}()
} else { // remote forwarder, udp over tcp
return
}
// remote forwarder, udp over tcp
resp, err := ioutil.ReadAll(rc)
if err != nil {
logf("error in ioutil.ReadAll: %s\n", err)
continue
return
}
rc.Close()
c.WriteTo(resp, clientAddr)
}
}()
logf("proxy-uottun %s <-> %s", clientAddr, s.raddr)
}