Compare commits
2 Commits
1fc335418b
...
30564efd85
Author | SHA1 | Date |
---|---|---|
wpetit | 30564efd85 | |
wpetit | 7aa977d2fe |
|
@ -117,7 +117,9 @@ func (c *Client) handleProxyRequest(ctx context.Context, m *control.Message) (*c
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pipe(stream, net)
|
if err := pipe(stream, net); err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
19
helper.go
19
helper.go
|
@ -5,22 +5,29 @@ import (
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pipe(client net.Conn, server net.Conn) {
|
func pipe(client net.Conn, server net.Conn) (err error) {
|
||||||
stop := make(chan bool)
|
stop := make(chan bool)
|
||||||
|
|
||||||
go relay(client, server, stop)
|
go func() {
|
||||||
go relay(server, client, stop)
|
err = relay(client, server, stop)
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
err = relay(server, client, stop)
|
||||||
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func relay(src net.Conn, dst net.Conn, stop chan bool) {
|
func relay(src io.ReadCloser, dst io.WriteCloser, stop chan bool) (err error) {
|
||||||
io.Copy(dst, src)
|
_, err = io.Copy(dst, src)
|
||||||
|
|
||||||
dst.Close()
|
dst.Close()
|
||||||
src.Close()
|
src.Close()
|
||||||
|
|
||||||
stop <- true
|
stop <- true
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,12 @@ func (c *RemoteClient) Proxy(ctx context.Context, network, address string) (net.
|
||||||
return c.control.Proxy(ctx, network, address)
|
return c.control.Proxy(ctx, network, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *RemoteClient) Close() {
|
||||||
|
if c.sess != nil && !c.sess.IsClosed() {
|
||||||
|
c.sess.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewRemoteClient() *RemoteClient {
|
func NewRemoteClient() *RemoteClient {
|
||||||
return &RemoteClient{}
|
return &RemoteClient{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ func (s *Server) handleNewConn(ctx context.Context, conn *kcp.UDPSession) {
|
||||||
ctx = logger.With(ctx, logger.F("remoteAddr", conn.RemoteAddr().String()))
|
ctx = logger.With(ctx, logger.F("remoteAddr", conn.RemoteAddr().String()))
|
||||||
|
|
||||||
remoteClient := NewRemoteClient()
|
remoteClient := NewRemoteClient()
|
||||||
|
defer remoteClient.Close()
|
||||||
|
|
||||||
remoteClient.ConfigureHooks(s.conf.Hooks)
|
remoteClient.ConfigureHooks(s.conf.Hooks)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue