mirror of
https://github.com/ICKelin/opennotr.git
synced 2025-10-05 15:56:50 +08:00
refactor: simplify client goroutine
This commit is contained in:
@@ -133,11 +133,9 @@ func (c *Client) tcpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
|
|||||||
io.Copy(remoteConn, stream)
|
io.Copy(remoteConn, stream)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
defer remoteConn.Close()
|
||||||
defer remoteConn.Close()
|
defer stream.Close()
|
||||||
defer stream.Close()
|
io.Copy(stream, remoteConn)
|
||||||
io.Copy(stream, remoteConn)
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) udpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
|
func (c *Client) udpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
|
||||||
@@ -177,25 +175,23 @@ func (c *Client) udpProxy(stream *yamux.Stream, p *proto.ProxyProtocol) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
defer remoteConn.Close()
|
||||||
defer remoteConn.Close()
|
defer stream.Close()
|
||||||
defer stream.Close()
|
buf := make([]byte, 64*1024)
|
||||||
buf := make([]byte, 64*1024)
|
for {
|
||||||
for {
|
nr, err := remoteConn.Read(buf)
|
||||||
nr, err := remoteConn.Read(buf)
|
if err != nil {
|
||||||
if err != nil {
|
log.Println(err)
|
||||||
log.Println(err)
|
break
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes := encode(buf[:nr])
|
|
||||||
_, err = stream.Write(bytes)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
bytes := encode(buf[:nr])
|
||||||
|
_, err = stream.Write(bytes)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func encode(raw []byte) []byte {
|
func encode(raw []byte) []byte {
|
||||||
|
Reference in New Issue
Block a user